主数据库操作 db01

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    wal_level = hot_standby
    archive_mode = on
    archive_command = 'cp -i %p /data/archive/%f'
    max_wal_senders = 3


    host    replication     postgres         0.0.0.0/0               md5


    pg_basebackup -D hotstandby -w -R -X stream --dbname="host=db01 user=postgres password=123456"
    scp -r hotstandby/* root@db02:/data/postgresql-

从数据库 db02

1
    hot_standby = on

从数据库恢复为主库

  • 1.在从数据库上的recovery.conf中配置trigger_file = ‘/data/trigger.unl’
  • 2.touch /data/trigger.unl
  • 3.hot_standby = off
  • 4.重启 即可