CentOS7 安装PostgreSQL及PostGIS扩展

安装PostgreSQL

1. 进入postgresql官网下载页面,提示了centos相关下载安装的信息,可以选择适合的版本,按照官网给出的步骤来进行安装。

https://www.postgresql.org/download/linux/redhat/

CentOS7 安装PostgreSQL及PostGIS扩展_第1张图片

linux版本查看方法:

cat /proc/version

下面就是按照上图4-7几个步骤来安装postgresql:

2. 安装rpm仓库

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

3. 安装Postgresql11客户端:

yum install postgresql11

安装完成如下所示:

4. 安装Postgresql11服务端

yum install postgresql11-server

5. 初始化数据库

/usr/pgsql-11/bin/postgresql-11-setup initdb

设置Postgresql自动启动

systemctl enable postgresql-11

systemctl start postgresql-11

6. 修改Postgresql配置文件postgresql.conf,设置Postgresql开放端口:

vim /var/lib/pgsql/11/data/postgresql.conf

CentOS7 安装PostgreSQL及PostGIS扩展_第2张图片

修改同一路径下的pg_hba.conf文件,增加如下一行

vim /var/lib/pgsql/11/data/pg_hba.conf

CentOS7 安装PostgreSQL及PostGIS扩展_第3张图片

7. 重启服务使修改生效

systemctl restart postgresql-11

8. 通过以下命令进入数据库

su postgres 

psql -U postgres 或 psql

离开数据库:

\q

su root

CentOS7 安装PostgreSQL及PostGIS扩展_第4张图片

查看版本

select version() 

修改密码:

\password

9. 远程连接

CentOS7 安装PostgreSQL及PostGIS扩展_第5张图片

安装PostGIS

1. 首先安装几个工具包

yum  install wget net-tools epel-release -y

2. 安装postgis

yum install postgis25_11 postgis25_11-client -y

3. 安装拓展工具

yum install ogr_fdw11 -y

yum install pgrouting_11 -y

创建数据库spatial_testdb,进入:

CREATE DATABASE spatial_testdb OWNER postgres;

\c spatial_testdb

4. 给新建的数据库安装PostGis扩展:

CREATE EXTENSION postgis;

CREATE EXTENSION postgis_topology;

CREATE EXTENSION ogr_fdw;

CentOS7 安装PostgreSQL及PostGIS扩展_第6张图片

验证安装是否成功

SELECT PostGIS_version();

你可能感兴趣的:(CentOS7 安装PostgreSQL及PostGIS扩展)