[旧]Up and Running: PostgreSQL and PostGIS on Ubuntu 8.10, Step By Step

每次安装pgsql的过程都是这么震撼人心。以下在Ubuntu 8.10上安装配置运行pgsql及postgis的简单步骤。和Windows相比,用apt-get安装不会再有服务安装不上的问题,但是可能会有包装不全、缺少配置的问题。

首先用apt-get下载安装pgsql和postgis的需要的包

sudo apt-get install postgresql-8.3 postgresql-8.3-postgis postgresql-client-8.3 postgresql-contrib-8.3 pgadmin3

安装过程中会提示创建一个默认名为postgres的用户。

安装结束后,启动pgsql服务器

sudo /etc/init.d/postgresql-8.3 start

在默认情况下pgsql ident的设置为postgres用户用ident sameuser的方式登录,这种方式类似于sqlserver使用windows的用户管理。因此要用postgres用户登录系统。

修改postgres用户的密码

sudo passwd postgres

用新密码登录为postgres

su – postgres

运行psql,可以检查pgsql的运行情况

psql

可以在psql中给postgres用户设置数据库密码

ALTER USER postgres ENCRYPTED PASSWORD ‘yournewpassword’;

继续在psql中创建plsql语言。如果安装时遗漏了contrib包这一步是不能完成的。

CREATE LANGUAGE plsql;

退出psql,创建Postgis数据库。

createdb postgis

导入postgis的两个sql文件,其中定义了EPSG数据库和Geometry类型。

psql -d postgis -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
psql -d postgis -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql

进入psql对当前用户GRAND ALL

GRANT ALL ON TABLE geometry_columns TO postgres;
GRANT ALL ON TABLE spatial_ref_sys TO postgres;

这样做的结果是这两张表被导入到默认的postgres数据库中。这样今后创建postgis数据库就可以以postgres为template_db,不过这么做的后果是这两张表的owner都是postgres。在GeoServer里创建FeatureType时必须用postgres用户登录,否则权限不足。

这时PostGIS应该可以正常工作了,可以尝试导入shp

shp2pgsql /your/shp/file tablename | psql newgisdb

创建一个新的数据库用户

createuser -p username

修改/etc/postgresql/8.3/main/pg_hda.conf,设置数据库访问的认证方式

将local all all一行的验证方式(method)由ident sameuser改为password就可以用密码登录psql了,在python-psycopg中用新建的用户连接pgsql也不会报ident失败了。

将host all 127.0.0.1/32一行的验证方式也改为password就可以在本地用jdbc以用户名密码连接数据库了。

This entry was written by Sunng , posted on Friday July 10 2009at 06:07 pm , filed under 装备 and tagged , , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word