Dear Readers,
In this article, we will see the following Oracle (SecureCRT) : Important Queries for UNDO Management.
MenuBar : UNDO
Tab Name : Undo_Usage
1 2 |
set linesize 200 pagesize 200 compute sum of "Total Space in GB" on report |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
select tablespace_name, status segment_status, count(extent_id) "Extent Count", sum(blocks) "Total Blocks", sum(blocks)*8/(1024) "Total Space in MB" from dba_undo_extents group by tablespace_name, status order by tablespace_name / TABLESPACE_NAME SEGMENT_S Extent Count Total Blocks Total Space in MB ------------------------------ --------- ------------ ------------ ----------------- UNDOTBS1 EXPIRED 173 10264 80.1875 UNDOTBS1 UNEXPIRED 68 5944 46.4375 UNDOTBS2 EXPIRED 177 9816 76.6875 UNDOTBS2 UNEXPIRED 76 6608 51.625 |
Tab Name : Undo_Contetion
1 2 3 4 |
SET TERMOUT OFF; COLUMN current_instance NEW_VALUE current_instance NOPRINT; SELECT rpad(instance_name, 17) current_instance FROM v$instance; SET TERMOUT ON; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
PROMPT PROMPT +------------------------------------------------------------------------+ PROMPT | Report : Undo Contention | PROMPT | Instance : ¤t_instance | PROMPT +------------------------------------------------------------------------+ SET ECHO OFF SET FEEDBACK 6 SET HEADING ON SET LINESIZE 180 SET PAGESIZE 50000 SET TERMOUT ON SET TIMING OFF SET TRIMOUT ON SET TRIMSPOOL ON SET VERIFY OFF CLEAR COLUMNS CLEAR BREAKS CLEAR COMPUTES COLUMN instance_name FORMAT a10 HEAD 'Instance' COLUMN class FORMAT a18 HEADING 'Class' COLUMN ratio HEADING 'Wait Ratio' BREAK ON instance_name SKIP 2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
SELECT i.instance_name instance_name , w.class class , ROUND(100*(w.count/SUM(s.value)),8) ratio FROM gv$instance i , gv$waitstat w , gv$sysstat s WHERE i.inst_id = w.inst_id AND i.inst_id = s.inst_id AND w.class IN ( 'system undo header' , 'system undo block' , 'undo header' , 'undo block' ) AND s.name IN ('db block gets', 'consistent gets') GROUP BY i.instance_name , w.class , w.count ORDER BY i.instance_name , w.class; Instance Class Wait Ratio ---------- ------------------ ---------- ORCL11 system undo block 0 system undo header 0 undo block .0001595 undo header .0002848 ORCL12 system undo block 0 system undo header 0 undo block .00018723 undo header .00030043 |
Tab Name : Undo_Trend_Today
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
set linesize 300 SELECT TO_CHAR(BEGIN_TIME, 'MM/DD/YYYY HH24:MI:SS') BEGIN_TIME, TO_CHAR(END_TIME, 'MM/DD/YYYY HH24:MI:SS') END_TIME, UNDOTSN, UNDOBLKS, TXNCOUNT, MAXCONCURRENCY AS "MAXCON", MAXQUERYLEN, TUNED_UNDORETENTION FROM v$UNDOSTAT WHERE rownum <= 144; Instance Class Wait Ratio ---------- ------------------ ---------- ORCL11 system undo block 0 system undo header 0 undo block .0001595 undo header .0002848 ORCL12 system undo block 0 system undo header 0 undo block .00018723 undo header .00030044 |
Tab Name : Undo_Usage_For_Sessions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
set linesize 300 set pagesize 300 col sid_serial for a30 SELECT TO_CHAR(s.sid)||','||TO_CHAR(s.serial#) sid_serial, NVL(s.username, 'None') orauser, s.program, r.name undoseg, t.used_ublk * TO_NUMBER(x.value)/1024||'K' "Undo" FROM sys.v_$rollname r, sys.v_$session s, sys.v_$transaction t, sys.v_$parameter x WHERE s.taddr = t.addr AND r.usn = t.xidusn(+) AND x.name = 'db_block_size'; |
Tab Name : Uncommited_Tran’s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
SET TERMOUT OFF; COLUMN current_instance NEW_VALUE current_instance NOPRINT; SELECT rpad(instance_name, 17) current_instance FROM v$instance; SET TERMOUT ON; PROMPT PROMPT +------------------------------------------------------------------------+ PROMPT | Report : Uncommited Transactions | PROMPT | Instance : ¤t_instance | PROMPT +------------------------------------------------------------------------+ SET ECHO OFF SET FEEDBACK 6 SET HEADING ON SET LINESIZE 180 SET PAGESIZE 50000 SET TERMOUT ON SET TIMING OFF SET TRIMOUT ON SET TRIMSPOOL ON SET VERIFY OFF CLEAR COLUMNS CLEAR BREAKS CLEAR COMPUTES COLUMN sid FORMAT 999999 HEADING 'SID' COLUMN serial_id FORMAT 99999999 HEADING 'Serial ID' COLUMN session_status FORMAT a9 HEADING 'Status' COLUMN oracle_username FORMAT a18 HEADING 'Oracle User' COLUMN os_username FORMAT a18 HEADING 'O/S User' COLUMN os_pid FORMAT a8 HEADING 'O/S PID' COLUMN session_program FORMAT a30 HEADING 'Session Program' TRUNC COLUMN session_machine FORMAT a30 HEADING 'Machine' TRUNC COLUMN number_of_undo_records FORMAT 999,999,999,999 HEADING "# Undo Records" COLUMN used_undo_size FORMAT 999,999,999 HEADING "Used Undo (MB)" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
SELECT s.sid sid , s.status session_status , s.username oracle_username , s.osuser os_username , p.spid os_pid , b.used_urec number_of_undo_records , (b.used_ublk * d.value)/1024/1024 used_undo_size , s.program session_program , s.machine session_machine FROM v$process p , v$session s , v$transaction b , v$parameter d WHERE b.ses_addr = s.saddr AND p.addr (+) = s.paddr AND s.audsid <> userenv('SESSIONID') AND d.name = 'db_block_size'; SID Status Oracle User O/S User O/S PID # Undo Records Used Undo (MB) Session Program Machine ------- --------- ------------------ ------------------ -------- ---------------- -------------- ------------------------------ ------------------------------ 1581 INACTIVE SCOTT scottos 45354 2 0 scott-00000c server04 299 ACTIVE SCOTT scottos 15569 1 0 scott-000019 server05 |
Tab Name : UndoFree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SELECT d.tablespace_name,a.maxbytes/1048576 as max_total_mb, round(((NVL(f.bytes,0) + (a.maxbytes - a.bytes))/1048576+ u.exp_space),2) as max_free_mb, round(((a.bytes - (NVL(f.bytes,0)+ (1024*1024*u.exp_space)))*100/a.maxbytes),2) used_pct FROM sys.dba_tablespaces d, (select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a, (select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f , (select tablespace_name , sum(blocks)*8/(1024) exp_space from dba_undo_extents where status NOT IN ('ACTIVE','UNEXPIRED') group by tablespace_name) u WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+) AND d.tablespace_name=u.tablespace_name AND d.contents = 'UNDO' AND u.tablespace_name = (select UPPER(value) from v$parameter where name = 'undo_tablespace'); TABLESPACE_NAME MAX_TOTAL_MB MAX_FREE_MB USED_PCT ------------------------------ ------------ ----------- ---------- UNDOTBS2 58350 57737.75 1.05 |
Thank you for giving your valuable time to read the above information.
Follow us on
Website : www.ktexperts.com
Facebook Page : KTexperts
Linkedin Page : KT EXPERTS
Follow Me
Linkedin : Venkat Vinod Kumar Siram
Note: Please test scripts in Non Prod before trying in Production.