0
0
PostgresqlHow-ToBeginner · 3 min read

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 systemctl commands without proper permissions (use sudo if needed).
  • Assuming pg_isready output means the server is fully operational; it only checks connection readiness.
  • Using service names incorrectly; some systems use postgresql@version-main instead of just postgresql.
bash
sudo systemctl status postgresql

# Wrong: systemctl status postgres
# Right: sudo systemctl status postgresql
📊

Quick Reference

CommandDescription
systemctl status postgresqlShows detailed status of PostgreSQL service on Linux with systemd
pg_isreadyChecks if PostgreSQL server is accepting connections
sudo systemctl start postgresqlStarts the PostgreSQL service
sudo systemctl stop postgresqlStops the PostgreSQL service
sudo systemctl restart postgresqlRestarts 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.