In this article, we will see how to find the PostgreSQL server uptime. To find the PstgreSQL server uptime, we use PostgreSQL built-in function pg_postmaster_start_time(). Or by checking the time host and postgresql server start time.
Find the PostgreSQL server uptime
We can find the time difference between current_timestamp and pg_postmaster_start_time() to find the PostgreSQL server uptime.
Step1: Connect to the PostgreSQL server:
sudo su - postgres psql
step2: Run the following statement to find out the POstgreSQL server uptime.
select current_timestamp - pg_postmaster_start_time() as uptime;
Step3: We can also get PostgreSQL server uptime by comparing PostgreSQL server start time and current host start time.
Find the PostgreSQL start time by checking following command:
systemctl status postgresql-14
From the above output, it is clearing stating PostgreSQL server up from last 1 hour and 15 minutes.
Now check the host time: