PostgreSQL Switchover and Switchback in 9.4.1

孤街醉人 提交于 2020-01-15 08:48:23

问题


Environment:

PostgreSQL EDB 9.4.1 OS:rhel 7

I have configured streaming replication with continuous archiving. I have performed the steps below for switch-over and switchback.

I have read this other articles.

I am confused what happens if the archive location is not a shared location. I have followed the steps below for switchover and switchback.

SWITCHOVER

At the master (192.xxxx.128)

  • pg_ctl -D /opt/PostgresPlus/9.4AS/data stop --mode=fast
    
  • Create recovery.conf:

    standby_mode = 'on'
    primary_conninfo = 'user=replication password=Replication@123 host=192.xxx.129 port=5432'
    recovery_target_timeline = 'latest'
    trigger_file = '/tmp/node1'
    restore_command = 'rsync -a /home/postgres/restore/%f %p
    
  • pg_ctl -D /opt/PostgresPlus/9.4AS/data start
    
  • psql -U postgres -c "select pg_is_in_recovery()"
    

At the standby (192.xx.129):

  • ps -ef | grep postgres
    
  • touch locationoftrigeerfile
    

AT the primary (192.xx.129):

  • connect applications and test

Switch-over was completed with the above steps.

NOW SWITCHBACK

AT the primary (192.xx.129):

  • pg_ctl -D $PGDATA stop --mode=fast
    
  • create recovery.conf and add

    standby_mode = 'on'
    primary_conninfo = 'user=replication password=postgres host=192.xxx.128 port=5432 sslmode=prefer sslcompression=1 krbsrvname=postgres'
    restore_command = 'cp %p /home/postgres/restore_5444/%f'
    recovery_target_timeline = 'latest'
    trigger_file='/tmp/pg_promote_5432'`
    
  • pg_ctl -D $PGDATA start --mode=fast
    
  • psql -U postgres -c "select pg_is_in_recovery();"
    

At the secondary (192.xxx.128):

  • ps -ef | grep postgres
    
  • touch locationoftrigeerfile
    

My question:

For every promotion a new timeline id is created as per the PostgreSQL documentation.

If we use recovery_target_timeline='latest' then it will use the timeline which was found in the archive, but in my environment archive is not a shared mount point.

If the timeline is not found in the archive, is it received via streaming replication?


回答1:


Yes, the history file containing the timeline switch will also be streamed to the standby server.

It will show up in the standby's pg_wal directory. The associated log message is:

LOG:  fetching timeline history file for timeline 2 from primary server

The standby will be able to follow the primary across the timeline switch.



来源:https://stackoverflow.com/questions/58949441/postgresql-switchover-and-switchback-in-9-4-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!