PostgreSQL Error 58000: System Error Fix Guide
In this article
PostgreSQL error 58000 means the server hit an operating-system-level failure and could not complete the request. The fix is almost never inside SQL itself: check the PostgreSQL server log for the underlying OS message, correct the disk, memory, permission, or file-descriptor problem it names, then restart the service. The steps below walk through that process in order.
What You'll Need
- Access to the PostgreSQL server host (SSH or local console) with permission to read the PostgreSQL log directory and restart the service.
- The PostgreSQL log file location. Common defaults are
/var/log/postgresql/on Debian/Ubuntu,/var/lib/pgsql/data/log/on RHEL-family systems, and thelog_directorysetting if it was changed. - Enough free disk space to write logs and let PostgreSQL create temporary files.
- Administrative access to the database (a superuser role) for read-only checks such as
SHOW data_directory;andSHOW log_directory;.
Step-by-Step
- Confirm the error is 58000 and capture the full message. In psql or your client, the error appears as
ERROR: 58000: ...followed by a system-level description. Copy the entire line, including the text after the code. That trailing text is the real clue; 58000 is only the class code for system errors. - Open the PostgreSQL server log. Find the newest log file in the directory shown by
SHOW log_directory;(relative to the data directory) or in the default path above. Search for the timestamp of the failure and for the string58000. The server log usually records the underlying OS error, such asNo space left on device,Too many open files,Permission denied, orCannot allocate memory. - Check free disk space and inodes. Run
df -handdf -ion the partition that holds the data directory and the log directory. If either is full, PostgreSQL cannot write WAL, temporary files, or logs, and 58000 is a common result. Free space by removing old logs or archives you no longer need, or move the archive destination. Do not delete files inside the data directory. - Check file-descriptor and process limits. If the log says
Too many open files, inspect the service limits withsystemctl show postgresql | grep -i limit(the unit name may bepostgresql,postgresql-16, or similar depending on version and distribution). RaiseLimitNOFILEin the service unit or the systemd drop-in, then reload systemd and restart PostgreSQL. Labels and unit names differ slightly by version, distribution, and region. - Check memory and the OOM killer. If the log mentions
Cannot allocate memoryor the process died abruptly, look atdmesgor the system journal for out-of-memory kills. Reduce memory-hungry settings such asshared_buffersorwork_memif they exceed what the host can provide, and confirm the host has swap or enough free RAM. - Verify ownership and permissions. The data directory must be owned by the PostgreSQL OS user and not readable by others. A
Permission deniedmessage after a restore, a move, or a backup often means ownership changed. Correct it withchown -R postgres:postgreson the data directory and the standard0700mode, then restart. Stop the service before changing ownership. - Restart the PostgreSQL service cleanly. Use
sudo systemctl restart postgresql(or the versioned unit name). Watch the log during startup for any remaining OS error. If startup fails, the log will name the file or resource that is blocking it. - Retry the original statement. If it succeeds, the cause was environmental and is now cleared. If it fails again with 58000, return to the log and compare the new message with the old one; a different OS error means a different root cause.
- Prevent recurrence. Set up log rotation, monitor disk and inode usage, and keep the service limits documented. For recurring memory errors, review
shared_buffers,work_mem, and connection counts against the host's capacity.
Common Mistakes
- Treating 58000 as a SQL syntax or data error. It is a system-level failure; rewriting the query will not help.
- Deleting files inside the data directory to free space. That can corrupt the cluster. Remove old logs or archives instead, and only with the service stopped if the files are in use.
- Changing ownership or permissions while PostgreSQL is running. Stop the service first, then correct ownership, then start it.
- Raising
work_memorshared_bufferswithout checking available RAM. That can trigger OOM kills and produce the same error again. - Ignoring inode exhaustion.
df -hcan show free space whiledf -ishows 100% used, which still blocks new files.
Tips
- Always read the text after the 58000 code first; it names the OS-level cause.
- Keep the PostgreSQL log on a separate partition from the data directory where possible, so a full data disk does not also silence logging.
- Use
SHOW data_directory;andSHOW log_directory;to confirm paths rather than assuming defaults. - Record the exact error text and timestamp before restarting, so you can compare after the fix.
Troubleshooting
If the log does not show a clear OS message, increase log verbosity temporarily by setting log_min_messages to debug1 in postgresql.conf, reload the configuration, and reproduce the error. Remember to revert the setting afterward.
If the service will not start after a disk-full event, free space first, then check for a stale postmaster.pid file in the data directory. Only remove it if no PostgreSQL process is running; confirm with ps aux | grep postgres. Removing it while the server is running can cause data corruption.
If the error persists after restart and the log points to a specific file, verify that file exists, is owned by the PostgreSQL user, and is not locked by another process. On systems with SELinux or AppArmor, check the audit log for denials affecting the data directory.
If you cannot resolve the OS-level cause, restore the most recent verified backup to a healthy host rather than repeatedly restarting a failing server. Test the restore on a separate instance first.
Frequently Asked Questions
What does PostgreSQL error 58000 mean?
It is the SQLSTATE class for system errors, meaning the server encountered an operating-system-level failure such as a full disk, permission problem, or resource limit.
Is 58000 caused by a bad query?
Usually not. The query may trigger it, but the root cause is environmental. Check the server log for the OS message.
Can I fix 58000 without restarting PostgreSQL?
Sometimes, if the cause is freed disk space or corrected permissions. A restart is the reliable way to clear stale resource state.
Where is the PostgreSQL log file?
It depends on the installation. Check SHOW log_directory; and the log_destination setting, or the default paths for your distribution.
Will restarting lose data?
A normal service restart does not lose committed data. Never delete files in the data directory to force a start.