FOR UPDATE cursor is causing Blocking/ Dead Locking issues

Hi,
I am facing one of the complex issues regarding blocking / dead locking issues. Please find below the details and help / suggest me the best approach to ahead with that.
Its core Investment Banking Domain, in Our Day to day Business we are using many transaction table for processing trades and placing the order. In specific there are two main transaction table
1)     Transaction table 1
2)     Transaction table 2
These both the tables are having huge amount of data. In one of our application to maintain data integrity (During this process we do not want other users to change these rows), we have placed SELECT …………….. FOR UPDATE CURSOR on these two table and we have locked all the rows during the process. And we have batch jobs (shell scripts ) , calling this procedure , we will be running 9 times per day 1 hrs each start at 7:15AM in the morn finish it up in the eve 5PM . Let’s say. The reason we run the same procedure multiple times is, our business wants to know the voucher before its finalized. Because there is a possibility that order can be placed and will be updated/cancelled several times in a single day. So at the end of the day , we will be sending the finalized update to our client.
20 07 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 08 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 09 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 10 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 11 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 12 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 13 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 14 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 15 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 16 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 17 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
Current Program will look like:
App_Prc_1
BEGIN
/***** taking the order details (source) and will be populate into the table ****/
CURSOR Cursor_Upload IS
SELECT col1, col2 … FROM Transaction table1 t 1, Source table 1 s
WHERE t1.id_no = t2.id_no
AND t1.id_flag = ‘N’
FOR UPDATE OF t1.id_flag;
/************* used for inserting the another entry , if theres any updates happened on the source table , for the records inserted using 1st cursor. **************/
CURSOR cursor_update IS
SELECT col1, col2 … FROM transaction table2 t2 , transaction table t1
WHERE t1.id_no = t2.id_no
AND t1.id_flag = ‘Y’
AND t1.DML_ACTION = ‘U’,’D’ -- will retrieve the records which are updated and deleted recently for the inserted records in transaction table 1 for that particular INSERT..
FOR UPDATE OF t1.id_no,t1.id_flag;
BLOCK 1
BEGIN
FOR v_upload IN Cursor_Upload;
LOOP
INSERT INTO transaction table2 ( id_no , dml_action , …. ) VALUES (v_upload.id_no , ‘I’ , … ) RETURNING v_upload.id_no INTO v_no -- I specify for INSERT
/********* Updating the Flag in the source table after the population ( N into Y ) N  order is not placed yet , Y  order is processed first time )
UPDATE transaction table1
SET id_FLAG = ‘Y’
WHERE id_no = v_no;
END LOOP;
EXCEPTION WHEN OTHER THEN
DBMS_OUTPUT.PUT_LINE( );
END ;
BLOCK 2
BEGIN -- block 2 starts
FOR v_update IN Cursor_Update;
LOOP;
INSERT INTO transaction table2 ( id_no ,id_prev_no, dml_action , …. ) VALUES (v_id_seq_no, v_upload.id_no ,, … ) RETURNING v_upload.id_no INTO v_no
UPDATE transaction table1
SET id_FLAG = ‘Y’
WHERE id_no = v_no;
END LOOP;
EXCEPTION WHEN OTHER THEN
DBMS_OUTPUT.PUT_LINE( );
END; -- block2 end
END app_proc; -- Main block end
Sample output in Transaction table1 :
Id_no | Tax_amt | re_emburse_amt | Activ_DT | Id_Flag | DML_ACTION
01 1,835 4300 12/JUN/2009 N I ( these DML Action will be triggered when ever if theres in any DML operation occurs in this table )
02 1,675 3300 12/JUN/2009 Y U
03 4475 6500 12/JUN/2009 N D
Sample output in Transaction table2 :
Id_no | Prev_id_no Tax_amt | re_emburse_amt | Activ_DT
001 01 1,835 4300 12/JUN/2009 11:34 AM ( 2nd cursor will populate this value , bcoz there s an update happened for the below records , this is 2nd voucher
01 0 1,235 6300 12/JUN/2009 09:15 AM ( 1st cursor will populate this record when job run first time )
02 0 1,675 3300 12/JUN/2009 8:15AM
003 03 4475 6500 12/JUN/2009 11:30 AM
03 0 1,235 4300 12/JUN/2009 10:30 AM
Now the issues is :
When these Process runs, our other application jobs failing, because it also uses these main 2 tranaction table. So dead lock is detecting in these applications.
Solutin Needed :
Can anyone suggest me , like how can rectify this blocking /Locking / Dead lock issues. I wants my other application also will use this tables during these process.
Regards,
Maran

hmmm.... this leads to a warning:
SQL> ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';
Session altered.
CREATE OR REPLACE PROCEDURE MYPROCEDURE
AS
   MYCOL VARCHAR(10);
BEGIN
   SELECT col2
   INTO MYCOL
   FROM MYTABLE
   WHERE col1 = 'ORACLE';
EXCEPTION
   WHEN PIERRE THEN
      NULL;
END;
SP2-0804: Procedure created with compilation warnings
SQL> show errors
Errors for PROCEDURE MYPROCEDURE:
LINE/COL                                                                          ERROR
     12/9        PLW-06009: procedure “MYPROCEDURE” PIERRE handler does not end in RAISE or RAISE_APPLICATION_ERROR
     :)

Similar Messages

  • For Update Cursor

    Hi ,
    Can you let me know what happen in this cursoe when we use for update?
    CURSOR TRAN_CUR
    IS
    SELECT TRANSACTION_ID
    ,YEAR_MONTH_DT
    ,SOURCE_CD
    ,INVOICE
    FROM
    TRANSACTION_CONTROL
    WHERE
    NEXT_PROCESS = 'MAP'
    FOR
    UPDATE;
    Thanks in advance,

    Assuming that the cursor is written correctly SQL will lock each row as it is selected. The lock will remain until you do a COMMIT or a ROLLBACK. Normally Oracle will lock rows when you perform DML on them but FOR UPDATE causes the row to be locked when the select occurs.
    FOR UPDATE also has the happy side effect of allowing use of the CURRENT OF predicate in select loops simplifying where clauses; when you say "WHERE CURRENT OF cursor_name" for a FOR UPDATE cursor you will only operate on the current row.
    Now for the unhappy side effects. FOR UPDATE cursors run more slowly than normal cursors because it takes time and effort to lock the rows. Second (and worse) you are locked into one transaction for the entire cursor execution because performing a SELECT after a commit or rollback results in the FETCH OUT OF SEQUENCE error (this is not usually a problem but could result in running out of rollback segments or undo space for newer databases. Its unlikely these days but can happen). Finally, performing DML in one statement (as in insert into/select from) is often faster than performing the select loops with DML inside them anyway.
    I wouldn't use FOR UPDATE unless I really needed the rows locked because of the performance hit.

  • Does dropping bitmap index and creation of b- index cause any dead locks

    Does dropping a bitmap index on table which is being used continuously for DML operations and creation of b- index cause any dead locks on a table
    in oracle 10g database
    ( 10.1.0.4.0 - 64bi).
    we have seen alert log file which has dead lock occurrence.. would index change/re-creation resulted dead lock or some other reason?
    Could you please give us info or help us on this.. thanks in advance..

    Bitmap indexes can be the cause of deadlocks on busy systems.
    Dropping indexes may cause some locking.
    Creating indexes may cause some locking.
    You haven't given any traces or scripts or lock information, so difficult to say which one (if any) was the cause of your deadlocks.
    It would be better to do this activity when the system is not busy.

  • For update cursor with nowait

    I have a 'for update' cursor defined with 'NOWAIT'. When soem of teh records that are supposed to be fetched by teh cursor are locked by another user for update..teh pl?SQL script returns
    "ORA-00054: resource busy and acquire with NOWAIT specified" error.
    If I declare teh cursor with out 'FOR UPDATE' or did NOT put 'NOWAIT' clause, teh script hangs waiting for teh records to be unlocked.
    If the user opens a record in the front end (web app) and does not close it.. i can not run the script. Is theer any way to ignore those records that are locked by other users and query only ones that are available as part of the select statement in the cursor.

    Optimistic locking implies, essentailly, that you never lock the row. Instead, if you want to update the row, you check all the other columns of the row to see whether they have changed. In other words, you'd do a straight SELECT here and then when you went to UPDATE the data, you'd do
    UPDATE <<change some column>>
    WHERE col1=<<old col1 value>>
       AND col2=<<old col2 value>>
       AND ...If the update changed 1 row, you're set. If it changed 0 rows, someone had changed the underlying row since you SELECTED it, so you'd have to handle that condition. If it returned an error indicating that someone else had locked the row, you could handle that situation as well. If you just continue on, however, be sure that you know how to identify that this row wasn't updated so you can try to do the update the next time (assuming that makes sense).
    If all your applications take the optimistic locking approach, you're pretty much guaranteed that no one else will have teh row locked, so you don't have to handle that state nearly as robustly.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com

  • How to update data when primary key is set through for update cursor

    Dear friends,
    I have tried to update data in the table through forms using cursor for update and i have given the plsql i have used please help me where i do mistake.
    DECLARE CURSOR EMP IS
    SELECT EMPNO,EMPNAME,FATHERNAME,COMMUNITY,SEX,BILLUNIT,BIRTHDATE,RLYJOINDATE,RETIREMENTDATE
    FROM PRMAEMP WHERE BILLUNIT=:CTRL.BILLUNIT AND SERVICESTATUS='SR'ORDER BY DESIGCODE,SCALECODE
    FOR UPDATE;
    BEGIN
    GO_BLOCK('EMP_DETAILS');
    SYNCHRONIZE;
    FOR I IN EMP
    LOOP
    I.BILLUNIT:=:EMP_DETAILS.BILLUNIT;     
    I.EMPNO:=:EMPNO;
    I.EMPNAME:=:EMPNAME;
    I.FATHERNAME:=:FATHERNAME;
    I.COMMUNITY:=:COMMUNITY;
    I.SEX:=:SEX;
    I.BIRTHDATE:=:BIRTHDATE;
    I.RLYJOINDATE:=:RLYJOINDATE;
    I.RETIREMENTDATE:=:RETIREMENTDATE;
    DOWN;
    END LOOP;
    COMMIT;
    END;
    your help is needed immediately

    DECLARE CURSOR ABC IS
       SELECT EMPNO,
              EMPNAME,
              FATHERNAME,
              COMMUNITY,
              SEX,
              BILLUNIT,
              BIRTHDATE,
              RLYJOINDATE,
              RETIREMENTDATE
    FROM PRMAEMP
    WHERE BILLUNIT=:CTRL.BILLUNIT
    AND SERVICESTATUS='SR'
    ORDER BY DESIGCODE,SCALECODE
    FOR UPDATE OF COMMUNITY;
    V_EMPNO           PRMAEMP.EMPNO%TYPE;
    V_EMPNAME         PRMAEMP.EMPNAME%TYPE;
    V_FATHERNAME      PRMAEMP.FATHERNAME%TYPE;
    V_COMMUNITY       PRMAEMP.COMMUNITY%TYPE;
    V_SEX             PRMAEMP.SEX%TYPE;
    V_BILLUNIT        PRMAEMP.BILLUNIT%TYPE;
    V_BIRTHDATE       PRMAEMP.BIRTHDATE%TYPE;
    V_RLYJOINDATE     PRMAEMP.RLYJOINDATE%TYPE;
    V_RETIREMENTDATE  PRMAEMP.RETIREMENTDATE%TYPE;
    BEGIN
       GO_BLOCK('EMP');
       SYNCHRONIZE;
       OPEN ABC;
       LOOP
          FETCH ABC INTO .... /*yOU NEED TO MENTION YOUR VARIABLES HERE*/;
          UPDATE PRMAEMP
          SET BILLUNIT= :EMP.BILLUNIT,
              EMPNO= :EMPNO,
              EMPNAME= :EMPNAME,
              FATHERNAME= :FATHERNAME,
              COMMUNITY= :COMMUNITY,
              SEX= :SEX,
              BIRTHDATE= :BIRTHDATE,
              RLYJOINDATE= :RLYJOINDATE,
              RETIREMENTDATE= :RETIREMENTDATE
          WHERE CURRENT OF ABC;
          EXIT WHEN ABC%NOTFOUND;
       END LOOP;
       CLOSE ABC;
    END;
    COMMIT;
    END;Cheers
    Sarma.

  • Looking for update on Palm 5.2.1 sync issues

    Wondering what the offical word is on the Palm OS 5.2.1 sync issue? Is there an ETA for the upgraded conduit?

    however we will only look into supporting the new
    Palm features (i.e. location, URL, birthday, address,
    etc.) in a subsequent release.Quite disapointing. Both Oracle Calendar and Palm are only
    interesting if they work closely together and mutally
    support all features.
    Another feature I would very much like to have is
    network synchronization directly with
    the server and not passing via this little executable
    on the PC.
    This would make Ocal/Palm support independent from the
    OS. (I use vmware to just run this executable, a lot of
    waste of resources.)
    Best
    Jens

  • For Update Query with Wait Clause from ORACLE Forms

    Hi
    We are using Oracle Forms 10g running with 10g database 10.2.0.1.0. We happend to see a query which is getting generated in AWR report like Select rowid, all_columns from TableName for Update of C1 Nowait. But no such query is really written in forms and we are aware that, Any query prefixed with rowid is definitely executing from Forms. But how the ForUpdate and Nowait clause is appended to the query.
    We have checked the following properties in the database Block
    *1) Locking Mode is set to Automatic*
    *2) Update Changed Columns only is set to YES*
    *3) Query all records is set to No (Though this particular property may not be relevant to the issue)*
    What is the property or setting which might trigger such a query from ORACLE Forms with ForUpdate and Nowait clause.
    Any ideas/suggestions on why such behaviour. Please have a healthy discussion on this. Thanks in advance.

    Why have you started another thread on the same thing?
    FOR UPDATE cursor is causing Blocking/ Dead Locking issues
    Just use one thread to avoid confusion.
    The fact that nobody has answered on the other thread for a couple of days could be to do with it being the weekend and most people are not at work.
    Either be patient or, if it's more "urgent" than that, raise a SR/Tar with Oracle metalink.

  • Dead lock error while updating data into cube

    We have a scenario of daily truncate and upload of data into cube and volumes arrive @ 2 million per day.We have Parallel process setting (psa and data targets in parallel) in infopackage setting to speed up the data load process.This entire process runs thru process chain.
    We are facing dead lock issue everyday.How to avoid this ?
    In general dead lock occurs because of degenerated indexes if the volumes are very high. so my question is does deletion of Indexes of the cube everyday along with 'deletion of data target content' process help to avoiding dead lock ?
    Also observed is updation of values into one infoobject is taking longer time approx 3 mins for each data packet.That infoobject is placed in dimension and defined it as line item as the volumes are very high for that specific object.
    so this is over all scenario !!
    two things :
    1) will deletion of indexes and recreation help to avoid dead lock ?
    2) any idea why the insertion into the infoobject is taking longer time (there is a direct read on sid table of that object while observed in sql statement).
    Regards.

    hello,
    1) will deletion of indexes and recreation help to avoid dead lock ?
    Ans:
    To avoid this problem, we need to drop the indexes of the cube before uploading the data.and rebuild the indexes...
    Also,
    just find out in SM12 which is the process which is causing lock.... Delete that.
    find out the process in SM66 which is running for a very long time.Stop  this process.
    Check the transaction SM50 for the number of processes available in the system. If they are not adequate, you have to increase them with the help of basis team
    2) any idea why the insertion into the infoobject is taking longer time (there is a direct read on sid table of that object while observed in sql statement).
    Ans:
    Lie item dimension is one of the ways to improve data load as well as query performance by eliminationg the need for dimensin table. So while loading/reading, one less table to deal with..
    Check in the transformation mapping of that chs, it any rouitne/formula  is written.If so, this can lead to more time for processing that IO.
    Storing mass data in InfoCubes at document level is generally not recommended because when data is loaded, a huge SID table is created for the document number line-item dimension.
    check if your IO is similar to doc no...
    Regards,
    Dhanya

  • FOR UPDATE...SKIP LOCKED - Is it supported to use in 10.2?

    Hi.
    Is the "SKIP LOCKED" feature in SELECT..FOR UPDATE..SKIP LOCKED supported to use in 10.2.0.3?
    It does exactly what we want to do. The patchsets for 10g also contains bug fixes for this feature.
    I know that it's supported (and documented) for 11g, but we have not upgraded yet.
    Also I'm fully aware of the locking mechanism using this feature (it does not lock when opening a cursor,
    it locks when the rows are fetched).
    Regards
    Krister Lundmark

    Also I'm fully aware of the locking mechanism using this feature (it does not lock when opening a cursor,
    it locks when the rows are fetched).Usual FOR UPDATE statement locks data at the moment of cursor opening - according to the concepts it has to get
    locked consistent snapshot before fetching. SKIP LOCKED differs from usual FOR UPDATE in that it
    tries to lock at the moment of fetch and skips rows already locked by other transactions:
    The first transaction:
    SQL> select ename from emp where ename = 'KING' for update;
    ENAME
    KINGThe second: I wait at the moment of cursor opening, not fetching
    SQL> declare
      2   cursor x is select * from emp for update;
      3  begin
      4   open x;
      5  end;
      6  /Now I lock 'KING' and open FOR UPDATE SKIP LOCKED cursor
    SQL> var rc refcursor
    SQL> exec open :rc for select ename from emp where ename in ('KING','ALLEN') for update skip locked;
    PL/SQL procedure successfully completed.I can lock 'ALLEN' in another transaction - cursor opening didn't lock it:
    SQL> select ename from emp where ename = 'ALLEN' for update;
    ENAME
    ALLENAnd then I fetch cursor I find it's empty - I can't find unlocked rows at the fetch stage:
    SQL> print rc
    no rows selectedRgds.

  • Cursor have for update clause

    Hi all,
    Can any one please tell me,what is main use of for update cursor.in which case we are using this clause.with simple example can any one please explain.
    Thanks,
    K.venkata Sanjeeva Rao.

    user13483989 wrote:
    Can any one please tell me,what is main use of for update cursor.in which case we are using this clause.with simple example can any one please explain.Where you are looping through data for some reason and want to update the current row.
    Simple example...
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
    14 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    cursor cur_emp is
      3      select empno, ename, comm
      4      from emp
      5      for update;
      6  begin
      7    for e in cur_emp
      8    loop
      9      dbms_output.put_line('('||e.empno||') '||e.ename);
    10      if e.comm is null then
    11        update emp
    12        set comm = 0
    13        where current of cur_emp;
    14        dbms_output.put_line('-- Commission reset to 0');
    15      else
    16        dbms_output.put_line('-- Commission: '||e.comm);
    17      end if;
    18    end loop;
    19* end;
    SQL> /
    (7369) SMITH
    -- Commission reset to 0
    (7499) ALLEN
    -- Commission: 300
    (7521) WARD
    -- Commission: 500
    (7566) JONES
    -- Commission reset to 0
    (7654) MARTIN
    -- Commission: 1400
    (7698) BLAKE
    -- Commission reset to 0
    (7782) CLARK
    -- Commission reset to 0
    (7788) SCOTT
    -- Commission reset to 0
    (7839) KING
    -- Commission reset to 0
    (7844) TURNER
    -- Commission: 0
    (7876) ADAMS
    -- Commission reset to 0
    (7900) JAMES
    -- Commission reset to 0
    (7902) FORD
    -- Commission reset to 0
    (7934) MILLER
    -- Commission reset to 0
    PL/SQL procedure successfully completed.
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800          0         20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975          0         20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850          0         30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450          0         10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000          0         20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000          0         10
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100          0         20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950          0         30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000          0         20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300          0         10
    14 rows selected.Though, of course this is a pointless example as a simple single update would achieve the same. It's more useful if there are 'other things' you need to do with the data that would exceed the capabilities of just using SQL. Personally I've had little need to use this sort of construct.

  • Select single for update not creating lock on entry

    Hi All,
    I want to update an entry from MARA table so what ii did is
    select single for update *   from mara where matnr = 'ZYS'.
    The for update is supposed to create a lock  for me and the the lock is released after the commit or roll back.
    I'm running this prg in debug mode and after the statment
    select single for update *   from mara where matnr = 'ZYS''.
    I opened MM02 for this material and could change the data which i'm not supposed to be as there is lock on this particular mater from single for update statemnt
    or
    I even tried from other program
    select single  *   from mara where matnr = 'ZYS'. in debug mode and it returned a sy-subrc eq 0.
    and i don't see a lock in SM12 FOR SELECT * FOR UPDATE.....
    Can anyone clarify on this
    Thanks
    David

    Hi All,
    I knew we can create a lock object but thought to give a shot without creating lock object.
    So i'm just curious to know when we can use select * for update
    F1 Help says select * for update creates an E type lock- which will prevent other locks(X AND S type locks) overwriting or even reading that entry
    Also ,
    can someone throw some light DB lock and SAP Lock ( is this same as SAP LUW and DB LUW)
    Thanks
    David

  • Frequenet dead locks in SQL Server 2008 R2 SP2

    Hi,
    We are experiencing frequent dead locks in our application. We are using MSSQL Server 2008 R2 SP2 version. When our application is configured for 5-6 app servers, this issue is occurring frequently.
    But, when the same application is used with the MSSQL Server 2008 R2 or SQL Server 2012, we don't see the dead lock issue. From the error lock and sql trace, the error message is thrown for the database table JobLock. We have a stored procedure to insert/update
    for the above table when the job moves from one service to other. The same procedure works fine when used with the 2008 R2 and SQL Server 2012 Version.
    Is the above issue related to the hotfix from the below url?
    http://support.microsoft.com/kb/2703275
    Following error message is seen frequently in the log file.
    INFO : 03/24/2014 10:26:30:290 PM: [00007900:00005932] [Xerox.ISP.Workflow.ManagedActivity.PersistInTransaction] System.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 62) was deadlocked on lock resources with another process and has been
    chosen as the deadlock victim. Rerun the transaction.
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteNonQuery(DbCommand command)
       at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery(DbCommand command, DbTransaction transaction)
       at Xerox.ISP.DataAccess.Data.Utility.ExecuteNonQuery(TransactionManager transactionManager, DbCommand dbCommand)
       at Xerox.ISP.DataAccess.Data.SqlClient.SqlActivityProviderBase.ActivityReady(TransactionManager transactionManager, Int32 start, Int32 pageLength, Nullable`1 ActivityID, Nullable`1 JobId, String ContentUrl, Nullable`1 PrevWorkStep, Nullable`1
    CurrentWorkStep, String Principal, Nullable`1 Status, Nullable`1 ServerID, String HostName, Nullable`1 LockUserID, Nullable`1& ErrorCode, Byte[]& Activity_TS)
       at Xerox.ISP.DataAccess.Domain.ActivityBase.ActivityReady(Nullable`1 ActivityID, Nullable`1 JobId, String ContentUrl, Nullable`1 PrevWorkStep, Nullable`1 CurrentWorkStep, String Principal, Nullable`1 Status, Nullable`1 ServerID, String HostName,
    Nullable`1 LockUserID, Nullable`1& ErrorCode, Byte[]& Activity_TS, Int32 start, Int32 pageLength)
       at Xerox.ISP.DataAccess.Domain.ActivityBase.ActivityReady(Nullable`1 ActivityID, Nullable`1 JobId, String ContentUrl, Nullable`1 PrevWorkStep, Nullable`1 CurrentWorkStep, String Principal, Nullable`1 Status, Nullable`1 ServerID, String HostName,
    Nullable`1 LockUserID, Nullable`1& ErrorCode, Byte[]& Activity_TS)
       at Xerox.ISP.Workflow.ManagedActivity.<>c__DisplayClass2f.<ActivityReady>b__2d()
       at Xerox.ISP.Workflow.ManagedActivity.PersistInTransaction(Boolean createNew, PersistMethod persist)
    ClientConnectionId:9e44a64f-5014-4634-9cee-4581e1b9c299
    I look forward to the suggestions to get the issue resolved. Your input is much appreciated.
    Thanks,
    Keshava.

    If you are having deadlock trouble in your SQL Server instance, this recipe demonstrates how to make sure deadlocks are logged to the SQL ServerManagement Studio SQL log appropriately using
    the DBCC TRACEON, DBCC TRACEOFF, and DBCC TRACESTATUS commands. These functions enable, disable, and check the status of trace flags.
    To determine the cause of a deadlock, we need to know
    the resources involved and the types of locks acquired and requested. For this kind of information, SQL Server provides
    Trace Flag 1222 (this flag supersedes 1204, which was frequently used in earlier versions of SQL Server.)
    DBCCTRACEON(1222,
    -1);
    GO
    With this flag enabled, SQL Server will provide output in the form of a deadlock graph, showing the executing statements
    for each session, at the time of the deadlock; these are the statements that were blocked and so formed the conflict or cycle that led to the deadlock.
    Be aware that it is rarely possible to guarantee that deadlocks will never occur. Tuning for deadlocks
    primarily involves minimizing the likelihood of their occurrence. Most of the techniques for minimizing the occurrence of deadlocks are similar to the general techniques for minimizing blocking problems.

  • Deadlock detected during SELECT FOR UPDATE - an application error?

    I have a general question about how Oracle prevents deadlocks from affecting
    applications: do I need to build support into the application for handling
    deadlocks when they occur in this particular scenario, or should Oracle handle
    this for me? I'd like to know whether this is "normal" behavior for an Oracle
    application, or if there is an underlying problem. Consider the following situation:
    Two sessions issue individual SELECT FOR UPDATE queries. Each query locates
    records in the table using a different index. These indexes point to rows in a
    different order from each other, meaning that a deadlock will occur if the two
    statement execute simultaneously.
    For illustrative purposes, consider these rows in a hypothetical table.
    ALPHABET
    alpha
    bravo
    charlie
    delta
    echo
    foxtrot
    golf
    hotel
    Index A results in traversing the table in ascending alphabetical order; index
    B, descending. If two SELECT FOR UPDATE statements concurrently execute on this
    table--one with an ascending order execution path and one in descending order--
    the two processes will deadlock at the point where they meet. If Session A
    locks alpha, bravo, charlie, and delta, while Session B locks hotel, golf,
    foxtrot, and echo, then neither process can proceed. A needs to lock echo, and
    B needs to lock delta, but one cannot continue until the other releases its
    locks.
    This execution path can be encouraged using hints. Executing queries similar to these on larger tables will generate the "collision" as described above.
    -- Session A
    select /*+ index_asc (customer) */
    from customer
    where gender = 'M'
    for update;
    -- Session B
    select /*+ index_desc (customer) */
    from customer
    where gender = 'M'
    for update;
    Oracle will recognize that both sessions are in a stand-off, and it will roll
    back the work performed by one of the two sessions to break the deadlock.
    My question pivots on whether or not, in this situation, the deadlock gets
    reported back to the application executing the queries as an ORA-00060. If
    these are the ONLY queries executed during these sessions, I would think that
    Oracle would rollback the locking performed in one of the SELECT FOR UPDATE
    statements. If I understand correctly,
    (1) Oracle silently rolls back and replays work performed by UPDATE statements
    when a deadlock situation occurs within the scope of the update statement,
    and
    (2) A SELECT FOR UPDATE statement causes Oracle, at the point in time the cursor
    is opened, to lock all rows matching the WHERE clause.
    If this is the case, then should I expect Oracle to produce an ORA-00060
    deadlock detection error for two SELECT FOR UPDATE statements?
    I would think that, for deadlock situations completely within Oracle's control,
    this should be perceived to the application invoking the SELECT FOR UPDATE
    statements as regular blocking. Since the query execution plans are the sole
    reason for this deadlock situation, I think that Oracle would handle the
    situation gracefully (like it does for UPDATE, as referenced in (1)).
    Notice, from the trace file below, that the waits appear to be from row locking,
    and not from an artificial deadlock (e.g. ITL contention).
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
    With the Partitioning option
    DEADLOCK DETECTED
    Current SQL statement for this session:
    SELECT XXX FROM YYY WHERE ZZZ LIKE 'AAA%' FOR UPDATE
    ----- PL/SQL Call Stack -----
    object line object
    handle number name
    58a1f8f18 4 anonymous block
    58a1f8f18 11 anonymous block
    The following deadlock is not an ORACLE error. It is a
    deadlock due to user error in the design of an application
    or from issuing incorrect ad-hoc SQL. The following
    information may aid in determining the deadlock:
    Deadlock graph:
    ---------Blocker(s)-------- ---------Waiter(s)---------
    Resource Name process session holds waits process session holds waits
    TX-002f004b-000412cf 37 26 X 26 44 X
    TX-002e0044-000638b7 26 44 X 37 26 X
    session 26: DID 0001-0025-00000002     session 44: DID 0001-001A-00000002
    session 44: DID 0001-001A-00000002     session 26: DID 0001-0025-00000002
    Rows waited on:
    Session 44: obj - rowid = 0000CE31 - AAANCFAApAAAAGBAAX
    Session 26: obj - rowid = 0000CE33 - AAANCHAArAAAAOmAAM
    Thanks for your insight,
    - Curtis
    (1) "Oracle will silently roll back your update and restart it"
    http://tkyte.blogspot.com/2005/08/something-different-part-i-of-iii.html
    (2) "All rows are locked when you open the cursor, not as they are fetched."
    http://download-east.oracle.com/docs/cd/A87860_01/doc/appdev.817/a77069/05_ora.htm#2170
    Message was edited by:
    Curtis Light

    Thanks for your response. In my example, I used the indexes to force a pair of query execution plans to "collide" somewhere in the table in question by having one query traverse the table via index in an ascending order, and another in descending. This is an artificial scenario for reproducible illustrative purposes, but similar collisions could legitimately occur in real world scenarios (e.g. a full table scan and an index range scan with lookup by ROWID).
    So, with that said, I think it would be unreasonable for Oracle to report the collision as a ORA-00060 every time it occurs because:
    (1) The UPDATE statement handles this situation automatically, and
    (2) An ORA-00060 results in a 100+KB trace file being written out, only rational for truly erroneous situations.
    I agree that, when the application misbehaves and locks rows out of order in separate SQL statements, then Oracle should raise an ORA-00060, as the deadlock is outside of its control. But in this case, the problem occurs with just two individual SQL statements, each within its own transaction.

  • Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination

    Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination
    Problem in committing transactions in Multiple Forms (Oracle Forms) with POST built-in command:
    Consider that the following statements are written in WHEN-WINDOW-CLOSED trigger of a called form.
    Statements in called form (Form name: FORM_CHILD):
    go_block('display_block') ;
    do_key('execute_query') ;
    -- Data from table_b will be populated in this block, based on the value of COLUMN_1 obtained
    -- from TABLE_A.
    -- Example: If the value of COLUMN_1 is 10, then all the matching records from TABLE_B, which
    -- are inserted with value 10 in TABLE_B.COLUMN_1 will be fetched and shown here.
    if user_choice = 'YES' then
    commit ;
    else
    rollback ;
    end if ;
    Statements in calling forms:
    There are two calling forms having following statements and it is going to call the above said called form.
    CALLING FORM 1
    Statements in KEY-COMMIT trigger:
    post;
    call_form(form_child, no_activate) ;
    Statements in ON-INSERT trigger:
    select column_1
    from table_a
    for update of column_1
    where column_2 = 'X' ;
    update table_a
    set column_1 = column_1 + 1
    where column_2 = 'X' ;
    insert into table_b ...;
    insert into table_b ...; Statements in KEY-COMMIT trigger:
    post;
    call_form(form_child, no_activate) ;
    CALLING FORM 2:
    Statements in ON-INSERT trigger:
    select column_1
    from table_a
    for update of column_1
    where column_2 = 'X' ;
    update table_a
    set column_1 = column_1 + 1
    where column_2 = 'X' ;
    insert into table_b ...;
    insert into table_b ...;
    insert into table_b ...;
    Our understanding:
    Assume that both the forms are running from two different machines/instances, issuing commit at the same time. In this case, forms will start executing the statements written in ON-INSERT trigger, the moment POST command is executed. Though the commit is issued at the same time, according to oracle, only one of the request will be taken for processing first. Assume that calling form 1 is getting processed first.
    So, it fetches the value available in COLUMN_1 of TABLE_A and locks the row from further select, update, etc. as SELECT...FOR UPDATE command is used (note that NOWAIT is not given, hence the lock will be released only when COMMIT or ROLLBACK happens) and proceed executing further INSERT statements. Because of the lock provided by the SELECT...FOR UPDATE command, the statements in calling form 2 will wait for the resource.
    After executing the INSERT statements, the FORM_CHILD is called. The rows inserted in to TABLE_A will be queried and shown. The database changes will be committed when user closes the window (as COMMIT is issued in its WHEN-WINDOW-CLOSED trigger). Then the SELECT...FOR UPDATE lock will be released and calling form 2's statements will be executed.
    Actual happenings or Mis-behavior:
    Calling form 2 starts executing INSERT statements instead of waiting for SELECT...FOR UPDATE lock. Also, the value selected from TABLE_A.COLUMN_1 is same in both the calling forms, which is wrong.
    The rows inserted into TABLE_B are having similar COLUMN_1 values in calling form 2 and they are fetched and shown in the called form FORM_CHILD.
    Note that in calling form 2 also POST only is issued, but the changes posted there are accessible in calling form 1 also, which is wrong.
    Kindly suggest us as to how to fix above problem. It will be much use, if you can send us the information regarding the behavior of Oracle Forms POST built-in also.
    Our mail ID: [email protected]
    Thanks a lot in advance.

    You have several problems:
    1. On-Insert will ONLY run if you have created a new record in a base-table block. If you haven't done that, then the POST command will not cause it to run.
    2. Select for update without a "no wait" will lock records for the first form, but when the second form tries this, it will hit the ORA-00054 exception, and will NOT wait. The only way you could make it wait is to issue an UPDATE sql command, which is not such a good way to go.
    All POST does is issues SQL insert or update commands for any changes the user has made to records in a form's base-table blocks, without following with a Commit command.
    Also understand that Commit is the same as Commit_Form, and Rollback is the same as Clear_Form. You should read up on these in the Forms help topics.

  • Sessions were still active eventhough Dead lock detected

    Hi all,
    Yesterday I saw very odd oracle behaviour.When oracle finds Dead lock it should kill those sessions automatically.In my case those two sessions were still trying to run the same update command and were casuing dead locks again and again for 1 Hour.I had to kill those sessions manually to avoid these dea lock.
    How can those sessions were still trying eventhough dead lock detected and causing deadlocks.My logfile filled with this dead lock error.When I killed those sesions it end up with snap shot too old error.
    Please suggest me
    Thanks

    hi
    just ROLLBACK or COMMIT any one session. you will out of dead lock.
    and one more thing is in dead lock situation the sessions were not terminated
    and session wating for releasing locks aquire by another session
    try this one if not work plz reply
    have a nice time
    best luck

Maybe you are looking for

  • Return multiple values from a function to a SELECT statement

    I hope I've provided enough information here. If not, just let me know what I'm missing. I am creating a view that will combine information from a few tables. Most of it is fairly straightforward, but there are a couple of columns in the view that I

  • When I accept a calendar invite iPhone 5 is sending multiple acceptance mails

    Hi there, I'm hoping someone can assist as I'm driivng my colleagues crazy. Just moved over from an iPhone 4 to iPhone 5. Everything has been copied over ok and I was happy as Larry. However I just got a meeting request from our works mail server (Ex

  • Problem - new MacBook Air cannot see external HD

    Hi, I'm hoping someone can help, as I have seen similar questions in the forums, but not with an answer that helps me solve my problem. Ok, I have a new MacBook Air running Lion (bought last year), a MacBook Pro running Leopard which is approx 4 year

  • Vendor Change in item conditions for ME21N

    hi frnds, in me21n, i have placed 1 more vendor in header section. now i need to pass this vendor in item condtions for some condition types. for this, i have gone thru LMEKO002 enhancement. in this enhancement i am not able to get any data of item c

  • Mail acting strangely - can't open Notes

    Trying to access my Notes in Mail, all created before I installed Lion. It won't load them, shows the load icon and nothing happens. If I try and open one, it launches the yellow page, and won't load it. Then I can't close the page, and have to force