Thursday, December 3, 2015

How to find the TEMP Tablespace usage and who is using more TEMP Sapce

Query to check TEMP Tablespace usage:
==============================


 set pagesize 10000
 set linesize 200


SELECT   A.tablespace_name , D.mb_total TOTAL_MB,
         SUM (A.used_blocks * 8192) / 1024 / 1024 USED_MB,
         D.mb_total - SUM (A.used_blocks * 8192) / 1024 / 1024 FREE_MB,((SUM (A.used_blocks * 8192) / 1024 / 1024)/D.mb_total)*100 Percentage
FROM     gv$sort_segment A,
         (
         SELECT   c.tablespace_name,  SUM (C.bytes) / 1024 / 1024 mb_total
         FROM      dba_temp_files C  group by c.tablespace_name
         ) D
WHERE    A.tablespace_name = D.tablespace_name
GRoUP by A.tablespace_name, D.mb_total
having ROUND((SUM (A.used_blocks * 8192) / 1024 / 1024)*100/D.mb_total,2) >0;



Query to check who is using more TEMP space:
=====================================

set pagesize 10000
set linesize 200
column tablespace format a11 heading 'Tablespace Name'
column segfile# format 9,999 heading 'File|ID'
column spid format 9,999 heading 'Unix|ID'
column segblk# format 999,999,999 heading 'Block|ID'
column size_mb format 999,999,990.00 heading "Mbytes|Used"
column username format a22
column program format a25
column osuser format a14
column sid format 9999
column event format a30

select a.inst_id,b.tablespace,round(((b.blocks*8192)/1024/1024),2) size_mb,
        a.sid,a.serial#,c.spid,a.username,a.osuser,a.program,a.status,a.event,a.sql_id
from    gv$session a ,gv$sort_usage b ,gv$process c
where
    a.inst_id=b.inst_id
  and  a.inst_id=c.inst_id
  and  a.saddr = b.session_addr
  and  a.paddr=c.addr
  and round(((b.blocks*8192)/1024/1024),2)>100

 order by 3 desc;


No comments:

Post a Comment