PostgreSQL system errors (error code 58000) indicate unforeseen issues external to the database itself, such as hardware failures, disk problems, or file system corruption. Diagnosing requires checking logs, verifying disk space, and testing system resources.
A PostgreSQL "System error" (class 58 error codes) represents problems that occur outside the database engine itself. These are typically caused by environmental factors like hardware faults, file system issues, insufficient disk space, or incorrect file permissions on the PostgreSQL data directory. Unlike application-level errors, system errors indicate that PostgreSQL cannot properly access or manage its underlying storage or system resources, which can threaten data integrity and availability.
Review the PostgreSQL server logs to identify the specific system error. Logs are typically located in /var/log/postgresql/ on Linux systems.
grep -i "system error" /var/log/postgresql/postgresql.log
grep -i "error" /var/log/postgresql/postgresql.log | tail -20The detailed error message will indicate whether the issue is related to disk I/O, permissions, file access, or other system resources.
Check that the PostgreSQL data directory has sufficient free space. PostgreSQL requires well over 20 MB free under /usr/local and at least 25 MB on the partition containing the data directory.
df -h /var/lib/postgresql
du -sh /var/lib/postgresql/mainIf disk space is low, delete old backups, logs, or temporary files, or expand the partition.
# Free up space by rotating old logs
postgresql-logrotateThe PostgreSQL data directory must be owned by the postgres user with permissions 0700 (owner access only).
ls -ld /var/lib/postgresql/mainThe output should show something like: drwx------ ... postgres postgres ...
If permissions are incorrect, fix them:
sudo chown -R postgres:postgres /var/lib/postgresql/main
sudo chmod 700 /var/lib/postgresql/mainIf PostgreSQL crashed and failed to shut down cleanly, the postmaster.pid file may prevent restart. Check if the process is truly gone before removing the file:
cat /var/lib/postgresql/main/postmaster.pid
ps aux | grep <PID from file>If the process is not running, safely remove the stale PID file:
sudo rm /var/lib/postgresql/main/postmaster.pid
sudo systemctl restart postgresqlPostgreSQL will attempt automatic recovery on the next start.
Use system monitoring tools to check for resource problems that could trigger system errors:
# Check disk I/O and errors
iostat -x 1
# Check memory usage
free -h
watch -n 1 free
# Check for filesystem errors
dmesg | grep -i error
fsck -n /dev/sdXX # (read-only check, safe to run)High I/O wait, memory pressure, or filesystem error messages in dmesg indicate hardware or system configuration problems.
If the logs show "database system was not properly shut down; automatic recovery in progress", PostgreSQL will handle recovery automatically on restart. Allow it to complete without interruption:
sudo systemctl start postgresql
sudo tail -f /var/log/postgresql/postgresql.logWait for logs to show the database is accepting connections before running queries. Recovery time depends on the number of incomplete transactions.
System errors can indicate serious hardware or filesystem issues. Consider running full hardware diagnostics (memory test with memtest86, disk tests with smartctl) if errors persist after basic troubleshooting. On Linux, check SELinux or AppArmor policies if you recently enabled enhanced security. For production systems, ensure you have WAL archiving and regular backups outside the primary data directory. PostgreSQL 9.6+ supports crash recovery more robustly; upgrading from very old versions may help. Always consult the PostgreSQL server logs and system logs (dmesg, journalctl) together to correlate database errors with system events.
insufficient columns in unique constraint for partition key
How to fix "insufficient columns in unique constraint for partition key" in PostgreSQL
ERROR 42501: must be owner of table
How to fix "must be owner of table" in PostgreSQL
trigger cannot change partition destination
How to fix "Trigger cannot change partition destination" in PostgreSQL
SSL error: certificate does not match host name
SSL error: certificate does not match host name in PostgreSQL
No SSL connection
No SSL connection to PostgreSQL