Oracle in depth fifth chapter locking and latchingLocksIn Single-user systems, locks is not needed. In multi-user system, in order to allow multi-user access to data, modify data, modify the structure, you need a mechanism to ensure that everyone's consistent modification. It's time to use lock. Lock,locks is a tool for you to use DB properly, so there is no need to avoid it (of course the unwanted lock should be avoided for poor design, and be sure to keep lock when you need it and release it when you don't need it). Lock on Row-level does not consume a lot of resources because the resources you need to lock 1 ROW and 1W Row,lock are the same. The read action is not block,write by the write action and is not blocked by the read action. The process is similar to a: Find the address of the line of data you want to manipulate. B: Go to this line. C:lock This line (wait for it to release if the line is already lock, unless you use the NOWAIT option) to manage it very simply because lock is managed as a property of data.
Lock TypesDML Locks: Produced by DML statements, such as Select,insert,update,merge,delete. Ensure that only one user operates on a single line, and that other users cannot modify the structure of the table you are working on. DML locks are subdivided into the following types
TX(Transaction)LocksTX Lock is the first change to start with a transaction (about transaction see Select for UPDATE related knowledge http://sunmoonking.spaces.live.com/blog/cns! E3bd9cbed01777ca!318.entry), ending with the DCL statement. A queue method is used so that other sessions await the end of the transaction. For example, select for update will produce a TX locks, see (Dbms_lock Package test Oracle LOCK http://sunmoonking.spaces.live.com/blog/cns! E3bd9cbed01777ca!590.entry)
TM (DML Enqueue) Locks General tips Ora-00054:resource busy and acquire with NoWait specified We can also cancel the TM lock with ALTER TABLE TableName DISABLE table lock so we can't drop the table. sql> CREATE TABLE t1 (x int); Table created. Sql> CREATE TABLE t2 (x int); Table created. sql> INSERT INTO T1 values (1); 1 row created. sql> INSERT INTO T2 values (1); 1 row created. 1 Select (select Username from v$session where sid = V$lock.sid) Username, Sid, &nbs p; id1, id2, Lmode, request, block, V$lock.type from V$lock &nbs p; WHERE sid = (select Sid from V$mystat where rownum=1) sql>/USERNAME&NB sp; SID---------------------------------------------------------------------- id1 id2 LMODE request block TYPE------------------------------------------------------ sbtopt 13444 0 3 0 0 TM SBTOPT 23 13445 0 3 0 0 TM sbtopt 23 327743 68571 6 0 0 TX sql> Select object_name, object_id 2 from user_objects 3 where object_name in (' T 1 ', ' T2 ') 4 /object_name object_id------------------------------------------------------------------------T2 13445 t1 13444 a transaction can onlyThere is a TX lock that can have multiple TM lock, or you can see that the ID1 of the TM Lock is the number of Object_id,tm locks determined by Dml_locks. What happens when we drop table T1 with TM lock sql> drop table T1 2 /table dropped. Why was the table removed? because drop is a DDL statement, a commit is triggered before and after the DDL statement regardless of whether the DDL statement succeeds. Then let's take a look at the DDL LOCKS.
DDL LocksExclusive DDL Locks:Prevent other sessions from obtaining DDL Lock or TM lock
Share DDL LocksOther sessions cannot modify the table structure, but you can modify the data
breakable Parse Locks:DDL statements are not blocked Internal locks and
LatchesTo protect the internal data structures, when Oracle parse a query and then produces a optimized query plan, it latch a library cache to hold the plan so that other sessions can also be used. (Some people may not agree to put latch into lock, seek common ground), Pmon responsible for cleaning up dies latch latch Follow the following procedure to obtain attempt to get latch If latch gotten return SUCCESS Else misses on that Latch = misses+1; Loop sleeps on Latch = sleeps + 1 for I in 1. Watts Loop attempt to get Latch If Latch gotten Then return SUCCESS End If
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.