PostgreSQL Server Troubleshooting Guide
This guide walks you through the process of checking if your PostgreSQL server is running and how to restart it if needed.
Checking if PostgreSQL Server is Running
1. Check Network Connections
First, check if PostgreSQL is listening on its network socket by examining open connections:
ss -ntaup | grep postgres
This command shows all TCP connections and listening ports, filtering for PostgreSQL-related processes. You should see entries with port 5432 (PostgreSQL’s default port) if the server is running correctly.
2. Check PostgreSQL Cluster Status
For PostgreSQL installed via Debian/Ubuntu packages, you can check the status of your specific cluster:
pg_ctlcluster 16 main status
The output will tell you whether the cluster is running or stopped. Replace 16
with your PostgreSQL version if different.
3. Verify Database Connectivity
The pg_isready
utility provides a simple way to check if the PostgreSQL server is accepting connections:
sudo -u postgres /usr/lib/postgresql/16/bin/pg_isready
If the server is running and ready to accept connections, you’ll see output like:
/var/run/postgresql:5432 - accepting connections
Restarting PostgreSQL Server
If your PostgreSQL server isn’t running or is experiencing issues, you can restart it using one of these methods:
Method 1: Using pg_ctlcluster (for Debian/Ubuntu package installations)
sudo pg_ctlcluster 16 main restart
Method 2: Using systemd (modern Linux distributions)
sudo systemctl restart postgresql
or for version-specific service:
sudo systemctl restart postgresql@16-main
Method 3: Restarting PostgreSQL in Docker
If you’re running PostgreSQL in a lxc container:
Then restart the container
## Troubleshooting Common Issues
If PostgreSQL still won't start after attempting to restart:
1. Check the PostgreSQL logs:
```bash
sudo tail -n 100 /var/log/postgresql/postgresql-16-main.log
-
Verify PostgreSQL data directory permissions:
sudo ls -la /var/lib/postgresql/16/main
-
Ensure you have sufficient disk space:
df -h