Skip to content

Instantly share code, notes, and snippets.

@akramarev
Created August 22, 2025 22:04
Show Gist options
  • Select an option

  • Save akramarev/1effcb732c1537c5b6b7fc50808cf5a4 to your computer and use it in GitHub Desktop.

Select an option

Save akramarev/1effcb732c1537c5b6b7fc50808cf5a4 to your computer and use it in GitHub Desktop.
[Subscription replication slot lag in Postgres]
SELECT
slot_name,
plugin,
slot_type,
active,
restart_lsn,
confirmed_flush_lsn,
pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) as lag_size_raw,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)) AS lag_size,
age(xmin) AS xmin_age
FROM pg_replication_slots
-- WHERE pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) > 3010425240
-- WHERE active = false
ORDER BY pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment