Oracle 테이블스페이스 용량확인 스크립트
SELECT TABLESPACE_NAME,
TOTAL_BYTES,
USED_BYTES,
FREE_BYTES,
USED_RATE
FROM (SELECT X.TABLESPACE_NAME,
X.TOTAL_BYTES,
X.USED_BYTES,
X.FREE_BYTES,
X.USED_RATE
FROM (SELECT A.TABLESPACE_NAME TABLESPACE_NAME,
SUBSTR(To_Char(Round(A.TOTAL_BYTES/1024000), '999,999,999'),2,11)||' MB ('||
SUBSTR(To_Char(Round(A.TOTAL_BYTES/1024000000, 2), '990.99'),2,6) ||' GB)' TOTAL_BYTES,
SUBSTR(To_Char(Round((A.TOTAL_BYTES-B.FREE_BYTES)/1024000), '999,999,999'),2,11)||' MB ('||
SUBSTR(To_Char(Round((A.TOTAL_BYTES-B.FREE_BYTES)/1024000000,2), '990.99'),2,6) ||' GB)' USED_BYTES,
SUBSTR(To_Char(Round(B.FREE_BYTES/1024000), '999,999,999'),2,11)||' MB ('||
SUBSTR(To_Char(Round(B.FREE_BYTES/1024000000, 2), '990.99'),2,6) ||' GB)' FREE_BYTES,
SUBSTR(To_Char(Round((A.TOTAL_BYTES-B.FREE_BYTES)/A.TOTAL_BYTES*100,2), '90.99'),2,5)||'%' USED_RATE
FROM (SELECT TABLESPACE_NAME, Sum(BYTES) TOTAL_BYTES
FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME LIKE UPPER(DECODE('%','','%', '%'))
GROUP BY TABLESPACE_NAME
) A,
(SELECT TABLESPACE_NAME, Sum(BYTES) FREE_BYTES
FROM USER_FREE_SPACE
WHERE TABLESPACE_NAME LIKE UPPER(DECODE('%','','%', '%'))
GROUP BY TABLESPACE_NAME
) B
WHERE A.TABLESPACE_NAME = B.TABLESPACE_NAME
) X
ORDER BY DECODE('&TS_ORDER_BASE', '1', X.TABLESPACE_NAME, '', X.TABLESPACE_NAME, '2', X.USED_RATE) DESC
)
UNION ALL
SELECT '------------------------------ ' TABLESPACE_NAME,
'-------------------------- ' TOTAL_BYTES,
'-------------------------- ' USED_BYTES,
'-------------------------- ' FREE_BYTES,
'----------' USED_RATE
FROM DUAL
UNION ALL
SELECT '전체' TABLESPACE_NAME,
SUBSTR(To_Char(Round(A.TOTAL_BYTES/1024000), '999,999,999'),2,11)||' MB ('||
SUBSTR(To_Char(Round(A.TOTAL_BYTES/1024000000, 2), '990.99'),2,6) ||' GB)' TOTAL_BYTES,
SUBSTR(To_Char(Round((A.TOTAL_BYTES-B.FREE_BYTES)/1024000), '999,999,999'),2,11)||' MB ('||
SUBSTR(To_Char(Round((A.TOTAL_BYTES-B.FREE_BYTES)/1024000000,2), '990.99'),2,6) ||' GB)' USED_BYTES,
SUBSTR(To_Char(Round(B.FREE_BYTES/1024000), '999,999,999'),2,11)||' MB ('||
SUBSTR(To_Char(Round(B.FREE_BYTES/1024000000, 2), '990.99'),2,6) ||' GB)' FREE_BYTES,
SUBSTR(To_Char(Round((A.TOTAL_BYTES-B.FREE_BYTES)/A.TOTAL_BYTES*100,2), '90.99'),2,5)||'%' USED_RATE
FROM (SELECT Sum(BYTES) TOTAL_BYTES
FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME LIKE UPPER(DECODE('%','','%', '%'))
) A,
(SELECT Sum(BYTES) FREE_BYTES
FROM USER_FREE_SPACE
WHERE TABLESPACE_NAME LIKE UPPER(DECODE('%','','%', '%'))
) B
;
Select ts.tablespace_name, ts.status, ts.contents, ts.extent_management, ts.bigfile,
size_info.megs_alloc, size_info.megs_free, size_info.megs_used,
size_info.pct_free, size_info.pct_used, size_info.max
From
(
select a.tablespace_name,
round(a.bytes_alloc / 1024 / 1024) megs_alloc,
round(nvl(b.bytes_free, 0) / 1024 / 1024) megs_free,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used,
round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_Free,
100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_used,
round(maxbytes/1048576) Max
from ( select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible, 'YES',f.maxbytes,'NO', f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
( select f.tablespace_name,
sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name (+)
union all
select h.tablespace_name,
round(sum(h.bytes_free + h.bytes_used) / 1048576) megs_alloc,
round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 1048576) megs_free,
round(sum(nvl(p.bytes_used, 0))/ 1048576) megs_used,
round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) Pct_Free,
100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) pct_used,
round(sum(f.maxbytes) / 1048576) max
from sys.v_$TEMP_SPACE_HEADER h, sys.v_$Temp_extent_pool p, dba_temp_files f
where p.file_id(+) = h.file_id
and p.tablespace_name(+) = h.tablespace_name
and f.file_id = h.file_id
and f.tablespace_name = h.tablespace_name
group by h.tablespace_name
) size_info,
sys.dba_tablespaces ts
where ts.tablespace_name = size_info.tablespace_name
;
'1. IT Story > Scripts' 카테고리의 다른 글
ORACLE SCN HELTH CHECK (0) | 2019.02.17 |
---|---|
Mysql DB 기본 점검 스크립트 (0) | 2019.02.09 |
Oracle DBMS_SCHEDULER 백업 설정 스크립트 (0) | 2019.02.06 |
Oracle Hot Backup 스크립트 (0) | 2019.02.05 |
Oracle 권한확인 스크립트 (0) | 2019.02.03 |
Oracle SEGMENT STAT 조회 스크립트 (0) | 2019.01.29 |
Oracle 인덱스 정리 대상 추출 스크립트 (0) | 2019.01.28 |
Oracle DB의 OS 상태 조회 스크립트 (0) | 2019.01.27 |