1

I have logical replication running among multiple PostgreSQL environments. I need to setup some alerting mechanism where I get an alert if one of my logical replication failed for whatever reason. How can I achieve that? I am aware of these Views, on which column can I use where class to catch the failure?

pg_stat_replication Pg_publication_tables Pg_replication_slots pg_stat_subscription pg_subscription_rel

Let me know, Thanks in advance !

1 Answers1

0

Use

SELECT max(pg_lsn_diff(
          pg_current_wal_lsn(),
          replay_lsn
       ))
FROM pg_stat_replication;

That will tell you how many bytes the most delayed standby server is behind.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • Should this also work for logical replication? On my Postgres 11 instance all columns except for pid, usesysid, usename, application_name ar null even though I have an active logical replication –  Oct 16 '20 at 12:32
  • I guess it is only for streaming replication. – Laurenz Albe Oct 16 '20 at 12:54