ubuntu源码安装postgresql
首先安装一些依赖
apt-get update
apt-get install gcc
apt-get install zlib1g-dev
apt-get install g++
apt-get install libxml2
apt-get install libxml2-dev
apt-get install libgdal1-dev
1、安装postgresql
wget http://ftp.postgresql.org/pub/source/v9.1.4/postgresql-9.1.4.tar.gz
mkdir /usr/local/pgsql
tar -zxvf postgresql-9.1.4.tar.gz
cd postgresql-9.1.4
./configure -prefix=/usr/local/pgsql --without-readline
make
make install
2、安装geos
mkdir /usr/local/geos
wget http://download.osgeo.org/geos/geos-3.3.5.tar.bz2
tar jxf geos-3.3.5.tar.bz2
cd geos-3.3.5
./configure -prefix=/usr/local/geos
make
make install
3、安装proj4
mkdir /usr/local/proj4
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar zxf proj-4.8.0.tar.gz
cd proj-4.8.0
./configure -prefix=/usr/local/proj4
make
make install
4、安装postgis
mkdir /usr/local/postgis
wget http://postgis.refractions.net/download/postgis-2.0.1.tar.gz
tar zxf postgis-2.0.1.tar.gz
cd postgis-2.0.1
./configure -prefix=/usr/local/postgis --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj4
PostGIS is now configured for x86_64-unknown-linux-gnu -------------- Compiler Info ------------- C compiler: gcc -g -O2 C++ compiler: g++ -g -O2 SQL preprocessor: /usr/bin/cpp -traditional-cpp -P -------------- Dependencies -------------- GEOS config: /usr/local/geos/bin/geos-config GEOS version: 3.3.5 GDAL config: /usr/bin/gdal-config GDAL version: 1.6.3 PostgreSQL config: /usr/local/pgsql/bin/pg_config PostgreSQL version: PostgreSQL 9.1.4 PROJ4 version: 48 Libxml2 config: /usr/bin/xml2-config Libxml2 version: 2.7.6 JSON-C support: yes PostGIS debug level: 0 Perl: /usr/bin/perl --------------- Extensions --------------- PostGIS Raster: enabled PostGIS Topology: enabled -------- Documentation Generation -------- xsltproc: xsl style sheets: dblatex: convert: mathml2.dtd: http://www.w3.org/Math/DTD/mathml2/mathml2.dtd
make
make install
5、简单配置
cd /usr/local/pgsql/
adduser postgres
mkdir /usr/local/pgsql/data
chown -R postgres /usr/local/pgsql
su postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
启动数据库
/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data
Success. You can now start the database server using:
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l log file start
停止数据库服务
/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data
重新启动数据库
/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data –l pgsql.log
7创建数据库
切换到postgres用户
su postgres
创建数据库gisdb
/usr/local/pgsql/bin/createdb gisdb
增加plpgsql语言
/usr/local/pgsql/bin/createlang plpgsql gisdb
增加动态链接库的搜索路径
vi /etc/ld.so.conf
在最后添加四行:
/usr/local/lib
/usr/local/proj4/lib
/usr/local/geos/lib
/usr/local/pgsql/lib
运行ldconfig命令,使以上修改生效:
/sbin/ldconfig
6、创建数据库
postgres@master:~$ /usr/local/pgsql/bin/psql -d gisdb -f /usr/local/pgsql/share/contrib/postgis-2.0/postgis.sql /usr/local/pgsql/bin/psql -d gisdb -f /usr/local/pgsql/share/contrib/postgis-2.0/topology.sql /usr/local/pgsql/bin/psql -d gisdb -f /usr/local/pgsql/share/contrib/postgis-2.0/rtpostgis.sql /usr/local/pgsql/bin/psql -d gisdb -f /usr/local/pgsql/share/contrib/postgis-2.0/postgis.sql /usr/local/pgsql/bin/psql -d gisdb -f /usr/local/pgsql/share/contrib/postgis-2.0/spatial_ref_sys.sql /usr/local/pgsql/bin/psql -d gisdb -f /usr/local/pgsql/share/contrib/postgis-2.0/legacy.sql select postgis_full_version(); gisdb=# select postgis_full_version(); postgis_full_version ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- POSTGIS="2.0.1 r9979" GEOS="3.3.5-CAPI-1.7.5" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.6.3, released 2009/11/19" LIBXML="2.7.6" LIBJSON="UNKNOWN" TOPOLOGY RASTER (1 row)
模板:
/usr/local/pgsql/bin/createdb -T gisdb ysdb