Oracle HangAnalyze
There comes a time in your life (more often then not and when you least expect) you will find that your sql session is hanging or some client application is hung or the database itself is hanging. While utilities AWR and ADDM are helpful, these don't tell the internal status of the instance, in particular if you are stuck with a hung instance. In such cases running AWR/ADDM is out of the equation. Oracle provides a additional tool as part of "oradebug" called "hanganalyze". This tool can be used to either diagnose a known hung session or the database in general.
This blog contains steps to generate hang analyze trace file
Run the following query to obtain the SPID of the hung session
Obtain session SPID
select a.inst_id,
a.sid,
a.serial#,
b.spid ospid,
to_char(logon_time,'dd-Mon-rr hh24:mi') LogonTime,
lower(status) status
from gv$session a, gv$process b
where a.inst_id = b.inst_id
and a.paddr = b.addr
and status = 'ACTIVE';
Invoking oradebug
1. Connect to the database as sys user
2. If spid of the hung session is know then execute the below command
SQL> oradebug setospid [spid]
3. If the spid is not know or if you want to generate a dump for the entire database choose this
SQL> oradebug setmypid;
4. SQL> oradebug unlimit;
5. SQL> oradebug hanganalyze 3 << This will return the name of the trace file that will contain the dump results.
6. SQL> !sleep 60 << This is optional and is used for second snapshot to be taken for comparison.
7. SQL> oradebug hanganalyze 3 << This will append to the same trace file generated in the above step. No need to run this if comparison is not required.
The trace file usually written to $ORACLE_BASE/diag/rdbms/[dbname]/[instance_name]/trace/ folder. Make sure there is enough diskspace to store this file.
In the trace file look for the section caleld "Chains most likely to have caused the hang:" (located towards the top of the report). This will give you general idea of what you are dealing with. Should you need additional information, for each of the chains listed in this section a breakdown is provided with details of the waiting and blocking sessions in the following section.
Note that this trace file when uploaded to Oracle Support along with a SR usually leads to speedier resolution