|
1. lock_sqlt.sql
col usr format a15 heading 'USR(DB/OS)'
col sid format 9999 heading 'SID'
col ser format 9999999 heading 'Serial#'
col status format a8 heading 'Status'
col ty format a4 heading 'Type'
col held format a4 heading 'Held'
col req format a4 heading 'Wait'
col id1 format 9999999 heading 'Lock ID1'
col id2 format 9999999 heading 'Lock ID2'
col ctime format 99999 heading 'RT(s)'
col program format a15 heading 'Program'
col process format a7 heading 'CliPID'
col spid format a7 heading 'OraPID'
col sql_text format a120 heading 'SQL Statement'
set pages 10000 lin 120
select /*+ rule */
substr(s.username||'/'||s.osuser,1,20) usr,
s.sid sid, s.serial# ser,
s.status,
l.type ty,
decode(lmode,1,'NONE',2,'SS',3,'SX',4,'S',5,'SSX',6,'X') held,
decode(request,1,'NONE',2,'SS',3,'SX',4,'S',5,'SSX',6,'X') req,
id1, id2, l.ctime,
substr(s.program,1,15) program, s.process, p.spid,
t.sql_text
from v$sqltext t , v$process p, v$session s, v$lock l
where l.sid = s.sid
and s.paddr = p.addr
and s.username is not null
and l.type in ('TX', 'DX')
and t.address (+) = s.sql_address
and t.hash_value (+) = s.sql_hash_value
order by id1, id2, held, s.sid
/
2. Ãâ·ÂµÇ´Â Ä÷³ ¼³¸í
USR(DB/OS) DBÀ¯Àú¸í°ú Client ÇÁ·Î±×·¥À» ¼öÇàÇÑ OS À¯Àú¸í
SID ¼¼¼Ç ID. LockÀ» °Ç sessionÀ» Á×ÀÌ°í ½Í´Ù¸é alter system kill session 'sid, seiral#';
Serial# ¼¼¼Ç³»ÀÇ ¼øÂ÷¹øÈ£. À§ÀÇ SQL¹® µî¿¡ ÇÊ¿äÇÏ´Ù.
STATUS ¿À¶óŬ¿¡¼ ÇØ´ç SQL¹® Çö»ó ¼öÇàÁß(ACTIVE)ÀÎÁö ¼öÇàÀÌ ³¡³µ´ÂÁö(INACTIVE) »óÅÂ
Type LOCK ŸÀÔ
Held LOCK ŸÀÔÀÌ TXÀÌ°í, Held°¡ XÀ̸é LockÀ» Àâ°í ÀÖ´Â ¼¼¼Ç
Wait LOCK ŸÀÔÀÌ TXÀÌ°í, Wait°¡ XÀ̸é LockÀÌ Ç®¸®±â¸¦ ±â´Ù¸®´Â ¼¼¼Ç
Lock ID1 LOCK ±¸ºÐ ID1
Lock ID2 LOCK ±¸ºÐ ID2 µ¿ÀÏÇÑ LOCKÀÎÁö¸¦ ±¸º°ÇÒ ¼ö ÀÖ´Â LOCK °íÀ¯ ¹øÈ£
RT(s) ¼öÇàÇÑ ½Ã°£
Program Ŭ¶óÀ̾ðÆ®ÀÇ ÇÁ·Î±×·¥¸í(tmaxÀÇ ¼¹öÇÁ·Î¼¼½º³ª jeusÀÇ dbpool µî)
CliPID Ŭ¶óÀ̾ðÆ® ÇÁ·Î¼¼½ºÀÇ PID
OraPID ¿À¶óŬ¼¹öÇÁ·Î¼¼½ºÀÇ PID
SQL Statement ¸¶Áö¸· ¼öÇàÇÑ SQL¹® (ÁÖÀÇ, ²À LockÀ» °Ç SQL¹®ÀÌ ¾Æ´Ò ¼öµµ ÀÖ´Ù.)
Áï, Update¸¦ Çؼ lockÀ» °Ç ÈÄ, select ¹®À» ¼öÇàÇÑ´Ù¸é, ÀÌ Ä÷³¿¡´Â select¹®ÀÌ ³ª¿Â´Ù.
< SQL Statement°¡ À߸ø³ª¿À´Â ¿¹Á¦ >
SCOTT/tmadm 54 2658 I TX X 655395 102140 1291 sqlplus@RC 29741 11638
BEGIN DBMS_APPLICATION_INFO.SET_MODULE(:1,NULL); END;
-> sqlplus¿¡¼ update¹®À» ¼öÇàÇÏ¿© lockÀ» °É¾ú´Âµ¥, ½ÇÁ¦ Á¶È¸½Ã PROCEDURE ÄÝ ·çƾÀÌ º¸ÀÓ.
ÀÌ´Â sqlplus¿¡¼ User SQL(update)À» ¼öÇà ÈÄ ³»ºÎÀûÀ¸·Î À§ÀÇ ÇÁ·Î½ÃÁ®¸¦ ÄÝÇϱ⠶§¹®¿¡,
¸¶Áö¸· ¼öÇàµÈ ÇÁ·Î½ÃÁ®ÄÝ ¹®ÀÌ ³ª¿À°Ô µÈ´Ù.
3. ½ÇÁ¦ Å×½ºÆ®¸¦ ÅëÇÑ ¼öÇà °á°ú ¹× Lock ºÐ¼®
< nonxa(sample1) ¿¡¼ lock °É±¸, ºÐ»êÆ®·£Á§¼Ç 2°³(xa1, xa2)°¡ waiting À϶§ >
USR(DB/OS) SID Serial# STATUS Type Held Wait Lock ID1 Lock ID2 RT(s) Program CliPID OraPID
--------------- ----- -------- -------- ---- ---- ---- -------- -------- ------ --------------- ------- -------
SQL Statement
----------------------------------------------------------------------
--------------------------------------------------
SCOTT/tmadm 608 308 ACTIVE DX X 483 0 5 xa2@RCNW4 (TNS 25688 17324
update lock_test set b='ann' where a=1
SCOTT/tmadm 24 1934 ACTIVE DX X 484 0 7 xa1@RCNW4 (TNS 25686 17290
update lock_test set b='aaa' where a=1
SCOTT/tmadm 35 2581 INACTIVE TX X 5242959 54516 12 sample1@RCNW4 ( 25685 17281
SCOTT/tmadm 24 1934 ACTIVE TX X 5242959 54516 7 xa1@RCNW4 (TNS 25686 17290
update lock_test set b='aaa' where a=1
SCOTT/tmadm 608 308 ACTIVE TX X 5242959 54516 5 xa2@RCNW4 (TNS 25688 17324
update lock_test set b='ann' where a=1
- TypeÀÌ TXÀÎ °Í Áß, Held°¡ XÀÎ °ÍÀÌ lockÀ» Àâ°í ÀÖ´Â ³ðÀÌ°í, Wait°¡ XÀÎ °ÍÀÌ lockÀ» WaitingÇÏ´Â °ÍÀÌ´Ù.
- ¾Æ¿ï·¯, ¾î¶² LockÀ» waitingÇÏ´ÂÁö´Â Lock ID1,2°¡ °°ÀºÁö¸¦ µûÁ®º¸¸é µÈ´Ù.
- Áï sample1ÀÌ Lock ID1,2°¡ 5242959, 54516ÀÎ LockÀ» Àâ°í ÀÖ°í, xa1, xa2°¡ °°Àº LockÀ» Waiting ÇÏ°í ÀÖ´Ù.
- nonxa°¡ lockÀ» °Ç °æ¿ì, nonxa¿¡¼ ¼öÇàÇÑ sql¹®Àº ³ª¿ÀÁö ¾Ê´Â´Ù.
- xa1°ú xa2°¡ ºÐ»êÆ®·£Á§¼ÇÀ̹ǷΠ°¢°¢ TypeÀÌ DXÀÎ Á¤º¸°¡ Çϳª¾¿ ´õ ³ª¿ÈÀ» ¾Ë ¼ö ÀÖ´Ù.
==============================================================
< xa1ÀÌ lockÀ» °É°í, sample1, xa2 ¼øÀ¸·Î LOCK Waiting >
SCOTT/tmadm 608 423 ACTIVE DX X 482 0 10 xa2@RCNW4 (TNS 25845 18957
update lock_test set b='ann' where a=1
SCOTT/tmadm 35 2591 INACTIVE TX X 2228308 105554 16 xa1@RCNW4 (TNS 25842 18912
update lock_test set b='aaa' where a=1
SCOTT/tmadm 39 157 ACTIVE TX X 2228308 105554 12 sample1@RCNW4 ( 25844 18925
update lock_test set b='ppp' where a=1
SCOTT/tmadm 608 423 ACTIVE TX X 2228308 105554 10 xa2@RCNW4 (TNS 25845 18957
update lock_test set b='ann' where a=1
- XA°¡ LockÀ» °Ç °æ¿ì, xa¿¡¼ ¼öÇàÇÑ sql¹®À» È®ÀÎÇÒ ¼ö ÀÖ´Ù.
- ´Ü, LockÀ» °Ç XA ÇÁ·Î±×·¥(xa1)ÀÌ ºÐ»êÆ®·£Á§¼ÇÀÎÁö¿¡ ´ëÇÑ Á¤º¸(type = DX)´Â ³ª¿ÀÁö ¾Ê´Â´Ù.
- Áï, LockÀ» °Ç ÇÁ·Î±×·¥ÀÇ SQL¹®ÀÌ º¸À̸é, DX Á¤º¸°¡ ¾ø¾îµµ ±× ÇÁ·Î±×·¥Àº XAÇÁ·Î±×·¥ÀÌ´Ù.
==============================================================
< xa1ÀÌ lockÀ» °É°í, xa2°¡ LOCK Waiting >
USR(DB/OS) SID Serial# STATUS Type Held Wait Lock ID1 Lock ID2 RT(s) Program CliPID OraPID
--------------- ----- -------- -------- ---- ---- ---- -------- -------- ------ --------------- ------- -------
SQL Statement
----------------------------------------------------------------------
--------------------------------------------------
SCOTT/tmadm 26 2471 ACTIVE DX X 484 0 6 xa2@RCNW4 (TNS 25949 19959
update lock_test set b='ann' where a=1
SCOTT/tmadm 39 172 INACTIVE TX X 655435 102144 9 xa1@RCNW4 (TNS 25948 19948
update lock_test set b='aaa' where a=1
SCOTT/tmadm 26 2471 ACTIVE TX X 655435 102144 6 xa2@RCNW4 (TNS 25949 19959
update lock_test set b='ann' where a=1
==============================================================
< xa1ÀÌ lockÀ» °É°í, xa2, sample1 ¼øÀ¸·Î LOCK Waiting >
USR(DB/OS) SID Serial# STATUS Type Held Wait Lock ID1 Lock ID2 RT(s) Program CliPID OraPID
--------------- ----- -------- -------- ---- ---- ---- -------- -------- ------ --------------- ------- -------
SQL Statement
----------------------------------------------------------------------
--------------------------------------------------
SCOTT/tmadm 441 5 ACTIVE DX X 484 0 13 xa2@RCNW4 (TNS 26142 22868
update lock_test set b='ann' where a=1
SCOTT/tmadm 210 5 INACTIVE TX X 4980816 54322 28 xa1@RCNW4 (TNS 26141 22723
update lock_test set b='aaa' where a=1
SCOTT/tmadm 441 5 ACTIVE TX X 4980816 54322 13 xa2@RCNW4 (TNS 26142 22868
update lock_test set b='ann' where a=1
SCOTT/tmadm 546 5 ACTIVE TX X 4980816 54322 7 sample1@RCNW4 ( 26154 22890
update lock_test set b='ppp' where a=1
4. LockÀ» °Ç ¼¼¼Ç °Á¦·Î Á×À̱â
1) Oracle session Á×À̱â
alter system kill session 'sid, seiral#'
¸¶Áö¸· ¿¹Á¦¿¡¼ µÎ¹ø° ·Î¿ìÀÎ xa1ÀÌ LockÀ» °É°í ÀÖ°í ÀÌ ÇÁ·Î±×·¥¿¡ ´ëÇÑ sessionÀ» killÇÏ°íÀÚ ÇÑ´Ù¸é,
sys³ª systemÀ¸·Î ·Î±ä ÈÄ ´ÙÀ½ SQLÀ» º¸³½´Ù.
alter system kill session '210,5';
< ÁÖÀÇ >
À§¿Í °°ÀÌ Á¶Ä¡ÇÑ °æ¿ì, ÀϹÝÀûÀ¸·Î ¿À¶óŬ ¼¹öÇÁ·Î¼¼½ºµµ Á¾·áµÇ³ª, °æ¿ì¿¡ µû¶ó ¿À¶óŬ ¼¹öÇÁ·Î¼¼½º´Â ¶°ÀÖ°í,
¿À¶óŬ³»ºÎ¿¡¼ ¼¼¼ÇÁ¤º¸¸¸ ¾ø¾îÁö´Â °æ¿ì°¡ ÀÖÀ½
±× °æ¿ì tmaxµî¿¡¼ ¼ºñ½º ÄÝÀ» Çϸé ORA-00028: your session has been kill °°Àº ¿¡·¯°¡ ¹ß»ýµÊ.
±×·¡¼ µÉ ¼ö ÀÖÀ¸¸é Oracle Server ÇÁ·Î¼¼½º¸¦ ã¾Æ killÇÏ´Â °ÍÀÌ ´õ ÁÁÀ½.
2) Oracle Server Process Kill
¼¼¼Ç Á¤º¸ Áß OraPID °ªÀ» ã¾Æ OS¿¡¼ kill -9 OraPID ÇÏ¸é µÊ.
¸¶Áö¸· ¿¹Á¦¿¡¼ kill -9 22723 ÇÏ¸é µÊ.
¿À¶óŬ ¼¹ö ÇÁ·Î¼¼½º¸¦ KillÇÏ°Ô µÇ¸é, OracleÀº Çß´ø ÀÛ¾÷À» rollbackÇÏ°í, sessionÀ» »èÁ¦ÇÔ
´Ü, rollback ½Ã°£ÀÌ ¼öÃÊ¿¡¼ ¼öºÐÀÌ °É¸®±âµµ ÇϹǷÎ, v$session Á¤º¸¿¡ ÇØ´ç ¼¼¼ÇÀÌ °è¼Ó ³ªÅ¸³ª±âµµ ÇÔ.
3) client program Á¾·á
°¡Àå ¸íÄèÇÑ ¼¼¼Ç clear ¹æ¹ýÀ¸·Î ¼¼¼ÇÁ¤º¸Áß Program°ú CliPID·Î ÇØ´ç client process¸¦ È®ÀÎÇÏ¿©
kill -9 CliPID ¶Ç´Â tmaxÀÇ °æ¿ì tmdown -i -S Program(Ƽ¸Æ½º¼¹ö) ·Î client ÇÁ·Î±×·¥À» Á¾·á
ÀÌ °æ¿ì, Oracle ¼¹ö ÇÁ·Î¼¼½º°¡ ÀÚµ¿ Á×°Ô µÇ°í, ÇÏ´ø ÀÛ¾÷À» rollbackÇÏ°í, ¼¼¼ÇÁ¤º¸µµ Clear ÇÔ.
4) Á¤¸®
tmaxÀÇ °æ¿ì 3¹ø ¹æ¹ýÀÌ °¡Àå ¾ÈÀüÇÏ°í,
JEUSÀÇ °æ¿ì poolÀ» »ç¿ëÇÔÀ¸·Î Ä¿³Ø¼Çº°·Î killÇÒ ¼ö°¡ ¾øÀ½À¸·Î Oracle Process¸¦ ã¾Æ KillÇÏ´Â °ÍÀÌ ÁÁ°í,
3), 2) ¸ðµÎ ½ÇÆÐÇÑ °æ¿ì 1)¹øÀ» ¼öÇàÇÏ´Â °ÍÀÌ ÁÁ½À´Ï´Ù.
5. Lock °ü·Ã ¿À¶óŬ ¿¡·¯
1) ora 2049
NonXAÀÇ °æ¿ì, Lock waiting½Ã ¹«ÇÑ ´ë±âÁö¸¸, XAÀÇ °æ¿ì 60ÃÊ(DISTRIBUTED_LOCK_TIMEOUT : È÷µåÆĶó¸ÞÅÍ)¸¸Å ±â´Ù¸®´Ù°¡
ŸÀӾƿô¿¡·¯(2049)¸¦ ¹ß»ý½ÃÅ°¸é¼ ±â´Ù¸®´Â °ÍÀ» Á¾·áÇÑ´Ù.
ÀÌ °æ¿ì, À§ÀÇ lock_sqlt.sqlÀ» ¼öÇàÇÏ¿© ¾î¶² ¼¼¼ÇÀÌ LockÀ» Àâ°í ÀÖ´ÂÁö¸¦ È®ÀÎÇÏ¿© Á¶Ä¡ÇÑ´Ù.
2) ora 1591
ºÐ»êÆ®·£Á§¼Ç 2PC ÀÛ¾÷ µµÁß, prepare¸¸ ¹Þ°í commitÀ̳ª rollbackÀ» ¸ø¹Þ´Â °æ¿ì, ÀÏÁ¤½Ã°£ µ¿¾È ±â´Ù¸®´Ù°¡
commitÀ̳ª rollbackÀÌ ¾øÀ¸¸é ÇØ´ç Æ®·£Á§¼ÇÀ» º¸·ù(pending) ½ÃÅ°°Ô µÇ´Âµ¥,
ÀÌ °æ¿ì ÇØ´ç Å×ÀÌºí¿¡ ´ëÇÑ ¶Ç´Ù¸¥ ÀÛ¾÷(select, insert, update, delete µîµî)À» Çϸé, µ¥ÀÌŸ°¡ ºÒÈ®½ÇÇϱ⠶§¹®¿¡
1591¿¡·¯¸¦ ¹Þ°Ô µÊ.
Á¶Ä¡´Â dba_2pc_pending view¿¡¼ prepared »óÅÂÀÎ tx¸¦ ã¾Æ °Á¦ commit ¶Ç´Â rollback ÇØÁÖ¾î¾ß ÇÔ.
$ sqlplus system/manager
SQL> select local_tran_id, global_tran_id, state from dba_2pc_pending where state='prepared';
LOCAL_TRAN_ID GLOBAL_TRAN_ID STATE
------------- ---------------------- --------
1.8.238 V817LOC.WORLD.89f6eafb prepared
SQL> rollback force '1.8.238';
¶Ç´Â
SQL> commit force '1.8.238';
JEUSÀÇ °æ¿ì´Â JEUS¸¦ ºñÁ¤»óÀûÀ¸·Î ³»·È´Ù ¿Ã¸®°Å³ª °Á¦·Î sync ¸í·ÉÀ» ³»¸®¸é ¹Ìó¸®µÈ ºÐ»êÆ®·£Á§¼ÇÀ» ó¸®ÇØÁØ´Ù.
Áï, commitÀ̳ª rollbackÀ» º¸³»ÁÜÀ¸·Î pendingµÈ Æ®·£Á§¼ÇÀÌ Ã³¸®°¡ µÊ.
3) xa trace file¿¡¼ xa_prepare, xa_commit, xa_rollback½Ã¿¡ -4¹ø ¿¡·¯
Oracle Session TimeOutÀÌ ¹ß»ýÇÑ °æ¿ì.
OPENINFO Àý¿¡ ÁÖ´Â SessTMÀÌ Àִµ¥,
XA¼ºñ½º ÄÝÀ» Á¾·áÇÏ°í(xa_end) ¶Ç´Ù¸¥ XA¼ºñ½º ÄÝ(xa_start)ÇÏ´Â »çÀÌ
¶Ç´Â XA¼ºñ½º ÄÝÀ» Á¾·áÇÏ°í(xa_end) xa_prepare µîÀÌ µé¾î¿À±â±îÁöÀÇ idle timeÀÌ SessTMÀ» ÃÊ°úÇÏ°Ô µÇ¸é
-4¹ø ¿¡·¯°¡ ¹ß»ýÇÏ°í, ¿À¶óŬÀº ³»ºÎÀûÀ¸·Î rollbackÀ» ¼öÇàÇÏ°Ô µÈ´Ù.
Á¶Ä¡´Â SessTMÀ» Á»´õ Å°¿öÁְųª, »çÀÌ¿¡ ÄݵǴ ¸®¸ðÆ® ¼ºñ½º¸¦ Æ©´×ÇÏ¿© ¼öÇà½Ã°£À» ÁÙ¿©¾ß ÇÑ´Ù.
|