disk full
Production Risk
A full disk halts all write operations including WAL generation. Without WAL writes the cluster cannot process any transactions. Streaming replicas will fall behind and may require a full base backup to resync. Immediate operator intervention is required; this is a Tier 3 production emergency.
The Postgres backend attempted to write data to disk (heap file, WAL segment, temporary file) and the operating system returned ENOSPC (no space left on device). All write operations fail until disk space is freed.
- 1Data directory (PGDATA) filesystem has no free space remaining
- 2WAL archive directory is full, blocking new WAL segment creation
- 3Temporary file directory (pgsql_tmp) is full due to large sort or hash operations
- 4A tablespace on a separate mount point is full
- 5Log file rotation is not configured and pg_log has grown unboundedly
A large INSERT or COPY operation fills the remaining disk space in the data directory.
-- Cannot be reliably triggered in SQL; requires the OS filesystem to be full. -- Diagnostics from psql: SELECT pg_size_pretty(pg_database_size(current_database())) AS db_size; -- Check WAL directory: SELECT count(*), pg_size_pretty(sum(size)) FROM pg_ls_waldir(); -- Check log directory: SELECT pg_size_pretty(sum(size)) FROM pg_ls_logdir();
expected output
ERROR: could not write to file "base/16384/1259": No space left on device
Fix 1
Free disk space immediately
WHEN As an emergency measure when Postgres cannot write anything.
-- OS-level steps: -- 1. du -sh /var/lib/postgresql/data/* to find large consumers -- 2. Rotate or truncate oversized log files -- 3. Remove old base backups from the backup directory -- Do NOT manually delete WAL files if archiving or replication is active. -- After freeing space, verify Postgres can write: CREATE TEMP TABLE _space_test (x INT); DROP TABLE _space_test;
Why this works
Postgres calls write()/pwrite() for all data file modifications. When the OS returns ENOSPC, the backend raises 53100. Freeing space on the filesystem allows subsequent write() calls to succeed without a Postgres restart for data writes. WAL-related failures may require pg_reload_conf() or a restart depending on severity.
Fix 2
Add a tablespace on a larger mount point
WHEN When the data volume is expected to grow and immediate space relief is needed.
CREATE TABLESPACE extra_space LOCATION '/mnt/large-disk/pgdata'; -- Move a large table to the new tablespace (acquires ACCESS EXCLUSIVE lock): ALTER TABLE large_table SET TABLESPACE extra_space;
Why this works
Tablespaces allow Postgres to store relation files on different filesystem paths. ALTER TABLE SET TABLESPACE rewrites the heap file to the new location. The operation is online but holds an ACCESS EXCLUSIVE lock for its duration.
✕ Delete files from PGDATA manually while Postgres is running
Deleting active heap or WAL files causes data corruption and may make the cluster unrecoverable.
✕ Delete WAL files manually when archiving or streaming replication is active
Replicas that have not consumed those segments become irrecoverably behind and require a full base backup to resync.
src/backend/storage/smgr/md.c — mdwrite()
Monitoring Disk Usage ↗Write-Ahead Logging ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev