One of the most basic administration task of Oracle DBA is to monitor the free space in tablespaces. Below script will give the total space allocated in megabytes, total used space in megabytes and how much percent of tablespace is free.
Here is the query:
select a.tablespace_name , A.Allocated "Total Space allocated", B.Freespace "Total Free space" , round(b.freespace/a.allocated*100) "% Free" from
(select tablespace_name ,sum(bytes)/1024/1024 Allocated from dba_data_files group by tablespace_name) A ,(select tablespace_name,sum(bytes)/1024/1024 Freespace
from dba_free_space group by tablespace_name) B
where a.tablespace_name=b.tablespace_name;
Example:
SQL> select a.tablespace_name , A.Allocated "Total Space allocated", B.Freespace "Total Free space" , round(b.freespace/a.allocated*100) "% Free" from
(select tablespace_name ,sum(bytes)/1024/1024 Allocated from dba_data_files group by tablespace_name) A ,(select tablespace_name,sum(bytes)/1024/1024 Freespace
2 3 from dba_free_space group by tablespace_name) B
where a.tablespace_name=b.tablespace_name;
4
TABLESPACE_NAME Total Space allocated Total Free space % Free
-------------------------- --------------------- ---------------- ----------
UNDOTBS1 30 23.375 78
SYSAUX 240 2.4375 1
USERS 5 1.9375 39
SYSTEM 480 7.125 1
EXAMPLE 100 31.75 32
ABC 25 24.8125 99
6 rows selected.
Here is the query:
select a.tablespace_name , A.Allocated "Total Space allocated", B.Freespace "Total Free space" , round(b.freespace/a.allocated*100) "% Free" from
(select tablespace_name ,sum(bytes)/1024/1024 Allocated from dba_data_files group by tablespace_name) A ,(select tablespace_name,sum(bytes)/1024/1024 Freespace
from dba_free_space group by tablespace_name) B
where a.tablespace_name=b.tablespace_name;
Example:
SQL> select a.tablespace_name , A.Allocated "Total Space allocated", B.Freespace "Total Free space" , round(b.freespace/a.allocated*100) "% Free" from
(select tablespace_name ,sum(bytes)/1024/1024 Allocated from dba_data_files group by tablespace_name) A ,(select tablespace_name,sum(bytes)/1024/1024 Freespace
2 3 from dba_free_space group by tablespace_name) B
where a.tablespace_name=b.tablespace_name;
4
TABLESPACE_NAME Total Space allocated Total Free space % Free
-------------------------- --------------------- ---------------- ----------
UNDOTBS1 30 23.375 78
SYSAUX 240 2.4375 1
USERS 5 1.9375 39
SYSTEM 480 7.125 1
EXAMPLE 100 31.75 32
ABC 25 24.8125 99
6 rows selected.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Script to calculate free tablespace considering maxsize clause.
WITH NEW_TBS AS
(
SELECT FILE_ID, TABLESPACE_NAME, FILE_NAME,
DECODE (AUTOEXTENSIBLE,
'YES', GREATEST (BYTES, MAXBYTES),
BYTES
) MYSIZE,
DECODE (AUTOEXTENSIBLE,
'YES', CASE
WHEN (MAXBYTES > BYTES)
THEN (MAXBYTES - BYTES)
ELSE 0
END,
0
) GROWTH
FROM DBA_DATA_FILES)
SELECT NEW_TBS.TABLESPACE_NAME,
ROUND (SUM (NEW_TBS.MYSIZE) / (1024 * 1024)) TOTSIZE,
ROUND (SUM (GROWTH) / (1024 * 1024)) GROWTH,
ROUND ((SUM (NVL (FREEBYTES, 0))) / (1024 * 1024)) DFS,
ROUND ((SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH)) / (1024 * 1024)
) TOTFREE,
ROUND ( (SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH))
/ SUM (NEW_TBS.MYSIZE)
* 100
) PERC
FROM NEW_TBS, (SELECT FILE_ID, SUM (BYTES) FREEBYTES
FROM DBA_FREE_SPACE
GROUP BY FILE_ID) DFS
WHERE NEW_TBS.FILE_ID = DFS.FILE_ID(+)
AND NEW_TBS.TABLESPACE_NAME NOT LIKE '%UNDOTB%'
GROUP BY NEW_TBS.TABLESPACE_NAME
ORDER BY 6
;
Also please find below more simpler scripts which just gives u tablespace details which matches following criteria:
Free space < 20 GB & Free percentage < 20 %
WITH NEW_TBS AS
(
SELECT FILE_ID, TABLESPACE_NAME, FILE_NAME,
DECODE (AUTOEXTENSIBLE,
'YES', GREATEST (BYTES, MAXBYTES),
BYTES
) MYSIZE,
DECODE (AUTOEXTENSIBLE,
'YES', CASE
WHEN (MAXBYTES > BYTES)
THEN (MAXBYTES - BYTES)
ELSE 0
END,
0
) GROWTH
FROM DBA_DATA_FILES)
SELECT * FROM
(SELECT 'TABLESPACE NAME:',NEW_TBS.TABLESPACE_NAME,
'FREE MB:', ROUND ((SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH)) / (1024 * 1024)) AS TOTFREE,
'FREE PERCENT:', ROUND ( (SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH))/ SUM (NEW_TBS.MYSIZE)* 100) AS PERC
FROM NEW_TBS, (SELECT FILE_ID, SUM (BYTES) FREEBYTES
FROM DBA_FREE_SPACE
GROUP BY FILE_ID) DFS
WHERE NEW_TBS.FILE_ID = DFS.FILE_ID(+)
AND NEW_TBS.TABLESPACE_NAME NOT LIKE '%UNDOTB%'
GROUP BY NEW_TBS.TABLESPACE_NAME) A
WHERE A.PERC < 20 AND A.TOTFREE < 20480
ORDER BY 6;
Script to calculate free tablespace considering maxsize clause.
WITH NEW_TBS AS
(
SELECT FILE_ID, TABLESPACE_NAME, FILE_NAME,
DECODE (AUTOEXTENSIBLE,
'YES', GREATEST (BYTES, MAXBYTES),
BYTES
) MYSIZE,
DECODE (AUTOEXTENSIBLE,
'YES', CASE
WHEN (MAXBYTES > BYTES)
THEN (MAXBYTES - BYTES)
ELSE 0
END,
0
) GROWTH
FROM DBA_DATA_FILES)
SELECT NEW_TBS.TABLESPACE_NAME,
ROUND (SUM (NEW_TBS.MYSIZE) / (1024 * 1024)) TOTSIZE,
ROUND (SUM (GROWTH) / (1024 * 1024)) GROWTH,
ROUND ((SUM (NVL (FREEBYTES, 0))) / (1024 * 1024)) DFS,
ROUND ((SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH)) / (1024 * 1024)
) TOTFREE,
ROUND ( (SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH))
/ SUM (NEW_TBS.MYSIZE)
* 100
) PERC
FROM NEW_TBS, (SELECT FILE_ID, SUM (BYTES) FREEBYTES
FROM DBA_FREE_SPACE
GROUP BY FILE_ID) DFS
WHERE NEW_TBS.FILE_ID = DFS.FILE_ID(+)
AND NEW_TBS.TABLESPACE_NAME NOT LIKE '%UNDOTB%'
GROUP BY NEW_TBS.TABLESPACE_NAME
ORDER BY 6
;
Also please find below more simpler scripts which just gives u tablespace details which matches following criteria:
Free space < 20 GB & Free percentage < 20 %
WITH NEW_TBS AS
(
SELECT FILE_ID, TABLESPACE_NAME, FILE_NAME,
DECODE (AUTOEXTENSIBLE,
'YES', GREATEST (BYTES, MAXBYTES),
BYTES
) MYSIZE,
DECODE (AUTOEXTENSIBLE,
'YES', CASE
WHEN (MAXBYTES > BYTES)
THEN (MAXBYTES - BYTES)
ELSE 0
END,
0
) GROWTH
FROM DBA_DATA_FILES)
SELECT * FROM
(SELECT 'TABLESPACE NAME:',NEW_TBS.TABLESPACE_NAME,
'FREE MB:', ROUND ((SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH)) / (1024 * 1024)) AS TOTFREE,
'FREE PERCENT:', ROUND ( (SUM (NVL (FREEBYTES, 0)) + SUM (GROWTH))/ SUM (NEW_TBS.MYSIZE)* 100) AS PERC
FROM NEW_TBS, (SELECT FILE_ID, SUM (BYTES) FREEBYTES
FROM DBA_FREE_SPACE
GROUP BY FILE_ID) DFS
WHERE NEW_TBS.FILE_ID = DFS.FILE_ID(+)
AND NEW_TBS.TABLESPACE_NAME NOT LIKE '%UNDOTB%'
GROUP BY NEW_TBS.TABLESPACE_NAME) A
WHERE A.PERC < 20 AND A.TOTFREE < 20480
ORDER BY 6;
No comments:
Post a Comment