To monitor the temporary Segment Usage
SELECT 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
FROM 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;
To monitor the temporary storage usage per session
SELECT S.sid , S.serial#, S.username, S.osuser, P.spid,
S.module, P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used,
T.tablespace, COUNT(*) statements
FROM v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE T.session_addr = S.saddr
AND S.paddr = P.addr
AND T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY sid, serial#;
To monitor the Temporary storage usage per statement
SELECT S.sid , S.serial#, S.username, Q.hash_value, Q.sql_text,
T.blocks * TBS.block_size / 1024 / 1024 mb_used, T.tablespace
FROM v$sort_usage T, v$session S, v$sqlarea Q, dba_tablespaces TBS
WHERE T.session_addr = S.saddrAND T.sqladdr = Q.address
AND T.tablespace = TBS.tablespace_name
ORDER BY S.sid;
Thanks
Friday, April 10, 2009
Subscribe to:
Post Comments (Atom)
2 comments:
Vinod,
Very nice post, after read it i just need to identify when the database actually need to use the temporary tablespace and when it use the pga to do sorts.
Therefore I realize that the second query need to do some little correction in the order by clause.
Thanks!
Caio Spadafora,
Thanks for pointing out the mistake.
Post a Comment