OracleBlocking & locks
Locked objects and who holds them
Every object with a DML lock, the session holding it and the lock mode in plain words. Exclusive locks from sessions that are INACTIVE usually mean an uncommitted transaction.
Not yet verified. How scripts are tested
1CLEAR COLUMNS2SET LINESIZE 180 PAGESIZE 100 TRIMOUT ON TAB OFF3COLUMN sid_serial HEADING "SID,SERIAL#" FORMAT A144COLUMN username FORMAT A155COLUMN object FORMAT A45 TRUNCATE6COLUMN object_type HEADING "TYPE" FORMAT A127COLUMN lock_mode HEADING "LOCK MODE" FORMAT A148COLUMN status FORMAT A89 10SELECT lo.session_id || ',' || s.serial# AS sid_serial,11 s.username,12 o.owner || '.' || o.object_name AS object,13 o.object_type,14 DECODE(lo.locked_mode, 0, 'None', 1, 'Null', 2, 'Row share',15 3, 'Row exclusive', 4, 'Share', 5, 'Share row excl',16 6, 'Exclusive', TO_CHAR(lo.locked_mode)) AS lock_mode,17 s.status18FROM v$locked_object lo19JOIN dba_objects o ON o.object_id = lo.object_id20JOIN v$session s ON s.sid = lo.session_id21ORDER BY o.owner, o.object_name;Save it as ora-locked-objects.sql and run it with SQL> @ora-locked-objects.
Helps with
More Oracle scripts: Blocking & locks
- Locked objects across all instances (three views)Three looks at DML locks from GV$LOCKED_OBJECT: which objects are locked and by whom, the lock mode per object, and the same with the OS process ID…
- Blocked sessions and their blockersSessions waiting on another session, joined to the blocker. Both sides show as SID,SERIAL#, ready to paste into a kill. On RAC, also check…
- Blocking treeThe whole chain as an indented tree, starting from the root blocker. When ten sessions are stuck, the one at the left margin is the one to deal with.