OracleBlocking & locks
Blocked sessions and their blockers
Sessions 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_instance.
Not yet verified. How scripts are tested
1CLEAR COLUMNS2SET LINESIZE 200 PAGESIZE 100 TRIMOUT ON TAB OFF3COLUMN blocked HEADING "BLOCKED" FORMAT A144COLUMN username HEADING "USER" FORMAT A155COLUMN event FORMAT A30 TRUNCATE6COLUMN wait_secs HEADING "WAIT SECS" FORMAT 999,9997COLUMN blocker HEADING "BLOCKER" FORMAT A148COLUMN blocker_user HEADING "BLOCKER USER" FORMAT A159COLUMN blocker_status HEADING "STATUS" FORMAT A810COLUMN blocker_sql_id HEADING "BLOCKER SQL" FORMAT A1311 12SELECT s.sid || ',' || s.serial# AS blocked,13 s.username, s.event,14 s.seconds_in_wait AS wait_secs,15 b.sid || ',' || b.serial# AS blocker,16 b.username AS blocker_user,17 b.status AS blocker_status,18 NVL(b.sql_id, b.prev_sql_id) AS blocker_sql_id19FROM v$session s20JOIN v$session b ON b.sid = s.blocking_session21WHERE s.blocking_session IS NOT NULL22ORDER BY s.seconds_in_wait DESC;Save it as b-ora-blocking.sql and run it with SQL> @b-ora-blocking.
Helps with
- ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
- ORA-04021: timeout occurred while waiting to lock object
Part of these runbooks
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…
- 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.
- Locked objects and who holds themEvery 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…