How to troubleshoot ORA-02049 and lock problems in general with Oracle

前端 未结 5 1314
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 03:39

I am getting ORA-02049 occasionally for some long-running and/or intensive transactions. There is seemingly no pattern to this, but it happens on a simple INSERT.

I

相关标签:
5条回答
  • 2020-12-31 03:58

    Try increasing the SHARED_POOL_SIZE value in init.ora .
    If that fails try ALTER SYSTEM FLUSH SHARED_POOL

    Also see this.

    0 讨论(0)
  • 2020-12-31 03:59

    Could it be a bitmap index causing the error as described here?

    0 讨论(0)
  • 2020-12-31 04:14

    One possible way might be to increase the INIT.ORA parameter for distributed_lock_timeout to a larger value. This would then give you a longer time to observe the v$lock table as the locks would last for longer.

    To achieve automation of this, you can either

    • Run an SQL job every 5-10 seconds that logs the values of v$lock or the query that sandos has given above into a table and then analyze it to see which session was causing the lock.

    • Run a STATSPACK or an AWR Report. The sessions that got locked should show up with high elapsed time and hence can be identified.

    v$session has 3 more columns blocking_instance, blocking_session, blocking_session_status that can be added to the query above to give a picture of what is getting locked.

    0 讨论(0)
  • 2020-12-31 04:16

    Ok, this was a silly problem.

    We are using Entity Framework 6.0 (upgraded to 6.2, but no change), Oracle.ManagedDataAccess +EntityFramework 12.2.1100, .NET 4.5.

    I was getting ORA-02049: timeout: distributed transaction waiting for lock with the following query:

    update "schemaname"."tablename"
    set "DUE_DATE" = :p0
    where ("ID" = :p1) 
    

    (via EF context.Database.Log event). A really simple query, shouldn't have any issues.

    Well, I was using the same login on the remote server, on my local debugger, and in Oracle SQL Developer. A co-worker pointed out I should kill all these multiple connections while debugging .... and it worked. So the solution in my case was not to connect to the database multiple times with the same login.

    0 讨论(0)
  • 2020-12-31 04:23

    Use this query to determine possible blocking locks:

    SELECT se.username,
           NULL,
           se.sid,
           DECODE( se.command,
                   0, 'No command',
                   1, 'CREATE TABLE',
                   2, 'INSERT',
                   3, 'SELECT',
                   4, 'CREATE CLUSTER',
                   5, 'ALTER CLUSTER',
                   6, 'UPDATE',
                   7, 'DELETE',
                   8, 'DROP CLUSTER',
                   9, 'CREATE INDEX',
                   10, 'DROP INDEX',
                   11, 'ALTER INDEX',
                   12, 'DROP TABLE',
                   13, 'CREATE SEQUENCE',
                   14, 'ALTER SEQUENCE',
                   15, 'ALTER TABLE',
                   16, 'DROP SEQUENCE',
                   17, 'GRANT',
                   18, 'REVOKE',
                   19, 'CREATE SYNONYM',
                   20, 'DROP SYNONYM',
                   21, 'CREATE VIEW',
                   22, 'DROP VIEW',
                   23, 'VALIDATE INDEX',
                   24, 'CREATE PROCEDURE',
                   25, 'ALTER PROCEDURE',
                   26, 'LOCK TABLE',
                   27, 'NO OPERATION',
                   28, 'RENAME',
                   29, 'COMMENT',
                   30, 'AUDIT',
                   31, 'NOAUDIT',
                   32, 'CREATE DATABASE LINK',
                   33, 'DROP DATABASE LINK',
                   34, 'CREATE DATABASE',
                   35, 'ALTER DATABASE',
                   36, 'CREATE ROLLBACK SEGMENT',
                   37, 'ALTER ROLLBACK SEGMENT',
                   38, 'DROP ROLLBACK SEGMENT',
                   39, 'CREATE TABLESPACE',
                   40, 'ALTER TABLESPACE',
                   41, 'DROP TABLESPACE',
                   42, 'ALTER SESSION',
                   43, 'ALTER USER',
                   44, 'COMMIT',
                   45, 'ROLLBACK',
                   46, 'SAVEPOINT',
                   47, 'PL/SQL EXECUTE',
                   48, 'SET TRANSACTION', 
                   49, 'ALTER SYSTEM SWITCH LOG',
                   50, 'EXPLAIN',
                   51, 'CREATE USER',
                   52, 'CREATE ROLE',
                   53, 'DROP USER',
                   54, 'DROP ROLE',
                   55, 'SET ROLE',
                   56, 'CREATE SCHEMA',
                   57, 'CREATE CONTROL FILE',
                   58, 'ALTER TRACING',
                   59, 'CREATE TRIGGER',
                   60, 'ALTER TRIGGER',
                   61, 'DROP TRIGGER',
                   62, 'ANALYZE TABLE',
                   63, 'ANALYZE INDEX',
                   64, 'ANALYZE CLUSTER',
                   65, 'CREATE PROFILE',
                   67, 'DROP PROFILE',
                   68, 'ALTER PROFILE',
                   69, 'DROP PROCEDURE',
                   70, 'ALTER RESOURCE COST',
                   71, 'CREATE SNAPSHOT LOG',
                   72, 'ALTER SNAPSHOT LOG',
                   73, 'DROP SNAPSHOT LOG',
                   74, 'CREATE SNAPSHOT',
                   75, 'ALTER SNAPSHOT',
                   76, 'DROP SNAPSHOT',
                   79, 'ALTER ROLE',
                   85, 'TRUNCATE TABLE',
                   86, 'TRUNCATE CLUSTER',
                   88, 'ALTER VIEW',
                   91, 'CREATE FUNCTION',
                   92, 'ALTER FUNCTION',
                   93, 'DROP FUNCTION',
                   94, 'CREATE PACKAGE',
                   95, 'ALTER PACKAGE',
                   96, 'DROP PACKAGE',
                   97, 'CREATE PACKAGE BODY',
                   98, 'ALTER PACKAGE BODY',
                   99, 'DROP PACKAGE BODY',
             TO_CHAR(se.command) ) command,
           DECODE(lo.type,
             'MR', 'Media Recovery',
             'RT', 'Redo Thread',
             'UN', 'User Name',
             'TX', 'Transaction',
             'TM', 'DML',
             'UL', 'PL/SQL User Lock',
             'DX', 'Distributed Xaction',
             'CF', 'Control File',
             'IS', 'Instance State',
             'FS', 'File Set',
             'IR', 'Instance Recovery',
             'ST', 'Disk Space Transaction',
             'TS', 'Temp Segment',
             'IV', 'Library Cache Invalidation',
             'LS', 'Log Start or Switch',
             'RW', 'Row Wait',
             'SQ', 'Sequence Number',
             'TE', 'Extend Table',
             'TT', 'Temp Table',
             'JQ', 'Job Queue',
             lo.type) ltype,
           DECODE( lo.lmode, 
             0, 'NONE',           /* Mon Lock equivalent */
             1, 'Null Mode',      /* N */
             2, 'Row-S (SS)',     /* L */
             3, 'Row-X (SX)',     /* R */
             4, 'Share (S)',      /* S */
             5, 'S/Row-X (SSX)',  /* C */
             6, 'Excl (X)',       /* X */
             lo.lmode) lmode,
           DECODE( lo.request, 
             0, 'NONE',           /* Mon Lock equivalent */
             1, 'Null',           /* N */
             2, 'Row-S (SS)',     /* L */
             3, 'Row-X (SX)',     /* R */
             4, 'Share (S)',      /* S */
             5, 'S/Row-X (SSX)',  /* C */
             6, 'Excl (X)',       /* X */
             TO_CHAR(lo.request)) request,
           lo.ctime ctime,
           DECODE(lo.block,
             0, 'No Block',
             1, 'Blocking',
             2, 'Global',
             TO_CHAR(lo.block)) blkothr,
           'SYS' owner,
           ro.name image
      FROM v$lock lo,
           v$session se,
           v$transaction tr,
           v$rollname ro
     WHERE se.sid = lo.sid
       AND se.taddr = tr.addr(+)
       AND tr.xidusn = ro.usn(+)
     ORDER BY sid
    
    0 讨论(0)
提交回复
热议问题