Skip to content

Instantly share code, notes, and snippets.

@adamjforster
Created April 25, 2018 14:24
Show Gist options
  • Save adamjforster/0396242c6b171d0afa2c34fefb3ea8d4 to your computer and use it in GitHub Desktop.
Save adamjforster/0396242c6b171d0afa2c34fefb3ea8d4 to your computer and use it in GitHub Desktop.
SQL queries to show Postgresql streaming replication delay
/***
* Secondary server commands.
*/
// Show the number of seconds between now and the last replayed transaction.
SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))::INT;
// Show the number of minutes between now and the last replayed transaction.
SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))::INT / 60;
// Get last transaction log location received and synced to disk by streaming replication.
SELECT pg_last_xlog_receive_location();
/***
* Primary server commands.
*/
// Get current transaction log write location.
SELECT pg_current_xlog_location();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment