Skip to content

Instantly share code, notes, and snippets.

@muhammad-asn
Created October 23, 2025 10:43
Show Gist options
  • Select an option

  • Save muhammad-asn/801b1ae22358e7a63f645cf261bc6a16 to your computer and use it in GitHub Desktop.

Select an option

Save muhammad-asn/801b1ae22358e7a63f645cf261bc6a16 to your computer and use it in GitHub Desktop.
PG Replication Slot check
postgres> SELECT active_pid, slot_name,
         active,
         restart_lsn,
         confirmed_flush_lsn,
         ROUND(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) / 1024 / 1024, 2) AS lag_mb,
         ROUND(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) / 1024 / 1024 / 1024, 2) AS lag_gb
  FROM pg_replication_slots;
+------------+------------------------+--------+-------------+---------------------+----------+--------+
| active_pid | slot_name              | active | restart_lsn | confirmed_flush_lsn | lag_mb   | lag_gb |
|------------+------------------------+--------+-------------+---------------------+----------+--------|
| 21613      | slot_1                 | True   | 2/5B020978  | 2/85E32820          | 14773.86 | 14.43  |
| 21577      | slot_2                 | True   | 2/E8EC2170  | 2/E9ACF7A8          | 12503.23 | 12.21  |
| 21701      | slot_3                 | True   | 3/DC265E38  | 3/E1AAB4F0          | 8611.59  | 8.41   |
+------------+------------------------+--------+-------------+---------------------+----------+--------+
postgres> SELECT pid, usename, application_name, client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn
 FROM pg_stat_replication;
+-------+---------------+--------------------+--------------+---------+------------+------------+------------+------------+
| pid   | usename       | application_name   | client_addr  | state   | sent_lsn   | write_lsn  | flush_lsn  | replay_lsn |
|-------+---------------+--------------------+--------------+---------+------------+------------+------------+------------|
| 21701 | kafka_connect | Debezium Streaming | 10.110.25.45 | catchup | 4/191A540  | 3/FEFDDC20 | 3/F5879590 | 3/F5879590 |
| 21577 | kafka_connect | Debezium Streaming | 10.110.25.45 | catchup | 2/F5D95B80 | 2/F144F178 | 2/ED789370 | 2/ED789370 |
| 21613 | kafka_connect | Debezium Streaming | 10.110.25.45 | catchup | 2/88CF7468 | 2/7EFD9DE8 | 2/6784FD18 | 2/6784FD18 |
+-------+---------------+--------------------+--------------+---------+------------+------------+------------+------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment