在做數據遷移的過程中,我們會面臨兩種常見的hang住場景:
1.表不能修改加字段,不能增大長度。
2.存儲過程不能覆蓋。
場景1:為表添加字段hang住的處理alter system kill session '8,16603';--干掉session,注意的是如果是RAC,視圖都要加上G,如v$lock,是GV$lock。
場景2:存儲過程不能覆蓋
session1 新建並執行:
create or replace procedure p_test_pin
as
begin
dbms_lock.sleep(3000);
end;
call p_test_pin();
session2 覆蓋:
create or replace procedure p_test_pin()
begin
dbms_lock.sleep(1000);
end;
方法1,找到所在會話和進程id,如果是RAC則都要查GV:
x$kglpn library cache pin信息
x$kglob library cache object信息
SQL> SELECT s.sid,s.SERIAL#, kglpnmod "Mode", kglpnreq "Req", SPID "OS Process"
FROM v$session_wait w, sys.x$kglpn p, v$session s, v$process o
WHERE p.kglpnuse = s.saddr
AND kglpnhdl = w.p1raw
and w.event like '%library cache pin%'
and s.paddr = o.addr;
SID SERIAL# Mode Req OS Process
---------- ---------- ---------- ---------- -------------------
8 17376 2 0 22118
133 4430 0 3 22120
先殺掉會話:alter system kill session '8,17376';
如果會話殺不掉,則只有從操作系統層面殺進程:kill -9 22118
方法2,找到持有者:
SQL> SELECT sid Holder_sid,
SERIAL# hold_SERIAL,
KGLPNUSE Sesion,
KGLPNMOD Held,
KGLPNREQ Req
FROM sys.x$kglpn, v$session
WHERE KGLPNHDL IN (SELECT p1raw
FROM v$session_wait
WHERE event LIKE 'library cache pin%')
AND KGLPNMOD <> 0
AND v$session.saddr = x$kglpn.kglpnuse;
HOLDER_SID HOLD_SERIAL SESION HELD REQ
---------- ----------- ---------------- ---------- ----------
8 17376 0000000127618FA8 2 0
找到持有者在執行什麼SQL
SQL> SELECT sid, sql_text
FROM v$session, v$sqlarea
WHERE v$session.sql_address = v$sqlarea.address AND sid =8;
SID SQL_TEXT
------ -----------
8 call p_test_pin()