[toc]
计划搭建一主一从的pg数据库集群

环境配置

主机名 IP地址 角色 数据目录
master 192.168.56.15 主库 /data
master1 192.168.56.16 standby /data

主库上的配置

  • 配置pg_hba.conf
  1. host replication postgres 192.168.56.0/24 trust
  • 修改postgresql.conf
  1. max_wal_senders = 5
  2. wal_level = hot_standby
  3. 指定同步复制的standby的名字
  4. synchronous_standby_names = 'standby01

备库上的配置

在/data 数据目录里面创建文件

  1. vi recovery.conf
  2. standby_mode = 'on'
  3. recovery_target_timeline = 'latest'
  4. primary_conninfo = 'application_name=standby01 user=postgres host=192.168.56.15 port=5432 password=postgres sslmode=disable sslcompression=1'

启动数据库及备库

  • 将两个主备依次启动

  • 从主库上进入数据库中可以查看到数据主备的状态

  1. postgres=# select * from pg_stat_replication;
  2. pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state |
  3. sent_lsn | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state
  4. ------+----------+----------+------------------+---------------+-----------------+-------------+-------------------------------+--------------+-----------+--
  5. ----------+------------+------------+------------+-----------+-----------+------------+---------------+------------
  6. 1859 | 10 | postgres | standby01 | 192.168.56.16 | | 7998 | 2018-07-04 16:11:33.549227+08 | | streaming | 5
  7. /DBA4F268 | 5/DBA4F268 | 5/DBA4F268 | 5/DBA4F268 | | | | 1 | sync
  8. (1 row)
本站文章,未经作者同意,请勿转载,如需转载,请邮件customer@csudata.com.
1 评论  
userImg
Stephev · 1L · 2018-10-19 19:54:05

1

添加一条新评论