Last active
March 17, 2017 14:07
-
-
Save victorpendleton/72222dd4b2edb1c8f7f3d2995faa607f to your computer and use it in GitHub Desktop.
Postgres lag and wal file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT '00000001' || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_replay_location() || ' ') FROM 1 FOR position('/' in trim(' ' || pg_last_xlog_replay_location() || ' '))-1), 8, '0') || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_replay_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_replay_location() || ' '))+1 FOR 2), 8, '0') as last_wal | |
, SUBSTRING(trim(' ' || pg_last_xlog_replay_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_replay_location() || ' '))+3 ) as last_lsn | |
, '00000001' || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_receive_location() || ' ') FROM 1 FOR position('/' in trim(' ' || pg_last_xlog_receive_location() || ' '))-1), 8, '0') || LPAD(SUBSTRING(trim(' ' || pg_last_xlog_receive_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_receive_location() || ' '))+1 FOR 2), 8, '0') as last_wal_rev | |
, SUBSTRING(trim(' ' || pg_last_xlog_receive_location() || ' ') FROM position('/' in trim(' ' || pg_last_xlog_receive_location() || ' '))+3 ) as last_lsn_recv | |
, CASE WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0 | |
ELSE round( CAST(EXTRACT(EPOCH FROM Now() - pg_last_xact_replay_timestamp()) as NUMERIC), 3) END As Seconds_behind |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment