Wednesday, March 29, 2006

SQL query to obtain tablespace usage

Below are some queries to obtain the amount of space available as well as total size:

-- All size
select a.tablespace_name,
ROUND(a.bytes,2) "SIZE(MB)",
ROUND(a.maxbytes,2) "MAX SIZE(MB)",
ROUND(nvl(b.bytes,0),2) "FREE SPACE(MB)",
ROUND((a.bytes - nvl(b.bytes,0)),2) "USED(MB)",
ROUND((a.bytes - nvl(b.bytes,0))/a.bytes*100,2) "PCT USED"
-- ,ROUND((a.bytes - nvl(b.bytes,0))/a.maxbytes*100,2) "PCT MAX USED"
from (
select TABLESPACE_NAME,
sum(BYTES/(1024*1024)) bytes,
sum(decode(MAXBYTES,0,bytes,maxbytes)/(1024*1024)) maxbytes
from dba_data_files
group by TABLESPACE_NAME) a,
(
select TABLESPACE_NAME,
sum(BYTES/(1024*1024)) bytes
from dba_free_space
group by TABLESPACE_NAME) b
where a.tablespace_name=b.tablespace_name(+)
order by 1;

-- tablespace size
select tablespace_name, sum(bytes)/1024/1024 mbytes from user_segments
group by tablespace_name
order by 2 desc;

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home