0% found this document useful (0 votes)
77 views3 pages

Querry Tablespace

The document contains multiple SQL queries that retrieve data from Oracle database tables and views related to tablespaces, data files, free space, and historical tablespace usage. The queries return metrics such as tablespace and data file sizes, free space, and usage percentages to analyze and monitor tablespace storage usage and capacity over time.

Uploaded by

M Dico Priatama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views3 pages

Querry Tablespace

The document contains multiple SQL queries that retrieve data from Oracle database tables and views related to tablespaces, data files, free space, and historical tablespace usage. The queries return metrics such as tablespace and data file sizes, free space, and usage percentages to analyze and monitor tablespace storage usage and capacity over time.

Uploaded by

M Dico Priatama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

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 ;

select * from dba_segments


select * from dba_data_files
select * from dba_free_space

select *
--tablespace_name,
--used_percent
from
dba_tablespace_usage_metrics
where
used_percent > 90;

SELECT tablespace_name, sum(bytes), sysdate


FROM dba_free_space
GROUP BY tablespace_name;

select b.tablespace_name, tbs_size SizeMb, a.free_space FreeMb


from
(select tablespace_name, round(sum(bytes)/1024/1024 ,2) as free_space
from dba_free_space group by tablespace_name) a,
(select tablespace_name, sum(bytes)/1024/1024 as tbs_size
from dba_data_files group by tablespace_name
UNION
select tablespace_name, sum(bytes)/1024/1024 tbs_size
from dba_temp_files
group by tablespace_name ) b
where a.tablespace_name(+)=b.tablespace_name;

/* Formatted on 05/12/2016 12:03:21 (QP5 v5.139.911.3011) */


SELECT SUBSTR (A.tablespace_name, 1, 16) "Tablespace",
MAX (A.contents) "Type",
MAX (A.status) "Status",
( SUM (B.BYTES)
* COUNT (DISTINCT B.FILE_ID)
/ COUNT (B.FILE_ID)
/ 1024
/ 1024)
- (ROUND (SUM (C.BYTES) / 1024 / 1024 / COUNT (DISTINCT B.FILE_ID)))
"USED SIZE(Mb)",
TO_CHAR (
100
- ( SUM (C.BLOCKS)
* 100
* COUNT (B.FILE_ID)
/ (SUM (B.BLOCKS) * COUNT (DISTINCT B.FILE_ID)))
/ COUNT (DISTINCT B.FILE_ID),
'999.99')
|| '%'
"USED USAGE",
ROUND (SUM (C.BYTES) / 1024 / 1024 / COUNT (DISTINCT B.FILE_ID))
"FREE SIZE(MB)",
TO_CHAR (
( SUM (C.BLOCKS)
* 100
* COUNT (B.FILE_ID)
/ (SUM (B.BLOCKS) * COUNT (DISTINCT B.FILE_ID)))
/ COUNT (DISTINCT B.FILE_ID),
'999.99')
|| '%'
"FREE USAGE",
SUM (B.BYTES)
* COUNT (DISTINCT B.FILE_ID)
/ COUNT (B.FILE_ID)
/ 1024
/ 1024
"TOTAL SIZE(Mb)",
SYSDATE
FROM dba_tablespaces A, DBA_DATA_FILES B, DBA_FREE_SPACE C
WHERE A.TABLESPACE_NAME = B.TABLESPACE_NAME
AND A.TABLESPACE_NAME = C.TABLESPACE_NAME
AND A.TABLESPACE_NAME='APPS_TS_MEDIA'
GROUP BY A.TABLESPACE_NAME
ORDER BY 1;

/* Formatted on 05/12/2016 12:06:02 (QP5 v5.139.911.3011) */


SELECT NAME,
RTIME,
TABLESPACE_SIZE / 1024 / 1024,
TABLESPACE_MAXSIZE / 1024 / 1024,
TABLESPACE_USEDSIZE / 1024 / 1024
FROM dba_hist_tbspc_space_usage, v$tablespace
WHERE TABLESPACE_ID = TS#
AND NAME='APPS_TS_MEDIA'
ORDER BY 1, 2;

SELECT * FROM dba_hist_tbspc_space_usage


SELECT * FROM v$tablespace
SELECT * FROM dba_tablespaces

select
to_char(CREATION_TIME,'RRRR') year,
to_char(CREATION_TIME,'MM') month,
sum(bytes) Bytes
from
--ee code depot for full script
v$datafile
group by
to_char(CREATION_TIME,'RRRR'),
to_char(CREATION_TIME,'MM')
order by
1, 2;
select * from v$datafile

You might also like