In this article, you will learn how to check database uptime in PostgreSQL. It evaluates its stability and performance.
Uptime refers to the length of time the database has been running without disruption since its last restart.
Follow the guide:
- PostgreSQL provides a built-in function called “pg_postmaster_start_time()” that returns the server’s start time. To calculate uptime, simply subtract this value from the current timestamp.
- Here’s the SQL query to recover the database uptime:
SELECT current_timestamp - pg_postmaster_start_time() AS up_time;
This will return the server uptime in a time interval format (hours, minutes, seconds).
- Example:
Let’s say the PostgreSQL server was started at 2:30 PM on March 15, 2025, and the current time is 2:52 PM. Running the uptime query would return:postgres=# SELECT current_timestamp - pg_postmaster_start_time() AS up_time; up_time ----------------- 00:21:45.389201 (1 row)
This indicates the server has been running for a little over 21 minutes.
Why It Matters?
Tracking uptime helps ensure your PostgreSQL server is running reliably. Regularly checking this metric can alert you to unexpected restarts or downtime, supporting better performance monitoring and system availability.
This way, you can check the database uptime in PostgreSQL. If you require additional assistance, feel free to contact our technical team.
Want to manage your PostgreSQL resources better? Learn How to decide the size of PostgreSQL databases and tables