patternsqlMinor
postgreSQL 9.3 streaming replication delay
Viewed 0 times
postgresqlstreamingdelayreplication
Problem
I'm running a fairly simple WAL streaming replication setup between two postgreSQL 9.3 servers that are on a private 1Gb LAN, but recently I've noticed that there is an increasing amount of replication delay:
The servers aren't particularly busy, so I was wondering what I could do to investigate this problem or possibly fix it.
# SELECT extract(epoch from now() - pg_last_xact_replay_timestamp()) AS slave_lag;
slave_lag
-----------
5.50896The servers aren't particularly busy, so I was wondering what I could do to investigate this problem or possibly fix it.
Solution
Have you tried looking at:
The idea here is if both servers are synchronized, then there is no delay. If they are not synchronized, then display the delay.
One potential issue here is if PostgreSQL replication stops, this won't work properly, so you'd need to check periodically by some other mechanism to see if replication is running.
SELECT
CASE
WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0
ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INTEGER
END
AS replication_lag;The idea here is if both servers are synchronized, then there is no delay. If they are not synchronized, then display the delay.
One potential issue here is if PostgreSQL replication stops, this won't work properly, so you'd need to check periodically by some other mechanism to see if replication is running.
Code Snippets
SELECT
CASE
WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0
ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INTEGER
END
AS replication_lag;Context
StackExchange Database Administrators Q#64756, answer score: 2
Revisions (0)
No revisions yet.