一、postgresql安装
1、编译安装
[root@Euler1 ~]# useradd postgres
[root@Euler1 ~]# mkdir -p /postgresql/data
[root@Euler1 ~]# chown postgres:postgres /postgresql/data -R
[postgres@Euler1 postgresql-15.1]$ ./configure --prefix=/postgresql --with-python --with-perl --enable-nls --with-readline
[postgres@Euler1 postgresql-15.1]$ make install-world
2、加入环境变量
export PGHOME=/postgresql
export PATH=$PGHOME/bin:$PATH
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGUSER=postgres
export PGPORT=5432
export PGDATA=$PGHOME/data
export MANPATH=/postgresql/share/man:$MANPATH
3、编译启动
[postgres@Euler1 ~]$ initdb -D /postgresql/data
[postgres@Euler1 ~]$ pg_ctl -D /postgresql/data -l /postgresql/data/logfile.log start
4、调整参数
vi /postgresql/data/postgresql.conf
max_connections = 100
max_wal_senders = 10
max_replication_slots = 10
max_worker_processes = 10
shared_preload_libraries = 'pg_stat_statements'
listen_addresses = '*'
port = 5432
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 0
log_checkpoints = on
log_connections = on
log_disconnections = on
log_error_verbosity = verbose
log_line_prefix = '%m [%p] '
log_timezone = 'PRC'
log_autovacuum_min_duration = 0
二、下载postgis
https://postgis.net/development/source_code/
三、解压
[root@Euler1 postgresql]# tar zxvf postgis-3.4.0beta1.tar.gz
postgis-3.4.0beta1/
postgis-3.4.0beta1/build-aux/
postgis-3.4.0beta1/build-aux/config.guess
postgis-3.4.0beta1/build-aux/config.sub
postgis-3.4.0beta1/build-aux/config.rpath
postgis-3.4.0beta1/build-aux/install-sh
...
三、编译
[postgres@Euler1 postgis-3.4.0beta1]$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
...
checking for geos-config... no
configure: error: could not find geos-config within the current path. You may need to try re-running configure with a --with-geosconfig parameter.
gis依赖项比较多,官方文档记录如下
PostGIS has the following requirements for building and usage:
Required
• PostgreSQL 12 - 16. A complete installation of PostgreSQL (including server headers) is required. PostgreSQL is available
from http://www.postgresql.org .
For a full PostgreSQL / PostGIS support matrix and PostGIS/GEOS support matrix refer to https://trac.osgeo.org/postgis/-
wiki/UsersWikiPostgreSQLPostGIS
• GNU C compiler (gcc). Some other ANSI C compilers can be used to compile PostGIS, but we find far fewer problems when
compiling with gcc.
• GNU Make (gmake or make). For many systems, GNU make is the default version of make. Check the version by invoking
make -v. Other versions of make may not process the PostGIS Makefile properly.
• Proj reprojection library. Proj 6.1 or above is required. The Proj library is used to provide coordinate reprojection support
within PostGIS. Proj is available for download from https://proj.org/ .
• GEOS geometry library, version 3.6 or greater, but GEOS 3.11+ is required to take full advantage of all the new functions and
features. GEOS is available for download from https://libgeos.org .
LibXML2, version 2.5.x or higher. LibXML2 is currently used in some imports functions (ST_GeomFromGML and ST_GeomFromKMLibXML2 is available for download from https://gitlab.gnome.org/GNOME/libxml2/-/releases.
• JSON-C, version 0.9 or higher. JSON-C is currently used to import GeoJSON via the function ST_GeomFromGeoJson.
JSON-C is available for download from https://github.com/json-c/json-c/releases/.
• GDAL, version 2+ is required 3+ is preferred. This is required for raster support. https://gdal.org/download.html.
• If compiling with PostgreSQL+JIT, LLVM version >=6 is required https://trac.osgeo.org/postgis/ticket/4125.
简单办法,以上需要的东西全部yum安装,./configure时,缺少什么补充什么
1、geos
[root@Euler1 postgresql]# yum install geos*
Last metadata expiration check: 1:00:14 ago on Thu 27 Jul 2023 02:03:06 AM CST.
Dependencies resolved.
===============================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================
Installing:
geos x86_64 3.6.1-13.oe1 everything 581 k
geos-debuginfo x86_64 3.6.1-13.oe1 debuginfo 5.3 M
geos-debugsource x86_64 3.6.1-13.oe1 debuginfo 549 k
geos-devel x86_64 3.6.1-13.oe1 everything 1.4 M
2、proj
[root@Euler1 postgresql]# yum install proj*
Last metadata expiration check: 0:01:00 ago on Thu 27 Jul 2023 03:04:32 AM CST.
Package proj-4.9.3-8.oe1.x86_64 is already installed.
Dependencies resolved.
===============================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================
Installing:
proj-debuginfo x86_64 4.9.3-8.oe1 debuginfo 328 k
proj-debugsource x86_64 4.9.3-8.oe1 debuginfo 215 k
proj-devel x86_64 4.9.3-8.oe1 everything 213 k
proj-epsg x86_64 4.9.3-8.oe1 everything 77 k
proj-help x86_64 4.9.3-8.oe1 everything 44 k
proj-nad x86_64 4.9.3-8.oe1 everything 2.1 M
Transaction Summary
checking for proj_api.h... yes
configure: error: PostGIS requires PROJ >= 6.1.0
需要的版本还挺高,Euler中yum下载版本为4.9.3。官方文档给出了官网
https://proj.org/
安装6.2即可
root@Euler1 ~]# tar -xvf proj-6.2.0.tar.gz
proj-6.2.0/
proj-6.2.0/CITATION
proj-6.2.0/man/
[root@Euler1 proj-6.2.0]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
...
make[1]: Leaving directory '/root/proj-6.2.0/cmake'
make[1]: Entering directory '/root/proj-6.2.0'
make[2]: Entering directory '/root/proj-6.2.0'
make[2]: Nothing to be done for 'install-exec-am'.
/usr/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 proj.pc '/usr/local/lib/pkgconfig'
make[2]: Leaving directory '/root/proj-6.2.0'
make[1]: Leaving directory '/root/proj-6.2.0'
[root@Euler1 proj-6.2.0]#
最新版本已经是9.2.1,安装需要使用cmake
cd proj-9.2.1
mkdir build
cd build
cmake ..
cmake --build .
cmake --build . --target install
3、protobuf-c
checking for protobuf-c/protobuf-c.h... no
configure: error: unable to find protobuf-c/protobuf-c.h using CPPFLAGS. You can disable MVT and Geobuf support using --without-protobuf
[root@Euler1 proj-6.2.0]# yum install protobuf-c*
Last metadata expiration check: 0:29:49 ago on Thu 27 Jul 2023 03:04:32 AM CST.
Dependencies resolved.
4、gdal
[root@Euler1 ~]# tar -zxvf gdal-3.7.0.tar.gz
大于3.5用cmake,小于3.5用make,编译起来费CPU。
config.status: executing po-directories commands
PostGIS is now configured for x86_64-pc-linux-gnu
-------------- Compiler Info -------------
C compiler: gcc -std=gnu99 -g -O2 -fno-math-errno -fno-signed-zeros -Wall
C++ compiler (Wagyu): gcc -std=c++11 -x c++
C++ compiler (FlatGeobuf): gcc -std=c++11 -x c++
CPPFLAGS: -I/usr/include -I/usr/include/libxml2 -DNDEBUG
LDFLAGS: -lm
SQL preprocessor: /usr/bin/cpp -traditional-cpp -w -P
Archiver: gcc-ar rs
-------------- Additional Info -------------
Interrupt Tests: ENABLED
-------------- Dependencies --------------
GEOS config: /usr/bin/geos-config
GEOS version: 3.6.1
GDAL config: /usr/local/bin/gdal-config
GDAL version: 3.0.1
PostgreSQL config: /postgresql/bin/pg_config
PostgreSQL version: PostgreSQL 15.3
PROJ4 version: 62
Libxml2 config: /usr/bin/xml2-config
Libxml2 version: 2.9.10
JSON-C support: no
protobuf support: yes
protobuf-c version: 1003002
PCRE support: Version 2
Perl: /usr/bin/perl
--------------- Extensions ---------------
PostgreSQL EXTENSION support: enabled
PostGIS Raster: enabled
PostGIS Topology: enabled
SFCGAL support: disabled
Address Standardizer support: enabled
-------- Documentation Generation --------
xsltproc: /usr/bin/xsltproc
xsl style sheets: /usr/share/sgml/docbook/xsl-stylesheets
dblatex:
convert:
mathml2.dtd: http://www.w3.org/Math/DTD/mathml2/mathml2.dtd
configure: WARNING: --------- GEOS VERSION WARNING ------------
configure: WARNING: You are building against GEOS 3.6.1.
configure: WARNING:
configure: WARNING: To take advantage of _all_ the features of
configure: WARNING: PostGIS, GEOS 3.9.0 or higher is required.
configure: WARNING:
configure: WARNING: For _many_ features, GEOS 3.6.0 is enough.
configure: WARNING:
configure: WARNING: We recommend GEOS 3.8.0 or higher
configure: WARNING:
configure: WARNING: You can download the latest versions from
configure: WARNING: http://geos.osgeo.org/
configure: WARNING:
[postgres@Euler1 postgis-3.4.0beta1]$
5、GEOS版本升级
[root@Euler1 gdal-3.0.1]# rpm -qa|grep geos
geos-3.6.1-13.oe1.x86_64
geos-debuginfo-3.6.1-13.oe1.x86_64
geos-devel-3.6.1-13.oe1.x86_64
geos-debugsource-3.6.1-13.oe1.x86_64
[root@Euler1 gdal-3.0.1]# rpm -e geos-3.6.1-13.oe1.x86_64
error: Failed dependencies:
geos = 3.6.1-13.oe1 is needed by (installed) geos-devel-3.6.1-13.oe1.x86_64
[root@Euler1 gdal-3.0.1]# rpm -e geos-debuginfo-3.6.1-13.oe1.x86_64
[root@Euler1 gdal-3.0.1]# rpm -e geos-devel-3.6.1-13.oe1.x86_64
[root@Euler1 gdal-3.0.1]# rpm -e geos-debugsource-3.6.1-13.oe1.x86_64
[root@Euler1 gdal-3.0.1]# rpm -e geos-3.6.1-13.oe1.x86_64
6、编译
[root@Euler1 bin]# cd /home/postgres/postgresql/postgis-3.4.0beta1/
[root@Euler1 postgis-3.4.0beta1]# ./configure --with-pgconfig=/postgresql/bin/pg_config
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
...
config.status: executing libtool commands
config.status: executing po-directories commands
PostGIS is now configured for x86_64-pc-linux-gnu
-------------- Compiler Info -------------
C compiler: gcc -std=gnu99 -g -O2 -fno-math-errno -fno-signed-zeros -Wall
C++ compiler (Wagyu): gcc -std=c++11 -x c++
C++ compiler (FlatGeobuf): gcc -std=c++11 -x c++
CPPFLAGS: -I/usr/local/include -I/usr/include/libxml2 -DNDEBUG
LDFLAGS: -lm
SQL preprocessor: /usr/bin/cpp -traditional-cpp -w -P
Archiver: gcc-ar rs
-------------- Additional Info -------------
Interrupt Tests: ENABLED
-------------- Dependencies --------------
GEOS config: /usr/local/bin/geos-config
GEOS version: 3.12.0
GDAL config: /usr/local/bin/gdal-config
GDAL version: 3.0.1
PostgreSQL config: /postgresql/bin/pg_config
PostgreSQL version: PostgreSQL 15.3
PROJ4 version: 62
Libxml2 config: /usr/bin/xml2-config
Libxml2 version: 2.9.10
JSON-C support: no
protobuf support: yes
protobuf-c version: 1003002
PCRE support: Version 2
Perl: /usr/bin/perl
--------------- Extensions ---------------
PostgreSQL EXTENSION support: enabled
PostGIS Raster: enabled
PostGIS Topology: enabled
SFCGAL support: disabled
Address Standardizer support: enabled
-------- Documentation Generation --------
xsltproc: /usr/bin/xsltproc
xsl style sheets: /usr/share/sgml/docbook/xsl-stylesheets
dblatex:
convert:
mathml2.dtd: http://www.w3.org/Math/DTD/mathml2/mathml2.dtd
7、make install
[root@Euler1 postgis-3.4.0beta1]# make install
/usr/bin/perl ./utils/repo_revision.pl
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
Can't determine revision from git log
Not updating existing rev file at 6520b33
for s in liblwgeom raster loader deps libpgcommon postgis regress topology utils doc extensions; do \
echo "---- Making all in ${s}"; \
make -C ${s} all || exit 1; \
done;
---- Making all in liblwgeom
make[1]: Entering directory '/home/postgres/postgresql/postgis-3.4.0beta1/liblwgeom'
/bin/sh ../libtool --mode=compile gcc -I./../deps/ryu/.. -I/usr/local/include -I/usr/include/libxml2 -DNDEBUG -I. -I. -std=gnu99 -g -O2 -fno-math-errno -fno-signed-zeros -Wall -fPIC -DPIC -c -o stringbuffer.lo stringbuffer.c
libtool: compile: gcc -I./../deps/ryu/.. -I/usr/local/include -I/usr/include/libxml2 -DNDEBUG -I. -I. -std=gnu99 -g -O2 -fno-math-errno -fno-signed-zeros -Wall -fPIC -DPIC -c stringbuffer.c -fPIC -DPIC -o .libs/stringbuffer.o
libtool: compile: gcc -I./../deps/ryu/.. -I/usr/local/include -I/usr/include/libxml2 -DNDEBUG -I. -I. -std=gnu99 -g -O2 -fno-math-errno -fno-signed-zeros -Wall -fPIC -DPIC -c stringbuffer.c -o stringbuffer.o >/dev/null 2>&1
...
'/postgresql/share/extension/address_standardizer--3.3.0--ANY.sql' -> 'address_standardizer--TEMPLATED--TO--ANY.sql'
'/postgresql/share/extension/address_standardizer--3.3.1--ANY.sql' -> 'address_standardizer--TEMPLATED--TO--ANY.sql'
'/postgresql/share/extension/address_standardizer--3.3.2--ANY.sql' -> 'address_standardizer--TEMPLATED--TO--ANY.sql'
'/postgresql/share/extension/address_standardizer--3.3.3--ANY.sql' -> 'address_standardizer--TEMPLATED--TO--ANY.sql'
'/postgresql/share/extension/address_standardizer--3.3.4--ANY.sql' -> 'address_standardizer--TEMPLATED--TO--ANY.sql'
'/postgresql/share/extension/address_standardizer--3.4.0dev--ANY.sql' -> 'address_standardizer--TEMPLATED--TO--ANY.sql'
make[3]: Leaving directory '/home/postgres/postgresql/postgis-3.4.0beta1/extensions/address_standardizer'
make[2]: Leaving directory '/home/postgres/postgresql/postgis-3.4.0beta1/extensions'
make[1]: Leaving directory '/home/postgres/postgresql/postgis-3.4.0beta1'
8、确认
postgres=# SELECT name, default_version,installed_version
postgres-# FROM pg_available_extensions WHERE name LIKE 'postgis%' or name LIKE 'address%';
name | default_version | installed_version
------------------------------+-----------------+-------------------
postgis_tiger_geocoder | 3.4.0beta1 |
address_standardizer | 3.4.0beta1 |
postgis_raster | 3.4.0beta1 |
postgis | 3.4.0beta1 |
postgis_topology | 3.4.0beta1 |
address_standardizer_data_us | 3.4.0beta1 |
(6 rows)
postgres=# \dx postgis*
List of installed extensions
Name | Version | Schema | Description
------------------------+------------+----------+------------------------------------------------------------
postgis | 3.4.0beta1 | public | PostGIS geometry and geography spatial types and functions
postgis_raster | 3.4.0beta1 | public | PostGIS raster types and functions
postgis_tiger_geocoder | 3.4.0beta1 | tiger | PostGIS tiger geocoder and reverse geocoder
postgis_topology | 3.4.0beta1 | topology | PostGIS topology spatial types and functions
(4 rows)
postgres=# SELECT postgis_full_version();
-[ RECORD 1 ]--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
postgis_full_version | POSTGIS="3.4.0beta1 6520b33" [EXTENSION] PGSQL="150" GEOS="3.12.0-CAPI-1.18.0" PROJ="6.2.0" GDAL="GDAL 3.0.1, released 2019/06/28" LIBXML="2.9.10" LIBPROTOBUF="1.3.2" WAGYU="0.5.0 (Internal)" TOPOLOGY RASTER
9、测试
postgres=# CREATE EXTENSION postgis;
ERROR: could not load library "/postgresql/lib/postgis-3.so": libgeos_c.so.1: cannot open shared object file: No such file or directory
postgres=# CREATE EXTENSION postgis;
ERROR: could not load library "/postgresql/lib/postgis-3.so": libgeos.so.3.12.0: cannot open shared object file: No such file or directory
[root@Euler1 /]# find ./ -name libgeos_c.so.1
./usr/local/lib64/libgeos_c.so.1
./root/geos-3.12.0/lib/libgeos_c.so.1
[root@Euler1 /]# cp /root/geos-3.12.0/lib/* /postgresql/lib/
postgres=# CREATE EXTENSION postgis;
CREATE EXTENSION
postgres=# CREATE EXTENSION postgis_raster;
CREATE EXTENSION
postgres=# CREATE EXTENSION postgis_sfcgal;
ERROR: extension "postgis_sfcgal" is not available
DETAIL: Could not open extension control file "/postgresql/share/extension/postgis_sfcgal.control": No such file or directory.
HINT: The extension must first be installed on the system where PostgreSQL is running.
postgres=# CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION
postgres=# CREATE EXTENSION address_standardizer;
CREATE EXTENSION
postgres=# CREATE EXTENSION address_standardizer_data_us;
CREATE EXTENSION
postgres=# CREATE EXTENSION postgis_tiger_geocoder;
CREATE EXTENSION
postgres=# CREATE EXTENSION postgis_topology;
CREATE EXTENSION
postgres=#
postgres=# SELECT name, default_version,installed_version
postgres-# FROM pg_available_extensions WHERE name LIKE 'postgis%' or name LIKE 'address%';
-[ RECORD 1 ]-----+-----------------------------
name | postgis_tiger_geocoder
default_version | 3.4.0beta1
installed_version | 3.4.0beta1
-[ RECORD 2 ]-----+-----------------------------
name | address_standardizer
default_version | 3.4.0beta1
installed_version | 3.4.0beta1
-[ RECORD 3 ]-----+-----------------------------
name | postgis_raster
default_version | 3.4.0beta1
installed_version | 3.4.0beta1
-[ RECORD 4 ]-----+-----------------------------
name | postgis
default_version | 3.4.0beta1
installed_version | 3.4.0beta1
-[ RECORD 5 ]-----+-----------------------------
name | postgis_topology
default_version | 3.4.0beta1
installed_version | 3.4.0beta1
-[ RECORD 6 ]-----+-----------------------------
name | address_standardizer_data_us
default_version | 3.4.0beta1
installed_version | 3.4.0beta1
10、关于postgis_sfcgal
在官方news中发现pg>9.6并且GEOS>3.6中,已经将postgis_sfcgal与postgis分离。
PostGIS 3.1.0
2020/12/18
This version requires PostgreSQL 9.6 or higher and GEOS 3.6 or higher
Additional features are enabled if you are running GEOS 3.9.
* Breaking changes *
- #4737, Bump minimum protobuf-c requirement to 1.1.0 (Raúl Marín)
The configure step will now fail if the requirement isn't
met or explicitly disabled (--without-protobuf)
- #4258, Separated postgis_sfcgal from postgis
into its own lib file and extension (Regina Obe)
- #4577, Drop support for PostgreSQL 9.5 (Raúl Marín)
- #4601, ST_TileEnvelope signature changed.
- #3057, ST_Force3D, ST_Force3DZ, ST_Force3DM and ST_Force4D signatures changed.
最后修改时间:2023-07-27 07:16:12
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




