[20230210]建立完善swcnm.sql指令碼.txt
[20230210]建立完善swcnm.sql指令碼.txt
--//遇到asm例子出現阻塞的情況.正常使用tpt的swc指令碼無法查詢.因為asm例項在nomount狀態.with subquery報錯.
--//自己建立一個新的查詢指令碼.使用v$instance,v$thread作為子查詢的子表.
SYS@test> startup nomount
ORACLE instance started.
Total System Global Area 805306368 bytes
Fixed Size 8924064 bytes
Variable Size 297796704 bytes
Database Buffers 490733568 bytes
Redo Buffers 7852032 bytes
SYS@test> set verify off
SYS@test> @ swc sid||','||SERIAL#||',@'||inst_id||','||event 1=1
THEN ' ['||NVL((SELECT class FROM bclass WHERE r = s.p3),'undo @bclass '||s.p3)||']' ELSE null END,'ON CPU')
*
ERROR at line 22:
ORA-01219: database or pluggable database not open: queries allowed on fixed tables or views only
--//主要裡面使用with子查詢,使用別名不對.
--//改寫如下:
$ cat swcnm.sql
prompt @ swcnm sid||','||SERIAL#||',@'||inst_id||','||event 1=1
col path format a180
WITH
v$instance AS (SELECT /*+ INLINE */ class, ROWNUM r from v$waitstat)
, v$thread AS (
SELECT
REPLACE(SYS_CONNECT_BY_PATH(&1, '->'), '->', ' -> ')
||CASE WHEN CONNECT_BY_ISLEAF = 1 AND ses.blocking_session IS NOT NULL
THEN ' -> [idle blocker '||ses.blocking_instance||','||ses.blocking_session||' ('||ses.program||')]' ELSE NULL
END path
FROM (
SELECT
s.*
, CASE WHEN s.type = 'BACKGROUND' AND s.program LIKE '%(DBW%)' THEN
'(DBWn)'
WHEN s.type = 'BACKGROUND' OR REGEXP_LIKE(s.program, '.*\([PJ]\d+\)') THEN
REGEXP_REPLACE(SUBSTR(s.program,INSTR(s.program,'(')), '\d', 'n')
ELSE
'('||REGEXP_REPLACE(REGEXP_REPLACE(s.program, '(.*)@(.*)(\(.*\))', '\1'), '\d', 'n')||')'
END || ' ' program2
, NVL(s.event||CASE WHEN event like 'enq%' AND state = 'WAITING'
THEN ' [mode='||BITAND(p1, POWER(2,14)-1)||']'
WHEN s.event IN (SELECT name FROM v$event_name WHERE parameter3 = 'class#')
THEN ' ['||NVL((SELECT class FROM v$instance WHERE r = s.p3),'undo @bclass '||s.p3)||']' ELSE null END,'ON CPU')
|| ' ' event2
, TO_CHAR(CASE WHEN state = 'WAITING' THEN p1 ELSE null END, '0XXXXXXXXXXXXXXX') p1hex
, TO_CHAR(CASE WHEN state = 'WAITING' THEN p2 ELSE null END, '0XXXXXXXXXXXXXXX') p2hex
, TO_CHAR(CASE WHEN state = 'WAITING' THEN p3 ELSE null END, '0XXXXXXXXXXXXXXX') p3hex
FROM
gv$session s
) ses
CONNECT BY NOCYCLE
( PRIOR ses.blocking_session = ses.sid
AND PRIOR ses.blocking_instance = ses.inst_id
)
START WITH (ses.state='WAITING' AND ses.wait_class!='Idle') AND &2
)
SELECT
COUNT(*) sessions
, path
FROM
v$thread
GROUP BY
path
ORDER BY
sessions DESC
/
--//例子:
@ swcnm sid||','||SERIAL#||',@'||inst_id||','||event 1=1
--//簡單測試:
--//先在nomunt下測試:
SYS@test> @ swcnm sid||','||SERIAL#||',@'||inst_id||','||event 1=1
@ swcnm sid||','||SERIAL#||',@'||inst_id||','||event 1=1
no rows selected
--//ok沒有問題,進入open模式,繼續測試:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
--//session 1:
SCOTT@test01p> @ spid
SID SERIAL# PROCESS SERVER SPID PID P_SERIAL# C50
---------- ---------- ------------------------ --------- -------------------- ------- ---------- --------------------------------------------------
169 61475 9544:1400 DEDICATED 12952 26 4 alter system kill session '169,61475' immediate;
SCOTT@test01p> create table t ( a number);
Table created.
SCOTT@test01p> insert into t values (1);
1 row created.
SCOTT@test01p> commit ;
Commit complete.
SCOTT@test01p> update t set a=1;
1 row updated.
--//session 2:
SCOTT@test01p> @ spid
SID SERIAL# PROCESS SERVER SPID PID P_SERIAL# C50
---------- ---------- ------------------------ --------- -------------------- ------- ---------- --------------------------------------------------
178 25684 8384:7108 DEDICATED 3004 42 7 alter system kill session '178,25684' immediate;
SCOTT@test01p> update t set a=2;
--//掛起!!
--//session 1:
SCOTT@test01p> @ swcnm sid||','||SERIAL#||',@'||inst_id||','||event 1=1
@ swcnm sid||','||SERIAL#||',@'||inst_id||','||event 1=1
SESSIONS PATH
---------- -----------------------------------------------------------------------------------------------
1 -> 178,25684,@1,enq: TX - row lock contention -> 169,61475,@1,SQL*Net message to client
1 -> 178,25684,@1,enq: TX - row lock contention
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2935472/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20241114]建立完善ext_kglob.sh指令碼.txt指令碼
- [20230302]建立完善tpt o2.sql指令碼.txtSQL指令碼
- [20230203]建立完善sp1x.sql指令碼.txtSQL指令碼
- [20210506]完善tix指令碼.txt指令碼
- [20201202]完善sosi指令碼.txt指令碼
- [20210623]完善清除aud指令碼.txt指令碼
- [20231117]完善ashtt.sql指令碼.txtSQL指令碼
- [20211230]完善sql_id指令碼.txtSQL指令碼
- [20211122]完善descx.sql指令碼.txtSQL指令碼
- [20221012]完善spsw.sql指令碼.txtSQL指令碼
- [20221010]完善descz.sql指令碼.txtSQL指令碼
- [20221101]完善descz.sql指令碼.txtSQL指令碼
- [20221101]完善gts.sql指令碼.txtSQL指令碼
- [20230203]完善awr.sql指令碼.txtSQL指令碼
- [20230123]完善curheapz.sql指令碼.txtSQL指令碼
- [20210407]完善ti.sql指令碼.txtSQL指令碼
- [20210125]完善hide.sql指令碼.txtIDESQL指令碼
- [20191111]完善bind_cap.sql指令碼.txtSQL指令碼
- [20220217]完善tpt gts.sql指令碼.txtSQL指令碼
- [20220510]完善tpt expandz.sql指令碼.txtSQL指令碼
- [20211202]完善d_buffer.sql指令碼.txtSQL指令碼
- [20211129]完善tpt tablist.sql指令碼.txtSQL指令碼
- [20211130]完善tpt t.sql指令碼.txtSQL指令碼
- [20211129]完善tpt killi.sql指令碼.txtSQL指令碼
- [20211126]完善tpt pr.sql指令碼.txtSQL指令碼
- [20230414]完善seg2.sql指令碼.txtSQL指令碼
- [20221208]完善bind_cap.sql指令碼.txtSQL指令碼
- [20220311]完善ash_wait_chains指令碼.txtAI指令碼
- [20220309]完善shp4.sql指令碼.txtSQL指令碼
- [20231025]完善tpt的trans.sql指令碼.txtSQL指令碼
- [20220111]完善tpt ashash_index_helper指令碼.txtIndex指令碼
- [20220323]完善tpt get_trace.sql指令碼.txtSQL指令碼
- [20220823]完善tpt的ashtop.sql指令碼.txtSQL指令碼
- [20221208]完善bind_cap_awr.sql指令碼.txtSQL指令碼
- [20190416]完善shared latch測試指令碼2.txt指令碼
- [20220129]完善tpt ash ash_index_helperx指令碼.txtIndex指令碼
- [20211111]補充完善ash_wait_chains指令碼.txtAI指令碼
- [20190510]快速建立執行指令碼.txt指令碼