Take the opportunity to calculate the uptime for the database by subtracting the value of startup_time from the current date.
col platform_name format a30 col open_mode format a20 col host_name format a20 col version format a10 col status format a20 col uptime format a30 col name format a10 set lines 300 SELECT D.NAME,D.PLATFORM_NAME,D.CREATED, D.OPEN_MODE,I.HOST_NAME,I.VERSION, I.ARCHIVER,I.STATUS, TO_DSINTERVAL( TO_CHAR( TO_TIMESTAMP(SYSDATE)-I.STARTUP_TIME ) ) "UPTIME", (SELECT ROUND(SUM(BYTES)/1024/1024/1024) FROM DBA_DATA_FILES) "DB size GB", ( SELECT ROUND(BYTES/1024/1024/1024) "mem GB" FROM V$SGAINFO WHERE NAME = 'Maximum SGA Size' ) "SGA max size GB" FROM V$DATABASE D INNER JOIN V$INSTANCE I ON UPPER(D.NAME) = UPPER(I.INSTANCE_NAME);
Result may look like the following:
NAME | PLATFORM_NAME | CREATED | OPEN_MODE | HOST_NAME | VERSION | ARCHIVER | STATUS | UPTIME | DB size GB | SGA max size GB |
---|---|---|---|---|---|---|---|---|---|---|
proddb01 | Linux x86 64-bit | 10.12.2015 14:16:46 | READ WRITE | prodserver01.mycompany.com | 11.2.0.4.0 | STARTED | OPEN | +00 13:59:55.000000 | 929 | 12 |
Your query wont work with RAC databases, where instance names differ from database name.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteTry this for RAC:
ReplyDeleteSELECT (SELECT DB_UNIQUE_NAME FROM v$database) "DB Name",
HOST_NAME,
INSTANCE_NAME,
TO_CHAR (STARTUP_TIME, 'DD-MON-YYYY HH24:MI:SS') AS "Started At(CT)",
status,
(SELECT OPEN_MODE FROM v$database) "Open Mode",
logins,
database_status,
FLOOR (SYSDATE - STARTUP_TIME)
|| ' DAYS(S) '
|| TRUNC (
24
* ( (SYSDATE - STARTUP_TIME) - TRUNC (SYSDATE - STARTUP_TIME)))
|| ' HOUR(S) '
|| MOD (
TRUNC (
1440
* ( (SYSDATE - STARTUP_TIME) - TRUNC (SYSDATE - STARTUP_TIME))),
60)
|| ' MINUTE(S) '
|| MOD (
TRUNC (
86400
* ( (SYSDATE - STARTUP_TIME) - TRUNC (SYSDATE - STARTUP_TIME))),
60)
|| ' SECONDS'
UPTIME
FROM sys.V_$INSTANCE