Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

Method 1
You can check the mode of the server using "pg_controldata".
[pgsql@test~]$ pg_controldata /usr/local/pgsql/data84/

Database cluster state:               in archive recovery   --> This is Standby  Database

Database cluster state:               in production  --> This is Production Database [Master]

Method 2
You can use pg_is_in_recovery() which returns True if recovery is still in progress(so the server is running in standby mode or slave)
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
If Return  false so the server is running in primary mode or master
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
f
(1 row)

No comments:

Post a Comment