Writing
PostgreSQL and Barman: when WAL arrives but the backup is not recoverable
Two infrastructure incidents exposed dependencies between CIFS, archiving, retention, and metrics
Ready to read this content aloud.
“pg_receivewal is running.” That should be good news for a PostgreSQL backup strategy, but it is not sufficient evidence that a recovery point is ready.
I learned that distinction through real incidents involving PostgreSQL, Barman, and a separate backup-storage server accessed from the backup VM over SMB/CIFS. In one incident, storage disappeared after a network-boot configuration failure. In another, Barman continued receiving WAL while its archiving stage repeatedly failed on one segment. New backups lacked the WAL they needed, retention could not release older recovery points, and the repository ran out of space.
This article is a practical continuation of my layered backup strategy. Real hostnames, paths, capacity, WAL identifiers, and credential configuration are deliberately omitted.
Recovery requires more than a completed full backup
Consistent PostgreSQL recovery relies on two complementary chains:
- Base backup: a consistent starting representation of the database cluster.
- WAL: records needed to bring that base into a usable state and recover to points covered by the available chain.
Barman may receive WAL segments through streaming and process them into its archive catalog afterward. Retention determines which recovery points can be removed without violating configured protection. Those are distinct functions even when files occupy the same repository.
When receiving works but archiving does not, the pipeline is only partially healthy. A WAITING_FOR_WALS backup is not yet an available recovery point until its required segments become valid.
Incident 1: a reboot disconnected storage
Following a power interruption, the machine hosting the repository booted without applying its expected network address. The file-sharing service was unavailable, and the Barman VM lost access to the CIFS mount.
Three symptoms appeared unrelated:
- repository reads and updates failed;
- monitoring dashboards looked stable but stopped receiving fresh data;
- a later VM restart could not finish cleanly.
The last issue was not caused by the hypervisor itself. A WAL receiving process held the filesystem mount open during shutdown, so the operating system needed to stop that process before unmounting the network resource. The required service ordering had not been explicit.
The fix combined storage-network recovery, share availability, ordered shutdown, and controlled VM reboot tests. The repository and WAL streaming returned to their observed operating state, and a reboot exercise demonstrated that the mount could be released properly.
The trap of stale metrics from a running process
The Barman exporter exposed another failure mode. Its main process remained active according to the service manager, but the collection routine had stopped updating metrics after an exception.
A positive systemctl is-active tells us that a process exists, not how recently a useful sample was collected. The watchdog was updated to check expected metrics and their freshness rather than just HTTP 200.
A locale problem also surfaced during the fix: floating-point timestamps in scientific notation can be parsed incorrectly when scripts implicitly rely on regional decimal conventions. Setting a controlled numeric locale prevented false exporter restarts.
This is a general observability lesson: process health, telemetry freshness, and health of the monitored service are different signals.
Incident 2: WAL reception worked while archiving was blocked
During another incident, new base backups finished copying files but stayed in WAITING_FOR_WALS. The receive-wal process was running; this was not simply a loss of the database’s WAL stream.
The investigation followed the exact failing stage:
| Pipeline check | Observed condition |
|---|---|
| Streaming running | OK |
| WAL segments received | OK |
archive-wal on first queued segment | CIFS access error |
| New valid recovery points | No |
| Older valid backups retained | Yes |
| Available storage | Decreasing |
Archiving failed consistently when accessing the first queued segment through the CIFS filesystem, returning an invalid-argument file-operation error. Simple reads and writes elsewhere on the share succeeded.
That distinction mattered: there was no evidence of a general permissions, network, or disk failure. The reproducible failure centered on the blocking object along the storage path. After preserving evidence and repairing that object on the storage server, the archiver advanced through the backlog.
The investigation did not assert unsupported causes such as disk hardware failure, network congestion, or an application defect. The proven facts were the reproducible failing file access and successful queue recovery after a controlled correction.
Correct retention can still consume available capacity
While new backups were incomplete, they could not replace older valid recovery points. The redundancy policy had to preserve the required number of recoverable backups, resulting in older valid base backups, newer incomplete copies, and growing queued WAL coexisting on disk.
Deleting older full backups just to free space would have weakened recovery protection precisely when it was needed most. Retention did its job, while exposing inadequate capacity headroom for a prolonged archiving backlog.
A later full backup failed with ENOSPC. Reserved ext4 blocks for privileged users reduced the space available to the file service’s effective writer, even when free-space values viewed from different ends of the CIFS connection did not look identical.
The lesson was not to disable reserved blocks indiscriminately. It was to size the repository using space actually writable by the service identity, plus headroom for incomplete backups, WAL backlog, and retention behavior under failure.
Recovery order changed the outcome
A safe recovery workflow does not start with deleting random files to free disk space:
- Preserve evidence: inspect catalog states, logs, the first archiving error, and effective capacity.
- Protect valid points: do not remove older recoverable backups while replacements remain incomplete.
- Repair the confirmed dependency: restore network, mounts, file access, or the specific failed component.
- Reprocess WAL backlog: verify that archiving advances and errors stop recurring.
- Validate the chain: confirm that pending backups become usable and retention resumes.
- Check storage and telemetry: measure writeable space, metric freshness, and new failures.
In the documented incident, the backlog normalized, pending backups became valid, retention resumed, and Barman health checks passed. A controlled WAL transition was also observed from closure on PostgreSQL through reception and archiving.
That proves the repaired pipeline at that checkpoint. It does not automatically establish that a complete application restore will succeed on any later date.
Monitor pipeline stages rather than one service
A trustworthy dashboard should distinguish at least:
| Signal | Question answered |
|---|---|
receive-wal process state | Is the receiver active? |
| Last archived WAL age | Is archiving making progress? |
| Valid / waiting / failed backups | How many points can be used? |
archive-wal errors | Is one segment blocking the queue? |
| Backlog size and age | Is the incident accumulating? |
| Effective repository free space | Can the service identity still write? |
| Exporter metric age | Is the dashboard showing current data? |
| Latest restore exercise | Is there recovery evidence beyond a green status? |
That last item is essential. Catalog and streaming were revalidated during specific incidents. A later inventory confirmed active processes and timers, but did not recheck the entire catalog, retention behavior, or restore. An engineering article should preserve that distinction instead of converting historical results into ongoing guarantees.
Separate protection by database and application
As infrastructure expands, the existence of Barman protecting one production database does not mean that another PostgreSQL cluster is included automatically.
New applications on separate infrastructure require distinct decisions about backup methods, consistency, recovery windows, testing, and data ownership. In the reviewed baseline, the additional services cluster was not configured in Barman; onboarding had been explicitly deferred. It must not be described as protected by a mechanism not yet enabled.
The same boundary appears in the secure Django deployment case study: with several applications sharing database infrastructure, restoring the entire database VM might roll back legitimate writes from unrelated databases. Selective recovery and application-level consistency are separate requirements.
Backup security goes beyond RPO
A network-mounted repository concentrates availability, credentials, and modification access. Ransomware, operator mistakes, and storage failure can affect data and copies together unless the design includes appropriate trust boundaries.
As future requirements — not claims that these controls were already deployed — I would evaluate separated credentials, copies outside the primary failure domain, protected or immutable retention where feasible, WAL-specific alerts, isolated restore drills, and business-approved RPO/RTO definitions.
Recovery exercises should be isolated from the still-running production cluster.
Conclusion
These incidents changed what I consider a healthy backup. The latest full copy existing or receive-wal running is not enough. The system must demonstrate a valid WAL chain, writeable storage, functioning retention, current monitoring, and a testable restore path.
The central paradox was correct retention creating capacity pressure: it could not delete the last recoverable points because newer backups were still waiting for WAL. The solution was to repair archiving, not reduce protection for convenience.
A reliable backup routine is a recovery system with explicit dependencies — and those dependencies need to be observable before the next incident.