postgresql13+postgis3.2安装教程
安装postgresql13
安装pg13
pg13安装包
cd /home/soft/pg
tar -zxvf postgresql-13.6.tar.gz
cd postgresql-13.6
# yum -y install -y readline-devel
./configure --prefix=/usr/local/pgsql
make -j4
make install
设置环境变量
vim /etc/profile
export PATH=/usr/local/pgsql/bin:$PATH
export PGHOME=/usr/local/pgsql:$PATH
export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
source /etc/profile
初始化数据库
mkdir /home/pgfile
chown -R postgres:postgres /home/pgfile
su - postgres
cd /usr/local/pgsql/bin
./initdb -D /home/pgfile/data/
启动数据库
指定数据库目录启动数据库
su - postgres
mkdir /home/pgfile/log
touch /home/pgfile/log/logfile
./pg_ctl -D /home/pgfile/data -l /home/pgfile/log/logfile start
修改数据库postgres用户密码
su postgres
psql
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
修改远程配置
配置文件位置和数据位置
/home/pgfile/data
修改pg_hba.conf
vim pg_hba.conf
host all all 0.0.0.0/0 trust
修改postgresql.conf
vim postgresql.conf
listen_addresses = '*'
重启数据库服务
su - postgres
./pg_ctl -D /home/pgfile/data -l /home/pgfile/log/logfile restart
安装postgis3.2
安装proj
# 安装proj
tar -zxvf proj-8.2.1.tar.gz
cd proj-8.2.1
./configure --prefix=/home/postgres/proj
#make -j4 使用多个核心去跑任务
make -j8
make install
yum uninstall sqlite-devel
错误1
SQLite
tar zxvf sqlite-autoconf-3400100.tar.gz
cd sqlite-autoconf-3400100/
./configure
make -j8 && make install
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
ln -s /usr/local/sqlite3/bin/sqlite3 /usr/bin/sqlite3
echo "/usr/local/sqlite3/lib" > /etc/ld.so.conf.d/sqlite3.conf
ldconfig
安装完成后
vi ~/.bash_profile
在文件中追加:
export PKG_CONFIG_PATH=/usr/local/sqlite3/lib/pkgconfig
source ~/.bash_profile
最后查看新的版本号
sqlite3 -version
参考
进入目录
cd sqlite-autoconf-3400100
修改源代码添加宏
vim sqlite3.c
在include下面添加宏
#define SQLITE_CORE 1
#define SQLITE_AMALGAMATION 1
#ifndef SQLITE_PRIVATE
# define SQLITE_PRIVATE static
#endif
#define SQLITE_ENABLE_COLUMN_METADATA 1 //注意这行
/************** Begin file ctime.c *******************************************/
/*
在重新编译:
./configure --prefix=/usr/local/sqlite3
make
sudo make uninstall
sudo make install
错误2
yum install curl-devel -y
安装geos
# 安装geos
# yum install -y bzip2
tar -jxvf geos-3.9.4.tar.bz2
cd geos-3.9.4
./configure --prefix=/home/postgres/geos
#make -j4
make -j8
make install
安装gdal
# 安装gdal
tar -zxvf gdal-3.5.3.tar.gz
cd gdal-3.5.3
./configure --prefix=/home/postgres/gdal --with-proj=/home/postgres/proj
#make -j4
make -j4
make install
或者使用低版本的-2.3.2
错误一
如果安装报错,提示SFCGAL缺少
由于SFCGAL需要依赖Boost、CGAL、GMP、MPFR这四个软件,所以具体总共需要先安装 以下四个软件:
boost-devel.x86_64
gmp-devel.x86_64
mpfr-devel.x86_64
CGAL-4.13.1
- 安装boost-devel
yum -y install boost-devel.x86_64
- 安装gmp-devel.x86_64
yum -y install gmp-devel
- 安装mpfr-devel.x86_64
yum -y install mpfr-devel
- 安装cgal
tar -zxvf cgal-releases-CGAL-4.14.3.tar.gz
cd cgal-releases-CGAL-4.14.3
# yum install -y cmake3
# 生成makefile
cmake3 .
# 编译并且安装
make -j4
make install
- 安装SFCGAL
tar -zxvf SFCGAL-1.3.8.tar.gz
cd SFCGAL-1.3.8
# 生成makefile
cmake3 .
# 编译并且安装
make -j4
make install
安装json-c
tar -zxvf json-c-json-c-0.16-20220414.tar.gz
cd json-c-json-c-0.16-20220414
#./configure --prefix=/home/postgres/json-c-0.16
cmake3 -DCMAKE_INSTALL_PREFIX=/home/postgres/json-c-0.16
make -j4
make install
tar -zxvf json-c-json-c-0.13.1-20180305.tar.gz
cd json-c-json-c-0.13.1-20180305
./configure --prefix=/home/postgres/json-c-0.13.1
make -j4
make install
安装Protobuf
#安装相关依赖
sudo yum install autoconf -y
sudo yum install automake -y
sudo yum install libtool -y
tar -zxvf protobuf-3.19.6.tar.gz
cd protobuf-3.19.6
./autogen.sh
#配置安装目录
./configure --prefix=/usr/local/protobuf-3.19.6
make -j4
make install
#配置环境变量,增加/home/postgres/protobuf-3.19.6安装目录
vim /etc/profile
export CMAKE_HOME=/usr/bin/cmake
export PKG_CONFIG_PATH=/usr/local/protobuf-3.19.6/lib/pkgconfig
export PROTOBUF_HOME=/usr/local/protobuf-3.19.6
export PATH=$CMAKE_HOME/bin:$PROTOBUF_HOME/bin:$PATH
#保存退出
source /etc/profile
#验证protobuf执行程序
protoc --version
#出现libprotoc 3.19.6说明安装成功
安装protobuf-c
tar -zxvf protobuf-c-1.4.1.tar.gz
cd protobuf-c-1.4.1
#导入protobuf的pkgconfig,否则"--No package 'protobuf' found"
export PKG_CONFIG_PATH=/usr/local/protobuf-3.19.6/lib/pkgconfig
./configure --prefix=/usr/local/protobuf-c-1.4.1
make -j4
make install
#配置环境变量,增加下protobuf-c-1.4.1/bin
vim /etc/profile
# 在export PATH=$CMAKE_HOME/bin:$PROTOBUF_HOME/bin:$PATH 追加
export PATH=$CMAKE_HOME/bin:$PROTOBUF_HOME/bin:$PATH:/usr/local/protobuf-c-1.4.1/bin
#保存退出
source /etc/profile
安装postgis
安装相关依赖
yum -y install gcc-c++.x86_64
yum install libxml2 libxslt -y
yum -y install libxml2 libxml2-dev libxml libxml2*
#安装postgis(mvt、json)
tar -zxvf postgis-3.2.4.tar.gz
cd postgis-3.2.4
./configure --prefix=/home/postgres/postgis --with-pgsql=/usr/local/pgsql/bin/pg_config --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/home/postgres/geos/bin/geos-config --with-projdir=/home/postgres/proj --with-gdalconfig=/home/postgres/gdal-2.3.2/bin/gdal-config --with-jsondir=/home/postgres/json-c-0.13.1 --with-protobufdir=/usr/local/protobuf-c-1.4.1
#make -j4
make -j16
make install
修改动态库的路径(so库的路径)
vim /etc/ld.so.conf
#编辑内容如下
include ld.so.conf.d/*.conf
/usr/local/protobuf-3.19.6/lib
/usr/local/protobuf-c-1.4.1/lib
/home/postgres/proj/lib
/home/postgres/gdal-2.3.2/lib
/home/postgres/geos/lib
/home/postgres/json-c-0.13.1/lib
#编辑完成后wq!保存退出
#保存配置,重启生效
ldconfig
测试
--测试postgis
EXPLAIN ANALYZE select st_geomfromtext('Point(103.667546 36.534295)');
-- 测试geohash
select st_geohash(st_transform(st_geomfromtext('Point(103.667546 36.534295)', 4326), 4326), 12) as geohash;
-- 测试mvt
WITH mvtgeom AS
(
SELECT ST_TileEnvelope(12, 513, 412) AS geom
)
SELECT ST_AsMVT(mvtgeom.*)
FROM mvtgeom;
安装uuid
yum -y install e2fsprogs-devel uuid-devel libuuid-devel
cd /home/soft/pg/postgresql-13.6
./configure --prefix=/usr/local/pgsql --with-uuid=ossp
cd /home/soft/pg/postgresql-13.6/contrib/uuid-ossp/
make && make install