Wednesday, 2 February 2022

Switchover and Switchback in PostgreSQL10

 





postgres=# select application_name, state, sync_priority, sync_state from pg_stat_replication;

 application_name |   state   | sync_priority | sync_state
------------------+-----------+---------------+------------
 walreceiver      | streaming |             0 | async









If Return  false so the server is running in Primary mode or Master
































/u02/PostgreSQL/10/data
cat recovery.conf
standby_mode = 'on'
primary_conninfo = 'user=replicator password=replicator host=192.168.0.106 port=5432 sslmode=prefer sslcompression=1 krbsrvname=postgres target_session_attrs=any'
recovery_target_timeline = 'latest'
trigger_file = '/u02/PostgreSQL/10/data/recovery.stop'





Now run the touch the file  (2nd step main)

touch /u02/PostgreSQL/10/data/recovery.stop








Standby has been promoted as master and a new timeline followed which you can notice in logs.

 2020-03-26 20:46:34 IST    LOG:  trigger file found: /u02/PostgreSQL/10/data/recovery.stop
 2020-03-26 20:46:34 IST    LOG:  redo done at 0/2B000028
 2020-03-26 20:46:34 IST    LOG:  last completed transaction was at log time 2020-03-25 19:45:14.642094+05:30
 2020-03-26 20:46:34 IST    LOG:  selected new timeline ID: 2
 2020-03-26 20:46:34 IST    LOG:  archive recovery complete
 2020-03-26 20:46:34 IST    LOG:  checkpoint starting: force
 2020-03-26 20:46:34 IST    LOG:  database system is ready to accept connections
 2020-03-26 20:46:34 IST    LOG:  checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.000 s, sync=0.000 s, total=0.028 s; sync files=0, longest=0.000 s, average=0.000 s; distance=0 kB, estimate=14702 kB













cat recovery.conf
recovery_target_timeline = 'latest'
standby_mode = 'on'
primary_conninfo = 'user=replicator password=replicator host=192.168.0.107 port=5432 sslmode=prefer sslcompression=1 krbsrvname=postgres target_session_attrs=any'
trigger_file = '/u02/PostgreSQL/10/data/recovery.stop'


















Check the data in primary and standby:-














No comments:

Post a Comment

Master and Slave - Sync check - PostgreSQL

  1) Run the below Query on Primary:- SELECT     pid,     usename,     application_name,     client_addr,     state,     sync_state,     sen...