linunx(ubuntu)安装postgresql并添加postgis支持

来源:互联网 发布:淘宝如何设置团购 编辑:程序博客网 时间:2024/06/08 00:59

本文只介绍postgresql的安装及添加postgis支持,安装过程缺少的依赖根据需要安装(根据报错搜索下载安装)《@中国人叔叔-lt》
本文postgresql9.1更高版本可能有更好的方式添加postgis支持

第一步、如果不自己下载安装文件,ubuntu提供命令下载安装

  1. 查看apt-get库中的软件版本支持 :sudo apt-cache search postgresql
  2. 安装:sudo apt-get install postgresql-9.1

第二步、安装postgis

  1. 查看apt-get库中的软件版本支持 :sudo apt-cache search postgis
  2. 安装:sudo apt-get install postgis

第三步、用户、密码及数据库创建与修改

修改PostgreSQL数据库默认用户postgres的密码

PostgreSQL数据库创建一个postgres用户作为数据库的管理员,密码随机,所以需要修改密码,方式如下:

步骤一:登录PostgreSQL:

sudo -u postgres psql

步骤二:修改登录PostgreSQL密码:
alter user postgres with password 'postgres';

修改linux系统postgres用户的密码

PostgreSQL会创建一个默认的linux用户postgres,修改该用户密码的方法如下:
步骤一:删除用户postgres的密码

sudo  passwd -d postgres 
步骤二:设置用户postgres的密码
sudo -u postgres passwd  
系统提示输入新的密码
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

第四步、创建数据库并添加postgis支持

进入postgres用户

sudo su postgres  
创建名为ltpostgis 数据库 自己取名
createdb ltpostgis 
执行postgis脚本,这些脚本默认在/usr/share/postgresql/9.1/contrib/postgis-1.5下 ,执行后ltpostgis 就有postgis支持了
psql -d ltpostgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql  psql -d ltpostgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql