Upgrades and observability
Overview
Plan major database upgrades in a test environment using compatible tools, extension and driver checks, a verified backup, a maintenance or cutover plan, and a rollback strategy that accounts for writes after cutover. PostgreSQL major upgrades may use dump/restore, pg_upgrade or suitable logical replication; minor and major upgrades have different requirements.
First example
SELECT SUM(requests),SUM(errors),ROUND(100.0*SUM(errors)/NULLIF(SUM(requests),0),2) FROM ad_metric;Observed SQLite result (rows in JSON):
[ [ 300, 5, 1.67 ]]How it works
Observe availability, request rate, latency distributions, error rates, saturation, lock waits, replication and backup freshness. ad_metric is synthetic interval data: sum errors and requests before computing an overall rate. Its latency_ms is an illustrative sample value, not a percentile or workload average. Compare baselines before and after migration; do not infer a production SLO from this dataset.
Practical example
PRAGMA user_version;Observed SQLite result (rows in JSON):
[ [ 0 ]]Practice and mistakes
Practice: calculate the weighted overall error percentage and inspect the schema version. Hint: use 100.0*SUM(errors)/NULLIF(SUM(requests),0). Check: about 1.67%. Mistake: averaging percentages without weights or treating a schema migration as an engine upgrade.
PostgreSQL 17 example — NOT RUN
SELECT current_setting('server_version'),numbackends,xact_commit,xact_rollback FROM pg_stat_database WHERE datname=current_database();Expected result, not executed: "Version and cumulative counters; sample differences over time, account for resets."