PostgreSQL error: No space left on device

ERROR:  could not extend file "base/16384/51829": No space left on device
HINT:  Check free disk space.

The filesystem hosting the database has no room left. Writes start failing; if the WAL itself cannot be written, the server will PANIC and shut down. One rule before anything else: never manually delete files inside the data directory — especially pg_wal. That path leads from an outage to a restore.

What this error means

Disk-full on a PostgreSQL host has a short list of usual suspects, and the most instructive one is WAL retention: pg_wal is self-cleaning under normal operation, so when it grows unbounded, something is telling PostgreSQL to keep WAL around. The two classic reasons: a failing archive_command (WAL cannot be recycled until archived) and an inactive replication slot — a replica that was decommissioned without dropping its slot keeps WAL pinned forever.

Common causes

How to diagnose it

# Dove sono finiti i GB:
df -h
du -sh /var/lib/postgresql/*/main/*   # base/ pg_wal/ log/ ...
-- Slot che trattengono WAL (guarda active=f e quanto trattengono):
SELECT slot_name, active,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal
FROM pg_replication_slots;

-- Query che scrivono troppi file temporanei (abilita log_temp_files per la storia):
SELECT datname, temp_files, pg_size_pretty(temp_bytes) FROM pg_stat_database;

How to fix it

🔍 Related reading: VACUUM & bloat — bloat inflates tables and indexes well past their live data size.