Oracle Explicit Locks

Hello experts ,
Once again i want to clear my basic knowldge in terms of oracle locks.
what i knows is that oracle atumatically locked the object whenever we perform any dml operation.( update,delete)
but it is row level exclusive lock ( i.e. RX,in v$locked_object, it show locked mode 3 )
It is implicit lock which oracle provided automatically.
and the other lock is Explicit lock,
it is either we have to locked the by using LOCK statement ( by using LOCK statement we can lock the table in modes
(i.e row share(2),row exclusive(3), share(4), row share exclusive(5),exclusive(6) )
OR
the table is also locked by statemet "select ..for update"( but its row exlusive lock (RX 3))
but
when and in what condition we apply explicit lock?
what are the practical future of these lock?
can you please explain about these explicit lock like
row share(2)
row exclusive(3)
share(4)
row share exclusive(5)
exclusive(6)
I have read about these lock from books , blogs and other internet sites , but still my concepts is not clear
in these area.
Thanks in advance for your help.
Regards,
Prashant Mhatre

Oracle uses locks (aka enqueues) to prevent destructive concurrent operations on a resource. Here is a short description of the different lock types written by Jonathan Lewis ("the international recognized Oracle Expert"): http://jonathanlewis.wordpress.com/2010/06/21/locks/.
Except of the SELECT FOR UPDATE case I don't think there are many situation in which setting an explicit lock is necessary - the server knows where and when locks have to be used.

Similar Messages

  • Explicit Lock on for Update Table

    If I want to perform explicit lock acquiring on updating all records in “customer” table with “state” equals to “CA”. What command should I run?

    Hi,
    Refer to following ppt.
    http://www.indiana.edu/~dbateam/Documents/oracle_locking.ppt#260,5,Oracle Isolation Levels
    You can get to know the things.
    - Pavan Kumar N

  • Oracle 10g - lock statistics

    What are the different situations in which Oracle will lock existing table/index statistics automatically?
    As per my undrstanding to lock the statistics we must use "dbms_stats" package with lock_table_stats/lock_schema_stats procedures. I dont see any other situation where Oracle automatically locks the statistics.
    Please share your experience.

    I dont see any other situation where Oracle automatically locks the statistics.Oracle never locks the statistics on its own. Oracle has only given methods so that one can decide whether to collect the statistics for volatile/static tables; so that the execution plans do not change drastically.

  • Where can I get oracle dead lock information

    Hi Experts,
    two days back I find oracle dead lock information at SM21 log file but when I checked today the old data was over written by new data.
    Where can I find oracle dead lock information other than SM21? can anyone please help
    Thanks in advance
    Regards
    Veera
    Edited by: Veerab on Apr 27, 2011 8:22 AM

    Hi,
    Have you refered [SAP Note 84348 - Oracle deadlocks, ORA-00060 |https://service.sap.com/sap/support/notes/84348]? It contains good detailed description about possible oracle deadlock situations and analysis.
    Along with the trace file generated by oracle (at directory /oracle/<SID>/saptrace/usertrace/), You can get historical information from alert<SID>.log file located at /oracle/<SID>/saptrace/background/.
    In alert<SID>.log file the deadlock situation is written with deadlock graph at the time of occurances.
    Regards,
    Bhavik G. Shroff

  • How can I prevent oracle from locking accounts after failed logins?

    how can I prevent oracle from locking accounts after failed logins?
    Thanks

    svarma wrote:
    So what is the difference between the profile settings ...FAILED_LOGIN_ATTEMPTS and the parameter settings SEC_MAX_FAILED_LOGIN_ATTEMPTS?
    Prior to 11g we only used profiles to control failed_login_attempts.. Then why we need thsi new parameter now?http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/initparams221.htm#I1010274
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17222/changes.htm#UPGRD12504
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_6010.htm#SQLRF01310
    As documented ...
    FAILED_LOGIN_ATTEMPTS is a property of a profile, and will lock an account
    SEC_MAX_FAILED_LOGIN_ATTEMPTS is an initialization parameter and will drop a connection but says nothing about locking accounts.

  • Oracle's locking strategy question

    I have a question related to Oracle's locking mechanism which I understand is related to taking "snapshots in time" to avoid writers blocking readers (which happens in SQL Server).
    Suppose I had a table T1 with 1 billion records and column C1 = 4 in every row. Suppose the following events occur:
    12:00 update T1 set C1 = 5
    12:01 select C1 from T1 where ... (and this statement returns only one row)
    1:00 the update statement executed at 12:00 finally finishes
    Would oracle return the value 4 regardless or which row was selected at 12:01?
    Why would this be more correct than locking the table and waiting until 1:00 and returning 5? Sure, this would be a long wait, but at 12:00 a command was issued to set every value to 5!

    You are question is related to oracle transaction
    control and read consistency in the database in
    Oracle database all the SQL and DML runs with SCN
    timestamp.
    for example
    Session 1 SQL 12:00 > UPDATE t1 SET c4=5 ;
    ---assuming this runs for an hour
    before updating c4=5 it takes the snapshot of the C4
    column data and keeps in
    UNDO segments to make other sessions read
    consistent.
    Session 2 SQL 12:01 > SELECT c4 FROM t1 WHERE ....
    this will return 4 as the DML is not yet comminted in
    the Session 1
    To happen this Oracle database server process reads
    the data from UNDO to answer your question.locks are
    matianed at the database BLOCK header level.
    Let me put a simple thought here
    You have two debit cards issued for one account one
    is with you and the other one is with your beloved
    one.Balance in your account = Rs 40000
    1) at 12:00 you went to a ATM and inserted your debit
    card to draw amt Rs 20000
    and your transaction is still processing ( you not
    recieved the cash)
    2) at 12:01 your beloved one went an another ATM and
    interested to see the balance so do you think Rs
    40000 should be shown or Rs 20000.
    hope you got some ideaNot to pick nits, but I think this is a bad example. If you had such an important action (especially if it was going to take a long time to complete) you would/should have some kind of lock on modifying the account value so that this very thing couldn't happen! Only one transaction at a time gets to update the balance. In a sense, that might make Oracle look like the SQL Server you appear to be familiar with (the 2nd transaction would wait. A very long time!) But for a bank account type transaction, you almost have to.
    Gaff

  • Explicit locking of Entity JavaBean

    Hi!
    I am developing local WD application based on EJB model using SAP NetWeaver Developer Studio 7.0.12
    There's Employee entity javabean, that is shown as a table on EmployeeView webdynpro view (model node, bound to controller).
    There's also EmployeeEdit webdynpro view, where Employee entity javabean is shown as set of InputFields (same model node, bound to controller).
    When user clicks Save button in EmployeeEdit view, changed values are saved.
    The problem arises when two users want to change the same record of Employee entity. Both can go to EmployeeEdit view, change values of record and click Save button, because actual transaction for saving is implemented only when users click Save button.
    The workaround for this would be explicit locking of entity record when first user goes to EmployeeEdit view, if it's not already locked. But I couldn't find enough information about this.
    [EJBLocking interface|http://help.sap.com/javadocs/nw04/current/en/com/sap/engine/interfaces/ejb/locking/EJBLocking.html] might be what I need, but I don't know how to use it.
    Can anyone give me an idea about all this?
    Thanks in advance
    Renat

    Hi, Ganga!
    Thank You for reply,
    I've already chosen "Local" locking for my entity bean and trying to realize explicit locking for my entity.
    I can't understand, what parameters do I need to pass to lock method.
    Here is code of entity home method, which is called to lock this entity.
         public void ejbHomeLockMe() {
              EJBLocking ejbl = null;
              Context ctx = null;
              try {
                   ctx = new InitialContext();
                   ejbl = (EJBLocking) ctx.lookup("java:comp/EJBLocking");
              } catch (NamingException ne) {
                   ne.printStackTrace();
                   throw new OklaException(ne.getMessage());
              try {
                   DataSource ds = (DataSource) ctx.lookup("jdbc/OKLA_DS");
                   ejbl.lock( //here I get NullPointerException
                        TableLocking.LIFETIME_TRANSACTION,
                        ds.getConnection(),
                        (EntityBean) this,
                        TableLocking.MODE_EXCLUSIVE_NONCUMULATIVE);
              } catch (SQLException sqle) {
                   sqle.printStackTrace();
                   throw new OklaException(sqle.getMessage());
              } catch (NamingException ne) {
                   ne.printStackTrace();
                   throw new OklaException(ne.getMessage());
    As a result I get this exception
       java.lang.NullPointerException
        at com.sap.engine.services.ejb.entity.pm.lock.EJBLockingImpl.getPKMap(EJBLockingImpl.java:108)
        at com.sap.engine.services.ejb.entity.pm.lock.EJBLockingImpl.lock(EJBLockingImpl.java:48)
        at my.company.okla.employee.EmployeeBean.ejbHomeLockMe(EmployeeBean.java:92)
    Any thoughts about this?
    Many thanks
    Renat

  • Ingres vs Oracle exclusive locking

    Ingres allows an exclusive lock on tables, set lockmode on tablename where readlock = exclusive which means the users can't access the same
    rows that are being modified by another query.
    Is there anything in oracle that does the same thing ? All of Oracle's locking seesm to be that you can
    still read data. And that is what my user is afraid of. He doesn't want to read old data, when it's
    being changed.
    How do you work around this ?
    Thanks.

    Ingres allows an exclusive lock on tables, set lockmode on tablename where readlock = exclusive which means the users can't access the same
    rows that are being modified by another query.
    Is there anything in oracle that does the same thing ? All of Oracle's locking seesm to be that you can
    still read data. And that is what my user is afraid of. He doesn't want to read old data, when it's
    being changed.
    How do you work around this ?
    Thanks.

  • Explicit Locking Question

    Dear all
    I have a question about <<Developer’s Guide>> Explicit Locking (27-3):
    "In a replicated cache, puts are blocked, but they are not blocked in a partitioned cache. "
    I want to know why "puts are not blocked in a partitioned cache."
    Thanks

    wangjw wrote:
    Dear all
    I have a question about <<Developer’s Guide>> Explicit Locking (27-3):
    "In a replicated cache, puts are blocked, but they are not blocked in a partitioned cache. "
    I want to know why "puts are not blocked in a partitioned cache."
    ThanksThe normal behaviour is that lock does not block anything other than another lock.
    The put-blocking behaviour at replicated caches is an anomaly which may be necessary due to backward compatibility reasons, or possibly a necessity due to the message flow for mutating operations in a replicated cache.
    So the question really would be why puts are blocked in a replicated cache, and I would also be interested in the answer, although I have my guesses.
    Best regards,
    Robert

  • Does Index in Oracle Text lock local files?

    Hi, I am planing to implement content search using file datastore. Let me explain how the whole search going to work, Users are going to upload the file, I am going to store the information about the file like filename, size, keywords, file path etc in Oracle table and I am going to store the original file in a different server. When indexing on filepath, does index lock local files on the Operating system? Does it affect the live data? Please I need answers to this ASAP. Can anyone help?
    Thanks,
    Meena

    Hi,
    there are differences between the Engine of Text indexing, in 10G it was Verity, in 11G (from version 11.1.0.7) it is the Stellent technology, but I do not hope this is it.
    Maybe you could make a dump of the creation of the indexes in both 10g and 11g. This can be done through:
    select ctxsys.ctx_report.create_index_script('KSK_FILE_TABLE_CTX1') from dual;
    This wil give you a create script with all the parameters. Maybe there is a different in your default settings for text indexes, possible the FILTER.
    Herald ten Dam
    Superconsult.nl

  • Oracle 8i locking and timeout

    Hi,
    I am talking to an Oracle 8.1.7 db through Perl DBI for a certain Web Application.
    In the back-end, a script is invoked every hour to sync parts of this db, with the master db. The sync'ing script takes quite a while to complete and it consists of a single transaction ( several update statements followed by a single commmit at the very end).
    Now, I want to know what happens to any user who tries to modify something through the web-interface. If a query from the web-interface finds that a row is locked by the syncing script, how long will it wait before a timeout? ( if any timeout occurs at all, in the first place ! ). Can I control this timeout?
    Please repond ASAP.
    Thanks in advance,
    Rajesh

    How much control do you have over the SQL being generated? There is a keyword 'NOWAIT' that can be added to a statement indicating that it shouldn't wiat for resources-- if it can't lock them immediately, it returns an ORA-00054 (if memory serves) resource locked and NOWAIT specified. Otherwise, by default, the statement will wait indefinitely.
    In ODBC, you can specify a query timeout that will kill all queries after some amount of time.
    Justin

  • Oracle's Locking Architecture

    I'm specifically talking about 9i & 10G.
    Is there any info that explains Oracle Locking mechanisms? I tried to find something on metalink but all I found was how to detect locks. I need to start from the beginning so that I understand the lock types when data is read, modified or deleted.
    Any info please?

    So in a nutshell, Oracle obtains an UPDATE lock to
    modify data but does obtain any locks to read data.
    Have I read this correctly?Effectively, yes.
    That's Oracle's magic ..... 'readers do not block writers and writers do not block readers'
    Oracle uses a 'Consistent Read' mechanism to rebuild any data block back to the time of query. If a user updates a row but has not committed, and another needs to see that row, the second user will recreate the image of the row using the in-memory copy of the updated row and the rollback/undo information about the row.
    A query only needs to put sufficient locks in place to ensure the table does not get whacked. Nothing at the row level.
    An update needs sufficient locks to ensure other writers can not change the row ... and to tell the readers to rebuild the block instead of using the 'current' version.

  • Root issue for oracle AE  lock

    Hi Friends,
    What kind of root issue leads to AE lock(Edition Lock) in oracle 11.2?
    How do we implement a solution for AE type locked?
    Thanks
    newdba

    Hi Karan,
    Thanks for your explaining. the reason is we have slow performance in database. Per checked, I found lots of block with AE. per your recommendation as
    OWNER VIEW_NAME TEXT_LENGTH TEXT TYPE_TEXT_LENGTH TYPE_TEXT OID_TEXT_LENGTH OID_TEXT VIEW_TYPE_OWNER VIEW_TYPE SUPERVIEW_NAME EDITIONING_VIEW READ_ONLY
    SYS CURRENTEDITION_OBJ 1490 select o."OBJ#",o."DATAOBJ#",o."OWNER#",o."NAME",o."NAMESPACE",o."SUBNAME",o."TY N N
    N N
    Thanks
    newdba

  • Oracle 8i Locks

    We are having problems with users locking each other throughout the day, in which one user is doing a select, and the other an update. In the last case, the user doing the following select statement acquired an exclusive lock:
    SELECT "INVENTORY"."INVENTORY_ID",
    SubStr( "INVENTORY"."RECEIPT_NUMBER", 1, 7 ) receipt_number,
    "INVENTORY"."AGENCY_REPORT_YEAR",
    "INVENTORY"."AGENCY_REPORT_NUMBER",
    "INVENTORY"."AGENCY_REPORT_SUFFIX",
    "INVENTORY"."NUMBER_OF_PACKAGES"
    FROM "INVENTORY"
    WHERE ( Upper ( receipt_officer_id ) Like '2026542%' )
    Should an exclusive lock be placed here?
    TIA
    null

    For the select statement there wont't be any locks on the table.
    In the select statement are you using the SELECT ... FROM table FOR UPDATE OF also (The sql statement you have given does not have the update clause) then a Row Share lock will be held on the table.
    Refer to the following URL http://technet.oracle.com/doc/oracle8i_816/server.816/a76965/c23cnsis.htm#9975
    for the table lock modes that statements acquire and operations that those locks permit and prohibit.

  • Oracle database locks

    Today I ran the following queries in my 2 node RAC database. Enterprise database server 11.7 linux version.
    SQL> select * from dba_blockers;
    no rows selected
    SQL> select * from dba_waiters;
    no rows selected
    SQL> SELECT substr(DECODE(request,0,'Holder: ','Waiter: ')||g.sid,1) sess,s.machine,s.serial#,s.sql_id sqlid,
    2 id1, id2, lmode, request, g.type, g.inst_id, seconds_in_wait
    3 FROM GV$LOCK g, gv$session s
    4 WHERE (id1, id2, g.type) IN
    5 (SELECT id1, id2, type FROM GV$LOCK WHERE request>0)
    6 and g.sid = s.sid
    7 and g.inst_id = s.inst_id
    order by sess desc;
    SESS MACHINE SERIAL# SQLID ID1 ID2 LMODE REQUEST TY INST_ID SECONDS_IN_WAIT
    Waiter: 6462 appserver 49027 2vzvm60fvf506 276026 0 0 6 TM 2 2078
    Holder: 6492 database server 8546 276026 0 3 0 TM 1 28815
    SQL> SELECT a.sql_text
    FROM gv$sqltext a,
    gv$session b
    WHERE a.address = b.sql_address
    AND a.hash_value = b.sql_hash_value
    AND b.sid = &1
    ORDER BY a.piece; 2 3 4 5 6 7
    Enter value for 1: 6492
    old 6: AND b.sid = &1
    new 6: AND b.sid = 6492
    no rows selected
    INST_ID SID OBJECT_OWNER OBJECT_NAME LOCKED_MODE OS_USER_NAME
    1 6492 ABC XYZ Row-X (SX) oracle
    2 6462 ABC XYZ None appuser
    I wanted to know why dba_blockers or dba_waiters not showing blocked or waiting sessions, why no sqlid associated to holder session ?
    Thanks for your time and help

    Thanks for your quick response. you provided good information
    I understood that currently no session is holding the lock for which other session is waiting, i.e dba_blockers showing zero rows.
    But how the below query is showing holder and waiting session and no sql query associated to holding session.
    SQL> SELECT substr(DECODE(request,0,'Holder: ','Waiter: ')||g.sid,1) sess,s.machine,s.serial#,s.sql_id sqlid,
    2 id1, id2, lmode, request, g.type, g.inst_id, seconds_in_wait
    3 FROM GV$LOCK g, gv$session s
    4 WHERE (id1, id2, g.type) IN
    5 (SELECT id1, id2, type FROM GV$LOCK WHERE request>0)
    6 and g.sid = s.sid
    7 and g.inst_id = s.inst_id
    order by sess desc;
    SESS MACHINE SERIAL# SQLID ID1 ID2 LMODE REQUEST TY INST_ID SECONDS_IN_WAIT
    Waiter: 6462 appserver 49027 2vzvm60fvf506 276026 0 0 6 TM 2 2078
    Holder: 6492 database server 8546 276026 0 3 0 TM 1 28815

Maybe you are looking for

  • ALC-DSC-000-000

    I have a Turnkey version of ES running on Windows XP Pro. During JBoss start-up as well as during run-time, I am getting some Internal Errors like below in the server.log. What does it mean? and how to fix it? The error didn't seem to affect anything

  • Date and time keeps going missing!

    Hi everybody, my date and time keeps going missing from the top bar every time I turn on my mac - sometimes other things go missing, like the airport status. It used to happen just once a fortnight but after I installed the latest security update, it

  • Making copies of layers when the document is in Preview mode

    When a document is put in Outline mode, it un-checks the Preview check-box in the Layer Options dialog for the top-most layers.  If these layers are then duplicated, they are also in Outline mode and this same check box is un-checked.  However, if th

  • I forgot my security answers how do I reset my security answers

    I have tried several times to reset my security answers but, itunes store keeps asking for the oringinal answers which, I forgot and I keep trying and have to keep waiting 8 hours times 4 tries can anyone help me

  • Any reason why should happen happ

    My son has a Sound Blaster X-Fi Fatalty in his pc, he just upgraded his speakers with a Logitech Z-5500 Digital package. Connection from the front panel of the pc to the Logitech Digital SoundTouch Control Panel is via an optical cable. However when