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 11 - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.