Obtain DDL lock information from DBA_DDL_LOCKS view

http://liwenshui322.iteye.com/blog/1166934

There are three types of DDL locks:

     1. Exclusive DDL lock: This prevents other sessions from getting their own DDL lock or TM (DML) lock. This means that you can query a table during a DDL operation, but you cannot modify the table in any way.

     2. Share DDL locks: These locks protect the structure of the referenced object from being modified by other sessions, but allow modification of data.

     3. Breakable parse locks: These locks allow an object (such as a query plan cached in a shared pool) to register its dependencies with another object. If you execute DDL on a dependent object, Oracle will look at the list of objects that have registered dependencies on the object, and invalidate those objects. Therefore, these locks are "interruptible", they do not prevent DDL from appearing.

Exclusive DDL lock : such as: Alter table t add new_column date

Shared DDL lock : When creating stored compiled objects (such as procedures and views), this shared DDL lock is applied to dependent objects. For example, if the following statement is executed:

      Create view MyView
          as
      select *  
      from emp, dept
      where emp.deptno = dept.deptno;

Case: delete a table, no response

SQL> select count(*) from T_LOG;

COUNT(*)
----------
9097
SQL> truncate TABLE "ELON"."T_LOG";
SQL> drop table "ELON"."T_LOG";

SQL> select owner,table_name,status from dba_tables where table_name='T_LOG';

OWNER TABLE_NAME STATUS
------------------------------ ------------------------------ --------
ELON T_LOG VALID

SQL> conn ELON/ELON

SQL> select sid,serial#,paddr,username,osuser,machine,program from v$session where sid in( select SESSION_ID from dba_ddl_locks where name='T_LOG');

SID SERIAL# PADDR USERNAME OSUSER MACHINE PROGRAM
---------- ---------- ---------------- ------------------------------ ------------------------------ --------------- -------------------------
58 61519 C000000CEB26D418 SYS oracle app01 sqlplus@app01 (TNS V1-
V3)

2808 16967 C000000CEB31B6E8 JDSS Administrator WIN-LLI9R4268RH JDBC Thin Client
5121 4795 C000000CEAF1F888 SYS oracle app01 oracle@app01 (J013)


Query the session holding DDL exclusive lock
SQL>select sid,serial#,s.sql_id,sql_text,program from v$session s,v$sql l where sid in(58,2808,5121) and s.sql_id=l .sql_id

SID SERIAL# SQL_ID SQL_TEXT PROGRAM
---------- ---------- ------------- -------------------------------------------------- -------------------------
2808 16967 fgzbtnugq630d update T_LOG a set (a.STATUS,a.ZGSTATUS)=( JDBC Thin Client
select STATUS,ZGSTATUS from T_LOG@ELON_XHDoT_WH b where b.txid=a.txid) where a.STATUS<>'1' and a.STATUS<>'2' and a.modify_time>sysdate-5 and ts='GCN'

5121 4795 1cv2jg0a6m0k8 begin DBMS_STATS.CLEANUP_STATS_JOB_PROC(:1,:2,:3,: oracle@app01 (J013)
4,:5); end;

 

SQL> alter system kill session '2808,16967';
alter system kill session '2808,16967'
*
ERROR at line 1:
ORA-00031: session marked for kill


SQL> select spid, osuser, s.program from v$session s,v$process p where s.paddr=p.addr and s.sid=2808;

SPID OSUSER PROGRAM
------------------------ ------------------------------ -------------------------
23928 Administrator JDBC Thin Client


app01@/data/diag/rdbms/prod/prod/trace$ps -ef | grep 23928
oracle 21349 19923 0 17:28:48 pts/0 0:00 grep 23928
oracle 23928 1 0 4? 10 ? 1:22 oraclecddb (LOCAL=NO)

app01@/data/diag/rdbms/prod/prod/trace$kill -9 23928
app01@/data/diag/rdbms/prod/prod/trace$ps -ef | grep 23928
oracle 21680 19923 0 17:31:45 pts/0 0:00 grep 23928

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324653912&siteId=291194637
DDL