Monitor PostgreSQL Replication

From Gejoreuy
Jump to navigation Jump to search

Find Out Which is Master or Slave

# select pg_is_in_recovery()

If it's true, we're on a slave; if false, master.

List All Databases

# \l

Check Synchronization Status

postgres@dbmaster:~$ psql -x -c "select * from pg_stat_replication;"

This must be run in master db node.
Or we can check the sync status only like below.

# select sync_state from pg_stat_replication;

Possible values of sync_state are:

async: This standby server is asynchronous -> CRITICAL!
potential: This standby server is asynchronous, but can potentially become synchronous if one of current synchronous ones fails -> WARNING
sync: This standby server is synchronous -> OK
quorum: This standby server is considered as a candidate for quorum standbys -> OK