Wednesday, February 27, 2013

Used/Free space in a tablespace Oracle

SELECT 
df.tablespace_name "Tablespace",
df.bytes / (1024 * 1024) "Size (in MB)",
SUM(fs.bytes) / (1024 * 1024) "Free (in MB)",
Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free Space",
Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used Space"
FROM 
dba_free_space fs,
(
SELECT 
tablespace_name
,SUM(bytes) bytes
FROM 
dba_data_files
GROUP BY 
tablespace_name
) df
WHERE 
fs.tablespace_name (+) = df.tablespace_name
GROUP BY 
df.tablespace_name,df.bytes
UNION ALL
SELECT 
df.tablespace_name tspace,
fs.bytes / (1024 * 1024),
SUM(df.bytes_free) / (1024 * 1024),
Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1),
Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes)
FROM
dba_temp_files fs,
(
SELECT 
tablespace_name
,bytes_free,bytes_used
FROM 
v$temp_space_header
GROUP BY tablespace_name,bytes_free,bytes_used
) df
WHERE 
fs.tablespace_name (+) = df.tablespace_name
GROUP BY 
df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used
ORDER BY 4 DESC;



Query 2 

col "Tablespace" for a22
col "Used MB" for 99,999,999
col "Free MB" for 99,999,999
col "Total MB" for 99,999,999

select 
df.tablespace_name "Tablespace",
totalusedspace "Used MB",
(df.totalspace - tu.totalusedspace) "Free MB",
df.totalspace "Total MB",
round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))
"Pct. Free"
from
(
select 
tablespace_name,
round(sum(bytes) / 1048576) TotalSpace
from 
dba_data_files 
group by 
tablespace_name
) df,
(select 
round(sum(bytes)/(1024*1024)) totalusedspace
, tablespace_name
from 
dba_segments 
group by 
tablespace_name
) tu
where 
df.tablespace_name = tu.tablespace_name ;

4 comments:

  1. top 50 tables consume space

    SELECT * FROM
    (SELECT
    SUBSTR(TABLE_NAME, 1, 21) TABLE_NAME,
    NUM_ROWS,
    AVG_ROW_LEN ROWLEN,
    BLOCKS,
    ROUND((AVG_ROW_LEN + 1) * NUM_ROWS / 1000000, 0) NET_MB,
    ROUND(BLOCKS * (8000 - 23 * INI_TRANS) *
    (1 - PCT_FREE / 100) / 1000000, 0) GROSS_MB,
    ROUND((BLOCKS * (8000 - 23 * INI_TRANS) * (1 - PCT_FREE / 100) -
    (AVG_ROW_LEN + 1) * NUM_ROWS) / 1000000) "WASTED_MB"
    FROM DBA_TABLES
    WHERE
    NUM_ROWS IS NOT NULL AND
    PARTITIONED = 'NO' AND
    (IOT_TYPE != 'IOT' OR IOT_TYPE IS NULL)
    ORDER BY 7 DESC)
    WHERE ROWNUM <=50;

    ReplyDelete
  2. here is the query to get the space used by per schema/user in oracle database

    select owner, segment_type, tablespace_name, sum(bytes)/1024/1024 as Space_in_MB
    from dba_segments
    group by owner, segment_type, tablespace_name
    order by SPACE_IN_MB ;

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete

web stats