TM LOCK MODE
1,在DML操作時,自動獲取表上的row exclusive mode(lmod=3)的鎖。
2,可以線上建立索引,但無法線上刪除索引或修改為UNUSABLE(被dml操作阻塞),報“ORA-00054: resource busy and acquire with NOWAIT specified”;一般透過多次嘗試刪除。
--可以嘗試如下方式刪除嗎?
lock table ta in row exclusive mode;
drop index idx_ta;
--問題:drop 操作時,首先提交,然後才執行刪除操作,由於鎖定表的事務結束,刪除操作需要再次排隊獲取TM鎖,實際上該會話並不一定能順利獲取鎖定。
3,不同鎖模式的相容性:
lockmode:
ROW SHARE(lmod=2):ROW SHARE permits concurrent access to the locked table but prohibits users from locking the entire table for exclusive access. ROW SHARE is synonymous with SHARE UPDATE, which is included for compatibility with earlier versions of Oracle Database.
--阻止表級排他鎖定
ROW EXCLUSIVE(lmod=3):ROW EXCLUSIVE is the same as ROW SHARE, but it also prohibits locking in SHARE mode. ROW EXCLUSIVE locks are automatically obtained when updating, inserting, or deleting.
--阻止表級排他鎖定,同時阻止共享鎖定
SHARE UPDATE(lmod=2):See ROW SHARE.
SHARE SHARE(lmod=4):permits concurrent queries but prohibits updates to the locked table.
--允許併發查詢,阻止更新
SHARE ROW EXCLUSIVE(lmod=5):SHARE ROW EXCLUSIVE is used to look at a whole table and to allow others to look at rows in the table but to prohibit others from locking the table in SHARE mode or from updating rows.
--阻止更新,同時阻止共享鎖定
EXCLUSIVE(lmod=6):EXCLUSIVE permits queries on the locked table but prohibits any other activity on it.
--阻止所有其他鎖定
lock table ta in row share mode nowait;
commit;
lock table ta in row exclusive mode nowait;
commit;
lock table ta in share mode nowait;
commit;
lock table ta in share row exclusive mode nowait;
commit;
lock table ta in exclusive mode nowait;
commit;
4,相容性測試:
4.1會話1:
lock table ta in row share mode;
會話2:
連線到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> lock table ta in row share mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in row exclusive mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share row exclusive mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in exclusive mode nowait;
lock table ta in exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
4.2會話1:
lock table ta in row exclusive mode;
會話2:
SQL>
SQL> lock table ta in row share mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in row exclusive mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share mode nowait;
lock table ta in share mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share row exclusive mode nowait;
lock table ta in share row exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in exclusive mode nowait;
lock table ta in exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
4.3會話1:
lock table ta in share mode;
會話2:
SQL> lock table ta in row share mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in row exclusive mode nowait;
lock table ta in row exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share row exclusive mode nowait;
lock table ta in share row exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in exclusive mode nowait;
lock table ta in exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
4.4會話1:
lock table ta in share row exclusive mode;
會話2:
SQL>
SQL> lock table ta in row share mode nowait;
表已鎖定。
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in row exclusive mode nowait;
lock table ta in row exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share mode nowait;
lock table ta in share mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share row exclusive mode nowait;
lock table ta in share row exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in exclusive mode nowait;
lock table ta in exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
4.5會話1:
lock table ta in exclusive mode;
會話2:
SQL> lock table ta in row share mode nowait;
lock table ta in row share mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in row exclusive mode nowait;
lock table ta in row exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share mode nowait;
lock table ta in share mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in share row exclusive mode nowait;
lock table ta in share row exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
SQL>
SQL> lock table ta in exclusive mode nowait;
lock table ta in exclusive mode nowait
*
第 1 行出現錯誤:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> commit;
提交完成。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-1069663/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle deadlock with TM lock in SX/SSX modeOracle
- ORACLE LOCK MODE 1.2.3.4.5.6Oracle
- innodb_autoinc_lock_mode
- Oracle blocking issue with lock table in exclusive modeOracleBloC
- [Oracle] Append hint(insert sql) will lead a TM LOCKOracleAPPSQL
- TM表鎖各種mode的實驗及2-6 的TM鎖相互間的互斥示例
- MySQL 共享鎖 (lock in share mode),排他鎖 (for update)MySql
- Oracle LOCK內部機制及最佳實踐系列(四)深入分析mode 2-6 的TM鎖相互間的互斥關係Oracle
- ORACLE基礎之oracle鎖(oracle lock mode)詳解Oracle
- InnoDBd的auto_increment以及innodb_autoinc_lock_modeREM
- master bug InnoDB Error unlock row could not find a 4 mode lockASTError
- 深入理解SELECT ... LOCK IN SHARE MODE和SELECT ... FOR UPDATE
- MySQL 5.7 SELECT ... LOCK IN SHARE MODE|FOR UPDATE語句說明MySql
- mysql innodb_autoinc_lock_mode 的與資料庫行為MySql資料庫
- MySQL自增鎖模式innodb_autoinc_lock_mode引數詳解MySql模式
- Select for update/lock in share mode 對事務併發性影響
- MySQL 表的自增欄位 預判功能innodb_autoinc_lock_modeMySql
- Innodb:為什麼lock in share mode在show engine看不到行鎖資訊
- MySQL自增列鎖模式 innodb_autoinc_lock_mode不同引數下效能測試MySql模式
- enq: TM - contention TM 等待事件的原因及模擬ENQ事件
- enq: TM - contentionENQ
- enq:TM contentionENQ
- oracle-tom-dmllock-tmOracle
- 又見enqueue(TM SRX)ENQ
- oracle的TM鎖、TX鎖Oracle
- Window mode
- consistent mode和current mode的區別
- Mysql加鎖過程詳解(4)-select for update/lock in share mode 對事務併發性影響MySql
- enq:TM-contention事件等待ENQ事件
- Docker Swarm modeDockerSwarm
- oracle time modeOracle
- javascript strict modeJavaScript
- sql_modeSQL
- Windws XP Mode
- Dataguard mode switch
- 更改Archive ModeHive
- Undo Mode (30)
- ftp命令 binary mode與ascii mode的區別FTPASCII