postgis是一个postgres的扩展,用于让postgres可以处理Gis。
Install the repository RPM:
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Disable the built-in PostgreSQL module:
dnf -qy module disable postgresql
Install PostgreSQL:
dnf install -y postgresql13-server
Optionally initialize the database and enable automatic start:
/usr/pgsql-13/bin/postgresql-13-setup initdb
systemctl enable postgresql-13
systemctl start postgresql-13
修改用户密码
su - postgres
alter user postgres with password '123456';
开启远程访问
编辑/var/lib/pgsql/13/data/pg_hba.conf
cat /var/lib/pgsql/13/data/pg_hba.conf
host all all 0.0.0.0/0 scram-sha-256
编辑/var/lib/pgsql/13/data/postgresql.conf
cat /var/lib/pgsql/13/data/postgresql.conf
listen_addresses = '*'
port = 5432
重启postgresql
systemctl restart postgresql-13
安装postgis
安装epel
yum install epel-release
启用PowerTools存储库(某些依赖项是必需的):
dnf config-manager --set-enabled powertools
安装postgis
dnf install postgis31_13
启用postgis
postgis需要在每一个数据中启用,但不要在postgres数据库中启用
* 切换到postgres用户
su - postgres
* 列出所有的数据库
psql -l
创建一个test_db数据库
# 创建用户
create user test_user;
# 创建数据库test_db
create database test_db;
# 为用户创建密码
alter user test_user with password 'a123456';
# 修改test_db的拥有者为test_user
alter database test_db owner to test_user;
# 回收test_db的public权限,默认情况下,其它用户也可以在test_db上创建schema为public的表
revoke connect on database test_db from public;
在test_db数据库中启用postgis
启用postgis需要有管理员权限
切换到test_db
psql -d test_db
为test_db启用postgis
# 启用PostGIS(从3.0版开始仅包含几何/地理)
# 执行下面一这个命令就已经启用了postgis
create extension postgis;
SELECT PostGIS_full_version();
# 启用其它扩展
## 启用栅格支持(3 +以上)
CREATE EXTENSION postgis_raster;
## 启用拓扑
CREATE EXTENSION postgis_topology;
## 启用PostGIS的高级3D 和其他地理处理算法,sfcgal不适用于所有发行
CREATE EXTENSION postgis_sfcgal;
## Tiger需要的模糊匹配
CREATE EXTENSION Fuzzystrmatch;
## 基于规则的标准化器
CREATE EXTENSION address_standardizer;
## 示例规则数据集
CREATE EXTENSION address_standardizer_data_us;
## 启用US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;
postgres常用操作
远程登录postgres
psql -h 127.0.0.1 -U test_user -d test_db -W
列出所有用户
查看所有数据库
\list
查看当前的数据库
select current_database();
列出当前数据库中的所有表
列出给定表的结构
\d 表名
切换到另一个数据库
\c 数据库名
Centos8安装PostGIS 3.1+PostgreSQL 13
在 CentOS 8 上安装 PostgresSQL 12 + PostGIS + GeoServer 连接