dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Home/Error Library/postgresql-wal-disk-full-no-space-left
PostgreSQL
PG 14 - 17Storage & WAL
12 min read
PANIC: could not write to file "pg_wal/..." No space left on device

PostgreSQL pg_wal Disk Exhaustion & Server Crash: Emergency WAL Evacuation & Resilient Storage Architecture

WAL accumulation due to failing archive_command or orphaned replication slots, emergency triage, and permanent max_slot_wal_keep_size safeguards.

Reviewed by:Senior Database Architect & SRE (dataiotech Labs)
Tested Versions: PostgreSQL 14 / 15 / 16 / 17

Operational Verification & Reliability Metadata

Last Technical Review: 2 Kasım 2026
Tested VersionsPostgreSQL 14.10, 15.6, 16.4, 17.11 (Alpine Linux / Ubuntu 24.04)
Required PrivilegesOS root/sudo and PostgreSQL SUPERUSER
Risk Assessment
CriticalBlindly deleting unarchived WAL segments causes permanent data corruption
Expected Outputpg_wal mount utilization dropping below 80% in df -h
Rollback Procedure:Expand WAL partition (LVM/EBS resize)
PostgreSQL Docs: WAL Configuration
First 60 Seconds Emergency Protocol:

The error string is a symptom, not the root cause. Do not restart the server blindly. Run the diagnostic queries below to pinpoint the actual failure mode.

▸Symptom

PostgreSQL aborts abruptly with a PANIC error:

plaintext
PANIC: could not write to file "pg_wal/xlogtemp.12345": No space left on device FATAL: the database system is in recovery mode

▸What You See in Production

The instance terminates instantly. Attempts to restart fail during recovery due to zero write capacity. df -h reveals 100% capacity on the WAL partition.


▸Root Cause Matrix

ProbabilityRoot CauseDescription
%55Archive Command FailureS3 or NFS target unreachable; PostgreSQL holds unarchived segments indefinitely.
%30Orphaned Replication SlotInactive replica keeps holding WAL retention threshold.
%15Checkpoint ThrottlingLarge batch operations exceeding WAL allocation thresholds.

▸EMERGENCY RUNBOOK (0-5 min)

CAUTION
**NEVER RUN rm -rf pg_wal/*!** Deleting pre-checkpoint WAL files corrupts the database cluster.
bash
# 1. Inspect filesystem and segments df -h ls -lh $PGDATA/pg_wal/ | wc -l # 2. Release emergency ballast file rm -f /var/lib/postgresql/emergency_disk_buffer.bin # 3. Check replication slots and drop offline slot psql -U postgres -c "SELECT slot_name, active FROM pg_replication_slots;" psql -U postgres -c "SELECT pg_drop_replication_slot('offline_replica_slot');"

▸PERMANENT BLUEPRINT

  1. 1Dedicated Mount Point: Isolate pg_wal on a dedicated partition (/pgwal).
  2. 2Retention Bounds: Configure max_slot_wal_keep_size = 32GB.
  3. 3Telemetry: Alert on pg_stat_archiver.failed_count > 0.

▸Verification

sql
SELECT count(*) AS total_wal_files, pg_size_pretty(count(*) * 16 * 1024 * 1024) AS total_wal_size FROM pg_ls_waldir(); SELECT archived_count, failed_count FROM pg_stat_archiver;

Other Database Error Triage Playbooks

Other battle-tested diagnostic guides for high-severity database errors.

All Errors (82)