root用户下安装
yum install sqlite-devel autoconf automake libtool boost-devel m4 #安装 cmake wget https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz tar -zxf cmake-3.16.2.tar.gz cd cmake-3.16.2 ./bootstrap --prefix=/usr --datadir=share/cmake --docdir=doc/cmake && make make install cmake --version
#安装 gmp tar xvf gmp-6.2.0.tar cd gmp-6.2.0/ ./configure make make check make install
#安装 mpfr tar -zxvf mpfr-4.1.0.tar.gz cd mpfr-4.1.0/ ./configure make && make install
#安装 CGAL tar -zxvf sc-oasis_lysen-cgal-releases-CGAL-4.13.1.tar.gz cd cgal/ mkdir build && cd build cmake .. make make install
安装geos
tar -jxf geos-3.9.3.tar.bz2
./configure --prefix=/home/postgres/postgis_req/geos-3.9.3
make
make install
安装libxml2
#普通用户没有安装成功,用root用户安装
tar -zxf libxml2-2.9.10.tar.gz
cd libxml2-2.9.10/
#./configure --prefix=/home/postgres/postgis_req/libxml2-2.9.10
./configure --prefix=/usr/local/libxml2-2.9.10
make
make install
安装 JSON-C
tar -zxf json-c-0.13.1.tar.gz
cd json-c-0.13.1/
./configure --prefix=/home/postgres/postgis_req/json-c-0.13.1
make
make install
安装proj
tar -zxvf proj-6.2.1.tar.gz
cd proj-6.2.1/
./configure --prefix=/home/postgres/postgis_req/proj-6.2.1
make -j 4
make install
#安装完后需要将proj的动态链接库添加到环境变量中,后续的gdal安装需要,如果root用户安装则不需要
安装GDAL
tar -zxf gdal-3.5.1.tar.gz
cd gdal-3.5.1/
./configure --prefix=/home/postgres/postgis_req/gdal-3.5.1 --with-pg=/home/postgres/postgresql-14.3/src/bin/pg_config --with-pg=no
make
make install
安装 protobuf,protobuf-c
unzip protobuf-3.13.0.1.zip
cd protobuf-3.13.0.1/
./autogen.sh
./configure --prefix=/home/postgres/postgis_req/protobuf-3.10.1
make -j 4
make install
tar -zxvf protobuf-c-1.3.3.tar.gz
cd protobuf-c-1.3.3/
export PKG_CONFIG_PATH=/home/postgres/postgis_req/protobuf-3.10.1/lib/pkgconfig
./configure --prefix=/home/postgres/postgis_req/protobuf-c-1.3.3
make -j 4
make install
安装sfcgal(三维,可选)
tar -zxvf v1.3.8.tar.gz
cd SFCGAL-1.3.8/
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/home/postgres/postgis_req/sfcgal-1.3.8 ..
make
make install
postgis安装
tar -zxf postgis-3.3.2.tar.gz
cd postgis-3.3.2/
./configure --prefix=/home/postgres/postgis_req/postgis-3.3.2 --with-gdalconfig=/home/postgres/postgis_req/gdal-3.5.1/bin/gdal-config --with-pgconfig=/pg/pghome/bin/pg_config --with-geosconfig=/home/postgres/postgis_req/geos-3.9.3/bin/geos-config --with-projdir=/home/postgres/postgis_req/proj-6.2.1 --with-xml2config=/home/postgres/postgis_req/libxml2-2.9.10/bin/xml2-config --with-jsondir=/home/postgres/postgis_req/json-c-0.13.1 --with-protobufdir=/home/postgres/postgis_req/protobuf-c-1.3.3 --with-sfcgal=/home/postgres/postgis_req/sfcgal-1.3.8/bin/sfcgal-config
make -j 4
make install
验证安装
psql postgres=# create database mytest; CREATE DATABASE postgres=# \c mytest You are now connected to database "mytest" as user "postgres". #验证postgis扩展 mytest=# create extension postgis; CREATE EXTENSION #验证栅格类数据需要的raster扩展 mytest=# create extension postgis_raster; CREATE EXTENSION #如果安装带有sfcgal,验证下三维sfcgal扩展 mytest=# create extension postgis_sfcgal; CREATE EXTENSION
mytest=# create table demogis(point geometry ,ts timestamp); 插入数据 mytest=# insert into demogis values ( GeomFromEWKT('SRID=4326;POINTM(116.39 39.9 10)'), now()); mytest=# insert into demogis values ( GeomFromEWKT('SRID=4326;POINTM(117.2 39.13 10)'), now()); mytest=# insert into demogis values ( GeomFromEWKT('SRID=4326;POINTM(112.57 22.26 10)'), now()); mytest=# insert into demogis values ( GeomFromEWKT('SRID=4326;POINTM(32.31 42.57 10)'), now());
mytest=# SELECT ST_Y(point) AS latitude, ST_X(point) AS longitude, ts AS time FROM demogis;
建立软连接,并重启数据库
ln -s /home/postgres/postgis_req/gdal-3.5.1/lib/libgdal.so.31.0.1 libgdal.so.31 ln -s /home/postgres/postgis_req/geos-3.9.3/lib/libgeos_c.so.1.14.3 libgeos_c.so.1 ln -s /home/postgres/postgis_req/proj-6.2.1/lib/libproj.so.15.2.1 libproj.so.15 ln -s /home/postgres/postgis_req/protobuf-c-1.3.3/lib/libprotobuf-c.so.1.0.0 libprotobuf-c.so.1 ln -s /home/postgres/postgis_req/sfcgal-1.3.8/lib64/libSFCGAL.so.1.3.8 libSFCGAL.so.1 ln -s /home/postgres/postgis_req/json-c-0.13.1/lib/libjson-c.so.4.0.0 libjson-c.so.4
pg_ctl -D /pgdata/pg14 -l /pgdata/pg14/postgresql.log stop pg_ctl -D /pgdata/pg14 -l /pgdata/pg14/postgresql.log start