HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How can I get my server's uptime?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cangethowserveruptime

Problem

I am working with postgresql-9.4 and for support and monitoring tasks I need to know how long my server has been up for? Is there any function or way to know this? Is there an sql way to know when my server started?

I really need to know the elapsed time since it started?

Solution

Use the built-in function pg_postmaster_start_time

select current_timestamp - pg_postmaster_start_time() as uptime


More details in the manual: http://www.postgresql.org/docs/current/static/functions-info.html

If you want seconds, use extract:

select extract(epoch from current_timestamp - pg_postmaster_start_time()) as uptime

Code Snippets

select current_timestamp - pg_postmaster_start_time() as uptime
select extract(epoch from current_timestamp - pg_postmaster_start_time()) as uptime

Context

StackExchange Database Administrators Q#99428, answer score: 16

Revisions (0)

No revisions yet.