PostGIS 13.5 主从搭建

PostGIS 主从搭建

适用版本

  • postgresql 13.5
  • PostGIS 3.1.4

服务器规划

服务器IP用途
postgis01172.88.0.181主库
postgis02172.88.0.182从库

主库 PostGIS 数据库安装

  • 安装 postgresql
[root@postgis01 ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm && yum install -y postgresql13 postgresql13-server
  • 安装 PostGIS 插件
[root@postgis01 ~]# yum -y install postgis31_13
  • 创建数据目录
[root@postgis01 ~]# mkdir -p /deploy/postgis/data && chown -R postgres:postgres /deploy/postgis/data
  • 修改配置(添加以下两行内容)
[root@postgis01 ~]# systemctl edit postgresql-13.service
[Service]
Environment=PGDATA=/deploy/postgis/data
  • 重新加载系统
[root@postgis01 ~]# systemctl daemon-reload
  • 初始化数据库
[root@postgis01 ~]# /usr/pgsql-13/bin/postgresql-13-setup initdb
  • 修改配置文件
[root@postgis01 ~]# vim /deploy/postgis/data/postgresql.conf
listen_addresses = '*'
[root@postgis01 ~]# vim /deploy/postgis/data/pg_hba.conf
host    all             all             0.0.0.0/0               trust
  • 启动
[root@postgis01 ~]# systemctl enable postgresql-13 && systemctl start postgresql-13
  • 修改密码
[root@postgis01 ~]# su - postgres
-bash-4.2$ psql
postgres=# alter user postgres with password '123456';
ALTER ROLE
postgres=# \q
-bash-4.2$ exit
登出

配置主从日志同步

  • 修改主节点配置
[root@postgis01 ~]# vim /deploy/postgis/data/postgresql.conf
synchronous_standby_names = '*'
[root@postgis01 ~]# vim /deploy/postgis/data/pg_hba.conf
host    replication     all             172.88.0.182/32         trust
  • 主库创建同步用户
[root@postgis01 ~]# su - postgres
-bash-4.2$ psql
postgres=# create role rpl login replication encrypted password '123456';
CREATE ROLE
postgres=# 
  • 创建用于从库复制的slot
postgres=# select * from pg_create_physical_replication_slot('stand_slot');
 slot_name  | lsn 
------------+-----
 stand_slot | 
(1 行记录)
postgres=# \q
-bash-4.2$ exit
  • 重启数据库
[root@postgis01 ~]# systemctl restart postgresql-13

从库 PostGIS 数据库安装

  • 安装 postgresql
[root@postgis02 ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm && yum install -y postgresql13 postgresql13-server
  • 安装 PostGIS 插件
[root@postgis02 ~]# yum -y install postgis31_13
  • 创建数据目录
[root@postgis02 ~]# mkdir -p /deploy/postgis/data
[root@postgis02 ~]# chown -R postgres:postgres /deploy/postgis/data
[root@postgis02 ~]# chmod 0700 /deploy/postgis/data
  • 修改配置
[root@postgis02 ~]# vim /usr/lib/systemd/system/postgresql-13.service
Environment=PGDATA=/deploy/postgis/data
  • 重新加载系统
[root@postgis02 ~]# systemctl daemon-reload
  • 备份主库数据
[root@postgis02 ~]# pg_basebackup --pgdata=/deploy/postgis/data --format=p --write-recovery-conf --checkpoint=fast --label=mffb --progress --host=172.88.0.181 --port=5432 --username=rpl
  • 修改从库配置
[root@postgis02 ~]# vim /deploy/postgis/data/postgresql.conf
listen_addresses = '*'
primary_conninfo = 'host=172.88.0.181 port=5432 user=rpl password=123456'
primary_slot_name = 'stand_slot'
[root@postgis02 ~]# vim /deploy/postgis/data/pg_hba.conf
host    all             all             0.0.0.0/0               trust
  • 重启从库
[root@postgis02 ~]# systemctl restart postgresql-13

添加 PostGIS 插件支持

-- 在对应的库下运行以下sql
create extension postgis;

完成主从同步!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值