How to Check PostgreSQL Status Quickly and Easily
To check the status of your
PostgreSQL server, use the command systemctl status postgresql on Linux systems with systemd. Alternatively, you can run pg_isready to test if the server is accepting connections.Syntax
There are two common ways to check PostgreSQL status:
systemctl status postgresql: Shows if the PostgreSQL service is running on Linux systems using systemd.pg_isready: Checks if the PostgreSQL server is ready to accept connections.
bash
systemctl status postgresql pg_isready
Example
This example shows how to check PostgreSQL status using systemctl and pg_isready. The first command shows detailed service status, and the second confirms if the server is ready for connections.
bash
systemctl status postgresql pg_isready
Output
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2024-06-14 10:00:00 UTC; 1h 30min ago
/postgresql:5432 - accepting connections
Common Pitfalls
Common mistakes when checking PostgreSQL status include:
- Running
systemctlcommands without proper permissions (usesudoif needed). - Assuming
pg_isreadyoutput means the server is fully operational; it only checks connection readiness. - Using service names incorrectly; some systems use
postgresql@version-maininstead of justpostgresql.
bash
sudo systemctl status postgresql # Wrong: systemctl status postgres # Right: sudo systemctl status postgresql
Quick Reference
| Command | Description |
|---|---|
| systemctl status postgresql | Shows detailed status of PostgreSQL service on Linux with systemd |
| pg_isready | Checks if PostgreSQL server is accepting connections |
| sudo systemctl start postgresql | Starts the PostgreSQL service |
| sudo systemctl stop postgresql | Stops the PostgreSQL service |
| sudo systemctl restart postgresql | Restarts the PostgreSQL service |
Key Takeaways
Use
systemctl status postgresql to check if the PostgreSQL service is running on Linux.Use
pg_isready to test if PostgreSQL is ready to accept connections.Run service commands with
sudo if you get permission errors.Service names may vary; check your system's exact PostgreSQL service name.
pg_isready only checks connection readiness, not full server health.