PostgreSQL disk full and WAL growth: what to do when pg_wal fills the disk
When pg_wal fills the volume, PostgreSQL can stop accepting writes, and the database may go down with it. The fix starts with finding out why WAL is being retained, not with deleting files from the directory. Every WAL segment left in pg_wal is there for a reason, and removing one by hand can break crash recovery, point-in-time recovery or a standby that is still catching up. Your first job is to identify which mechanism is holding the segments, then remove that cause so the server can recycle them on its own.
Write-ahead log (WAL) is the sequential record of every change PostgreSQL makes to its data files, written before the change itself is applied. After a crash, the server replays WAL to bring the data files back to a consistent state. Replication and point-in-time recovery depend on the same records: a standby applies WAL to stay current, and a restore replays archived WAL to reach a chosen moment. Normally the server recycles old segments once a checkpoint makes them unnecessary, so the directory stays within a predictable size. Growth beyond that means something is preventing recycling, and that is the situation this runbook covers.
Teams need this runbook when free space on the WAL volume is falling faster than expected, when the server logs archive or replication errors, or when the volume is already full and writes are failing. Confirm before you start which of your setups apply: whether archive_mode is on, whether archive_command is returning success, whether replication slots exist on the primary, and where your standbys and backups read from. Your vendor documentation and your own monitoring history will tell you which of these is in play. Read the continuous archiving documentation before changing any setting, because the archive and the WAL directory depend on each other.
Triage path from a full pg_wal volume to the cause
The path starts at the pg_wal directory on a volume that has run out of space, then checks four suspects in order: its size against free space, whether archive_command is failing, whether any replication slot is inactive or lagging, and whether a long-running transaction is holding back WAL recycling. Each check hands off to the next only when the previous one comes back clean. Only after a cause is identified does the path reach the fix, so the reader does not delete WAL files that the server still needs.
Four checks run in order before any WAL is removed.
Three causes behind most pg_wal growth
When pg_wal fills the disk, the cause is almost always a condition that stops PostgreSQL from recycling WAL segments. Failed archiving, inactive replication slots and old transactions or lagging standbys each hold WAL in a different way, so each needs its own check before anyone deletes anything.
Failed WAL archiving
When archive_command or archive_library returns an error, PostgreSQL keeps every segment it has not yet archived in pg_wal. Check the server log for repeated archive failure messages and inspect pg_stat_archiver for the last failed WAL name and failure time. Confirm that the archive destination has free space, that credentials still work and that the destination is reachable from the database host.
Inactive replication slots
A replication slot tells PostgreSQL to retain WAL until the consumer confirms it has read that WAL. A standby that is offline, a logical consumer that stopped or a slot left behind after a failed rebuild can hold WAL indefinitely. Query pg_replication_slots and look for slots with active set to false and a restart_lsn far behind the current WAL position. Confirm with the owner of each consumer before dropping any slot.
Long-running transactions
PostgreSQL cannot remove WAL that a long transaction may still need for recovery bookkeeping, and an open transaction also holds back cleanup of old row versions. Review pg_stat_activity for sessions whose xact_start is hours old, especially those in the idle in transaction state. Confirm which application or batch job opened the transaction and whether it can be stopped or retried safely.
Lagging standbys
With replication slots in use, a standby that falls behind keeps the primary from recycling WAL it has not yet received. Compare the primary's current WAL position with the replay position on each standby, and check standby logs for network, disk or apply errors. Confirm the expected lag for each standby and decide in advance whether a lagging standby should be repaired, rebuilt or detached.
Full archive or backup destination
An archive location can fill up even when archiving is configured correctly, and the failure then looks the same as an unreachable destination. Check free space and inode use on the archive volume, along with retention on any object store bucket used for archiving. Confirm which team owns that storage and whether its alerts reach the same people who respond to database alerts.
Safe cleanup steps when the disk is nearly full
This sequence frees enough space to keep PostgreSQL running, removes the cause of WAL growth, and confirms that checkpoints, WAL recycling and archiving have recovered. It is meant to be followed in order, with a check at each step before moving on.
Confirm the disk and WAL state before touching anything
The on-call DBA checks free space on the volume holding pg_wal, the size of the directory, and whether the server is still accepting writes. Run
df -hon the data volume,du -shon pg_wal, and note the current WAL segment count. Record the output in the incident log. The step is done when you know how much space remains and how much of it WAL is using, so later checks have a baseline.Free space with the least risky means first
Before any WAL removal, clear space that is safe to recover: remove old log files, temporary files and backup staging copies that you have verified are not needed. Do not delete files from pg_wal by hand. If the volume is still tight, confirm with the owner of the archive destination whether archived copies can be moved to larger storage. The step is done when the volume has enough headroom for the server to keep writing, which you confirm with
df -hand a test query that writes a small row.Check archiving status in pg_stat_archiver
Query
pg_stat_archiverand readlast_archived_wal,last_archived_time,failed_countandlast_failed_wal. A risingfailed_countwith a recentlast_failed_walmeans the archive command is failing, which is the most common cause of WAL growth. Check the server log for the error text from the archive command. The step is done when you know whether archiving is failing, stalled or working, and which WAL segment it is stuck on.Find stale replication slots and long transactions
Query
pg_replication_slotsfor slots withactiveset to false and comparerestart_lsnwith the current WAL position. Then querypg_stat_activityfor sessions withstateset to idle in transaction and for transactions with an oldxact_start. Both block WAL recycling. The step is done when you have a list of inactive slots and long transactions, each with the owning application or consumer identified.Fix the root cause with the owner of each consumer
Repair the archive destination so the archive command succeeds, and confirm with the storage team that the destination has space and access. For a stale replication slot, dropping it is irreversible for the consumer: the consumer loses its position and must be rebuilt from a new base backup, so confirm the drop with the team that owns that consumer before running
pg_drop_replication_slot. For a long transaction, ask the application owner to end it or terminate the backend withpg_terminate_backendonce they agree. The step is done when the owner has confirmed the action and it has been taken.Confirm checkpoints and WAL recycling resume
Run
CHECKPOINTonce the root cause is fixed and watchpg_walshrink or stop growing. Check the server log for checkpoint completion messages and confirm no new archive failures appear. Compare the WAL directory size with the baseline from the first step. The step is done when old segments are being recycled and the directory size is stable or falling, with no new errors in the log over a period you have agreed with the team.Verify archiving is current and record the incident
Re-query
pg_stat_archiverand confirmlast_archived_walis advancing,failed_countis no longer climbing, andlast_failed_walis no longer updating. Confirm that the most recent archived segment is recent enough for your point-in-time recovery plan. Record the causes, the owners who approved each action, and the commands run. The step is done when archiving is current and the incident record is complete.
What never to delete by hand from pg_wal
The first rule in a WAL emergency is that no one removes files from pg_wal by hand, even when the disk is full and the directory is the obvious culprit. The WAL segments in that directory are the record the server uses for crash recovery, and they are also the raw material for point-in-time recovery and for standbys that need to catch up. Deleting a segment the server still needs can leave the cluster unable to start, can break replay on a standby so it must be rebuilt, or can leave a gap that makes a restore stop short of the target time. Deleting files also bypasses the server's own bookkeeping about which segments are still required, so the damage may not show until the next restart or failover.
The same caution applies to the archive. Archived WAL files and the base backups they depend on form one chain, and a base backup is only useful together with every archived segment from its start point forward. Before pruning an archive location to free space, check which base backup is the oldest one you must still be able to restore, and confirm that the WAL needed to reach your recovery target is kept. Incremental backups add a further dependency, because pg_combinebackup needs the full backup and each incremental in sequence. Confirm your retention rules against your recovery point and recovery time targets, and record who approved any deletion. Note that a deleted archive copy cannot be recreated from the primary later.
The controlled tools are the server's own mechanisms and pg_archivecleanup, which removes WAL files older than a named segment and is meant for standby archive directories when paired with the correct restart point. Retention for the primary's own WAL is governed by server settings and by the state of replication slots and archiving, not by file deletion. Confirm the exact behavior, flags and supported procedure for your PostgreSQL version in the continuous archiving documentation and the vendor notes for your platform, and test any cleanup procedure on a copy before running it against production.
Which fix fits each cause
This table pairs each common cause of WAL growth with the signal that confirms it, the safe first action and the step to avoid. Read it top to bottom by checking the signal before acting, because the same symptom of a full pg_wal directory can come from different causes. The main takeaway is that the fix depends on the cause, and deleting WAL files by hand is never the fix.
| Cause | Signal to check | Safe action | What to avoid |
|---|---|---|---|
| Failed archiving | Failing archive_command in logs; pg_stat_archiver shows a growing failed_count and no recent archived file | Fix the archive destination or permissions, then confirm the archiver resumes and the backlog drains | Deleting unarchived WAL files, which breaks point-in-time recovery |
| Inactive replication slot | pg_replication_slots shows active set to false and a large retained WAL distance | Confirm with the consumer owner whether the slot is still needed, then restart the consumer or drop the slot if it is abandoned | Dropping a slot that a live subscriber or standby still needs, or removing WAL files under it |
| Lagging standby holding WAL | Replay lag or a slot's restart_lsn far behind the current position on the standby | Restore the standby's network or I/O capacity, then confirm lag falls and retained WAL shrinks | Turning off replication or removing the standby's WAL files while it is still catching up |
| Long-running or idle-in-transaction session | pg_stat_activity shows an old xact_start or a session in idle in transaction state | Identify the owning application and end the session with pg_terminate_backend after confirming impact | Restarting the whole server to clear it, or assuming a vacuum will free WAL that a session still pins |
| Archive destination out of space | Archive command errors citing no space, and the archive volume's free space is near zero | Free or expand the archive storage, then verify new archives are written and retained as planned | Filling the archive volume with unrelated data, or disabling archiving to keep the cluster running |
Alerts and settings that prevent a repeat
Archiving is the first thing to alert on, because a failing archive_command stops WAL segments from being recycled and the directory grows until the disk is full. PostgreSQL records the state of archiving in the pg_stat_archiver view, which shows the last archived WAL file, the count of failures and the time of the last failure. Alerting on the failure count and on the age of the last successful archive catches the problem while there is still time to act. Keep in mind that a command can return success while the destination is incomplete, so verify archived files against the destination as well.
- Failed archive count: alert when
failed_countinpg_stat_archiverincreases between checks. - Archive lag: alert when the time since
last_archived_timeexceeds the interval you expect from your own WAL generation rate. - Server log messages: match "archive command failed with exit code" and "archiver process" messages in the PostgreSQL log.
- Destination health: monitor the free space, credentials and reachability of the archive target, since the command depends on them.
- Archive directory growth: watch the number of files in
pg_walas an early indicator when archiving has stalled.
Confirm the exact column names and log text against the PostgreSQL version you run, and set the archive lag threshold from measured WAL output, not a generic figure.
Disk free space alerts are the safety net for every other cause. Set them on the volume that holds pg_wal, not only on the data volume, because a separate WAL volume can fill while the data disk has room. Use two levels: a warning that gives you time to find the cause, and a critical alert that pages someone. Thresholds should come from the size of the volume and the WAL generation rate you measure during normal and peak load, expressed as the number of hours of writes the free space can absorb.
- Free space warning: alert when free space falls below the hours of WAL generation you need to investigate and act.
- Free space critical: alert at a smaller margin that assumes an operator is already responding.
- Growth rate: alert on the rate of change of used space on the WAL volume, which catches fast growth before the absolute threshold is crossed.
- Trend during batch jobs: measure WAL generation during bulk loads and migrations, and schedule maintenance windows around them.
- Filesystem reserved blocks: check that the filesystem reserve does not hide free space from your monitoring.
Ask your storage or platform team to confirm the volume size and reserve behavior, and measure WAL generation from your own system before you set any numbers.
Replication slots keep WAL until every consumer confirms it has read it. An inactive slot, such as one left behind by a retired standby, a logical consumer that stopped, or a failed subscriber, retains WAL indefinitely. Alert on both the inactive state and the amount of WAL each slot holds, since an inactive slot with no retained WAL is a cleanup task while one that holds gigabytes of WAL is an emergency.
- Inactive slots: alert when any slot shows
activeas false for longer than your maintenance tolerance. - Retained WAL per slot: calculate the distance between the current WAL position and each slot's
restart_lsnand alert when it grows past a threshold you set. - Slot list changes: alert when a slot is created or dropped outside the change process, since unexpected slots often come from test tools or ad hoc subscriptions.
- Standby feedback: check that
hot_standby_feedbackis not holding back cleanup more than intended on long-running replicas. - Decommissioning checklist: require that retiring a replica or subscriber includes dropping its slot.
The pg_replication_slots view exposes these fields, but confirm the column names for your version. Decide the retained WAL threshold from the disk size and your generation rate.
A long transaction blocks cleanup of WAL and dead rows that it could still see, so it prevents the WAL that replication and archiving have finished with from being removed when the transaction is still open. The alert should identify the session that has been open too long, along with its state and age, so the on-call engineer can decide whether to end it. Long transactions and idle-in-transaction sessions are the usual application pattern behind this problem.
- Transaction age: alert when the oldest transaction in
pg_stat_activityexceeds the duration your workload normally needs. - Idle in transaction: alert on sessions in the
idle in transactionstate for longer than a set limit. - Session timeouts: consider
idle_in_transaction_session_timeoutas a guard so idle sessions end on their own, after confirming application behavior. - Log long statements: use
log_min_duration_statementto record slow statements in the log for later review. - Batch job tagging: set
application_nameon batch and migration jobs so alerts can name the owner.
Set the duration thresholds from the longest legitimate transaction in your workload, and confirm the timeout behavior with the application owners before enabling enforcement.
Operational and access considerations during an emergency
During a WAL emergency, the people who can drop slots, delete files and change archive settings determine whether the incident ends cleanly or creates a second one. The cards below cover who holds those permissions, how archive credentials and retention are governed, why ad hoc deletes are avoided, and how actions are recorded for review.
Limit who can drop replication slots
Dropping a replication slot is the fastest way to free retained WAL, and it is also irreversible for the consumer behind it. Restrict pg_drop_replication_slot and the superuser role to a short named list of on-call database administrators, and confirm in advance who owns each subscriber or standby that depends on a slot. Before anyone drops a slot, check its consumer, its restart_lsn and whether the consumer can be rebuilt.
Keep archive credentials under change control
When archive_command fails, the usual cause is a changed credential, bucket policy or network path on the archive target. Store archive write credentials in your secrets manager, give the database role write-only access, and route any change to them through a ticket with a named approver. Confirm that a rotation does not silently break archiving, because the failure only surfaces as a growing pg_wal directory.
Govern retention rules as configuration
Retention for base backups and archived WAL decides how far back point-in-time recovery can reach, so changes to it are a recovery decision, not a disk decision. Record the agreed recovery window, the backup tool's retention settings and the lifecycle rules on archive storage in one versioned document. Any change to those values should be reviewed against the recovery targets the business has agreed.
Avoid ad hoc deletes during incidents
Under disk pressure, engineers often remove files directly from pg_wal or from the archive directory. Deleting a WAL segment that a standby, a slot or a restore still needs can make the database unrecoverable or force a full rebuild. Make the emergency runbook the only permitted path, require a second person to confirm each destructive step, and log the command before it runs.
Use a written emergency runbook
A runbook gives the on-call team an ordered list of checks: confirm the cause, free space safely, restore archiving and verify recovery. Keep it in a location that survives the incident, such as a repository the team can read when the database host is full. Test it on a non-production cluster so that commands, paths and role names are known to work before a real emergency.
Record every action for review
A post-incident review depends on a timeline of what was observed and what was changed, with timestamps and the person responsible. Capture pg_stat_replication, pg_replication_slots and archiver status before and after each step, along with the commands run and the approvals given. Store the record outside the affected database host so that it remains available if the disk fills again.
Questions teams ask before hiring outside help
What drives the cost of an emergency pg_wal fix compared with planned hardening?
The main driver is how much of the work happens while the database is already failing. An emergency fix means diagnosing under pressure, freeing space without losing recoverable WAL, and restoring archiving or replication while the business waits. Planned hardening is scoped in advance: archive command reviews, slot cleanup rules, alert thresholds and a tested runbook. Ask any provider to split the quote into diagnosis, stabilization, root-cause repair and follow-up alerting, and to state which parts are one-time and which recur. Retainers cover ongoing review, not the original incident. Any quote should also say what happens if the cause turns out to be a separate problem, such as a wraparound risk or a stuck replica.
Can our own team handle a pg_wal disk full incident?
Often yes, if the team has shell access, reads PostgreSQL logs confidently and knows where its backups and archives live. The risk lies in the actions that look like cleanup but break recovery. Deleting files in pg_wal by hand can remove WAL that point-in-time recovery or a standby still needs. A team can handle the first response by checking the archive command, the replication slots and long-running transactions, then making a documented decision with a second engineer. Outside help is most useful when the team has no tested restore, when the primary is serving production traffic under pressure, or when the cause is unclear after the first checks.
What do you need from our team before the work starts?
Prepare access and evidence before anyone opens a ticket. The list usually includes:
- Shell access to the primary and standbys, with sudo rights for the postgres user or an approved path for a change
- PostgreSQL and archive logs covering at least the period when disk usage began to climb
- The current
archive_commandorarchive_librarysetting,max_wal_size,wal_keep_sizeand the output of the replication slot view - A backup inventory: base backup dates, archive retention, where archives are stored and whether a restore has been tested
- A change window for restarts, reloads or slot changes, and a named person who can approve each step
Also confirm which monitoring data exists, because disk history often explains the cause faster than logs.
How long does a pg_wal fix take?
Duration depends on the cause more than on the size of the server. A failed archive command with a working fix is usually the shortest path, because the fix is a configuration correction and a check that archives drain. A stale replication slot is usually quick to remove once you confirm the consumer is gone, but confirming that takes time. Long transactions require finding the application or job holding them, which can involve other teams. Wider root-cause work, such as reviewing archive storage capacity or rebuilding a standby, takes longer and depends on data volume and network speed. Ask for a time estimate broken down by cause, and for the conditions that would change it. No general duration is given here because none is supplied.
What does an alert and retainer review include after an incident?
A post-incident review should produce a written record of what filled the disk, the timeline of actions taken, and the changes made to configuration or monitoring. Alerts are normally set on WAL directory size, free space on the volume holding pg_wal, archiver failures in pg_stat_archiver, inactive replication slots and the age of the oldest transaction. Each alert should name an owner and a response step. A retainer review usually repeats these checks on a schedule, tests a restore, reviews slot and archive retention, and confirms alert thresholds still match data growth. Ask whether the review includes testing alerts with a simulated condition and who receives the notifications outside business hours.
Who is responsible for the database after the emergency is resolved?
Your organization keeps ownership of the database, its backups and its change decisions. Under a fixed-scope engagement, DeployOpen works from a written scope and delivers the agreed fixes, documentation and handover. Ongoing support, upgrades and continuous testing are available as retainers if you want them. Before work starts, agree who approves production changes, who holds backup credentials and who will run the alert response. Clear ownership prevents the same failure from returning when the engagement ends, for example when a new replication slot is created by a team that never saw the runbook.
Does the work involve access to our data, and how is that handled?
Yes, a pg_wal investigation can touch sensitive data because WAL records contain changes to database pages. Work happens inside your infrastructure, in your cloud accounts or data centers, so the data does not need to leave your environment. Ask for the access model in writing: which accounts are used, whether shared credentials are avoided, how commands are logged and when temporary access is revoked. If your data falls under a regulation or contract, check how the scope handles that before any logs or query output are shared. Keep copies of logs you send out of production systems to the minimum needed to diagnose the issue.
How DeployOpen scopes and supports WAL and disk recovery work
DeployOpen is a Chainscore Labs company that plans, implements, hardens, backs up and supports self-hosted open-source platforms, including PostgreSQL, inside infrastructure the client controls: their cloud accounts, data centers or air-gapped networks. For a WAL emergency, that means the database, its archive destination, its replicas and its monitoring all stay where your team can inspect them. DeployOpen does not need a copy of your data to work on the problem, and the work is scoped around your systems rather than a generic runbook.
Most engagements are fixed-scope, with the scope, deliverables and timelines agreed in writing before work starts. For a disk-full or WAL growth engagement, a written scope typically needs to name the systems in view (primary, standbys, archive target, replication slots, backup tooling and monitoring), the cleanup and root-cause work to be done, the alert rules and thresholds to be delivered, and who on your side approves changes to production. Ask any provider to state which items are included, which depend on access you provide, and which would be a separate change request. A quote should follow from that written scope, so compare proposals on the same list of systems and deliverables.
Retainers cover ongoing support and continuous review after the emergency is closed, such as periodic checks of archive health, slot activity, retention settings and alert coverage, plus help with upgrades and restore tests. Confirm with any provider what response expectations are written into the retainer, since no response times are published for this topic. Your own team keeps the decisions on what to delete, retain or reconfigure, and the written scope should record who holds each of those decisions.

