Oracle Blocking and Long running sessions troubleshooting
As an Oracle DBA this is one of the biggest challenge to identify the root cause of any performance issue. This article will help to kickstart the journey to begin the troubleshooting. I have seen hundreds of issues and thousands of questions being asked by the application and business team. I believe these set of queries will help you identify the root cause of the issue and fix it efficiently.
Note: This queries are drafted sequentially for my demo instance, before running in your environment, please check all the prerequisites. For major issues, please talk to Oracle Support for more customized issue finding.
Check for long running sessions:
select SID,SERIAL#,sql_id,username,TARGET,TOTALWORK,SOFAR,TIME_REMAINING/60 Mins_Remaining,ELAPSED_SECONDS,Elapsed_seconds/60 Elapsed_in_minsfrom v$session_longops where TIME_REMAINING>0 order by TIME_REMAINING;
Run this to check the query:
select sql_text from v$sql where sql_id='&sqlid';
Query to check if anything is running for more than 5 mins(300secs):
--SQL running for more than 5 minsset lines 300set pages 400col username format a20col sql_id format a12col sql_text format a40col mins_running format 9999.99col sql_text format a80col sql_text heading 'SQL Text'col sql_text format a80selects.username,s.sid,s.serial#,s.sql_id,s.last_call_et/60 mins_running,t.sql_textfrom v$session sjoin v$sqltext_with_newlines ton s.sql_address = t.addresswhere status='ACTIVE'and type <>'BACKGROUND'and last_call_et> 3600order by sid,serial#,t.piece;
check for blocking sessions:
select s1.username || '@' || s1.machine|| ' ( SID=' || s1.sid || ' ) is blocking '|| s2.username || '@' || s2.machine|| ' ( SID=' || s2.sid || ' ) ' AS blocking_statusfrom v$lock l1, v$session s1, v$lock l2, v$session s2where s1.sid=l1.sid and s2.sid=l2.sidand l1.BLOCK=1 and l2.request > 0and l1.id1 = l2.id1and l2.id2 = l2.id2;
Find lock wait time:
SELECTblocking_session "BLOCKING_SESSION",sid "BLOCKED_SESSION", serial# "BLOCKED_SERIAL#",seconds_in_wait/60 "WAIT_TIME(MINUTES)"FROM v$sessionWHERE blocking_session is not NULLORDER BY blocking_session;
Check when the gather stat last executed:
SELECT * FROM(SELECT log_date,job_name,status,actual_start_date,run_durationFROM DBA_SCHEDULER_JOB_RUN_DETAILSWHERE job_name='GATHER_STATS_JOB'ORDER BY log_id DESC)WHERE rownum<=2;
Find blocked sql from sid:
SELECT SES.SID, SES.SERIAL# SER#, SES.PROCESS OS_ID, SES.STATUS, SQL.SQL_FULLTEXTFROM V$SESSION SES, V$SQL SQL, V$PROCESS PRCWHERESES.SQL_ID=SQL.SQL_ID ANDSES.SQL_HASH_VALUE=SQL.HASH_VALUE ANDSES.PADDR=PRC.ADDR ANDSES.SID=&Enter_blocked_session_SID;
Note: Input is the blocked sid
Check sessions that are blocking objects:
select a.sid,a.serial#,a.username,a.status,a.schemaname,a.osuser,a.machine,a.terminal,c.owner,c.object_name,c.statusfrom v$session a, v$locked_object b, dba_objects cwhere b.object_id = c.object_idand a.sid = b.session_id
Hope this helps in troubleshooting the issues.
Best Wishes!!
No comments:
Post a Comment
If you have any queries/ any suggestion please do comment and let me know.