postgres+postgis[转载]

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

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

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

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

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

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

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

de>sudo passwd postgres
de>

用新密码登录为postgres

de>su postgres
de>

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

de>psql
de>

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

de>ALTER USER postgres ENCRYPTED PASSWORD ‘yournewpassword’;
de>

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

de>CREATE LANGUAGE plpgsql;
de>

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

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

进入psql对当前用户GRAND ALL

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

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

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

de>shp2pgsql /your/shp/file tablename   psql newgisdb
de>

创建一个新的数据库用户

de>createuser -p username
de>

修改/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以用户名密码连接数据库了。

转载自:https://blog.csdn.net/zhanghw0917/article/details/5640447

You may also like...