Row Lock

Hi,
I am running a scheduler thread which runs after every 30 minutes.The problem is that we are using cluster environment and we are using 2 servers. These 2 servers initiante different threads and one task is implemented twice so i want to do a locking on the database side so that form a single table. If one picks a value that value shoud not be picked up by another thread.so i want to lock a row value in a table.
So basically we want to put a lock on row in a table. As soon as one thread will select the value from that row, that row should get locked and another thread will not be able to read that and also should not get any error back.

try your select in the threads like:
SELECT * FROM TABLE WHERE condition FOR UPDATE;
the other thread will wait for the first to finish its processing.

Similar Messages

  • V$system_event, timeouts and row lock contention

    Hello everyone,
    What is the meaning of the total_timeouts column in the v$system_event view if it is related to the event "enq: TX - row lock contention"?
    How can we have a timeout since "query timeout" is a non existent concept on Oracle?
    Maybe I am wrong.
    Regards.
    Carl

    Hello everyone,
    What is the meaning of the total_timeouts column in
    the v$system_event view if it is related to the event
    "enq: TX - row lock contention"?
    How can we have a timeout since "query timeout" is a
    non existent concept on Oracle?
    Maybe I am wrong.
    Regards.
    CarlThe value for timeouts, in this case, indicates the number of times one of the sessions had to wait a full 3 second time slice while waiting for a second session to either commit or roll back, in anticipation of a potential primary key violation. If the second session commits, the first session will receive an error indicating a primary key violation.
    Test setup:
    In session 2:
    CREATE TABLE T1 (C1 VARCHAR2(20) PRIMARY KEY);
    INSERT INTO T1 VALUES ('ORACLE');
    In session 1:
    INSERT INTO T1 VALUES ('ORACLE');
    After executing tha above, allow 60 seconds to elapse after the insert in session 1, and then check the delta values in either V$SYSTEM_EVENT or V$SESSION_EVENT:
    20 waits on ENQ: TX - ROW LOCK CONTENTION, 19 timeouts, 59.99 seconds, with an average wait of 2.9995 seconds.
    Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • OIM DB Row LOCK Exception on Quartz tables

    I am facing db row lock error in Prod OIM due to which the Scheduler fails to kick off and an OIM Restart is required to release the lock and start the Scheduler again.
    This Error is occuring at any time when none of the scheduler( Custom as well as House Keeping) are scheduled.The OIM Version is 9.0.3.1.
    I have enabled Database logs in Debug mode but there are no logs corresponding to the table where lock occured.
    This Error was encountered long back with OIM 9.0.1 and was reported as Bug 6491465, but was suspended because of no response from Customer.
    The Error trace is as follows
    ERROR,11 Sep 2009 16:57:05,497,[org.quartz.core.ErrorLogger],An error occured while scanning for the next trigger to fire.
    org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Io exception: Connection reset [See nested exception: java.sql.SQLException: Io ex
    ception: Connection reset]
    at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.obtainLock(StdRowLockSemaphore.java:154)
    at org.quartz.impl.jdbcjobstore.JobStoreCMT.acquireNextTrigger(JobStoreCMT.java:1376)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:231)
    * Nested Exception (Underlying Cause) ---------------
    java.sql.SQLException: Io exception: Connection reset
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:287)
    at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:515)
    at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:1029)
    at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1126)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3001)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3043)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
    at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.obtainLock(StdRowLockSemaphore.java:137)
    at org.quartz.impl.jdbcjobstore.JobStoreCMT.acquireNextTrigger(JobStoreCMT.java:1376)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:231)
    Did anyone had ever encountered this error.Any Hints?

    I would check the network pieces as suggested in our internal emails. If the connection is dropping somewhere on your network, the lock would never be released.
    -Kevin

  • Read only users and row locks

    Can read-only users obtain row locks on non-temporary (i.e,. visible to other users) tables, for example through SELECT FOR UPDATE, even though they couldn't not ultimately modify said tables?

    Yes.
    Here is an example with Oracle XE 11G and HR schema:
    Connecting as user having only CREATE SESSION and SELECT privilege on HR.JOBS table:
    SQL> desc hr.jobs;
    Name                                      Null?    Type
    JOB_ID                                    NOT NULL VARCHAR2(10)
    JOB_TITLE                                 NOT NULL VARCHAR2(35)
    MIN_SALARY                                         NUMBER(6)
    MAX_SALARY                                         NUMBER(6)
    SQL> select * from session_roles;
    no rows selected
    SQL> select * from session_privs;
    PRIVILEGE
    CREATE SESSION
    SQL> select owner, table_name, privilege from user_tab_privs;
    OWNER                          TABLE_NAME
    PRIVILEGE
    HR                             JOBS
    SELECT
    SQL> select job_title from hr.jobs for update;
    JOB_TITLE
    President
    Administration Vice President
    Administration Assistant
    Finance Manager
    Accountant
    Accounting Manager
    Public Accountant
    Sales Manager
    Sales Representative
    Purchasing Manager
    Purchasing Clerk
    JOB_TITLE
    Stock Manager
    Stock Clerk
    Shipping Clerk
    Programmer
    Marketing Manager
    Marketing Representative
    Human Resources Representative
    Public Relations Representative
    19 rows selected.
    SQL>Now connecting as HR following statement hangs:
    SQL> connect hr/hr
    Connected.
    SQL> select * from jobs for update;Going back to first session:
    SQL> update hr.jobs set min_salary=0;
    update hr.jobs set min_salary=0
    ERROR at line 1:
    ORA-01031: insufficient privileges

  • TX - row lock contention in SELECT query without update clause

    Hi,
    We are having problem in one of our application on production. The ASH report shows 'eq: Tx row lock contention' for only Select statements. There is no FOR UPDATE in the select statements. The exact statement is
    enq: TX - row lock contention : SELECT COUNT (1) FROM Table1 WHERE col1= :1 AND col2= :1 AND col3= :1 AND ROWNUM = 1
    enq: TX - row lock contention : SELECT MODULE_CD , MSG_DESC , SEVERITY FROM GS_ERROR_MSG WHERE MSG_NUM = :1
    I don't know why the select are locking the table rows and resulting in waits..
    Our environment is Oracle 10g and Forms & Reports..
    Please help.
    -- Prashant

    Hi,
    are you sure that there is no dml against the tables?
    You can query v$active_session_history (eg column BLOCKING_SESSION) to see which session locked the row.
    HTH..
    - wiZ

  • How to release row lock by using jdbc

    hi, currently we are using jdbc to create a connection and create a row lock , is there anyway to release the row lock? right now i am using resultset.close(), but this cause me problem since it release other resultset's row lock too. please help.

    hi, from your post, i understood that u know how to do row locking..
    How was it done ??
    I'm currently looking for answer to do row locking in Microsoft Access...
    These are the SQL stmt i've done without success..
    SELECT * FROM BSPerson WITH UPDLOCK WHERE ID = 'P001';
    SELECT * FROM BSPerson WHERE ID = 'P001' FOR UPDATE;
    Both stmt having error........
    Please help !
    A miliion thanks....

  • SQL_ID row locks

    Hi,
    Every day from 23.00 to 01.00 the performance of the database becomes slow, when i traced i found the following "The SQL statement with SQL_ID "4pgt142s271gy" was blocked on row locks.", which i think is the reason for poor performance and also i found the query with this SQL_ID.
    Dut to this my Application at this time Hangs.
    What should be my next step,i can't change this query because till last week the database was going fine.
    Please advice me ASAP.

    Hi,
    Do these tables involve Workspace Manager? If so, I would need a better understanding of exactly which operations you are performing before commenting on any performance issues.
    Otherwise, I would recommend to use the following forum for general database questions.
    General Database Discussions
    Regards,
    Ben

  • DB row lock from servlet.

    Hi to all,
    we're developing a J2EE application (with NO Ejb, actually we cannot use them) in which users can select orders from a DB2 database, modify the order, or create a new order. Any order is implemented by a class (Order.java) that exposes methods to execute SELECTs, INSERTs and UPDATEs to the db2 order table; the class mantains a Connection to the database and it's responsible to manage the connection, resultset, prepared statement and so on, and it's possible to specify if we want only read data (executing a select) or read for update the data (so, executing a select ... for update).
    Users can access the data via web: the instances of Order are created by a servlet, which load the data and show them passing the Order instance to a JSP that fills up a form.
    The problem is we want to lock the row corrisponding to the data mapped into Order instance. Initially, we thought we can instantiate an Order, load data with a select for update, saving on a session the instance, and redirect to the Jsp for visualization, without closing the connection; when the user send data via a form, the order is retrieved from the session, updates are performed and session closed. Unluckily, this approach does not work 'cause the Web Container rolls back automatically all unclosed connection. The row lock is lost.
    In very few words, we are trying to keep-alive a Connection after a Servlet method ends. It seems that Servlet specification 2.3 does not allow this, while specification 2.2 does.
    How can we avoid this problem ? We cannot just implement an application-level Lock manager, because the database is a legacy database and data are concurrently accessed by legacy applications.
    Any suggestion would be very appreciated.
    Thanx in advance !
    Claudio.

    Heck (can you say "hec|<" or will the **** filter nuke it?), I had a reply all written up.
    And then I noticed you were cross-posting.
    Please don't.

  • Is row locking available in Oracle 10g?

    Hi,
    Does anybody knows if Oracle 10g can do a row locking?
    Thanks,
    Amorsolo

    Teymur Hajiyev wrote:
    amorsolo wrote:
    Hi,
    Does anybody knows if Oracle 10g can do a row locking?
    Thanks,
    AmorsoloIn my opinion locking mechanism in Oracle is one of the features/option which made Oracle the best in Database world.
    Regards,
    Teymur Hajiyev
    Oracle 10g Certified Master
    http://teymur-hajiyev.blogspot.com
    http://dba.az
    Agree with Teymur. As Tom Kyte said in the "Comparison between Oracle and Others" topic:
    For example -- all of the above would get check marks for having "row level locking". Once you look at the implementations however, you'll find they are way different. In Oracle, the overhead of having 1 lock is the same as having 1billion locks (eg: none).
    In the others there is a HUGE different between the two as locks are a scare resource in those systems, they consume memory, take up space, are stored in in-memory data structures. Our implementation of the feature is so different as to not be comparable.
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1886476148373

  • Acquiring database row lock in session bean

    I am getting a "ora-01002 fetch out of sequence" exception when trying to acquire a row lock by doing a select for update nowait sql command.
    The code that is trying to get the lock is running inside a session bean deployed in both weblogic 6.0 sp2 and JBOSS 3.0.4. I have read some other threads in the JDBC forum and they suggest me to use the con.setAutoCommit(false) to avoid this error. This solution works on weblogic but not on JBOSS. In JBOSS I got a message saying I should not be setting the auto commit value in a container managed transaction.
    Is there something I could do to do avoid the error without explicitly setting this value in the code?
    Thanks.

    Below are the settings in my ejb-jar.xml, weblogic-ejb-jar.xml, and jboss.xml. Can you see any wrong with the transaction settings?
    Please help.
    ************ejb-jar.xml*************
    <ejb-jar>
          <enterprise-beans>
                <session>
                  <ejb-name>mybean.MybeanRemoteHome</ejb-name>
                  <home>testing.mybean.MybeanRemoteHome</home>
                  <remote>testing.mybean.MybeanRemote</remote>
                  <ejb-class>mybean.Mybean</ejb-class>
                  <session-type>Stateless</session-type>
                  <transaction-type>Container</transaction-type>
                </session>
          </enterprise-beans>
          <container-transaction>
            <method>
              <ejb-name>mybean.MybeanRemoteHome</ejb-name>
              <method-intf>Remote</method-intf>
              <method-name>*</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
          </container-transaction>
    </ejb-jar>
    ************weblogic-ejb-jar.xml*************
    <weblogic-ejb-jar>
        <weblogic-enterprise-bean>
            <ejb-name>mybean.MybeanRemoteHome</ejb-name>
        <stateless-session-descriptor>
          <pool>
            <max-beans-in-free-pool>10</max-beans-in-free-pool>
            <initial-beans-in-free-pool>5</initial-beans-in-free-pool>
          </pool>
        </stateless-session-descriptor>
        <jndi-name>mybean.MybeanRemoteHome</jndi-name>
        </weblogic-enterprise-bean>
        <transaction-isolation>
              <isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
              <method>
                <ejb-name>mybean.MybeanRemoteHome</ejb-name>
                <method-intf>Remote</method-intf>
                <method-name>*</method-name>
              </method>
        </transaction-isolation>
    </weblogic-ejb-jar>
    ************jboss.xml*************
    <jboss>
       <enterprise-beans>
           <session>
              <ejb-name>mybean.Mybean</ejb-name>
              <jndi-name>mybean.MybeanRemoteHome</jndi-name>
              <local-jndi-name>mybean.MybeanLocalHome</local-jndi-name>
           </session>
       </enterprise-beans>
       <resource-managers>
       </resource-managers>
    </jboss>

  • Index contention & row lock contention

    Hi,
    Recently our application loaded a handsome amount of data into our production database. The process took around 5 to 6 hours. During this process, we observed that the performance degraded.
    The major wait events are
    1) TX index contention (concurrency) and
    2) ROW LOCK CONTENTION (application).
    The sql which lead to index contention is a simple insert statement into a table x and row lock contention is into a table y.
    Both x and y are major detail tables of our application. X has around 4 foreign keys, one foriegn key is referencing table y. the foreign key column x is indexed.
    our database is on 10gR2 and using ASSM.
    The data block wait event stats during the load process is as follows
    select * from dba_hist_waitstat where snap_id between '21454' and '21462' AND WAIT_COUNT>0 and class='data block';
    SNAP_ID DBID INSTANCE_NUMBER CLASS WAIT_COUNT TIME
    21454 3937665896 1 data block 195089769 33899167
    21455 3937665896 1 data block 195095958 33902183
    21456 3937665896 1 data block 195096398 33902377
    21457 3937665896 1 data block 195097225 33902843
    21458 3937665896 1 data block 195628987 34037147
    21459 3937665896 1 data block 195944006 34055524
    21460 3937665896 1 data block 195944496 34055642
    21461 3937665896 1 data block 196183308 34112433
    21462 3937665896 1 data block 196213292 34127409
    9 rows selected.
    select snap_id,eq_type,req_reason, total_req#, total_wait#,failed_req#, cum_wait_time from dba_hist_enqueue_stat where snap_id between '21454' and '21462' and failed_req#>0 and eq_type='TM'
    SYS@sqdb AS SYSDBA> /
    SNAP_ID EQ REQ_REASON TOTAL_REQ# TOTAL_WAIT# FAILED_REQ# CUM_WAIT_TIME
    21454 TM contention 682928465 14 2735 1750
    21455 TM contention 682939964 14 2735 1750
    21456 TM contention 682950668 14 2735 1750
    21457 TM contention 682967980 14 2735 1750
    21458 TM contention 682983109 14 2735 1750
    21459 TM contention 682998136 14 2735 1750
    21460 TM contention 683006816 14 2735 1750
    21461 TM contention 683018179 14 2735 1750
    21462 TM contention 683432945 14 2735 1750
    9 rows selected.
    I dont see any significant ITL contention on these objects compared to other contention. (from segment statistics)
    SYS@sqdb AS SYSDBA> select b.object_name,a.snap_id, a.physical_writes_total,a.physical_writes_delta,a.physical_reads_total,a.physical_reads_delta, a.itl_waits_total,a.itl_waits_delta from dba_hist_seg_stat a,(select object_id,object_name from dba_objects where owner='ABCD') b where snap_id between '21454' and '21462' and a.obj#= b.object_id and a.itl_waits_delta> 0 order by itl_waits_delta,2,1;
    OBJECT_NAME SNAP_ID PHYSICAL_WRITES_TOTAL PHYSICAL_WRITES_DELTA PHYSICAL_READS_TOTAL PHYSICAL_READS_DELTA ITL_WAITS_TOTAL ITL_WAITS_DELTA
    IX4_Y 21462 37958 169 105668 174 38 1
    IX4_X 21462 102380 1480 147196 5780 56 1
    As per the application design, for each row of Y, there are multiple number of rows in X and it varies. What additional information do you think I should be collecting and any tips to fix the issue?
    Thanks,
    Murthy

    hi
    Are you using in your insert statement something like "SELECT ... FOR UPDATE"
    post the result of this query during the error:
    SELECT * FROM DBA_BLOCKERS;
    SELECT * FROM DBA_WAITERS;

  • Tuning row lock contention wait events

    Hello everyone,
    Working on 10g/windows
    Top 5 events
    EVENT TOTAL_WAITS TIME_WAITED AVG_MS PERCENT
    CPU 9462339 48
    enq: TX - row lock contention 12531 3660728 2921.34 18
    control file parallel write 1300731 3088079 23.74 16
    log file parallel write 1510503 1264080 8.37 6
    log file sync 1072553 968007 9.03 5
    Distribution of row lock wait during the last 4 days in the database server
    END_INTERVAL_TIME TOTAL_WAITS TIME_WAITED_MICRO AVG_WAIT_MS
    2008-04-01 16:00:58 909 2721008230 2993.41
    2008-04-01 15:00:27 50 149941140 2998.82
    2008-03-31 12:00:42 193 575595397 2982.36
    2008-03-29 23:00:13 172 513058700 2982.9
    2008-03-29 22:00:37 164 483940046 2950.85
    2008-03-27 22:00:35 565 1667120838 2950.66
    2008-03-26 18:00:59 348 1042918982 2996.89
    My analysis:
    It's obvious that the row lock contention wait time is huge, and this direct me to find out SQL stmt, causing this.
    all the SQL statement was SELECT ....... FOR UPDATE stmt.
    I was also able to find out locked tables.
    My tuning idea:
    1. I'm thinking to reorganize hot tables as well as their indexes, but by instinct it seems to not give so much value to avoid the huge row lock wait time.
    2. I'm also seeing if I can reduce the number of rows per block, by increasing PCTFREE and diminishing PCTUSED, so the contention will spread over many blocks instead of one heavy block.
    Question
    As SQL stmt related to those locked tables are select ... for update, how could I tune this kind of stmt?
    Does someone have other idea to come up with this row lock contention?
    Tanks for your effort and help

    Taking another look at your suggested function based index, it depends on the data type of the DEV.POS_FOLIO_ID.POS_FOLIO_ID column. If the column is defined as a number, and it is a primary key, there will already be a usable index on that column.
    Yesterday, I wrote this: "Once I understood why or how the sessions were trying to insert duplicate primary key values, I would try to determine why the average number of seconds for the wait event is almost 3 seconds (maybe a timeout)."
    After fixing the formatting of the top 5 wait events (total duration unknown):
    EVENT                        TOTAL_WAITS  TIME_WAITED   AVG_MS PERCENT
    CPU                                         94,623.39             48
    enq: TX - row lock contention     12,531    36,607.28  2921.34    18
    control file parallel write    1,300,731    30,880.79    23.74    16
    log file parallel write        1,510,503    12,640.80     8.37     6
    log file sync                  1,072,553     9,680.07     9.03     512,531 * 3 second time out = 37,593 seconds = 10.44 hours.
    What if the reason for the 3 second average wait time is due to a timeout. I performed a little experiment... I changed a row in a test table and then made a pot of coffee.
    In session 1:
    CREATE TABLE T1 (
      C1 NUMBER(10),
      C2 NUMBER(10),
      PRIMARY KEY (C1));
    INSERT INTO T1
    SELECT
      ROWNUM,
      ROWNUM*10
    FROM
      DUAL
    CONNECT BY
      LEVEL<=1000000;
    COMMIT;I now have a test table with 1,000,000 rows. I start monitoring the changes in the wait events roughly every 60 seconds, and V$SESSION_WAIT and V$LOCK roughly 4 times per second.
    Back in session 1:
    UPDATE
      T1
    SET
      C1=-C1
    WHERE
      C1<=100;I have now modified the first 100 rows that were inserted into the table, time to make the pot of coffee.
    In session 2, I try to insert a row with a primary key value of -10:
    INSERT INTO T1 VALUES (
      -10,
      10);Session 2 hangs.
    If I take the third 60 second snap of the system wide wait events as the zero point, and the 11th snap as the end point. There were 149 waits on ENQ: TX - ROW LOCK CONTENTION, 148 time outs, 446.62 seconds of total time in the wait event, with an average wait time of 2.997450 seconds.
    Rolling down to the session level wait events, SID 208 (my session 2) had 149 waits on ENQ: TX - ROW LOCK CONTENTION, for a total time of 446.61 seconds with an average wait time of 2.997383 seconds. All of the 149 waits and the wait time was in this one session that was locked up for the full duration of this time period because session 1 was making a pot of coffee.
    Rolling down to V$SESSION_WAIT (sampled roughly 4 times per second): At the start of the third time interval, SID 208 has been in the ENQ: TX - ROW LOCK CONTENTION wait event for 39 seconds and is actively waiting trying to execute SQL with a hash value of 1001532423, the wait object is -1, wait file is 0, wait block is 0, wait row is 0, P1 is 1415053316, P2 is 196646, P3 is 4754.
    At the end of the 11th time interval: , SID 208 has been in the ENQ: TX - ROW LOCK CONTENTION wait event for 483 seconds and is actively waiting trying to execute SQL with a hash value of 1001532423, the wait object is -1, wait file is 0, wait block is 0, wait row is 0, P1 is 1415053316, P2 is 196646, P3 is 4754.
    Rolling down to V$LOCK (sampled roughly 4 times per second): I see that SID 214 (session 1) is blocking SID 208 (session 2). SID 214 has a TX lock in mode 6 with ID1 of 196646 and ID2 of 4754. SID 208 is requesting a TX lock in mode 4 with ID1 of 196646 and ID2 of 4754.
    So, it seems that I need a faster coffee pot rather than an additional index on my table. It could be that the above process would have found that the application associated with SID 214 was abandoned or crashed and for some reason the lock was not released for a long period of time, a little less than 10.44 hours in your case.
    Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Heavy row lock contention

    Guys,
    I really appreciate your views on this.. Please can some one who have worked on RAC and have an understanding how RAC works, guide me.
    We currently are running a loadtest on one of the new RAC system and we are seeing excessive row lock contention for one table. The table basically has very few rows, say about 6-8 and pretty much every user uses this table to lock rows before fetching some data from other tables. When have a heavy load, we see very high wait on this table and enq TX : Row lock contention.
    What is the best way to avoid this ? Is there anyway, we can modify the design of the application and ensure locking.. The typical query that locks the rows in the table looks like this
    SELECT WL0.CLUB_NAME, WL0.SCHEDULE_ID FROM VF_BINGO_NEXT_CLUB_DRAW WL0 WHERE ( WL0.CLUB_NAME = :1 ) FOR UPDATE As said, they table has only 6-8 rows, so query plan etc doesn't apply. Please can someone who have extensive application knowledge guide me thru ?
    Many thanks in advance.
    G

    > But is there a way to alliviate the concurrency issue, if there is a genuine
    requirement to hold lock on a table. What other options do we have other
    than locking ?
    The purpose of a lock is to ensure data consistency - only 1 process can change that row. So what I find puzzling is why so many app sessions want to change that single row. What data does that row hold that requires continual change? Just what is the purpose of this data if it is consistently and continually changing? What business requirement does it attempt to solve?
    To be honest, this sounds like a major design problem to me.
    Like the surrogate key generator approach I mentioned. You create a PK_SEQUENCE table with columns (tablename, pk_value). Any insert against a table requires a lock on PK_SEQUENCE for the table being inserted into - a read of the PK_VALUE, incrementing it by one and then updating that row with the latest sequence. This way each INSERT gets a "nice sequential number" to use as surrogate key for new rows.
    Even when this is done as an autonomous transaction, it introduces a very expensive resource - why? Because only one session at a time can be serviced by that resource.
    If there are a lot of INSERTs into a table, this approach will quickly become a severe bottleneck as every single insert requires a new surrogate key value and a lock on that PK_SEQUENCE table to obtain that value.
    This problem is solved by allowing/enabling such a resource to serve multiple sessions concurrently. Which is for example what Oracle Sequence objects do within this example I've described.
    The bottom line is that the design you describe introduced a bottleneck by create an expensive and serialised resource that can only serve a single session at a time.
    You need to re-look at the business requirement - and find another way to solve it than to introduce this type of serialised resource and contention.

  • Row lock contention...

    Hello,
    I am working on Oracle 10.2.0.4 on AIX .
    In awr reports we found 'row lock contention' as top wait events. As my knowledge There are two types of locks..
    1. Deadlock - where oracle will automatically rollback the locking query and generate deadlock trace file.
    2. A user session update some rows and not commit/rollback , so other sessions which need to lock same rows , were witing. So dba need to manully kill first
    session which was holding lock.
    We want to know , in which of above scenario in awr report we can see 'row lock contention' wait.
    any idea ..

    Ok, first, I think your definitions are a bit off.
    There is the concept of a lock, or an enqueue. The terms 'lock' and 'enqueue' are synonymous, in Oracle.
    A lock (or enqueue) protects a 'resource'. A TX (transaction) enqueue protects rows which have been locked. Only one transaction is permitted to modify a specific row in a specific table, at a time, for obvious reasons.
    A row-level lock occurs when a session attempts to modify a row that another session has already locked. When that occurs, the session attempting the lock will wait on a TX enqueue.
    These types of locks occur all the time in Oracle, and are not necessarily a bad thing. They are a sign that Oracle is protecting the integrity of your data, and that's a good thing.
    However, when waits on row-level locks begin to dominate the response time of your application, then you have a problem. Generally, this is going to come down to your application design. How can you avoid concurrent sessions colliding on their updates to specific rows? This is something that only you, with your knowledge of your application, can answer.
    Finally, you mentioned the term 'deadlock' before. A deadlock occurs when two or more sessions are simultaneously holding a lock that the other is waiting on, while waiting on a lock the other is holding.
    A simple example would be as follows:
    Consider table_a, with row1 and row2.
    Session 1 takes a lock on row1, no problem.
    Session 2 takes a lock on row2, no problem.
    Now, session 1 attempts to take a lock on row2, but session 2 has lock, so it waits.
    Now, session 2 attempts to take a lock on row1, but session 1 has lock, so it waits.
    This is a deadlock. It would wait forever. But, the Oracle kernel has a deadlock detection mechanism. So, within 3 seconds, Oracle will detect a deadlock, and one of the sessions (usually the one that has been waiting the longest) will catch ORA-00060 deadlock detected, and statement level rollback will occur.
    Hope that clarifies your questions and/or doubts,
    -Mark

  • Row lock contention error to resolve

    hi,
    i m facing sever issue with row lock contention error for the statement and causing concurrency and application usage more making database vulnerable
    UPDATE RULE_DATA SET RULE_DATA = :B3 , UPDATED_BY = :B2 , UPDATED_DATE = SYSDATE WHERE RULE_DATA_SEQ_ID = :B1
    RETURNING PAT_GEN_DETAIL_SEQ_ID INTO :O0
    in this query RULE_DATA_SEQ_ID is primary key and and having index too, how can i over come row lock contention error ,
    if i try like this will it work
    UPDATE RULE_DATA SET RULE_DATA = :B3 , UPDATED_BY = :B2 , UPDATED_DATE = SYSDATE WHERE RULE_DATA_SEQ_ID = :B1
    RETURNING PAT_GEN_DETAIL_SEQ_ID INTO :O0
    log errors into temp_log (sysdate||:O0 ) REJECT LIMIT UNLIMITED;
    commit;
    please help me;

    select sid,  sql_text from v$session s, v$sql q
    where sid in (select sid from v$session
    where state in ('WAITING')
    and wait_class != 'Idle'
    and event='enq: TX - row lock contention'
    and (q.sql_id = s.sql_id or q.sql_id = s.prev_sql_id));
    from the above query if found the sid and sql_text,
    actually three procedures been called at once as a batch from java and given auto commit at once for the batch;
    and in one of the procedure it is called by multiple times with different seq_id's
    what i thought is by logging error can we skip the update statement from locking , this what happening
    where v_tariff_detail_seq_id will be 25,26,28,29,30 like records
    begin
    IF v_tariff_detail_seq_id = 0 THEN
    INSERT INTO pat_tariff_details (
    tariff_detail_seq_id,
    pat_gen_detail_seq_id,
    ward_type_id ,
    room_type_id ,
    days_of_stay ,
    requested_amount,
    approved_amount,
    maximum_allowed_amount,
    notes,
    added_by,
    added_date )
    VALUES (
    pat_tariff_details_seq.NEXTVAL ,
    v_pat_gen_detail_seq_id,
    v_ward_type_id ,
    v_room_type_id ,
    v_days_of_stay ,
    v_requested_amount ,
    v_approved_amount,
    v_maximum_allowed_amount,
    v_notes,
    v_added_by,
    SYSDATE );
    ELSE
    UPDATE pat_tariff_details SET
    room_type_id = v_room_type_id,
    days_of_stay = v_days_of_stay,
    requested_amount = v_requested_amount,
    approved_amount = v_approved_amount,
    maximum_allowed_amount = v_maximum_allowed_amount,
    notes = v_notes,
    updated_by = v_added_by,
    updated_date = SYSDATE
    WHERE tariff_detail_seq_id = v_tariff_detail_seq_id;
    END IF;
    end;
    version is Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    Edited by: user13134817 on Nov 2, 2012 2:39 AM

  • Row lock contention on WWV_FLOW_DATA

    I'm hosting an APEX app on one of my Oracle servers
    Oracle 10.1.0.4.0
    APEX 3.0.0
    The users (and APEX developer) are complaining about slow performance. One of the primary reasons seems to be as a result of row lock contention. And as this is on an APEX table, I think it is fair to think that this is not a finger-up-nose mistake from the APEX developer.
    This is what I for example just saw some minutes ago. 3 APEX sessions running for application 103 and page 1 according to V$SESSION.
    Wait status for all 3 sessions (ticking over into many minutes) is:
    enq: TX - row lock contention
    The one session shows this SQL:
    INSERT INTO WWV_FLOW_DATA ( FLOW_INSTANCE, ITEM_ID, ITEM_VALUE )
    VALUES ( :B4 , :B3 , :B2 ||':'||:B1 ||':0:0')
    The other two sessions shows this SQL:
    UPDATE WWV_FLOW_DATA SET ITEM_VALUE = NVL(NVL(:B6 ,:B5 ),1)||':'
    || NVL(NVL(:B4 ,:B3 ),15)||':0:0' WHERE ITEM_ID = :B2 AND FLOW_I
    NSTANCE = :B1
    Fair to assume that all 3 are hitting the same row? (same flow instance and item?)
    I've done some searching and it seems that a lot of dead locks have been reported on similar APEX tables. Is this potentially the same underlaying issue, but with just slightly different symptoms?
    Some speculation... tabbed browsing is very common with Firefox. I often open multiple tabs on the same APEX app for different pages. What will the back-end impact be if this is done on the same page? Could it be that APEX expects a single-HTTP-request-at-a-time-from-a-web-session?
    What does not make sense though is why the update will show row lock contention, assuming all 3 hit the same row. The INSERT should when inserting a row with the same PK as that of an uncommitted inserted row of another session. But why would the UPDATEs in this scenario show row lock enqueues? The INSERT row enqueue points that the row has not yet been committed. If so, the 3rd session's UPDATE should return "no row found" and not be stuck on a row lock enqueue.. right?
    This does not make much sense to me.
    Any comments, suggestions, and ideas to troubleshoot and resolve this will be much appreciated.

    > When you and the APEX developer say "slow performance", have you ensured
    that this is not logic in the APEX application itself?
    The "slow performance" the APEX developer and users mention are usually pages timing out all together. There are no real heavy and complex SQLs executed to my knowledge (none I see on the server side). So I do not think it is an application SQL issue - besides, the "slow performance" on the back-end side, when reported, I seen as sessions spinning on enqueue TX locks.
    Not my APEX system so I'm not that familiar with it, but I had a quick look at it. The pages are relatively simplistic as there is no custom stuff (unlike some my APEX apps ;-) ).
    Also, this problem does not occur on a specific page, but intermittently on different pages.
    > were they all for the same APEX session emanating from the same client?
    Unsure.. I kind of expect these will have to be or else the SQL statement will be hitting a different flows row all together (which is why I speculated about the tabbed browser issue). Busy investigating this closer.
    >Have statistics been computed recently on the FLOWS_030000 schema?
    No. Interesting point as I've (very stupidly) never even considered running DBMS_STATS on the flows schema...
    What is interesting btw is that SQL is not static. The latest blocks (same event, same symptoms as described in my original posting) were on this SQL:
    UPDATE WWV_FLOW_PREFERENCES$ SET ATTRIBUTE_VALUE = :B5 WHERE USE
    R_ID = NVL(:B4 ,NVL(:B3 ,USER)) AND PREFERENCE_NAME = :B2 AND SE
    CURITY_GROUP_ID = :B1
    It also could be as a result of multiple sessions from the same web browser due to clicking a button/link more than once, or refreshing the browser without waiting at least a few seconds for a response.. (also, the fact that the browser is waiting for a response is not very visual/noticeable to the user)
    Am planning to spend some time on this issue tomorrow and will try and provide better technical feedback.
    If you have anything specific I can test from my side, please just shout Joel.

Maybe you are looking for

  • My Image Getting Scrolled in Tabstrip Change or Pagedown in Module Pool

    Hi All ,             I have designed a module pool with Tabstrip . On the Top i have displayed image . My Tab1 is for Coversion , Tab2 is for Interface . When Click on the Interface Tab and Press page down the image also scrolls down and gets display

  • Disk drive disappears

    I've got a Powermac G4 DP 800 that the disk drive works fine, but when I attach a hard drive to the ATA ribbon, neither drive shows up,not in Disk Utility, not even in System Profiler. Unhook the hard drive, again disk drive works fine. Tried a diffe

  • 10.6.3 Snow Leopard stuck at grey screen.

    Hello folks, as the topic subject states, I'm having problems as my Snow Leopard now refuses to boot beyond the grey screen. I'm pretty sure the only recent changes I made was to update iTunes. I attempted guiding the computer into the diagnostics mo

  • Export as a mp4 file?

    Hi. I'm trying to make my video into a Mp4 file or a Flash when I'm exporting from Final Cut pro, but the only thing I can export is a mov.? Does anybody know what to do? :-) /Nadia

  • Cannot recognize wifi networks

    My laptop is hardwired to a wi-fi network and works fine. However, when I take it elsewhere, it does not recognize any wireless networks - including the hard-wired one -- other devises and computers recognize it fine, so it must be the laptop. If any