-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pg_replication_lag is invalid for postgres newer than 9.3 #385
Comments
When I tried to use the recommended query I got a parsing error on the
|
FWIW, not sure about earlier versions but 10/11/12 you can get replication lag from primary node without any math in it. It is directly available there in microseconds value. |
@akamensky You mean I have postgresql 12.5 here and implemented it as
ExplanationFrom postgres documentation https://www.postgresql.org/docs/12/monitoring-stats.html#PG-STAT-REPLICATION-VIEW
|
Releases after postgresql 9.3 had a change in logic where it would have no WAL updates while master host is idle, which would result in linear lag values increase when master is idle and use old query:
SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag
Appropriate query should be checking if we are on the latest know WAL position and if not then use this query, thus correct query is something like below:
SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN make_interval(0,0,0,0,0,0,0.0) ELSE (now() - pg_last_xact_replay_timestamp()) END AS replication_lag;
The text was updated successfully, but these errors were encountered: