Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check postgres replication status

Can someone suggest the steps to check pgsql replication status and when to say replication is not happening properly?

We use streaming replication with pgsql9.0 and pgsql9.4

Thanks.

like image 987
Dino Daniel Avatar asked Apr 13 '17 09:04

Dino Daniel


People also ask

What to look for if your PostgreSQL replication is lagging?

The only way to get the replica lag in seconds on a current PostgreSQL version is to have an external process commit an update to a dedicated timestamp table periodically.

How can you tell fake lag?

You can use the replica_lag and network_lag metrics to monitor replication lag and identify whether the cause of the lag is in the primary database, the network, or the replica. The number of seconds that the replica's state is lagging behind the state of the primary instance.

What is PostgreSQL replication?

What Is PostgreSQL Replication? The process of copying data from a PostgreSQL database server to another server is called PostgreSQL Replication. The source database server is usually called the Master server, whereas the database server receiving the copied data is called the Replica server.


2 Answers

I use following SQL queries to check status on Postgres v11 usually.

On master:

select * from pg_stat_replication; 

On replica (streaming replication in my case):

select * from pg_stat_wal_receiver; 
like image 109
Alexey Avatar answered Sep 19 '22 17:09

Alexey


On your master, pg_stat_replication provides data about ongoing replication:

select client_addr, state, sent_location, write_location,         flush_location, replay_location from pg_stat_replication; 

On postgresql v10:

select client_addr, state, sent_lsn, write_lsn,     flush_lsn, replay_lsn from pg_stat_replication; 
like image 30
Reinsbrain Avatar answered Sep 21 '22 17:09

Reinsbrain