Tuesday, May 6, 2008

Information about Temporary Segments.

A)The users who is Performing Sort operation in Temp Segments:
--------------------------------------------------------------------
SQL> SELECT b.tablespace,b.segfile#,b.segblk#,b.blocks,a.sid,a.serial#,a.username,a.osuser, a.status
FROM v$session a,v$sort_usage b
WHERE a.saddr = b.session_addr
ORDER BY b.tablespace, b.segfile#, b.segblk#, b.blocks;


TABLESPACE SEGFILE# SEGBLK# BLOCKS SID SERIAL# USERNAME OSUSER STATUS
----------- ------------- ---------- ---------- ---------- ---------- ------ ------ -------
TEMP 201 217865 748928 277 1185 PROD7 oracle ACTIVE


B)Information about Tablespace Containing sort Segments.

SQL> SELECT tablespace_name, extent_size, total_extents, used_extents,
free_extents, max_used_size
FROM v$sort_segment;


TABLESPACE_NAME EXTENT_SIZE TOTAL_EXTENTS USED_EXTENTS FREE_EXTENTS MAX_USED_SIZE
------------------------------- ----------- ------------- ------------ ------------ -------------
TEMP 128 11896 5851 6045 11322

Here,
Extent_size : size of one extent, in number of Oracle blocks
Total_extents: total number of extents in the segment (free or in use)
Used_extents : total number of extents currently in use
Free_extents : total number of extents currently marked as free
Max_used_size: maximum number of extents ever needed by an operation

C)If you want to keep interest of how much space is used in temporary segments then query as
,

SELECT EXTENT_SIZE*DB_BLOCK_SIZE*USED_EXTENTS/1024/1024/1024 "Space used in GigaByte" FROM v$sort_segment ;
If your database block size is 8192 (Query from select value from v$parameter where NAME='db_block_size';) then the space used by temp segments is ,

SQL>SELECT EXTENT_SIZE*8192*USED_EXTENTS/1024/1024/1024 "Space used in GigaByte" FROM v$sort_segment;
Space used in GigaByte
----------------------
11.6181641

From V$SORT_SEGMENT you can also query like,
SQL> SELECT TABLESPACE_NAME,EXTENT_SIZE,TOTAL_EXTENTS,USED_EXTENTS,FREE_EXTENTS,MAX_USED_BLOCKS,TOTAL_BLOCKS from V$SORT_SEGMENT;

TABLESPACE EXTENT_SIZE TOTAL_EXTENTS USED_EXTENTS FREE_EXTENTS MAX_USED_BLOCKS TOTAL_BLOCKS
---------- ----------- ------------- ------------ ------------ --------------- ------------
TEMP 128 11896 4526 7370 1449216 1522688


D)In order to know SQL ID and which type of Sort Segment issue,

SQL>SELECT USERNAME, SQLADDR,SQL_ID,TABLESPACE,SEGTYPE,EXTENTS,BLOCKS FROM V$TEMPSEG_USAGE;


USERNAME SQLADDR SQL_ID TABLESP SEGTYPE EXTENTS BLOCKS
------------ ---------------- ------------- ------- --------- ---------- ----------
SYSTEM 00000004129E28C0 b058ymxj1rvkg TEMP LOB_DATA 1 128
PROD7 0000000412E1C9F8 1t1v0wvyzwzuj TEMP SORT 5193 664704


E)To know which SQL is is using Temporary Segments query,
SQL> SELECT s.SQL_TEXT, t.USERNAME,t.TABLESPACE,t.SEGTYPE,t.BLOCKS,t.EXTENTS from V$SQL s, V$TEMPSEG_USAGE t WHERE t.SQL_ID=s.SQL_ID;

SQL_TEXT
------------------------------------------------------------------------------------
-------------------------------------------------------------
USERNAME TABLESP SEGTYPE BLOCKS EXTENTS
------------------------------ ------- --------- ---------- ----------
SELECT sql_id,sql_text from v$sql WHERE sql_id in (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10)
SYSTEM TEMP LOB_DATA 128 1

select * from user_activity order by ACTION,COOKIE_INFO
PROD7 TEMP SORT 36736 287

No comments:

Post a Comment