oracle sql 表空間利用率

netwant發表於2019-07-22


SELECT nvl(t.name, 'CDB$ROOT') as DB_NAME,

D.TABLESPACE_NAME,

TOTAL_SPACE,

(SPACE - NVL(FREE_SPACE, 0)),

ROUND((SPACE - NVL(FREE_SPACE, 0)) / TOTAL_SPACE * 100, 2) ratio,

FREE_SPACE

FROM (SELECT TABLESPACE_NAME,

con_id,

ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,

ROUND(SUM(decode(maxbytes, 0, bytes, maxbytes)) /

(1024 * 1024),

2) TOTAL_SPACE,

SUM(BLOCKS) BLOCKS

FROM containers(DBA_DATA_FILES)

GROUP BY TABLESPACE_NAME, con_id) D,

(SELECT TABLESPACE_NAME,

con_id,

ROUND(SUM(BYTES) / (1024 * 1024), 2) FREE_SPACE

FROM containers(DBA_FREE_SPACE)

GROUP BY TABLESPACE_NAME, con_id) F,

v$pdbs t

WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)

and D.CON_ID = F.CON_ID

and F.con_id = t.CON_ID(+)

UNION ALL

SELECT nvl(t.name, 'CDB$ROOT') as DB_NAME,

D.TABLESPACE_NAME,

SPACE,

USED_SPACE,

ROUND(NVL(USED_SPACE, 0) / SPACE * 100, 2) ratio,

NVL(FREE_SPACE, 0)

FROM (SELECT TABLESPACE_NAME,

con_id,

ROUND(SUM(decode(maxbytes, 0, bytes, maxbytes)) /

(1024 * 1024),

2) SPACE,

SUM(BLOCKS) BLOCKS

FROM containers(DBA_TEMP_FILES)

GROUP BY TABLESPACE_NAME, con_id) D,

(SELECT TABLESPACE_NAME,

con_id,

ROUND(SUM(BYTES_USED) / (1024 * 1024), 2) USED_SPACE,

ROUND(SUM(BYTES_FREE) / (1024 * 1024), 2) FREE_SPACE

FROM containers(V$TEMP_SPACE_HEADER)

GROUP BY TABLESPACE_NAME, con_id) F,

v$pdbs t

WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)

and D.CON_ID = F.CON_ID

and F.con_id = t.CON_ID(+)

ORDER BY 1


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/309902/viewspace-2651323/,如需轉載,請註明出處,否則將追究法律責任。

相關文章