PostgreSQLXVI · Observability, Logging and AlertingObservability
Alerting that is actionable
What you'll learn
- Distinguish alerts from dashboards by what each is for
- Write alerts that name a symptom and imply an action
- Choose thresholds from measurements taken in this course
- Avoid the alerts that reliably produce noise
Prerequisites
Verified against PostgreSQL 18.x · PostgreSQL (comparison targets) 17.11, 16.15 · PostgreSQL (support calendar) 18, 17, 16, 15, 14 supported · pgBackRest 2.59.1 · PgBouncer 1.25.2 · Patroni 4.1.5 · Ubuntu (host baseline) 26.04 LTS · 2026-08-27
Every view in this part can be graphed. Very few should page anyone.
The test
An alert is worth having if a human must do something and there is something they can do. Everything else is a dashboard.
| Alert | Dashboard | |
|---|---|---|
| Purpose | Someone must act now | Understanding, and investigation |
| Trigger | A symptom users feel, or a hard limit approaching | Anything |
| Failure | Nobody acts | Nobody looks — which is fine |
The alerts worth having
Grouped by what they mean.
The cluster is unavailable or about to be
-- can we connect and run a query at all?
SELECT 1;
- Connection failure. The most important alert, and it must not depend on the database’s own monitoring.
pg_walfilesystem above 75%. Lesson XII-03’s outage. Alert onpg_walseparately from the data directory.- Data filesystem above 85%.
- Connections above 80% of
max_connections. Lesson IV-02.
Replication is not protecting you
SELECT count(*) AS connected FROM pg_stat_replication;
- Fewer standbys connected than expected. Zero rows produces no alert from a naive aggregate — lesson XIV-04.
replay_lagabove the RPO. Measured baseline: 2.5 ms healthy, 30 s when replay was blocked.- Any slot with
wal_statusnotreserved, orsafe_wal_sizefalling. Lesson XIV-06 measured 56 MB → 28 MB → NULL. - Any inactive replication slot. Lesson XII-03’s classic outage.
Maintenance is failing
age(datfrozenxid)above 1 billion. Wraparound, lesson VIII-05. The autovacuum failsafe is at 1.6 billion by default, and the point of alerting at 1 billion is to act long before it.- Autovacuum not completing on a table for far longer than its churn implies.
pg_stat_archiver.failed_countincreasing, orlast_archived_timefalling behind. Lesson XIII-05.
Something is wrong with the data
checksum_failuresnon-zero. Ever. Part XVIII.deadlocksincreasing. Part IX.
Users are suffering
- Query latency at the application, which is the only measure that reflects what users experience.
temp_filesincreasing. Lesson XI-05.sessions_fatalorsessions_killedclimbing. Lesson XVI-03.
Alerts that reliably produce noise
Cache hit ratio below 99%. Lesson XVI-03: a page-cache hit counts as a miss, and a cluster doing large scans is healthy with a low ratio.
Any single slow query. One slow query is normal. A change in the rate of slow queries is a signal.
CPU above 80%. A database using the CPU it was bought for is working. Alert on what users experience instead.
Connection count above a fixed number, without reference to
max_connections or to what is normal.
Replication lag on an idle cluster. The lag columns are NULL, which is health — lesson XIV-04’s monitoring bug.
Disk usage above a fixed percentage on a volume that is meant to be full, such as a dedicated archive volume with retention.
What to take from this
- Alert when a human must act and can. Everything else is a dashboard.
- An alert that fires and needs no action is a bug in the alert.
- The list is short: availability, filesystem, connections, replication and slots, wraparound age, archiving, checksums, deadlocks, latency, temp files.
- Derive thresholds from your own baseline; use rates for cumulative counters.
- Known noise: cache hit ratio, single slow queries, CPU percentage, NULL lag on an idle cluster.
- Check from outside, from the host, and from inside — the outside check is the one usually missing.
- Add a dead-man’s-switch, or silence is indistinguishable from health.
Cross-course references
- Observability for Production Sysadmins — Part XVIII (Alerting rules), Part XX (Alert quality) and Part XXII (SLO-based alerting) cover the same discipline in depth: an alert that fires and needs no action is a defect in the alert.
- Linux for Production Sysadmins — Part LXVIII (Cluster incident response) covers what happens to a team that has learned to ignore a page.
Quiz
Knowledge check · 6 questions
Q1. An alert fires every night during a batch job. The team has learned to ignore it. What is the correct response?
Q2. Why can a monitoring agent running on the database host not be the only source of availability alerting?
Q3. Which of these is a well-known noise generator rather than a useful PostgreSQL alert?
Q4. Which alerts are worth paging someone for? Select all that apply.
Q5. Without a dead-man's-switch, silence from a monitoring system is indistinguishable from health.
Q6. How should thresholds be chosen, and why do published values so often produce noise?
Passing score: 75%. Answers are checked in this browser.