Oracle For Update row lock

To: http://hi.baidu.com/mcj0127/blog/item/111a900777db06c87b89473c.html

SELECT FOR UPDATE-related knowledge of the application of an e-mail every piece had a certain amount of time to check the database is not issued by mail and send the message, after the success of e-mail databases logo has been replaced by non-fat fat.
This application deployed in the websphere on, websphere using vertical cloning, there are four server, when all four server when open, the four appeared at the same time made the same message to the same user.
At this time, for update lock will be able to solve this problem!
1: the state of the interpretation
statement: a SQL statement.
session: a user-generated ORACLE connection, a user can have multiple SESSION, but is independent of each other.
transaction: all of the changes can be divided in the transaction, a transaction contains one or more SQL. SESSION created when a time is a time to start TRANSACTION since the beginning and end of the transaction by the DCL control, that is, each COMMIT / ROLLBACK have marked the end of a transaction.
consistency: is the statement level rather than in terms of transaction-level. sql statement the data is the beginning of the sql statement to IMAGE.

2: sql explained
LOCK of the basic situation: update, insert, delete, select ... for update will LOCK the ROW.
There is only one TRANSACTION can LOCK the corresponding line, that is to say if a ROW has been LOCKED, it can not be a LOCK by other TRANSACTION.
LOCK generated by the statement but by the TRANSACTION (commit, rollback) at the end, that is a SQL will continue to exist after the completion of LOCK only when the COMMIT / ROLLBACK before LOCK after RELEASE.

SELECT .... FOR UPDATE [OF cols] [NOWAIT];
OF cols: SELECT cols FROM tables [WHERE ...] FOR UPDATE [OF cols] [NOWAIT];

3: sql notes
a: on the OF
running transaction A
select a.object_name, a.object_id from wwm2 a, wwm3 b where b.status = 'VALID' and a.object_id = b.object_id for update of a.status
While transaction B can wwm3 corresponding b table DML lines, but not on a table wwm2 lines corresponding DML operation.

Anti-click to see
running transaction A
select a.object_name, a.object_id from wwm2 a, wwm3 b where b.status = 'VALID' and a.object_id = b.object_id for update of b.status
While transaction B can wwm2 on a table row corresponding to DML, but can not b the corresponding table wwm3 line DML operation.
LOCK is the line that is to say, but if not, then OF will LOCK all of the table, only after the addition of OF where LOCK OF the words TABLE.

b: on the NOWAIT (If you must use FOR UPDATE, I also suggest that with NOWAIT)
When there is a conflict between the LOCK will be prompted STATEMENT errors and end there rather than wait for (for example: To check the line has been locked by other services, the current conflict with lock affairs, together with the nowait, the end of the current affairs will be prompted to error STATEMENT immediately rather than waiting for the end). the return of error is "ORA-00054: resource busy and acquire with NOWAIT pecified"

Also note the following usage should also be recommended, should consider the use of discretion.
1: FOR UPDATE WAIT 5
After five seconds will be prompted to ORA-30006: resource busy; acquire with WAIT timeout expired
2: FOR UPDATE NOWAIT SKIP LOCKED;
No rows selected will be prompted to
3: TABLE LOCKS
LOCK TABLE table (s) IN EXCLUSIVE MODE [NOWAIT];
Also in the transaction before the end of the release lock.
4: DEADLOCK
transaction a lock rowA, then transaction b lock rowB
then transaction a tries to lock rowB, and transaction b tries to lock rowA
Transaction that is to say the two are mutually lock each other has been to try to lock the ROW, the other party has been waiting for the release of their own lock, thus deadlock.
600 tips will deadlock.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Oracle For Update row lock

  • ORACLE10G full version centos5 installed (the installation has passed)

    ORACLE10G full version centos5 installed (the installation has passed) 1. Centos 5.0 install rn GUI must be installed, it is best not to start selinux rn rn rn 2. . Ready to install the software: (this is very important, is the first installation fai ...

  • SGA extended the principle of 32bit oracle

    SGA extended the principle of 32bit oracle From: http://www.itpub.net/247048.html Because the median 32bitrnoracle restrictions can only visit the oracle process 4g (2 of 32 power) following virtual memory address, the time at a lot of people this is ...

  • SQL optimization (1) - full table scan and index the test

    Test Objective: To test CBO and RBO, as well as full table scan than index the situation quickly. 1. To create a test environment SQL> select * from v $ version; BANNER -------------------------------------------------- -------------- Oracle Datab ...

  • Dbms_obfuscation_toolkit use of Oracle's encryption and decryption of data (to)

    In order to protect sensitive data, oracle start from 8i to provide a data encryption package: dbms_obfuscation_toolkit. Take advantage of this package, our data can be DES, Triple DES or MD5 encryption. This article on the use of this and the use of ...

  • Oracle XDB relax resolve port conflict of 8080

    In this paper, carried: http://www.enet.com.cn/article/2008/0306/A20080306175452.shtml Oracle 9i from the start, Oracle includes the installation of the default XDB. After starting the database, Oracle XDB's http service will automatically take u ...

  • Oracle in the relationship between User and Schema

    If we want to know the database and the User What is the relationship between Schema, we must first know about User and Schema database What is the concept in the end. In SQL Server2000 in architecture because of the reason, User and Schema there is ...

  • High Availability Oracle Flashback

    Brief introduction Flashback Database is a point in time (PIT) restore the database approach. This incomplete recovery strategy can be used to restore the logic because of human error cause damage to the database. At the introduction of 10g, it is de ...

  • An example of the use of TKPROF

    First, view and edit parameters SQL> show parameter max_dump_file_size NAME TYPE VALUE ------------------------------------ ----------- --- --------------------------- max_dump_file_size string UNLIMITED SQL> show parameter user_dump_dest NAME TYPE

  • Diagnosis and principles of order

    SQL> select disk.value "Disk", mem.value "Mem", 2 (disk.value / mem.value) * 100 "Ratio" 3 from v $ sysstat mem, v $ sysstat disk 4 where mem.name = 'sorts (memory)' 5 and disk.name = 'sorts (disk)'; D ...

  • ORACLE 10G dataguard configuration Step by Step

    oracle dataguard

Leave a Reply

Recent
Recent Entries
Tag Cloud
Random Entries
Latest Comments