How to get PostgreSQL uptime

There is not direct command to get the server uptime. We can get it by the difference of PostgreSQL server start time and current timestamp of PostgreSQL database.

Run the following query in psql or pgadmin tool.

select date_trunc('second',current_timestamp-pg_postmaster_start_time()) as uptime; Output uptime ---------- 19:02:47 (1 row)

To get current postgresql server time:

postgres=# select current_timestamp; now ------------------------------- 2017-05-13 04:39:05.675475-07

To get PostgreSQL server start time

postgres=# select pg_postmaster_start_time(); pg_postmaster_start_time ------------------------------- 2017-05-12 09:32:11.749947-07

Related Posts

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: