could not extend file: No space left on device
This error occurs when PostgreSQL runs out of disk space. Learn how to diagnose and prevent disk space issues.
The No space left on device error means PostgreSQL can't write because the disk is full.
Understanding the Error
ERROR: could not extend file "base/16384/12345": No space left on device
HINT: Check free disk space.
The disk or partition where PostgreSQL stores data is out of space.
Common Causes
1. Large Tables Growing
Tables growing faster than expected due to data volume.
2. WAL Files Accumulating
Write-ahead log files building up, often from replication lag.
3. Temp Files from Large Queries
SQL
4. Unvacuumed Dead Tuples
Dead rows not being cleaned up by autovacuum.
5. Log Files Growing
PostgreSQL logs filling up the disk.
How to Fix It
Solution 1: Check Disk Usage
BASH
Solution 2: Clean Up WAL Files
SQL
Solution 3: Vacuum Tables
SQL
Solution 4: Remove Unused Data
SQL
Solution 5: Move Data Directory
BASH
Solution 6: Configure Log Rotation
BASH
Monitoring Disk Space
SQL
Best Practices
- Monitor disk space with alerts at 80% threshold
- Configure autovacuum appropriately
- Implement data retention policies
- Use table partitioning for large tables
- Plan for growth with adequate disk space