skip to content

What does wal-g wal-verify check on a PostgreSQL WAL archive, and how do you act on an integrity FAILURE or a timeline FAILURE?

level: seniorimportance: should knowfreq 26%

answer

  1. two named checks
  2. oldest backup to current segment
  3. lost vs delayed vs uploading
  4. highest timeline in storage
  5. take a backup after the gap

basics

~20 s

wal-g wal-verify integrity checks that every WAL segment from the oldest backup's start to the current segment is in storage; timeline checks that no higher timeline exists there. An integrity FAILURE needs a fresh backup; a timeline FAILURE means another cluster writes there.

solid answer

~40 s

`wal-g wal-verify integrity timeline` runs two checks against the live PostgreSQL cluster. `integrity` scans segments from the oldest backup's start to the current segment and labels each `FOUND`, `MISSING_DELAYED`, `MISSING_UPLOADING` or `MISSING_LOST`; the result is `OK`, `WARNING` (only delayed or uploading gaps) or `FAILURE` (any lost segment). A lost segment means no backup older than the gap can recover past it, so find the cause (failed archiving, a bucket lifecycle rule, a manual delete) and run `backup-push` at once so a restorable chain starts after the gap. `timeline` fails when the highest timeline in storage differs from the cluster's, which usually means a promoted old primary or a restored copy is pushing to the same prefix: stop it and give each cluster its own prefix. Add `--json` and alert on the status fields.

code

console · 14 lines
console
$ wal-g wal-verify integrity timeline
[wal-verify] integrity check status: FAILURE
[wal-verify] integrity check details:
+-----+--------------------------+--------------------------+----------------+--------------+
| TLI | START                    | END                      | SEGMENTS COUNT | STATUS       |
+-----+--------------------------+--------------------------+----------------+--------------+
|   1 | 000000010000000000000010 | 00000001000000000000003F |             48 | FOUND        |
|   1 | 000000010000000000000040 | 000000010000000000000040 |              1 | MISSING_LOST |
|   1 | 000000010000000000000041 | 0000000100000000000000A2 |             98 | FOUND        |
+-----+--------------------------+--------------------------+----------------+--------------+
[wal-verify] timeline check status: OK
[wal-verify] timeline check details:
Highest timeline found in storage: 1
Current cluster timeline: 1

go deeper

for a junior

Remember the two checks, integrity and timeline, and that integrity looks for missing WAL segments since the oldest backup.

for a middle

Explain the four segment statuses and the OK, WARNING and FAILURE outcomes, and why the check needs a connection to the running cluster.

for a senior

Show how you respond to a lost segment: find the cause, take a backup-push at once, and treat a timeline FAILURE as two writers in one prefix.

for a principal

Design the alerting and the prefix-per-cluster convention so archive gaps and split brain are prevented or caught before anyone needs a restore.

## What wal-verify runs `wal-g wal-verify` takes a list of check names and connects to the running PostgreSQL cluster to learn its current WAL position and timeline: - `wal-g wal-verify integrity timeline` runs both checks. - `--json` switches the output from text tables to JSON, which is what you feed to alerting. - `--timeline` and `--lsn` check up to a given position instead, for example to prove a replica could be rebuilt from the archive; `--backup-name` starts the scan at one backup instead of the oldest. ## The integrity check `integrity` checks that every WAL segment in the range **from the oldest backup's start segment up to (not including) the current segment** is in storage. With no backups at all it scans from the first segment. Each segment gets one of four statuses: | Status | Meaning | |---|---| | `FOUND` | the segment is in storage | | `MISSING_DELAYED` | not in storage, but probably not yet handed to `archive_command`; the window is `WALG_INTEGRITY_MAX_DELAYED_WALS` (default 0) | | `MISSING_UPLOADING` | not in storage, but within the range that may still be uploading, sized from `WALG_UPLOAD_CONCURRENCY` | | `MISSING_LOST` | missing and neither of the above | The overall status is `OK` with nothing missing, `WARNING` when segments are missing but none is lost, and `FAILURE` as soon as one segment is `MISSING_LOST`. ## The timeline check `timeline` compares the cluster's current timeline with the highest timeline found in WAL storage: - `OK`: they match. - `WARNING`: WAL-G could not decide. - `FAILURE`: they differ. A higher timeline in storage than on the cluster you are running means **another server, promoted later, writes WAL into this prefix**: an old primary that was promoted during a failover drill, or a restored copy left pointing at production's bucket. That is the split-brain signal. The docs note the check only works if storage is fresh or cleaned after a restore or `pg_upgrade`, which is another argument for one prefix per cluster. ## Reading a FAILURE When `integrity` reports `MISSING_LOST`: 1. **Find the range.** The output groups segments by timeline and status; note the first and last lost segment. 2. **Find the cause.** Typical ones: `archive_command` was failing (credentials expired, environment lost after a container rebuild) and someone cleared `pg_wal` by hand; a bucket lifecycle or expiry rule deleted objects under `wal_005/`; a manual delete; `delete target` followed by `delete garbage` in the wrong order. 3. **Understand the damage.** Every backup that started before the gap can still be restored up to the gap, but not past it. Point-in-time recovery to any moment after the gap needs a base backup taken after it. 4. **Close the exposure.** Run `wal-g backup-push` immediately, then re-run `wal-verify integrity` once that backup's start segment is behind the current position. 5. **Remove the cause**, then keep the check scheduled. When `timeline` reports `FAILURE`, stop the second writer first, then move one of the clusters to its own `WALG_S3_PREFIX`; deleting WAL before you know which cluster is the real primary can destroy the only good copy. ## Checking a replica or one backup The default range answers "can every kept backup reach now?" Two narrower questions come up in practice: - **Could this replica be rebuilt from the archive?** Pass the replica's position with `--timeline` and `--lsn`, and `integrity` checks the segments up to that point instead of the primary's current one. - **Is this particular backup restorable to now?** Pass `--backup-name <name>`, and the scan starts at that backup's start segment, which is the question to ask before you rely on an older backup for a restore drill. ## Scheduling and alerting - Run `wal-g wal-verify integrity timeline --json` from the same scheduler that runs `backup-push`, at least daily. - Alert on `FAILURE` at once; treat a `WARNING` that persists across runs as a stuck archiver. - If archiving routinely trails by a few segments, raise `WALG_INTEGRITY_MAX_DELAYED_WALS` so normal lag shows as delayed instead of lost. - `wal-g wal-show` gives a per-timeline view of the same storage with the backups on each timeline, and reports `LOST_SEGMENTS` when it finds a gap. The server-side counters in `pg_stat_archiver` show whether `archive_command` is failing; `wal-verify` shows whether the archive is complete. You want both, because objects can vanish from storage long after PostgreSQL reported success.

  • wal-g wal-verify integrity reports WARNING on every run with a few MISSING_UPLOADING segments. Is that a problem?
    A single run, no: segments just behind the current one may still be uploading. The same gap on every run means archiving is stuck or slow. Check `pg_stat_archiver` for failures and the age of the newest object under `wal_005/`; if archiving simply trails a little, raise `WALG_INTEGRITY_MAX_DELAYED_WALS` so normal lag reads as delayed.
  • Why prefer one WAL-G prefix per PostgreSQL cluster when wal-verify can already detect timeline conflicts?
    Detection comes after the damage: by the time `timeline` fails, two servers have pushed WAL and history files into one namespace, and `delete retain` ordering can be wrong too. A separate prefix per cluster, per restore and per major version makes the conflict impossible instead of merely visible.

  • wal-verify only checks WAL written after the newest backup
  • A WARNING from wal-verify integrity means segments are lost
  • A lost segment is fixed by re-running wal-push for it later
  • A timeline FAILURE is harmless after any normal failover
  • pg_stat_archiver showing no failures proves the archive is complete