Is there any unique identifier or any global variable which can tell us if replication is configured in current PostgreSQL server. Other than this query

select pg_is_in_recovery();

The above query results whether the server is in recovery or not, If 't' we consider it as a slave and we can judge it is a part of replication but

If it is 'f' how can we determine the corresponding PostgreSQL server is a part of replication.

Because even a server which is not a part of replication will also return 'f' as a result of the above query.

You can say, why can't I run a query like

select * from pg_stat_replication;

which will return the list of slaves connected to it. Then we can determine it is a master or not.

Am facing a scenario like "if the master is having only one slave, after some time that slave went down, then how can we determine replication is configured or not in that server"

  • 1
    What's wrong with select * from pg_stat_replication;? It will show one row for each stanby connected to the server where you run it. – a_horse_with_no_name Apr 15 at 9:47
  • @a_horse_with_no_name I think you didn't understand what am asking. I want to know how can I determine a server is a master server even though one and only slave having is went down. Because a standalone server will also return empty set on querying select * from pg_stat_replication; like a master which lost its one and only slave server. In a simple way, how can I differentiate a standalone server with master server? – manvith Apr 15 at 12:21

Your Answer


Browse other questions tagged or ask your own question.