How to hanganalyze and systemstate dumps for Oracle database?

Oracle support request hang analysis and system state dumps when rasing SR.

One 10.1 or higher versions login as

sqlplus -prelim / as sysdba

To do a hanganalyze

oradebug setmypid;
oradebug unlimit;
oradebug hanganalyze 3;

Wait 60 – 90 seconds and run the last command again to identify the process state changes.

To get a systemstate dump

oradebug setmypid;
oradebug unlimit;
oradebug dump systemstate 266;

Wait 60 – 90 seconds and run again to identify the system state changes.
If it is taking too long then cancel and run with level 258.

One a cluster environment use
for hang analyze

oradebug -g all hanganalyze 3

for system state dumps.

oradebug -g all dump systemstate 266

get dump trace file path

oradebug tracefile_name

If there are system issues with your database, you can typically collect the following data trace to SR.

Action Plan
====================
1) For single node
$sqlplus / as sysdba <==When you can login to DB
~or~
$sqlplus -prelim / as sysdba <==When you can't login to DB when DB is hanging 

SQL>oradebug setmypid <<==if you can't login to DB when DB is hanging, please using setospid to pmon OS pid 

SQL>oradebug unlimit
SQL>oradebug hanganalyze 3
SQL>oradebug dump systemstate 258
Wait for some 20 seconds
SQL>oradebug hanganalyze 3
SQL>oradebug dump systemstate 258
Wait for some 20 seconds
SQL>oradebug hanganalyze 3
SQL>oradebug dump systemstate 258
SQL>oradebug tracefile_name ==>This will get the trace file name and trace directory.
SQL>oradebug close_trace

2) For RAC, please take the below steps and upload tracefile_name

Please generate systemstate dump and hanganalyze as sysdba:

$sqlplus / as sysdba <==When you can login to DB
~or~
$sqlplus -prelim / as sysdba <==When you can't login to DB when DB is hanging 

SQL>oradebug setmypid <<==if you can't login DB when DB is hanging, please using setospid to pmon OSpid 
SQL>oradebug unlimit
sql>oradebug setinst all
SQL>oradebug -g all hanganalyze 3
SQL>oradebug -g all dump systemstate 258
Wait for 30 seconds
SQL>oradebug -g all hanganalyze 3
SQL>oradebug -g all dump systemstate 258
Wait for 30 seconds
SQL>oradebug -g all hanganalyze 3
SQL>oradebug -g all dump systemstate 258
SQL>oradebug tracefile_name ==>This will get the trace file path.
SQL>oradebug close_trace

12c 11g:upload all instances diag+dia0+lck trace files