Determine Database Uptime


Problem

Determine Database Uptime

There are a lot of system views from which you can pull a lot of information. There's of course one that tells you the uptime of your database.


Solution

Recipe #1 - Query v_$instance to get the uptime

SELECT host_name, 
       instance_name,
       TO_CHAR(startup_time, 'DD-MM-YYYY HH24:MI:SS') startup_time,
       FLOOR(sysdate-startup_time) days
FROM   sys.v_$instance;

This query will return some additional information like the host and database instance name as well as the number of days the database is running in the last column.

Recipe #2 - Query v$session to get database uptime

You'll often see articles telling you to query the session with SID 1, but this won't work everywhere. The following query seems to be more reliable, it checks the process with the name PMON, which is part of the database and reads its logon time:

SELECT TO_CHAR(logon_time, 'DD-MM-YYYY HH24:MI:SS')
FROM v$session 
WHERE program LIKE '%PMON%'

Comments




Please sign-in to post a comment