Checking replication to ensure availability

One of the core jobs of every administrator is to ensure that replication stays up and running all the time. 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 you to take a deep look at what is going on. One of those views is pg_stat_replication:

test=# \d pg_stat_replication          View "pg_catalog.pg_stat_replication" Column            | Type                     | Modifiers-------------------+--------------------------+----------- pid               | integer                  | usesysid          | oid                      | usename           | name                     | application_name  | text                     | client_addr       | inet                     | client_hostname   | text                     | client_port | integer ...

Get Mastering PostgreSQL 10 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.