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 LOCK MODE 1.2.3.4.5.6Oracle
- MySQL 共享鎖 (lock in share mode),排他鎖 (for update)MySql
- 深入理解SELECT ... LOCK IN SHARE MODE和SELECT ... FOR UPDATE
- ORACLE基礎之oracle鎖(oracle lock mode)詳解Oracle
- Innodb:為什麼lock in share mode在show engine看不到行鎖資訊
- MySQL自增列鎖模式 innodb_autoinc_lock_mode不同引數下效能測試MySql模式
- 又TM遇到傻B了
- time time_t tm用法
- IDBTransaction.mode
- Docker Swarm modeDockerSwarm
- javascript strict modeJavaScript
- Oracle等待事件之enq: TM – contentionOracle事件ENQ
- emacs go-modeMacGo
- 【Java】The Java Headless ModeJava
- MySQL Strict SQL MODEMySql
- UFS之Power Mode
- chmod命令(change mode)
- Lock 鎖
- Fescar example解析 - TM傳送邏輯
- mysql innodb lock鎖之record lock之一MySql
- Bash 設定 vi mode
- webcodecs mix-blend-modeWeb
- LPDDR4 byte mode
- 3.3.4 Shutting Down with the Transactional Mode
- Docker Swarm Mode簡介DockerSwarm
- mysql lock操作MySql
- V$LOCK(zt)
- Android Media Framework(五)Tunnel ModeAndroidFramework
- oracle 11.2.0.4 rac叢集等待事件enq: TM - contentionOracle事件ENQ
- ubuntu解決Could not get lock /var/lib/dpkg/lock-frontendUbuntu
- Library Cache 診斷:Lock, Pin 以及 Load Lock (文件 ID 1548524.1)
- Linux報錯:Could not get lock /var/lib/dpkg/lock-frontendLinux
- MySQL:Innodb 讓MDL LOCK和ROW LOCK 記錄到errlogMySql
- 為什麼要這樣寫final ReentrantLock lock = this.lock; ?ReentrantLock
- [Java併發]LockJava
- MySQL:理解MDL LockMySql
- 看懂Podfile.lock
- LOCK_SGA(zt)
- apt could not get lockAPT