Checking replication to ensure availability

One of the core jobs of every administrator is to ensure that replication stays up and running at all times. If replication is down, it is possible that data could be lost if the master crashes. Therefore, keeping an eye on replication is absolutely necessary.

Fortunately, PostgreSQL provides system views, which allow us to take a deep look at what is going on. One of those views is pg_stat_replication:

\d pg_stat_replication                     View "pg_catalog.pg_stat_replication"      Column      | Type                     | Collation | Nullable | Default ------------------+--------------------------+-----------+----------+--------- pid              | integer                  |           |          |  usesysid         | oid                      |           |          |  usename          | name                     |           |          |  application_name | text                     |           |          |  client_addr | ...

Get Mastering PostgreSQL 12 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.