Sunteți pe pagina 1din 2

SQL : temp tablespace usage

/*
The query below will display which sessions are using TEMP tablespace and how mu
ch space is
being used by each session:
*/
set pages 100
set lines 300
col tablespace for a20
col username for a15
col osuser for a10
SELECT b.TABLESPACE
, b.segfile#
, b.segblk#
, ROUND ( ( ( b.blocks * p.VALUE ) / 1024 / 1024 ), 2 ) size_mb
, a.SID
, a.serial#
, a.username
, a.osuser
, a.program
, a.status
FROM v$session a
, v$sort_usage b
, v$process c
, v$parameter p
WHERE p.NAME = 'db_block_size'
AND a.saddr = b.session_addr
AND a.paddr = c.addr
ORDER BY b.TABLESPACE, b.segfile#, b.segblk#, b.blocks;
/*
To see how much space is being used and free in TEMP tablespace run the followin
g sql:
*/
SELECT tablespace_name, SUM(bytes_used), SUM(bytes_free)
FROM v$temp_space_header
GROUP BY tablespace_name;
/*
Run the following statement to check the free space within the used portion of T
EMPFILE (if
you are running older version of Oracle and don't have tempfile you can replace
v$tempfile
with v$datafile):
*/
SELECT
FROM

A.tablespace_name tablespace, D.mb_total,


SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
v$sort_segment A,
(
SELECT B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
FROM
v$tablespace B, v$tempfile C
WHERE
B.ts#= C.ts#
GROUP BY B.name, C.block_size

) D
WHERE
A.tablespace_name = D.name
GROUP by A.tablespace_name, D.mb_total;

S-ar putea să vă placă și