欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

oracle數(shù)據(jù)庫事務(wù)transaction鎖lock模式思考之一

前言

        數(shù)據(jù)庫事務(wù)是oracle非常基礎(chǔ)又極為重要的概念。之前已經(jīng)介紹過相關(guān)的一些概念,相關(guān)文章見下:  
  

創(chuàng)新互聯(lián)專注于臨縣企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),成都商城網(wǎng)站開發(fā)。臨縣網(wǎng)站建設(shè)公司,為臨縣等地區(qū)提供建站服務(wù)。全流程按需定制設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

oracle產(chǎn)生事務(wù)transaction幾種方式或方法  
oracle事務(wù)隔離級別transaction isolation level初識

      產(chǎn)生數(shù)據(jù)庫事務(wù)時,必然會在數(shù)據(jù)庫事務(wù)運行期間產(chǎn)生各種各樣的鎖。與鎖相關(guān)的動態(tài)性能視圖為v$lock,里面有個列l(wèi)mode,即持鎖模式或叫鎖模式,其具體含義及取值

oracle數(shù)據(jù)庫事務(wù)transaction鎖lock模式思考之一

鎖模式lmode可以有7種不同的取值,每個值到底是什么意思,具體含義見下

oracle數(shù)據(jù)庫事務(wù)transaction鎖lock模式思考之一

鎖模式測試實踐

創(chuàng)建測試表并插入記錄

SQL> create table t_lockmode(a int,b int);
Table created.
SQL> insert into t_lockmode select 1,1 from dual;
1 row created.
SQL> commit;
Commit complete.
  • row share

這種鎖模式 允許 多個會話并發(fā)訪問被鎖定的表,但是不允許 其它會話以 exclusive排它模式鎖定整個表
這種鎖模式也是鎖模式 share update的同義詞
這種鎖模式仍然存在是為了兼容 oracle舊版本
--未加鎖前的測試會話的持鎖信息
(可見數(shù)據(jù)庫一直會持有各種鎖,下述的鎖是系統(tǒng)鎖,而非用戶鎖)
SQL> select addr,sid,type,lmode,request,block from v$lock where sid=73;
ADDR			SID TY	    LMODE    REQUEST	  BLOCK
---------------- ---------- -- ---------- ---------- ----------
000000008D2498B8	 73 AE		4	   0	      0
000000008D249AE8	 73 TO		3	   0	      0
--測試會話加 row share鎖模式
SQL> lock table t_lockmode in row share mode;
Table(s) Locked.
--加鎖模式 row share后的持鎖信息
SQL> /
ADDR			SID TY	    LMODE    REQUEST	  BLOCK
---------------- ---------- -- ---------- ---------- ----------
000000008D2498B8	 73 AE		4	   0	      0
000000008D249AE8	 73 TO		3	   0	      0
00007FE54C209CD8	 73 TM		2	   0	      0  --lmode=2
---其它會話可以row share鎖模式并發(fā)訪問表
SQL> select sid from v$mystat where rownum=1;
       SID
----------
	28
SQL> lock table t_lockmode in row share mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
--其它會話可以 row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row exclusive mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
---其它會話可以share鎖模式并發(fā)訪問表
SQL> lock table t_lockmode in share mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
----其它會話可以 share row exclusive鎖模式并發(fā)訪問表
SQL> lock table t_lockmode in share row exclusive mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
----其它會話不能以 exclusive鎖模式并發(fā)訪問表
--卡住
SQL> lock table t_lockmode in exclusive mode;
SQL> /
ADDR			SID TY	    LMODE    REQUEST	  BLOCK
---------------- ---------- -- ---------- ---------- ----------
000000008D2498B8	 73 AE		4	   0	      0
000000008D249AE8	 73 TO		3	   0	      0
00007FE54C2042E0	 73 TM		2	   0	      1
  • row exclusive

這種鎖模式 同于row share,但是不允許其它會話以 share鎖模式訪問
這種鎖模式 在執(zhí)行DML操作(update,insert,delete)會自動獲取這種鎖模式
測試會話以row exclusive鎖模式持有表
SQL> lock table t_lockmode in row exclusive mode;
Table(s) Locked.
SQL> select addr,sid,type,lmode,request,block from v$lock where sid=73;
ADDR			SID TY	    LMODE    REQUEST	  BLOCK
---------------- ---------- -- ---------- ---------- ----------
000000008D2498B8	 73 AE		4	   0	      0
000000008D249AE8	 73 TO		3	   0	      0
00007FE54C2042E0	 73 TM		3	   0	      0  --lmode=3
--其它會話可以row share鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row share mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
--其它會話可以 row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row exclusive mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
--其它會話 不能以share鎖模式 并發(fā)訪問表
--卡住
SQL> lock table t_lockmode in share mode;
^Clock table t_lockmode in share mode
           *
ERROR at line 1:
ORA-01013: user requested cancel of current operation
--其它會話 不能以share row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in share row exclusive mode;
^Clock table t_lockmode in share row exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
--其它會話 不能以exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in exclusive mode;
^Clock table t_lockmode in exclusive mode
           *
ERROR at line 1:
ORA-01013: user requested cancel of current operation
  • share

這種鎖模式 允許 多個會話并發(fā)查詢,但是不允許 對于鎖定表的update操作
測試會話以share鎖模式持有表
SQL> lock table t_lockmode in share mode;
Table(s) Locked.
SQL> select addr,sid,type,lmode,request,block from v$lock where sid=73;
ADDR			SID TY	    LMODE    REQUEST	  BLOCK
---------------- ---------- -- ---------- ---------- ----------
000000008D2498B8	 73 AE		4	   0	      0
000000008D249AE8	 73 TO		3	   0	      0
00007FE54C209CD8	 73 TM		4	   0	      0  --lmode=4
--其它會話可以row share鎖模式 并發(fā)訪問表
SQL>  lock table t_lockmode in row share mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
--其它會話不能以 row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row exclusive mode;
^Clock table t_lockmode in row exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
--其它會話可以 share鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in share mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
---其它會話 不允許以 share row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in share row exclusive mode;
^Clock table t_lockmode in share row exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
---其它會話 不允許以 exclusive鎖模式 并發(fā)訪問表
SQL>  lock table t_lockmode in  exclusive mode;
^C lock table t_lockmode in  exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
  • share row exclusive

這種鎖模式 用于查看整個表,允許 其它會話查看表的數(shù)據(jù),但是不允許其它會話 以share鎖模式獲取表 ,也不允許 其它會話update被鎖定表
這種鎖模式 允許 對于鎖定表的查詢,但不允許 對于鎖定表的其它任何操作
測試會話以 share row exclusive鎖模式持有表
SQL> lock table t_lockmode in share row exclusive mode;
Table(s) Locked.
SQL> /
ADDR			SID TY	    LMODE    REQUEST	  BLOCK
---------------- ---------- -- ---------- ---------- ----------
000000008D2498B8	 73 AE		4	   0	      0
000000008D249AE8	 73 TO		3	   0	      0
00007FE54C209CD8	 73 TM		5	   0	      0
--其它會話 允許 以row share鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row share mode;
Table(s) Locked.
SQL> rollback;
Rollback complete.
--其它會話 不允許 以row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row exclusive mode;
^Clock table t_lockmode in row exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
---其它會話 不允許 以share鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in  share mode;
^Clock table t_lockmode in  share mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
---其它會話 不允許 以share row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in share row exclusive mode;
^Clock table t_lockmode in share row exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
---其它會話 不允許以 exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in exclusive mode;
^Clock table t_lockmode in exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
  • exclusive

這種鎖模式 允許 對于鎖定表的查詢,但不允許 對于鎖定表的其它任何操作
--測試會話以  exclusive鎖模式持有表
SQL> lock table t_lockmode in exclusive mode;
Table(s) Locked.
SQL> /
ADDR			SID TY	    LMODE    REQUEST	  BLOCK
---------------- ---------- -- ---------- ---------- ----------
000000008D2498B8	 73 AE		4	   0	      0
000000008D249AE8	 73 TO		3	   0	      0
00007FE54C2042E0	 73 TM		6	   0	      0  --lmode=6
--其它會話 不允許以 row share鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row share mode;
^Clock table t_lockmode in row share mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
---其它會話不允許 以row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in row exclusive mode;
^Clock table t_lockmode in row exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
---其它會話不允許以 share鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in share mode;
^Clock table t_lockmode in share mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
---其它會話不允許 以share row exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in share row exclusive mode;
^Clock table t_lockmode in share row exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
--其它會話不允許 以exclusive鎖模式 并發(fā)訪問表
SQL> lock table t_lockmode in exclusive mode;
^Clock table t_lockmode in exclusive mode
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation

鎖模式之間的的兼容性圖

oracle數(shù)據(jù)庫事務(wù)transaction鎖lock模式思考之一

小結(jié)

  • exclusive鎖模式最牛逼,它是唯我獨尊,獨對排它訪問,它一占用表鎖資源,其它會話只能等待

  • row share(share update)鎖模式相對而言最溫和,它基本和所有的鎖模式可以并存,只是不允許exclusive鎖模式

  • share row exclusive鎖模式雖然沒有exclusive鎖模式這么牛逼,它可以排第二種嚴厲鎖模式,它只能兼容row share(share update)鎖模式

  • row exclusive及share鎖模式排位在share row exclusive之后,它可以兼容3種鎖模式,不兼容余下2種鎖模式

培訓(xùn)課件

(收費20元)

oracle數(shù)據(jù)庫事務(wù)transaction鎖lock模式思考之一

oracle數(shù)據(jù)庫事務(wù)transaction鎖lock模式思考之一

當(dāng)前題目:oracle數(shù)據(jù)庫事務(wù)transaction鎖lock模式思考之一
URL標(biāo)題:http://www.chinadenli.net/article36/iejhsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化網(wǎng)站設(shè)計網(wǎng)站策劃電子商務(wù)響應(yīng)式網(wǎng)站Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營