Problem
Whenever you try to do any structural changes on a table oracle try to lock the table exclusively with NOWAIT option (even creating index or altering the table defn)
Solution
In 10.2g you are limited to several choices to solve the problem. To avoid it,
-Re run the DDL at a later time when the database become idle.
or,
-Kill the sessions that are preventing the exclusive lock.
or,
-Prevent end user to connect to the database and then run the DDL.
You have different views to see locking information about the table.
1)DBA_BLOCKERS: Displays a session if it is not waiting for a locked object but is holding a lock on an object for which another session is waiting. In our scenario this view will not help.
2)DBA_DDL_LOCKS: It lists all DDL locks held in the database and all outstanding requests for a DDL lock.
3)DBA_DML_LOCKS: It lists all DML locks held in the database and all outstanding requests for a DML lock.
If you query from it in the mode_held field you will see 'row exclusive lock'.
SQL> select mode_held from dba_dml_locks where owner='MAXIMSG';
MODE_HELD
-------------
Row-X (SX)
4)DBA_LOCK: It lists all locks or latches held in the database, and all outstanding requests for a lock or latch.
5)DBA_LOCK_INTERNAL: It displays a row for each lock or latch that is being held, and one row for each outstanding request for a lock or latch.
6)DBA_LOCKS is a synonym for DBA_LOCK.
7)DBA_WAITERS: Shows all the sessions that are waiting for a lock
select oracle_username || ' (' || s.osuser || ')' username
, s.sid || ',' || s.serial# sess_id
, owner || '.' || object_name object
, object_type
, decode( l.block
, 0, 'Not Blocking'
, 1, 'Blocking'
, 2, 'Global') status
, decode(v.locked_mode
, 0, 'None'
, 1, 'Null'
, 2, 'Row-S (SS)'
, 3, 'Row-X (SX)'
, 4, 'Share'
, 5, 'S/Row-X (SSX)'
, 6, 'Exclusive', TO_CHAR(lmode)) mode_held
from v$locked_object v
, dba_objects d
, v$lock l
, v$session s
where v.object_id = d.object_id
and v.object_id = l.id1
and v.session_id = s.sid
order by oracle_username
, session_id
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment