通過shell指令碼檢視鎖資訊
在生產環境維護中,如果碰到較長時間的鎖等待,很可能會造成各種可能的問題。我們可以使用如下的指令碼來實時監控鎖的情況。
sqlplus -S $DB_CONN_STR@$SH_DB_SID <
set linesize 160
set pages 100
set feedback off
set verify off
set echo on
col object_name format a25
col osuser format a10
col machine format a12
col program format a20
--col object_type format a10
col state format a10
col status format a10
col oracle_username format a12
col sid_serial format a12
col sec_wait format 99999999
col lock_type format a5
col mode_held format a10
set linesize 200
prompt Current Locks
prompt --------------
select ses.sid||','||ses.serial# sid_serial,loc.oracle_username,object_name,
--object_type,
ses.LOGON_TIME,ses.SECONDS_IN_WAIT sec_wait,ses.osuser,ses.machine,ses.program,ses.state,ses.status,
decode(d.type,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distrib Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table',
d.type) lock_type,
decode(d.lmode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
to_char(d.lmode)) mode_held
from v\$locked_object loc,v\$session ses,dba_objects obj,v\$lock d
where loc.object_id=obj.object_id
and loc.session_id=ses.sid
and obj.object_id=d.id1
and ses.sid=d.sid
order by oracle_username,seconds_in_wait desc
;
set head off
SELECT 'There are also '||count(*)||' transaction locks'
FROM v\$transaction_enqueue
;
prompt
prompt Blocking Session Details
select BLOCKING_SESSION ||' IS BLOCKING '||sid||','||serial# from v\$session where blocking_session is not null;
exit
EOF
指令碼執行的結果如下:
Current Locks
-------------
SID_SERIAL ORACLE_USERN OBJECT_NAME LOGON_TIM SEC_WAIT OSUSER MACHINE PROGRAM STATE STATUS LOCK_ MODE_HELD
------------ ------------ ------------------------- --------- --------- ---------- ------------ -------------------- ---------- ---------- ----- ----------
5480,2261 PRODUSER TMP_CONTROL 04-DEC-14 419010 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5480,2261 PRODUSER TMP_CONTROL 04-DEC-14 419010 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
4086,35783 PRODUSER TMP_CONTROL 08-DEC-14 44446 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
4086,35783 PRODUSER TMP_CONTROL 08-DEC-14 44446 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
7190,24855 PRODUSER TMP_CONTROL 09-DEC-14 8601 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
7190,24855 PRODUSER TMP_CONTROL 09-DEC-14 8601 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
8322,17323 PRODUSER BILL_SUMMARY 09-DEC-14 1597 lwrk01 fromClient2 sqlplus@ccbdbpr1 (TNS V1-V3) WAITING ACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE TO Row-X (SX)
5179,65435 PRODUSER TEMP_DAEMON_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE TO Row-X (SX)
sqlplus -S $DB_CONN_STR@$SH_DB_SID <
set pages 100
set feedback off
set verify off
set echo on
col object_name format a25
col osuser format a10
col machine format a12
col program format a20
--col object_type format a10
col state format a10
col status format a10
col oracle_username format a12
col sid_serial format a12
col sec_wait format 99999999
col lock_type format a5
col mode_held format a10
set linesize 200
prompt Current Locks
prompt --------------
select ses.sid||','||ses.serial# sid_serial,loc.oracle_username,object_name,
--object_type,
ses.LOGON_TIME,ses.SECONDS_IN_WAIT sec_wait,ses.osuser,ses.machine,ses.program,ses.state,ses.status,
decode(d.type,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distrib Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table',
d.type) lock_type,
decode(d.lmode,
0, 'None', /* Mon Lock equivalent */
1, 'Null', /* N */
2, 'Row-S (SS)', /* L */
3, 'Row-X (SX)', /* R */
4, 'Share', /* S */
5, 'S/Row-X (SSX)', /* C */
6, 'Exclusive', /* X */
to_char(d.lmode)) mode_held
from v\$locked_object loc,v\$session ses,dba_objects obj,v\$lock d
where loc.object_id=obj.object_id
and loc.session_id=ses.sid
and obj.object_id=d.id1
and ses.sid=d.sid
order by oracle_username,seconds_in_wait desc
;
set head off
SELECT 'There are also '||count(*)||' transaction locks'
FROM v\$transaction_enqueue
;
prompt
prompt Blocking Session Details
select BLOCKING_SESSION ||' IS BLOCKING '||sid||','||serial# from v\$session where blocking_session is not null;
exit
EOF
指令碼執行的結果如下:
Current Locks
-------------
SID_SERIAL ORACLE_USERN OBJECT_NAME LOGON_TIM SEC_WAIT OSUSER MACHINE PROGRAM STATE STATUS LOCK_ MODE_HELD
------------ ------------ ------------------------- --------- --------- ---------- ------------ -------------------- ---------- ---------- ----- ----------
5480,2261 PRODUSER TMP_CONTROL 04-DEC-14 419010 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5480,2261 PRODUSER TMP_CONTROL 04-DEC-14 419010 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
4086,35783 PRODUSER TMP_CONTROL 08-DEC-14 44446 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
4086,35783 PRODUSER TMP_CONTROL 08-DEC-14 44446 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
7190,24855 PRODUSER TMP_CONTROL 09-DEC-14 8601 mwrk01 fromClient1 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
7190,24855 PRODUSER TMP_CONTROL 09-DEC-14 8601 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
8322,17323 PRODUSER BILL_SUMMARY 09-DEC-14 1597 lwrk01 fromClient2 sqlplus@ccbdbpr1 (TNS V1-V3) WAITING ACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE TO Row-X (SX)
5179,65435 PRODUSER TEMP_DAEMON_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE DML Row-X (SX)
5179,65435 PRODUSER TMP_BULK_LOCKING 09-DEC-14 296 mwrk01 fromClient2 JDBC Thin Client WAITING INACTIVE TO Row-X (SX)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23718752/viewspace-1362396/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 通過shell指令碼檢測MySQL服務資訊指令碼MySql
- Shell指令碼 – 檢視網路介面資訊指令碼
- 【資訊採集】IBM AIX系統硬體資訊檢視命令(shell指令碼)IBMAI指令碼
- 通過shell指令碼批量操作mysql資料庫指令碼MySql資料庫
- Laravel 通過遷移指令碼建立MySQL檢視Laravel指令碼MySql
- [ Shell ] 通過 Shell 指令碼匯出 CDL 網表指令碼
- 通過shell指令碼防止埠掃描指令碼
- [ Shell ] 通過 Shell 指令碼匯出 GDSII/OASIS 檔案指令碼
- 通過shell指令碼 批量新增使用者指令碼
- Bash 指令碼實現每次登入到 Shell 時可以檢視 Linux 系統資訊指令碼Linux
- 案例:通過shell指令碼實現mysql資料備份與清理指令碼MySql
- shell指令碼企業巡檢指令碼
- Shell 系統資訊監控指令碼指令碼
- Linux通過Shell指令碼命令修改密碼不需要互動Linux指令碼密碼
- Innodb中怎麼檢視鎖資訊
- 通過 shell 指令碼完成 GitLab11.9.11 的一鍵安裝指令碼Gitlab
- Laravel 透過遷移指令碼建立MySQL檢視Laravel指令碼MySql
- shell指令碼指令碼
- 傳送kafka訊息的shell指令碼Kafka指令碼
- 常用shell指令碼指令碼
- shell指令碼案例指令碼
- Linux Shell指令碼Linux指令碼
- 使用shell 指令碼備份資料指令碼
- 如何使用 Shell 指令碼來檢視多個伺服器的埠是否開啟?指令碼伺服器
- shell指令碼(6)-shell陣列指令碼陣列
- 使用Python和Java呼叫Shell指令碼時的死鎖陷阱PythonJava指令碼
- 通過shell指令碼和企業微信實現報警功能(完整版)指令碼
- 尚矽谷大資料視訊_Shell視訊教程大資料
- shell指令碼總結指令碼
- shell 指令碼寫法:指令碼
- shell 指令碼加密 | shc指令碼加密
- 執行shell指令碼指令碼
- Shell 指令碼語句指令碼
- 如何加密shell指令碼加密指令碼
- 初識shell指令碼指令碼
- 【指令碼】shell語法指令碼
- 【Linux】通過shell指令碼對mysql的增刪改查以及my.cnf的配置Linux指令碼MySql
- 根據ip列表檢測主機狀態(shell指令碼)指令碼
- iOS逆向 Shell指令碼+指令碼重簽名iOS指令碼