Monday, November 28, 2016

Script to check the Dead locks and Blocking sessions and table locks

Blokked sessions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT (
SELECT username
FROM gv$session
WHERE sid=a.sid) blocker,
a.sid, ' is blocking ', (
SELECT username
FROM gv$session
WHERE sid=b.sid) blockee,
b.sid
FROM gv$lock a, gv$lock b
WHERE a.block = 1
AND b.request > 0
AND a.id1 = b.id1
AND a.id2 = b.id2;






SELECT (SELECT username
          FROM gv$session
         WHERE SID = a.SID AND inst_id = a.inst_id) blocker, a.SID,
       ' is blocking ', (SELECT username
                           FROM gv$session
                          WHERE SID = b.SID AND inst_id = b.inst_id) blockee,
       b.SID,b.type,b.lmode,b.request
  FROM gv$lock a, gv$lock b
 WHERE a.BLOCK > 0
   AND b.request > 0
   AND a.id1 = b.id1
   AND a.id2 = b.id2
   AND a.TYPE = b.TYPE
   AND a.inst_id = b.inst_id;












SELECT B.USERNAME,b.sid, B.MACHINE, B.TERMINAL, B.STATUS, A.SQL_FULLTEXT, A.SQL_TEXT FROM V$SQLAREA A, V$SESSION B WHERE A.HASH_VALUE=B.PREV_HASH_VALUE AND b.username='STDUIAPR29A' and sid=1531;



Script to check High water mark

SET LINESIZE 300
SET SERVEROUTPUT ON
SET VERIFY OFF

DECLARE
  CURSOR cu_tables IS
    SELECT a.owner,
           a.table_name
    FROM   all_tables a
    WHERE  a.table_name = Decode(Upper('&&Table_Name'),'ALL',a.table_name,Upper('&&Table_Name'))
    AND    a.owner      = Upper('&&Table_Owner')
    AND    a.partitioned='NO'
    AND    a.logging='YES'
order by table_name;

  op1  NUMBER;
  op2  NUMBER;
  op3  NUMBER;
  op4  NUMBER;
  op5  NUMBER;
  op6  NUMBER;
  op7  NUMBER;
BEGIN

  Dbms_Output.Disable;
  Dbms_Output.Enable(1000000);
  Dbms_Output.Put_Line('TABLE                             UNUSED BLOCKS     TOTAL BLOCKS  HIGH WATER MARK');
  Dbms_Output.Put_Line('------------------------------  ---------------  ---------------  ---------------');
  FOR cur_rec IN cu_tables LOOP
    Dbms_Space.Unused_Space(cur_rec.owner,cur_rec.table_name,'TABLE',op1,op2,op3,op4,op5,op6,op7);
    Dbms_Output.Put_Line(RPad(cur_rec.table_name,30,' ') ||
                         LPad(op3,15,' ')                ||
                         LPad(op1,15,' ')                ||
                         LPad(Trunc(op1-op3-1),15,' '));
  END LOOP;

END;
/








solution for ORA-19809: limit exceeded for recovery files

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================

RMAN-03009: failure of backup command on ORA_DISK_1 channel at 08/27/2013 15:58:
05
ORA-19809: limit exceeded for recovery files
ORA-19804: cannot reclaim 52428800 bytes disk space from 4327473152 limit
When I went through some forums, I found a lot of solutions, but when I checked with their situations, it doesn't match.

One solution was to increase the db_recovery space. So I checked the space and got this result.
db_recovery size

 SQL> show parameter db_recovery;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /u01/app/oracle/fast_recovery_
                                                 area
db_recovery_file_dest_size           big integer 4127M

Space Usage

SQL> select SPACE_USED/1024/1024/1024,SPACE_LIMIT/1024/1024/1024 from  v$recovery_file_dest;

SPACE_USED SPACE_LIMIT
---------- -----------
 800155136  4327473152
Available Space

 SQL>SELECT
NAME,
TO_CHAR(SPACE_LIMIT, '999,999,999,999') AS SPACE_LIMIT,
TO_CHAR(SPACE_LIMIT - SPACE_USED + SPACE_RECLAIMABLE,
'999,999,999,999') AS SPACE_AVAILABLE,
ROUND((SPACE_USED - SPACE_RECLAIMABLE)/SPACE_LIMIT * 100, 1)
AS PERCENT_FULL
FROM V$RECOVERY_FILE_DEST;

NAME
--------------------------------------------------------------------------------
SPACE_LIMIT      SPACE_AVAILABLE  PERCENT_FULL
---------------- ---------------- ------------
/u01/app/oracle/fast_recovery_area
   4,327,473,152    3,488,460,800         19.4





 select * from v$flash_recovery_area_usage;

FILE_TYPE    PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
------------ ------------------ ------------------------- ---------------
CONTROLFILE                   0                         0               0
ONLINELOG                     0                         0               0
ARCHIVELOG                    0                         0               0
BACKUPPIECE                   0                         0               0
IMAGECOPY                 99.63                         0             244
FLASHBACKLOG                  0                         0               0

6 rows selected

*****************************************************

change the FRA (DB_RECOVERY_FILE_DEST) size
delete old archive logs from the list

Sunday, November 27, 2016

How to lock/unlock statistics on a table?

How to lock/unlock statistics on a table?

In certain cases you may want to lock statistics in a table in certain cases, for example if you want a table not be analyzed by automatic statistics job but analyze it later or in cases where you want prevent from analyzing statistics in cases where data in the table doesn’t change.

The following example shows how to lock table statistics and what happens when one tries to gather statistics on table that has statistics locked.

— create table
SQL> create table test ( x number );

Table created.

— create index
SQL> create index test_idx on test(x);

Index created.

— shows when stats is not locked the value of stattype_locked is NULL
SQL> SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = 'TEST' and owner = 'SCOTT';

STATT
—–
— lock statistics
SQL> exec dbms_stats.lock_table_stats('scott', 'test');

PL/SQL procedure successfully completed.

— shows when stats is locked the value of stattype_locked is ALL
SQL> SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = 'TEST' and owner = 'SCOTT';

STATT
—–
ALL

— try to gather statistics on locked table
SQL> exec dbms_stats.gather_index_stats('scott', 'test_idx');
BEGIN dbms_stats.gather_index_stats('scott', 'test_idx'); END;

*
ERROR at line 1:
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at “SYS.DBMS_STATS”, line 10640
ORA-06512: at “SYS.DBMS_STATS”, line 10664
ORA-06512: at line 1

— try to gather statistics on the index using analyze
SQL> analyze index ajaffer.test_idx compute statistics;
analyze index ajaffer.test_idx compute statistics
*
ERROR at line 1:
ORA-38029: object statistics are locked

— unlock statistics
SQL> exec dbms_stats.unlock_table_stats('scott', 'test');

PL/SQL procedure successfully completed.




Oracle 12c:New feature ------- Logging DDL data..

Oracle 12c:New feature ------- Logging DDL data..





Oracle had introduced a cool feature in version 11g, where we were able to log or track DDL statements executed in the database by means of a parameter called ENABLE_DDL_LOGGING without setting up database auditing. Setting ENABLE_DDL_LOGGING to TRUE results in logging DDL statements in to the instance alert log (s). Since the DDL statements are logged into alert log file, it becomes a hard task to scan through the alert log and find the DDL logs.

Oracle has made a significant change in terms of DDL logging with version 12c. In Oracle 12c, the DDL logs are maintained in dedicated DDL log file (s) unlike the instance alert log file which was the case with Oracle 11g. This makes it easier to track DDL statements executed in a database.

In 12c, Oracle maintains the DDL logs in two files (XML and plain text) under the ADR_HOME as listed below.

    XML Version: $ADR_BASE/diag/rdbms/${DBNAME}/${ORACLE_SID}/log/ddl/log.xml
    Text Version: $ADR_BASE/diag/rdbms/${DBNAME}/${ORACLE_SID}/log/ddl_${ORACLE_SID}.log

As per the Oracle documentation, setting ENABLE_DDL_LOGGING to TRUE will log following DDL statements executed in a database.

    ALTER/CREATE/DROP/TRUNCATE CLUSTER
    ALTER/CREATE/DROP FUNCTION
    ALTER/CREATE/DROP INDEX
    ALTER/CREATE/DROP OUTLINE
    ALTER/CREATE/DROP PACKAGE
    ALTER/CREATE/DROP PACKAGE BODY
    ALTER/CREATE/DROP PROCEDURE
    ALTER/CREATE/DROP PROFILE
    ALTER/CREATE/DROP SEQUENCE
    CREATE/DROP SYNONYM
    ALTER/CREATE/DROP/RENAME/TRUNCATE TABLE
    ALTER/CREATE/DROP TRIGGER
    ALTER/CREATE/DROP TYPE
    ALTER/CREATE/DROP TYPE BODY
    DROP USER
    ALTER/CREATE/DROP VIEW

There are some discrepancies while using ENABLE_DDL_LOGGING for tracking DDL statements particularly in the context of multi tenant architecture. In this post, I will go through a quick demonstration to explore how this feature works and what are the discrepancies associated with this feature.

Let’s start with our demonstration. By default, DDL logging is not enabled as we can find by querying the v$parameter view.

   
---//
---// DDL logging is disabled by default //---
---//
SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> select name,value,default_value from v$parameter where name='enable_ddl_logging';

NAME                      VALUE      DEFAULT_VALUE
------------------------- ---------- ---------------
enable_ddl_logging        FALSE      FALSE

Let’s enable DDL logging in our database by setting ENABLE_DDL_LOGGING to TRUE as shown below. My demonstration is targeted against a Oracle 12c (12.1.0.2) container database to understand how the feature works in a multi tenant environment.

---//
---// Enable DDL logging //---
---//
SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> alter system set enable_ddl_logging=TRUE;

System altered.

---//
---// Validate DDL logging is enabled in the database //---
---//

SQL> select name,value,default_value from v$parameter where name='enable_ddl_logging';

NAME                      VALUE      DEFAULT_VALUE
------------------------- ---------- ---------------
enable_ddl_logging        TRUE       FALSE

At this point, we have enabled DDL logging for our container database. However, there is no log file created yet as we haven’t performed any DDL after enabling the DDL logging. This can be confirmed by looking to the DDL log locations as shown below.

   
##---
##--- DDL log files are not created yet ---##
##---
[oracle@test1 ~]$ cd /app/oracle/diag/rdbms/OCDB1/OCDB1/log/ddl/
[oracle@test1 ddl]$ ls -lrt
total 0

Let’s perform few DDL statements on both container (CDB$ROOT) and pluggable (CPDB1) databases and observe how these statements are logged by Oracle.

---//
---// executing DDL in root(CDB$ROOT) container //---
---//
16:24:02 SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

16:24:16 SQL> create user utest identified by utest;

User created.

16:24:29 SQL> drop user utest cascade;

User dropped.


---//
---// connecting to PDB CPDB1 //---
---//
16:24:36 SQL> conn ktest@CPDB1
Enter password:
Connected.

---//
---// executing DDL in pluggable database CPDB1 //---
---//
16:24:49 SQL> show con_name

CON_NAME
------------------------------
CPDB1

16:25:34 SQL> create table test as select * from all_users;

Table created.

16:25:48 SQL> create table test1 as select * from test;

Table created.

16:26:04 SQL> truncate table test1;

Table truncated.

16:26:13 SQL> drop table test purge;

Table dropped.

We have performed a number of DDL statements in both root (CDB$ROOT) and pluggable (CPDB1) databases. We can now see the existence of respective DDL log files as shown below.

   
##---
##--- DDL logs are created after DDL execution ---##
##---
[oracle@test1 ddl]$ pwd
/app/oracle/diag/rdbms/OCDB1/OCDB1/log/ddl
[oracle@test1 ddl]$ ls -lrt
total 4
-rw-r----- 1 oracle dba 1650 May  8 16:26 log.xml

[oracle@test1 log]$ pwd
/app/oracle/diag/rdbms/OCDB1/OCDB1/log
[oracle@test1 log]$ ls -lrt ddl_${ORACLE_SID}.log
-rw-r----- 1 oracle dba 225 May  8 16:26 ddl_OCDB1.log

Let’s see what is logged in the DDL log files for these DDL statements. First, let’s take a look into the text version of the logs
   
##---
##--- DDL logs from text version of log file ---##
##---
[oracle@test1 log]$ cat ddl_OCDB1.log
diag_adl:drop user utest cascade
Sun May 08 16:25:48 2016
diag_adl:create table test as select * from all_users
diag_adl:create table test1 as select * from test
diag_adl:truncate table test1
diag_adl:drop table test purge

We can see that all the DDL statements are logged (except the “create user” statement as that is not supported) into the log file. However, looks like the log file is just a sequence of DDL statements without any context of those statements. There are some vital information missing from this log file. If you observe it closely, you will find that TIMESTAMP information is missing for most of the statements. I was also expecting the container information to be associated with each of the logged DDL statement. However, that information is not there in the log file. Since, we are dealing with multi tenant database; the container information is very much required to be able to determine in which container a particularly DDL statement was executed. Without the container details, these DDL logging could not server any purpose.

Now let’s take a look into the XML version of the DDL log file to see if we can find any missing information there.

   
##---
##--- DDL logs from XML version of log file ---##
##---
[oracle@test1 ddl]$ cat log.xml
<msg time="2016-05-08T16:24:36.772+05:30" org_id="oracle" comp_id="rdbms" msg_id="opiexe:4409:2946163730" type="UNKNOWN" group="diag_adl" level="16" host_id="test1.oraclebuffer.com" host_addr="192.168.230.15" version="1">
 <txt>drop user utest cascade
 </txt>
</msg>
<msg time="2016-05-08T16:25:48.587+05:30" org_id="oracle" comp_id="rdbms" msg_id="kpdbLogDDL:18891:2946163730" type="UNKNOWN" group="diag_adl" level="16" host_id="test1.oraclebuffer.com" host_addr="192.168.230.15">
 <txt>create table test as select * from all_users
 </txt>
</msg>
<msg time="2016-05-08T16:26:04.508+05:30" org_id="oracle" comp_id="rdbms" msg_id="kpdbLogDDL:18891:2946163730" type="UNKNOWN" group="diag_adl" level="16" host_id="test1.oraclebuffer.com" host_addr="192.168.230.15">
 <txt>create table test1 as select * from test
 </txt>
</msg>
<msg time="2016-05-08T16:26:13.874+05:30" org_id="oracle" comp_id="rdbms" msg_id="kpdbLogDDL:18891:2946163730" type="UNKNOWN" group="diag_adl" level="16" host_id="test1.oraclebuffer.com" host_addr="192.168.230.15">
 <txt>truncate table test1
 </txt>
</msg>
<msg time="2016-05-08T16:26:25.462+05:30" org_id="oracle" comp_id="rdbms" msg_id="kpdbLogDDL:18891:2946163730" type="UNKNOWN" group="diag_adl" level="16" host_id="test1.oraclebuffer.com" host_addr="192.168.230.15">
 <txt>drop table test purge
 </txt>
</msg>




The XML version of the log file looks to be more informative than the text version. We have now additional details available for each of the DDL statements executed like the TIMESTAMP of the DDL along with some session specific details like host_id and host_addr

However, the logs are still not sufficient for a multi tenant container database. The container information is still missing from the logs and we can’t rely on it to track on which container a particular DDL statement was executed
Footnote:

ENABLE_DDL_LOGGING feature can be considered for use in Oracle 11g or Oracle 12c non-CDB database. We must query the XML version of the log file for detailed information related to a DDL statement rather than querying the text version as the text version seems to miss the TIMESTAMP and session specific information for most DDL statements. Moreover, ENABLE_DDL_LOGGING feature seems not to be an ideal option for DDL tracking in a multi tenant container database considering the fact that it doesn’t log the container details of DDL statements and in turn serves no purpose for tracking.







Saturday, October 1, 2016

Controlfile restore from Primaey database to Standby

Below are the steps to accomplish the task :

Step 1: Create the Standby control file on primary database
 Step 2: Copy the controlfile backup to the standby system
 Step 3: Shutdown, restore, rename.

Example

Step 1 : Create the Standby control file on primary database.

$ export ORACLE_SID=test1
 $rman target /
 RMAN> backup current controlfile for standby format 'stdbyctl.bkp';
 RMAN> EXIT;

stdbyctl.bkp file will be created in "$ORACLE_HOME/dbs" (Unix) or "$ORACLE_HOME/database" (Windows).

Step 2. Copy the controlfile backup to the standby system

Using ftp/scp move stdbyctl.bkp to standby system

Step 3: Shutdown, restore, rename.

A. Shutdown all instances of the standby.

$ export ORACLE_SID=test
 $sqlplus / as sysdba
 SQL> shutdown immediate
 ORA-01109: database not open


Database dismounted.
 ORACLE instance shut down.

B. Depending on the location of the logfiles on the standby server remove all online and standby redo logs from the standby directories Using an Operating System utility or ASMCMD and make sure that you have the LOG_FILE_NAME_CONVERT parameter defined to translate any directory paths.

C. Startup one instance of Standby database in nomount stage:

$sqlplus / as sysdba
 SQL> startup nomount
 ORACLE instance started.

Total System Global Area 209715200 bytes
 Fixed Size 1248116 bytes
 Variable Size 75498636 bytes
 Database Buffers 125829120 bytes
 Redo Buffers 7139328 bytes

D. Connect to RMAN with nocatalog option and Restore the standby control file:

$rman nocatalog target /
 RMAN> restore standby controlfile from '\tmp\stdbyctl.bkp';

Starting restore at 29-AUG-08
 using target database control file instead of recovery catalog
 allocated channel: ORA_DISK_1
 channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: restoring control file
 channel ORA_DISK_1: restore complete, elapsed time: 00:00:17
 output filename=+DATA1/test1/controlfile/current.257.661096899
 Finished restore at 29-AUG-08

E. Mount standby database

RMAN> alter database mount;

database mounted

F. Catalog the datafiles of standby database

Below command will give you a list of files and ask if they should all be catalog. Review the list and say YES if all the datafiles are properly listed
 In below command while cataloging the files, the string specified should refer to the diskgroup/filesystem destination of the standby data files.

RMAN> catalog start with '+DATA1/test/DATAFILE/';

Starting implicit crosscheck backup at 29-AUG-08
 using target database control file instead of recovery catalog
 allocated channel: ORA_DISK_1
 channel ORA_DISK_1: sid=155 devtype=DISK
 Crosschecked 10 objects
 Finished implicit crosscheck backup at 29-AUG-08

Starting implicit crosscheck copy at 29-AUG-08
 using channel ORA_DISK_1
 Finished implicit crosscheck copy at 29-AUG-08

searching for all files in the recovery area
 cataloging files...
 cataloging done

List of Cataloged Files
 =======================
 File Name: +fra/test/BACKUPSET/2008_07_28/nnndf0_TAG20080728T113319_0.296.661260801
 File Name: +fra/test/BACKUPSET/2008_07_28/ncsnf0_TAG20080728T113319_0.297.661260847
 File Name: +fra/test/CONTROLFILE/backup.272.661096103

searching for all files that match the pattern +DATA1/test/DATAFILE/

List of Files Unknown to the Database
 =====================================
 File Name: +data1/test/DATAFILE/SYSTEM.258.661097855
 File Name: +data1/test/DATAFILE/SYSAUX.259.661097855
 File Name: +data1/test/DATAFILE/UNDOTBS1.260.661097855
 File Name: +data1/test/DATAFILE/USERS.261.661097855

Do you really want to catalog the above files (enter YES or NO)? YES
 cataloging files...
 cataloging done

List of Cataloged Files
 =======================
 File Name: +data1/test/DATAFILE/SYSTEM.258.661097855
 File Name: +data1/test/DATAFILE/SYSAUX.259.661097855
 File Name: +data1/test/DATAFILE/UNDOTBS1.260.661097855
 File Name: +data1/test/DATAFILE/USERS.261.661097855

NOTE:
 a) This will only work if you are using OMF. If you are using ASM without OMF you have to catalog all non-OMF Datafiles as Datafile Copies manually using

RMAN> catalog datafilecopy '<File-Specification>';

b) If you have Datafiles on different Diskgroups you have to catalog from all Diskgroups, of course.


G. Commit the changes to the controlfile

RMAN> switch database to copy;

datafile 1 switched to datafile copy "+DATA1/test/datafile/system.258.661097855"
 datafile 2 switched to datafile copy "+DATA1/test/datafile/undotbs1.260.661097855"
 datafile 3 switched to datafile copy "+DATA1/test/datafile/sysaux.259.661097855"
 datafile 4 switched to datafile copy "+DATA1/test/datafile/users.261.661097855"

RMAN> EXIT;

H. Re-enable flashback on the standby database.
 $sqlplus / as sysdba
 SQL> alter database flashback off;

Database altered.

SQL> alter database flashback on;

Database altered.

I. Query v$log and clear all online redo log groups

SQL> select group# from v$log;

GROUP#
 ----------
 1
 2
 3

SQL> alter database clear logfile group 1;

Database altered.

SQL> alter database clear logfile group 2;

Database altered.

SQL> alter database clear logfile group 3;

Database altered.

J. Query v$standby_log and clear all standby redo logs

SQL> select group# from v$standby_log;

GROUP#
 ----------
 4
 5
 6

SQL> alter database clear logfile group 4;

Database altered.

SQL> alter database clear logfile group 5;

Database altered.

SQL> alter database clear logfile group 6;

Database altered.

Recreate the standby redo logs on standby database if standby redo logs are not present on the primary.

SQL> select group# from v$standby_log;

no row selected

SQL> alter database add standby logfile group 4 size 50m;

Database altered.

SQL> alter database add standby logfile group 5 size 50m;

Database altered.

SQL> alter database add standby logfile group 6 size 50m;

Database altered.

K. Start Managed recovery process on standby

SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL> exit







Oracle12c - The Top New 12c Features of Oracle 12c! (Part 1)

Oracle 12c Upgrade 112040 to 121010

Oracle Database 12c Multitenant Architecture Overview

Saturday, September 24, 2016

Script to find BROKEN JOBS

Broken Jobs
--------------

SQL> select JOB,LOG_USER,PRIV_USER,SCHEMA_USER,FAILURES,WHAT from dba_jobs where BROKEN='Y';

       JOB LOG_USER   PRIV_USER  SCHEMA_USE   FAILURES WHAT
---------- ---------- ---------- ---------- ---------- ----------------------------------------
        55 SYS        SYS        SYS                16    DAILY_PRODUCT_MOVEMENT_LOAD(50000);



col what for a45
set linesize 200
select JOB,LOG_USER,PRIV_USER,SCHEMA_USER,FAILURES,WHAT from dba_jobs where BROKEN='Y';

       JOB LOG_USER        PRIV_USER       SCHEMA_USER       FAILURES WHAT
---------- --------------- --------------- --------------- ---------- --------------------
        26 SECADMIN        SECADMIN        SECADMIN                16 CLEAN_AUDIT;



Mark a job as not broken

If a job fails to successfully execute it will go into a broken state after 16 attempts. To reset, issue command:

EXEC dbms_ijob.broken(jobno, FALSE);----  to kill other users jobs as well
EXEC dbms_job.broken(jobno, FALSE);----  to kill only the users in which you gets connected









Script to check the blocking session



select    'SID ' || l1.sid ||' is blocking  ' || l2.sid blocking
from      v$lock l1, v$lock l2
where   l1.block =1 and l2.request > 0
and        l1.id1=l2.id1
and        l1.id2=l2.id2
/


Scripts to check the ASM disk and Diskgroup space details


select name,total_mb/1024,free_mb/1024 from v$asm_disk;

select name,total_mb/1024,free_mb/1024 from v$asm_diskgroup;

SELECT name, free_mb, total_mb, free_mb/total_mb*100 as Free   FROM v$asm_diskgroup;

select DISK_NUMBER,NAME,PATH,FAILGROUP,TOTAL_MB,FREE_MB from v$asm_disk;




Script to check the ASM Disks and Diskgroup SIZE details(Total / Free ) & status of the disks and location

 set pagesize 250 linesize 250 lines 250
  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
 columns cleared
  CLEAR BREAKS
 breaks cleared
  CLEAR COMPUTES
 computes cleared

  COLUMN disk_group_name        FORMAT a25           HEAD 'Disk Group Name'
   COLUMN disk_file_path         FORMAT a20           HEAD 'Path'
   COLUMN disk_file_name         FORMAT a20           HEAD 'File Name'
   COLUMN disk_file_fail_group   FORMAT a20           HEAD 'Fail Group'
   COLUMN total_mb               FORMAT 999,999,999   HEAD 'File Size (MB)'
   COLUMN used_mb                FORMAT 999,999,999   HEAD 'Used Size (MB)'
   COLUMN pct_used               FORMAT 999.99        HEAD 'Pct. Used'
 
  BREAK ON report ON disk_group_name SKIP 1
 COMPUTE sum LABEL ""              OF total_mb used_mb ON disk_group_name
 COMPUTE sum LABEL "Grand Total: " OF total_mb used_mb ON report

  SELECT  NVL(a.name, '[CANDIDATE]')    disk_group_name
    , b.path   disk_file_path
    , b.name    disk_file_name
    , b.failgroup   disk_file_fail_group
   , b.total_mb  total_mb,
  (b.total_mb - b.free_mb)   used_mb
  FROM
   v$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number)
  ORDER BY
    b.failgroup   ;



ARCHIVE genataion script

SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300
SET VERIFY OFF

COL "Generation Date" FORMAT a20

SELECT TRUNC(completion_time)  "Generation Date" ,
   round(SUM(blocks*block_size)/1048576,0) "Total for the Day in MB"
FROM gv$archived_log
GROUP BY TRUNC(completion_time)
ORDER BY TRUNC(completion_time)
/




Script to check the ARCHIVES genearation HOURLY / DAILY

HOURLY
~~~~~~~~~~~~~~~~~~~~~~~~

set pages 1000
select trunc(COMPLETION_TIME,'HH') Hour,thread# , round(sum(BLOCKS*BLOCK_SIZE)/1048576) MB,count(*) Archives from v$archived_log
group by trunc(COMPLETION_TIME,'HH'),thread#  order by 1 ;



Daily
~~~~~~~~~~~~~~~~~~~~~~~~~
set pages 1000
select trunc(COMPLETION_TIME,'DD') Day, thread#, round(sum(BLOCKS*BLOCK_SIZE)/1048576) MB,count(*) Archives_Generated from v$archived_log
group by trunc(COMPLETION_TIME,'DD'),thread# order by 1;


1week hourly basis switch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT to_date(first_time) DAY,
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') "00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') "01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') "02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') "03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') "04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') "05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') "06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') "07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') "08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') "09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') "10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') "11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') "12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') "13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') "14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') "15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') "16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') "17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') "18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') "19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') "20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') "21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') "22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') "23"
from
v$log_history
where to_date(first_time) > sysdate -8
GROUP by
to_char(first_time,'YYYY-MON-DD'), to_date(first_time)
order by to_date(first_time)
/


Archive backup and DELETE scripts

Script to delete archives, which are backed up tape

rman target /
DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE' BACKED UP 1 TIMES TO DEVICE TYPE 'SBT';

crosscheck archivelog all;

delete archivelog all backed up 1 times to device type sbt completed before 'sysdate-2/24';

delete archivelog all backed up 1 times to device type sbt;






Backup Archive scripts to tape and tape


run {
allocate channel t1 type 'sbt_tape';
allocate channel t2 type 'sbt_tape';
allocate channel t3 type 'sbt_tape';
allocate channel t4 type 'sbt_tape';
backup
filesperset 100
format '%t_%s_%r.arc'
archivelog all delete input skip inaccessible;
release channel t1;
release channel t2;
release channel t3;
release channel t4;
}



Backup Archive scripts to tape and disk

run {
allocate channel t1 type 'disk';
allocate channel t2 type 'disk';
allocate channel t3 type 'disk';
allocate channel t4 type 'disk';
backup
filesperset 100
format '%t_%s_%r.arc'
archivelog all delete input skip inaccessible;
release channel t1;
release channel t2;
release channel t3;
release channel t4;
}

Add a disk to existing Diskgroup in ASM and some DISKGROUP scripts


sqlplus / as sysasm

alter diskgroup DATA add disk '/dev/ora_Data13','/dev/ora_Data14','/dev/ora_Data15','/dev/ora_Data16' rebalance power 9 ;


 Diskgroup altered.
 

Beow query is to check the disk addtion process


   select * from V$asm_operation ;
 
 GROUP_NUMBER OPERA STAT      POWER     ACTUAL      SOFAR   EST_WORK   EST_RATE EST_MINUTES
 
 ------------ ----- ---- ---------- ---------- ---------- ---------- ---------- -----------
 
            1 REBAL RUN           9          9       3079     299726      10511          28


ALTER DISKGROUP disk_group_1 ADD DISK  '/devices/disk*3',  '/devices/disk*4';


DROP diskgroup

ALTER DISKGROUP disk_group_1 DROP DISK diska2;

-- Resize a specific disk.
ALTER DISKGROUP disk_group_1  RESIZE DISK diska1 SIZE 100G;



-- Resize all disks in a failure group.
ALTER DISKGROUP disk_group_1  RESIZE DISKS IN FAILGROUP failure_group_1 SIZE 100G;



-- Resize all disks in a disk group.
ALTER DISKGROUP disk_group_1  RESIZE ALL SIZE 100G;





-- Create a directory.
ALTER DISKGROUP disk_group_1 ADD DIRECTORY '+disk_group_1/my_dir';

-- Rename a directory.
ALTER DISKGROUP disk_group_1 RENAME DIRECTORY '+disk_group_1/my_dir' TO '+disk_group_1/my_dir_2';

-- Delete a directory and all its contents.
ALTER DISKGROUP disk_group_1 DROP DIRECTORY '+disk_group_1/my_dir_2' FORCE;

-- Drop file using an alias.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/my_dir/my_file.dbf';

-- Drop file using a numeric form filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1.342.3';

-- Drop file using a fully qualified filename.
ALTER DISKGROUP disk_group_1 DROP FILE '+disk_group_1/mydb/datafile/my_ts.342.3';





CREATE TABLESPACE my_ts DATAFILE '+disk_group_1' SIZE 100M AUTOEXTEND ON;




scripts to add database and resize database and autoextend on in ASM




alter tablespace USERS add datafile '+DATA' size 3G ;


alter tablespace DATA  add datafile '+DATA' size 30G autoextend on  maxsize 50G;



ALTER DATABASE DATAFILE '+DATA/pr599/datafile/jet_data_03.366.862104147' resize 50G;



ALTER DATABASE DATAFILE '+DATA/pr599/datafile/jet_data_03.366.862104147' AUTOEXTEND ON maxsize 50G;



alter tablespace MGMT_TABLESPACE add datafile '+DATA' size 5G;

alter database datafile  '+DATA/pr746/datafile/users.257.861050819' autoextend on  maxsize 5G;


Above scripts is for ASM,

We can use the same for NON-ASM also, but while adding database we need to mention full datafile path and name



alter tablespace MGMT_TABLESPACE add datafile '/u01/test/test1.dbf' size 5G;


















Script to find active sql for specific users

SELECT a.username, b.sql_text,a.status from v$session a INNER JOIN v$sqlarea b ON a.sql_id = b.sql_id where a.username in ('USERNAME')  and a.status='ACTIVE';





Scripts for finding session details

SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time
FROM V$Session
WHERE
Status='ACTIVE' AND
UserName IS NOT NULL;


SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time FROM V$Session WHERE Status='INACTIVE' AND UserName IS NOT NULL;



Sql queries to check ACTIVE / INACTIVE Sessions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Total Count of sessions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select count(s.status) TOTAL_SESSIONS
from gv$session s;




Total Count of Inactive sessions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select count(s.status) INACTIVE_SESSIONS
from gv$session s, v$process p
where
p.addr=s.paddr and
s.status='INACTIVE';


SESSIONS WHICH ARE IN INACTIVE STATUS FROM MORE THAN 1HOUR
select count(s.status) "INACTIVE SESSIONS > 1HOUR "
from gv$session s, v$process p
where
p.addr=s.paddr and
s.last_call_et > 3600 and
s.status='INACTIVE';




COUNT OF ACTIVE SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select count(s.status) ACTIVE_SESSIONS
from gv$session s, v$process p
where
p.addr=s.paddr and
s.status='ACTIVE';



TOTAL SESSIONS COUNT ORDERED BY PROGRAM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col program for a30
select s.program,count(s.program) Total_Sessions
from gv$session s, v$process p
where  p.addr=s.paddr
group by s.program;




TOTAL COUNT OF SESSIONS ORDERED BY MODULE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col module  for a30
prompt TOTAL SESSIONS
select s.module,count(s.sid) Total_Sessions
from gv$session s, v$process p
where  p.addr=s.paddr
group by s.module;



TOTAL COUNT OF SESSIONS ORDERED BY ACTION
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col action for a30
prompt TOTAL SESSIONS
select s.action,count(s.sid) Total_Sessions
from gv$session s, v$process p
where  p.addr=s.paddr
group by s.action;



INACTIVE SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

prompt INACTIVE SESSIONS
select p.spid, s.sid,s.last_call_et/3600 last_call_et ,s.status,s.action,s.module,s.program
from gv$session s, v$process p
where
p.addr=s.paddr and
s.status='INACTIVE';


INACTIVE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

prompt INACTIVE SESSIONS
select count(s.status) INACTIVE
from gv$session s, gv$sqlarea t,v$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE';



INACTIVE PROGRAMS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col module for a40           
prompt INACTIVE SESSIONS
col INACTIVE_PROGRAMS FOR A40
select distinct (s.program) INACTIVE_PROGRAMS,s.module
from gv$session s, v$process p
where  p.addr=s.paddr and
s.status='INACTIVE';


INACTIVE PROGRAMS with disk reads
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

prompt INACTIVE SESSIONS
select distinct (s.program) INACTIVE_PROGRAMS,SUM(T.DISK_READS)
from gv$session s, gv$sqlarea t,v$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
GROUP BY S.PROGRAM;



INACTIVE SESSIONS COUNT WITH PROGRAM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col program for a30
prompt TOTAL INACTIVE SESSIONS
col INACTIVE_PROGRAMS FOR A40
select s.program,count(s.program) Total_Inactive_Sessions
from gv$session s,v$process p
where     p.addr=s.paddr  AND
s.status='INACTIVE'
group by s.program
order by 2 desc;




TOTAL INACTIVE SESSIONS MORE THAN 1HOUR
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col program for a30
col INACTIVE_PROGRAMS FOR A40
select s.program,count(s.program) Inactive_Sessions_from_1Hour
from gv$session s,v$process p
where     p.addr=s.paddr  AND
s.status='INACTIVE'
and s.last_call_et > (3600)
group by s.program
order by 2 desc;





TOTAL INACTIVE SESSIONS GROUP BY  MODULE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
col program for a60
COL MODULE FOR A30
prompt TOTAL SESSIONS
col INACTIVE_PROGRAMS FOR A40
select s.module,count(s.module) Total_Inactive_Sessions
from gv$session s,v$process p
where     p.addr=s.paddr  AND
s.status='INACTIVE'
group by s.module;




INACTIVE SESSION DETAILS MORE THAN 1 HOUR
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et_Hrs for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a60
col elapsed_time for 999999999999
select p.spid, s.sid,s.last_call_et/3600 last_call_et_Hrs ,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.last_call_et > (3600)
order by last_call_et;




INACTIVE PROGRAM  --ANY--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select p.spid, s.sid,s.last_call_et/3600 last_call_et_Hrs ,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
And s.program='&PROGRAM_NAME'
order by last_call_et;




INACTIVE MODULES  --ANY--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select p.spid, s.sid,s.last_call_et/3600 last_call_et_Hrs ,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr
And s.module like '%order_cleanup_hazmat_v3.sql'
order by last_call_et;




INACTIVE JDBC SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a60
col elapsed_time for 999999999999
select p.spid, s.sid,s.last_call_et/3600 last_call_et ,s.status,s.action,
s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.program='JDBC Thin Client'
and s.last_call_et > 3600
order by last_call_et;





COUNT OF INACTIVE SESSIONS MORE THAN ONE HOUR
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT COUNT(P.SPID)
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.program='JDBC Thin Client'
and s.last_call_et > 3600
order by last_call_et;




TOTAL FORM SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT COUNT(S.SID) INACTIVE_FORM_SESSIONS FROM V$SESSION S
WHERE S.STATUS='INACTIVE' and
s.action like ('%FRM%');




FORMS SESSIONS DETAILS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col "Last SQL" for a30
select p.spid,s.sid,s.status,s.last_call_et/3600 last_call_et_hrs ,
s.sid,t.disk_reads, t.elapsed_time,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.action like ('FRM%') and
s.last_call_et > 3600
order by spid;                    


col machine for a15
col "Last SQL" for a30
select p.spid,s.sid,s.status,s.last_call_et/3600 last_call_et_hrs ,
S.ACTION,s.process Client_Process,s.machine
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.action like ('FRM%') and
s.last_call_et > 3600;       
order by 4;                         




INACTIVE FORMS SESSIONS DETAILS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col program for a15
col last_call_et for 999.99
select p.spid, s.sid, s.process,s.last_call_et/3600 last_call_et ,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600
order by last_call_et desc;



UNIQUE SPID
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select unique(p.spid)
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600;




COUNT FORMS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select COUNT(p.spid)
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600;



ZERO HASH VALUE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select COUNT(p.spid)
from gv$session s,gv$process p
where
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like 'FRM:%'
and s.last_call_et > 3600
AND S.SQL_HASH_VALUE=0;




INACTIVE FORM BY NAME
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select count(s.sid) from v$session S
where s.action like ('%&ACTION%')
AND S.STATUS='INACTIVE';



GROUP BY ACTION
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT S.ACTION,COUNT(S.SID) FROM V$SESSION S
WHERE S.STATUS='INACTIVE' and
s.action like ('%FRM%')
group by s.action;



FROM A SPECIFIC USERNAME
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SET LINSIZE 152
col spid for a10
col process_spid for a10
col user_name for a20
col form_name for a20
select a.pid,a.spid,a.process_spid, c.user_name,to_char(a.start_time,'DD-MON-YYYY HH24:MI:SS') "START_TIME" ,
d.user_form_name "FORM_NAME"
from apps.fnd_logins a, apps.fnd_login_resp_forms b, apps.fnd_user c,
apps.fnd_form_tl d
where
a.login_id=b.login_id
and c.user_name like 'JROMO'
and a.user_id=c.user_id
and trunc(b.start_time) >trunc(sysdate -11)
and trunc(b.end_time) is null
and b.form_id=d.form_id
and d.language='US';



INACTIVE FORM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a30
col elapsed_time for 999999999999
select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.action like ('FRM%')
and s.last_call_et > (3600*3)
order by last_call_et;





INACTIVE FORM SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col cli_proc for a9
COL AUDSID FOR A6
COL PID FOR A6
COL SID FOR A5
COL FORM_NAME FOR A25
COL USER_NAME FOR A15
col last_call_et for 9999.99
SELECT
-- /*+ ORDERED FULL(fl) FULL(vp) USE_HASH(fl vp) */
( SELECT SUBSTR ( fu.user_name, 1, 20 )
FROM apps.fnd_user fu
WHERE fu.user_id = fl.user_id
) user_name,vs.status,
TO_CHAR ( fl.start_time, 'DD-MON-YYYY HH24:MI' ) login_start_time,
TO_CHAR ( fl.end_time, 'DD-MON-YYYY HH24:MI' ) login_end_time,
vs.last_call_et/3600 last_call_et,
SUBSTR ( fl.process_spid, 1, 6 ) spid,
SUBSTR ( vs.process, 1, 8 ) cli_proc,
SUBSTR ( TO_CHAR ( vs.sid ), 1, 3 ) sid,
SUBSTR ( TO_CHAR ( vs.serial#), 1, 7 ) serial#,
SUBSTR ( TO_CHAR ( rf.audsid ), 1, 6 ) audsid,
SUBSTR ( TO_CHAR ( fl.pid ), 1, 3 ) pid,
SUBSTR ( vs.module || ' - ' ||
( SELECT SUBSTR ( ft.user_form_name, 1, 40 )
FROM apps.fnd_form_tl ft
WHERE ft.application_id = rf.form_appl_id
AND ft.form_id        = rf.form_id
AND ft.language       = USERENV('LANG')
), 1, 40 ) form_name
FROM apps.fnd_logins           fl,
gv$process            vp,
apps.fnd_login_resp_forms rf,
gv$session            vs
WHERE fl.start_time   > sysdate - 7 /* login within last 7 days */
AND fl.login_type   = 'FORM'
AND fl.process_spid = vp.spid
AND fl.pid          = vp.pid
AND fl.login_id     = rf.login_id
AND rf.end_time    IS NULL
AND rf.audsid       = vs.audsid
and vs.status='INACTIVE'
ORDER BY
vs.process,
fl.process_spid;



ACTIVE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

prompt ACTIVE SESSIONS
select count(s.status) ACTIVE
from gv$session s, gv$sqlarea t,v$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='ACTIVE';



MODULE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

set pagesize 40
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et for 9999.99
col sql_hash_value for 9999999999999col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a30
col elapsed_time for 999999999999
select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr
and s.MODULE like ('&MODULE_NAME_1HR%')
and s.last_call_et > ('&TIME_HRS' * 3600)
order by last_call_et;

select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
p.addr=s.paddr
and s.MODULE like ('%TOAD%')
Order by last_call_et;



TOAD SESSIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,
s.status,s.action,s.module,s.program
from gv$session s, gv$process p
where
p.addr=s.paddr
and s.MODULE like ('%TOAD%')
Order by last_call_et;




CLIENT MACHINE SESSIONS COUNT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select count(s.process) TOTAL from v$session S
where s.machine like ('%&CLIENT_MACHINE%');

select count(s.process) INACTIVE from v$session S
where s.machine like ('%&CLIENT_MACHINE%')
and s.status='INACTIVE';



hash value=0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

select count(s.process) from v$session S
where s.machine like ('%&CLIENT_MACHINE%')
AND S.SQL_HASH_VALUE=0;

select count(s.process) from v$session S
where s.machine like ('%&CLIENT_MACHINE%')
AND S.SQL_HASH_VALUE=0
AND S.LAST_CALL_ET > 3600;




Unique Actions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col module for a40           
prompt INACTIVE SESSIONS
col INACTIVE_PROGRAMS FOR A40
select distinct (s.program) INACTIVE_PROGRAMS,s.module
from gv$session s, gv$sqlarea t,v$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
s.machine like ('%&CLIENT_MACHINE%') AND
p.addr=s.paddr and
s.status='INACTIVE';




GROUP BY  program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

col program for a60
prompt TOTAL SESSIONS
col INACTIVE_PROGRAMS FOR A40
select s.program,count(s.program) Total_Inactive_Sessions
from gv$session s, gv$sqlarea t,v$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr  AND
s.machine like ('%&CLIENT_MACHINE%') AND
s.status='INACTIVE'
group by s.program;





Friday, August 12, 2016

List out Hidden parameters with their values.............


#####################################################################
LIST ALL HIDDEN PARAMETERS
#####################################################################

SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300

COLUMN ksppinm FORMAT A50
COLUMN ksppstvl FORMAT A50

SELECT
  ksppinm,
  ksppstvl
FROM
  x$ksppi a,
  x$ksppsv b
WHERE
  a.indx=b.indx
AND
  substr(ksppinm,1,1) = '_'
ORDER BY ksppinm
/




#####################################################################
LIST SPECIFIC PARAMETER
#####################################################################


SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300

COLUMN ksppinm FORMAT A50
COLUMN ksppstvl FORMAT A50

SELECT
  ksppinm,
  ksppstvl
FROM
  x$ksppi a,
  x$ksppsv b
WHERE
  a.indx=b.indx and a.ksppinm='&a'
AND
  substr(ksppinm,1,1) = '_'
ORDER BY ksppinm
/





Thursday, August 11, 2016

ORA-31623: a job is not attached to this session via the specified handle



impdp parfile=imp1.par

Import: Release 11.2.0.1.0 - Production on Mon Jan 31 12:54:56 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Username: system
Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

UDI-31623: operation generated ORACLE error 31623
ORA-31623: a job is not attached to this session via the specified handle
ORA-06512: at "SYS.DBMS_DATAPUMP", line 3263
ORA-06512: at "SYS.DBMS_DATAPUMP", line 4488
ORA-06512: at line 1





Solution:
~~~~~~~~~~~~~~~~~~~~~~
clear the invalid objects in sys schema

increrase the stream pool size to fix the issue






SQL>sho parameter stream

Name               TYPE         Value
--------------     ------------ ----------------
Stream_pool_size   Big Integer   0                



SQL>alter system set   Stream_pool_size=200m scope=spfile;
or
SQL>alter system set   Stream_pool_size=200m;

System altered.



SQL>sho parameter stream

Name               TYPE         Value
--------------     ------------ ----------------
Stream_pool_size   Big Integer   200M




                



Tuesday, August 9, 2016

Enqueue Wait events and their descriptions in Oracle Database 10g

Enqueue waits events usually causes problems in busy Oracle databases. But oracle online document only have some of them until 11gR2, not sure why. 


In Oracle Database 10g Release 1, each enqueue type is represented by its own wait event, making it much easier to understand exactly what type of enqueue the session is waiting for. You do not need to decipher the values from the P1, P2, P3, P1RAW, P2RAW, and P3RAW columns in the V$SESSION_WAIT or the V$SESSION view.

The following table lists all the enqueue waits in Oracle Database 10g Release 1 and describes what the enqueue is for. This information is available in the X$KSQST structure. The aggregated statistics for each of these enqueue types is displayed by the view V$ENQUEUE_STAT.

types is displayed by the view V$ENQUEUE_STAT.
Enqueue Type Description
enq: AD – allocate AU Synchronizes accesses to a specific OSM (Oracle Software Manager) disk AU
enq: AD – deallocate AU Synchronizes accesses to a specific OSM disk AU
enq: AF – task serialization Serializes access to an advisor task
enq: AG – contention Synchronizes generation use of a particular workspace
enq: AO – contention Synchronizes access to objects and scalar variables
enq: AS – contention Synchronizes new service activation
enq: AT – contention Serializes alter tablespace operations
enq: AW – AW$ table lock Allows global access synchronization to the AW$ table (analytical workplace tables used in OLAP option)
enq: AW – AW generation lock Gives in-use generation state for a particular workspace
enq: AW – user access for AW Synchronizes user accesses to a particular workspace
enq: AW – AW state lock Row lock synchronization for the AW$ table
enq: BR – file shrink Lock held to prevent file from decreasing in physical size during RMAN backup
enq: BR – proxy-copy Lock held to allow cleanup from backup mode during an RMAN proxy-copy backup
enq: CF – contention Synchronizes accesses to the controlfile
enq: CI – contention Coordinates cross-instance function invocations
enq: CL – drop label Synchronizes accesses to label cache when dropping a label
enq: CL – compare labels Synchronizes accesses to label cache for label comparison
enq: CM – gate Serializes access to instance enqueue
enq: CM – instance Indicates OSM disk group is mounted
enq: CT – global space management Lock held during change tracking space management operations that affect the entire change tracking file
enq: CT – state Lock held while enabling or disabling change tracking to ensure that it is enabled or disabled by only one user at a time
enq: CT – state change gate 2 Lock held while enabling or disabling change tracking in RAC
enq: CT – reading Lock held to ensure that change tracking data remains in existence until a reader is done with it
enq: CT – CTWR process start/stop Lock held to ensure that only one CTWR (Change Tracking Writer, which tracks block changes and is initiated by the alter database enable block change tracking command) process is started in a single instance
enq: CT – state change gate 1 Lock held while enabling or disabling change tracking in RAC
enq: CT – change stream ownership Lock held by one instance while change tracking is enabled to guarantee access to thread-specific resources
enq: CT – local space management Lock held during change tracking space management operations that affect just the data for one thread
enq: CU – contention Recovers cursors in case of death while compiling
enq: DB – contention Synchronizes modification of database wide supplemental logging attributes
enq: DD – contention Synchronizes local accesses to ASM (Automatic Storage Management) disk groups
enq: DF – contention Enqueue held by foreground or DBWR when a datafile is brought online in RAC
enq: DG – contention Synchronizes accesses to ASM disk groups
enq: DL – contention Lock to prevent index DDL during direct load
enq: DM – contention Enqueue held by foreground or DBWR to synchronize database mount/open with other operations
enq: DN – contention Serializes group number generations
enq: DP – contention Synchronizes access to LDAP parameters
enq: DR – contention Serializes the active distributed recovery operation
enq: DS – contention Prevents a database suspend during LMON reconfiguration
enq: DT – contention Serializes changing the default temporary table space and user creation
enq: DV – contention Synchronizes access to lower-version Diana (PL/SQL intermediate representation)
enq: DX – contention Serializes tightly coupled distributed transaction branches
enq: FA – access file Synchronizes accesses to open ASM files
enq: FB – contention Ensures that only one process can format data blocks in auto segment space managed tablespaces
enq: FC – open an ACD thread LGWR opens an ACD thread
enq: FC – recover an ACD thread SMON recovers an ACD thread
enq: FD – Marker generation Synchronization
enq: FD – Flashback coordinator Synchronization
enq: FD – Tablespace flashback on/off Synchronization
enq: FD – Flashback on/off Synchronization
Enqueue Type Description
enq: FG – serialize ACD relocate Only 1 process in the cluster may do ACD relocation in a disk group
enq: FG – LGWR redo generation enq race Resolves race condition to acquire Disk Group Redo Generation Enqueue
enq: FG – FG redo generation enq race Resolves race condition to acquire Disk Group Redo Generation Enqueue
enq: FL – Flashback database log Synchronizes access to Flashback database log
enq: FL – Flashback db command Synchronizes Flashback Database and deletion of flashback logs
enq: FM – contention Synchronizes access to global file mapping state
enq: FR – contention Begins recovery of disk group
enq: FS – contention Synchronizes recovery and file operations or synchronizes dictionary check
enq: FT – allow LGWR writes Allows LGWR to generate redo in this thread
enq: FT – disable LGWR writes Prevents LGWR from generating redo in this thread
enq: FU – contention Serializes the capture of the DB feature, usage, and high watermark statistics
enq: HD – contention Serializes accesses to ASM SGA data structures
enq: HP – contention Synchronizes accesses to queue pages
enq: HQ – contention Synchronizes the creation of new queue IDs
enq: HV – contention Lock used to broker the high watermark during parallel inserts
enq: HW – contention Lock used to broker the high watermark during parallel inserts
enq: IA – contention Information not available
enq: ID – contention Lock held to prevent other processes from performing controlfile transaction while NID is running
enq: IL – contention Synchronizes accesses to internal label data structures
Enqueue Type Description
enq: IM – contention for blr Serializes block recovery for IMU txn
enq: IR – contention Synchronizes instance recovery
enq: IR – contention2 Synchronizes parallel instance recovery and shutdown immediate
enq: IS – contention Synchronizes instance state changes
enq: IT – contention Synchronizes accesses to a temp object’s metadata
enq: JD – contention Synchronizes dates between job queue coordinator and slave processes
enq: JI – contention Lock held during materialized view operations (such as refresh, alter) to prevent concurrent operations on the same materialized view
enq: JQ – contention Lock to prevent multiple instances from running a single job
enq: JS – contention Synchronizes accesses to the job cache
enq: JS – coord post lock Lock for coordinator posting
enq: JS – global wdw lock Lock acquired when doing wdw ddl
enq: JS – job chain evaluate lock Lock when job chain evaluated for steps to create
enq: JS – q mem clnup lck Lock obtained when cleaning up q memory
enq: JS – slave enq get lock2 Gets run info locks before slv objget
enq: JS – slave enq get lock1 Slave locks exec pre to sess strt
enq: JS – running job cnt lock3 Lock to set running job count epost
enq: JS – running job cnt lock2 Lock to set running job count epre
enq: JS – running job cnt lock Lock to get running job count
enq: JS – coord rcv lock Lock when coord receives msg
enq: JS – queue lock Lock on internal scheduler queue
enq: JS – job run lock – synchronize Lock to prevent job from running elsewhere
enq: JS – job recov lock Lock to recover jobs running on crashed RAC inst
Enqueue Type Description
enq: KK – context Lock held by open redo thread, used by other instances to force a log switch
enq: KM – contention Synchronizes various Resource Manager operations
enq: KP – contention Synchronizes kupp process startup
enq: KT – contention Synchronizes accesses to the current Resource Manager plan
enq: MD – contention Lock held during materialized view log DDL statements
enq: MH – contention Lock used for recovery when setting Mail Host for AQ e-mail notifications
enq: ML – contention Lock used for recovery when setting Mail Port for AQ e-mail notifications
enq: MN – contention Synchronizes updates to the LogMiner dictionary and prevents multiple instances from preparing the same LogMiner session
enq: MR – contention Lock used to coordinate media recovery with other uses of datafiles
enq: MS – contention Lock held during materialized view refresh to set up MV log
enq: MW – contention Serializes the calibration of the manageability schedules with the Maintenance Window
enq: OC – contention Synchronizes write accesses to the outline cache
enq: OL – contention Synchronizes accesses to a particular outline name
enq: OQ – xsoqhiAlloc Synchronizes access to olapi history allocation
enq: OQ – xsoqhiClose Synchronizes access to olapi history closing
enq: OQ – xsoqhistrecb Synchronizes access to olapi history globals
enq: OQ – xsoqhiFlush Synchronizes access to olapi history flushing
enq: OQ – xsoq*histrecb Synchronizes access to olapi history parameter CB
enq: PD – contention Prevents others from updating the same property
enq: PE – contention Synchronizes system parameter updates
Enqueue Type Description
enq: PF – contention Synchronizes accesses to the password file
enq: PG – contention Synchronizes global system parameter updates
enq: PH – contention Lock used for recovery when setting proxy for AQ HTTP notifications
enq: PI – contention Communicates remote Parallel Execution Server Process creation status
enq: PL – contention Coordinates plug-in operation of transportable tablespaces
enq: PR – contention Synchronizes process startup
enq: PS – contention Parallel Execution Server Process reservation and synchronization
enq: PT – contention Synchronizes access to ASM PST metadata
enq: PV – syncstart Synchronizes slave start_shutdown
enq: PV – syncshut Synchronizes instance shutdown_slvstart
enq: PW – prewarm status in dbw0 DBWR0 holds this enqueue indicating pre-warmed buffers present in cache
enq: PW – flush prewarm buffers Direct Load needs to flush prewarmed buffers if DBWR0 holds this enqueue
enq: RB – contention Serializes OSM rollback recovery operations
enq: RF – synch: per-SGA Broker metadata Ensures r/w atomicity of DG configuration metadata per unique SGA
enq: RF – synchronization: critical ai Synchronizes critical apply instance among primary instances
enq: RF – new AI Synchronizes selection of the new apply instance
enq: RF – synchronization: chief Anoints 1 instance’s DMON (Data Guard Broker Monitor) as chief to other instance’s DMONs
enq: RF – synchronization: HC master Anoints 1 instance’s DMON as health check master
enq: RF – synchronization: aifo master Synchronizes critical apply instance failure detection and failover operation
enq: RF – atomicity Ensures atomicity of log transport setup
Enqueue Type Description
enq: RN – contention Coordinates nab computations of online logs during recovery
enq: RO – contention Coordinates flushing of multiple objects
enq: RO – fast object reuse Coordinates fast object reuse
enq: RP – contention Enqueue held when resilvering is needed or when data block is repaired from mirror
enq: RS – file delete Lock held to prevent file from accessing during space reclamation
enq: RS – persist alert level Lock held to make alert level persistent
enq: RS – write alert level Lock held to write alert level
enq: RS – read alert level Lock held to read alert level
enq: RS – prevent aging list update Lock held to prevent aging list update
enq: RS – record reuse Lock held to prevent file from accessing while reusing circular record
enq: RS – prevent file delete Lock held to prevent deleting file to reclaim space
enq: RT – contention Thread locks held by LGWR, DBW0, and RVWR (Recovery Writer, used in Flashback Database operations) to indicate mounted or open status
enq: SB – contention Synchronizes logical standby metadata operations
enq: SF – contention Lock held for recovery when setting sender for AQ e-mail notifications
enq: SH – contention Enqueue always acquired in no-wait mode; should seldom see this contention
enq: SI – contention Prevents multiple streams table instantiations
enq: SK – contention Serialize shrink of a segment
enq: SQ – contention Lock to ensure that only one process can replenish the sequence cache
enq: SR – contention Coordinates replication / streams operations
enq: SS – contention Ensures that sort segments created during parallel DML operations aren’t prematurely cleaned up
Enqueue Type Description
enq: ST – contention Synchronizes space management activities in dictionary-managed tablespaces
enq: SU – contention Serializes access to SaveUndo Segment
enq: SW – contention Coordinates the ‘alter system suspend’ operation
enq: TA – contention Serializes operations on undo segments and undo tablespaces
enq: TB – SQL Tuning Base Cache Update Synchronizes writes to the SQL Tuning Base Existence Cache
enq: TB – SQL Tuning Base Cache Load Synchronizes writes to the SQL Tuning Base Existence Cache
enq: TC – contention Lock held to guarantee uniqueness of a tablespace checkpoint
enq: TC – contention2 Lock during setup of a unique tablespace checkpoint in null mode
enq: TD – KTF dump entries KTF dumping time/scn mappings in SMON_SCN_TIME table
enq: TE – KTF broadcast KTF broadcasting
enq: TF – contention Serializes dropping of a temporary file
enq: TL – contention Serializes threshold log table read and update
enq: TM – contention Synchronizes accesses to an object
enq: TO – contention Synchronizes DDL and DML operations on a temp object
enq: TQ – TM contention TM access to the queue table
enq: TQ – DDL contention DDL access to the queue table
enq: TQ – INI contention TM access to the queue table
enq: TS – contention Serializes accesses to temp segments
enq: TT – contention Serializes DDL operations on tablespaces
enq: TW – contention Lock held by one instance to wait for transactions on all instances to finish
Enqueue Type Description
enq: TX – contention Lock held by a transaction to allow other transactions to wait for it
enq: TX – row lock contention Lock held on a particular row by a transaction to prevent other transactions from modifying it
enq: TX – allocate ITL entry Allocating an ITL entry in order to begin a transaction
enq: TX – index contention Lock held on an index during a split to prevent other operations on it
enq: UL – contention Lock held used by user applications
enq: US – contention Lock held to perform DDL on the undo segment
enq: WA – contention Lock used for recovery when setting watermark for memory usage in AQ notifications
enq: WF – contention Enqueue used to serialize the flushing of snapshots
enq: WL – contention Coordinates access to redo log files and archive logs
enq: WP – contention Enqueue to handle concurrency between purging and baselines
enq: XH – contention Lock used for recovery when setting No Proxy Domains for AQ HTTP notifications
enq: XR – quiesce database Lock held during database quiesce
enq: XR – database force logging Lock held during database force logging mode
enq: XY – contention Lock used by Oracle Corporation for internal testing


We can get the description of p1, p2 and p3 at v$event_name. You can also get them from p1text, p2text and p3text from v$session if the event is happening right now.


NAME PARAMETER1 PARAMETER2 PARAMETER3
enq: AD – allocate AU name|mode group and disk number AU number
enq: AD – deallocate AU name|mode group and disk number AU number
enq: AF – task serialization name|mode task id 0
enq: AG – contention name|mode workspace # generation
enq: AM – client registration name|mode id1 id2
enq: AM – rollback COD reservation name|mode id1 id2
enq: AM – shutdown name|mode id1 id2
enq: AO – contention name|mode workspace # object #
enq: AS – modify service name|mode 0 0
enq: AS – service activation name|mode 0 0
enq: AT – contention name|mode 0 0
enq: AU – audit index file name|mode XML audit index file 0
enq: AW – AW generation lock name|mode operation workspace #
enq: AW – AW state lock name|mode operation workspace #
enq: AW – AW$ table lock name|mode operation workspace #
enq: AW – user access for AW name|mode operation workspace #
enq: BF – PMON Join Filter cleanup name|mode node#/parallelizer# bloom#
enq: BF – allocation contention name|mode node#/parallelizer# bloom#
enq: BR – file shrink name|mode operation file #
enq: BR – proxy-copy name|mode operation file #
enq: CF – contention name|mode 0 operation
enq: CI – contention name|mode opcode type
enq: CL – compare labels name|mode object # 0
enq: CL – drop label name|mode object # 0
enq: CM – gate name|mode disk group # type
enq: CM – instance name|mode disk group # type
enq: CN – race with init name|mode reg id 0
enq: CN – race with reg name|mode reg id 0
enq: CN – race with txn name|mode reg id 0
enq: CT – CTWR process start/stop name|mode operation operation parm
enq: CT – change stream ownership name|mode operation operation parm
enq: CT – global space management name|mode operation operation parm
enq: CT – local space management name|mode operation operation parm
enq: CT – reading name|mode operation operation parm
enq: CT – state name|mode operation operation parm
enq: CT – state change gate 1 name|mode operation operation parm
enq: CT – state change gate 2 name|mode operation operation parm
enq: CU – contention name|mode handle handle
enq: DB – contention name|mode EnqMode 0
enq: DD – contention name|mode disk group type
enq: DF – contention name|mode 0 file #
enq: DG – contention name|mode disk group type
enq: DL – contention name|mode object # 0
enq: DM – contention name|mode type type
enq: DN – contention name|mode 0 0
enq: DP – contention name|mode 0 0
enq: DR – contention name|mode 0 0
enq: DS – contention name|mode 0 0
enq: DT – contention name|mode 0 0
enq: DV – contention name|mode object # 0
enq: DX – contention name|mode transaction entry # 0
enq: FA – access file name|mode disk group number file number
enq: FB – contention name|mode tablespace # dba
enq: FC – open an ACD thread name|mode disk group thread
enq: FC – recover an ACD thread name|mode disk group thread
enq: FD – Flashback coordinator name|mode Internal Internal
enq: FD – Flashback on/off name|mode Internal Internal
enq: FD – Marker generation name|mode Internal Internal
enq: FD – Restore point create/drop name|mode Internal Internal
enq: FD – Tablespace flashback on/off name|mode Internal Internal
enq: FG – FG redo generation enq race name|mode disk group type
enq: FG – LGWR redo generation enq race name|mode disk group type
enq: FG – serialize ACD relocate name|mode disk group type
enq: FL – Flashback database log name|mode Log # zero
enq: FL – Flashback db command name|mode Log # zero
enq: FM – contention name|mode 0 0
enq: FP – global fob contention name|mode low file obj add high file obj add
enq: FR – contention name|mode disk group unused
enq: FS – contention name|mode 0 type
enq: FT – allow LGWR writes name|mode disk group thread
enq: FT – disable LGWR writes name|mode disk group thread
enq: FU – contention name|mode 0 0
enq: HD – contention name|mode disk group 0
enq: HP – contention name|mode tablespace # dba
enq: HQ – contention name|mode object # hash value
enq: HV – contention name|mode object # 0
enq: HW – contention name|mode table space # block
enq: IA – contention name|mode 0 0
enq: ID – contention name|mode 0 0
enq: IL – contention name|mode object # 0
enq: IM – contention for blr name|mode pool # 0
enq: IR – contention name|mode 0 0/1
enq: IR – contention2 name|mode 0 0/1
enq: IS – contention name|mode 0 type
enq: IT – contention name|mode object # 0
enq: JD – contention name|mode 0 0
enq: JI – contention name|mode view object # 0
enq: JQ – contention name|mode 0 0
enq: JS – contention name|mode service ID queue type
enq: JS – evt notify name|mode service ID queue type
enq: JS – evtsub add name|mode service ID queue type
enq: JS – evtsub drop name|mode service ID queue type
enq: JS – job recov lock name|mode service ID queue type
enq: JS – job run lock – synchronize name|mode service ID queue type
enq: JS – q mem clnup lck name|mode service ID queue type
enq: JS – queue lock name|mode service ID queue type
enq: JS – sch locl enqs name|mode service ID queue type
enq: JS – wdw op name|mode service ID queue type
enq: KK – context name|mode 0 redo thread
enq: KM – contention name|mode type type
enq: KO – fast object checkpoint name|mode 2 0
enq: KP – contention name|mode 0 0
enq: KT – contention name|mode plan # 0
enq: MD – contention name|mode master object # 0
enq: MH – contention name|mode 0 0
enq: MK – contention name|mode 0 0
enq: ML – contention name|mode 0 0
enq: MN – contention name|mode session ID 0
enq: MO – contention name|mode 0 0
enq: MR – contention name|mode 0 or file # type
enq: MS – contention name|mode master object # 0
enq: MW – contention name|mode Schedule Id 0
enq: OC – contention name|mode 1 2
enq: OL – contention name|mode hash value 0
enq: OQ – xsoq*histrecb name|mode resource id 0
enq: OQ – xsoqhiAlloc name|mode resource id 0
enq: OQ – xsoqhiClose name|mode resource id 0
enq: OQ – xsoqhiFlush name|mode resource id 0
enq: OQ – xsoqhistrecb name|mode resource id 0
enq: OW – initialization name|mode 0 0
enq: OW – termination name|mode 0 0
enq: PD – contention name|mode property name key hash
enq: PE – contention name|mode parno 0
enq: PF – contention name|mode 0 0
enq: PG – contention name|mode 0 0
enq: PH – contention name|mode 0 0
enq: PI – contention name|mode operation serial #
enq: PL – contention name|mode 0 0
enq: PR – contention name|mode 0 0
enq: PS – contention name|mode instance slave ID
enq: PT – contention name|mode disk group # type
enq: PV – syncshut name|mode 0 0
enq: PV – syncstart name|mode 0 0
enq: PW – flush prewarm buffers name|mode 0 0
enq: PW – perwarm status in dbw0 name|mode 0 0
enq: RB – contention name|mode disk group 0
enq: RF – RF – Database Automatic Disable name|mode lock operation lock value
enq: RF – RF – FSFO Observed name|mode lock operation lock value
enq: RF – RF – FSFO connectivity name|mode lock operation lock value
enq: RF – RF – FSFO state name|mode lock operation lock value
enq: RF – RF – FSFO synchronization name|mode lock operation lock value
enq: RF – RF – FSFO wait name|mode lock operation lock value
enq: RF – atomicity name|mode lock operation lock value
enq: RF – new AI name|mode lock operation lock value
enq: RF – synch: DG Broker metadata name|mode lock operation lock value
enq: RF – synchronization: HC master name|mode lock operation lock value
enq: RF – synchronization: aifo master name|mode lock operation lock value
enq: RF – synchronization: chief name|mode lock operation lock value
enq: RF – synchronization: critical ai name|mode lock operation lock value
enq: RN – contention name|mode thread number log number
enq: RO – contention name|mode 2 0
enq: RO – fast object reuse name|mode 2 0
enq: RP – contention name|mode file # 1 or block
enq: RR – contention name|mode lock# not used
enq: RS – file delete name|mode record type record id
enq: RS – persist alert level name|mode record type record id
enq: RS – prevent aging list update name|mode record type record id
enq: RS – prevent file delete name|mode record type record id
enq: RS – read alert level name|mode record type record id
enq: RS – record reuse name|mode record type record id
enq: RS – write alert level name|mode record type record id
enq: RT – contention name|mode redo thread type
enq: RU – contention name|mode 0 0
enq: RU – waiting name|mode 0 0
enq: RW – MV metadata contention name|mode table obj# 0
enq: SB – contention name|mode 0 0
enq: SE – contention name|mode Session-id Serial#
enq: SF – contention name|mode 0 0
enq: SH – contention name|mode 0 0
enq: SI – contention name|mode object # 0
enq: SK – contention name|mode tablespace # dba
enq: SQ – contention name|mode object # 0
enq: SR – contention name|mode operation sequence # / apply #
enq: SS – contention name|mode tablespace # dba
enq: ST – contention name|mode 0 0
enq: SU – contention name|mode table space # 0
enq: SW – contention name|mode 0 0
enq: TA – contention name|mode operation undo segment # / other
enq: TB – SQL Tuning Base Cache Load name|mode 1 2
enq: TB – SQL Tuning Base Cache Update name|mode 1 2
enq: TC – contention name|mode checkpoint ID 0
enq: TC – contention2 name|mode checkpoint ID 0
enq: TD – KTF dump entries name|mode 0 0
enq: TE – KTF broadcast name|mode 0 0
enq: TF – contention name|mode tablespace # relative file #
enq: TL – contention name|mode 0 0
enq: TM – contention name|mode object # table/partition
enq: TO – contention name|mode object # 1
enq: TQ – DDL contention name|mode QT_OBJ# 0
enq: TQ – INI contention name|mode QT_OBJ# 0
enq: TQ – TM contention name|mode QT_OBJ# 0
enq: TS – contention name|mode tablespace ID dba
enq: TT – contention name|mode tablespace ID operation
enq: TW – contention name|mode 0 operation
enq: TX – allocate ITL entry name|mode usn<<16 | slot sequence
enq: TX – contention name|mode usn<<16 | slot sequence
enq: TX – index contention name|mode usn<<16 | slot sequence
enq: TX – row lock contention name|mode usn<<16 | slot sequence
enq: UL – contention name|mode id 0
enq: US – contention name|mode undo segment # 0
enq: WA – contention name|mode 0 0
enq: WF – contention name|mode 0 0
enq: WL – contention name|mode log # / thread id # sequence #
enq: WP – contention name|mode 0 0
enq: WR – contention name|mode thread id # sequence #
enq: XH – contention name|mode 0 0
enq: XQ – recovery name|mode disk group # unused
enq: XQ – relocation name|mode disk group # unused
enq: XR – database force logging name|mode operation 0
enq: XR – quiesce database name|mode operation 0
enq: XY – contention name|mode id1 id2
enq: ZG – contention name|mode file group id version id

For the P1 values which is “name|mode”, we can decode it like this:

select chr(bitand(p1,-16777216)/16777215)||chr(bitand(p1, 16711680)/65535) "Name",
bitand(p1, 65535) "Mode"
from v$session;








Reference : Oracle Wait Interface: A Practical Guide to Performance Diagnostics & Tuning
                   https://alexzeng.wordpress.com/2013/07/16/enqueue-waits-in-oracle-database-10g/