Една от малките, но удобни благинки в 11.1 (release one!) е новият синтаксис на ALTER SYSTEM KILL SESSION. Освен стандартните SID и SERIAL, вече има трети, опционален параметър, в който може да се зададе instance id. Това позволява да се прекъсват сесии на „друг“ instance.
Според документацията нещата стоят така:
KILL SESSION Clause
The KILL SESSION clause lets you mark a session as terminated, roll back ongoing transactions, release all session locks, and partially recover session resources. To use this clause, your instance must have the database open. Your session and the session to be terminated must be on the same instance unless you specify integer3.You must identify the session with the following values from the V$SESSION view:
– For integer1, specify the value of the SID column.
– For integer2, specify the value of the SERIAL# column.
– For the optional integer3, specify the ID of the instance where the target session to be killed exists. You can find the instance ID by querying the GV$ tables.
Тук, обаче, не е цялата истина. Ето какво се случва ако следваш документацията:
SQL> select instance_number from v$instance;
INSTANCE_NUMBER
---------------
1
SQL> select inst_id, sid, serial#
2 from gv$session
3 where username = 'YAVOR'
4 and program not like '%PZ99%';
INST_ID SID SERIAL#
---------- ---------- ----------
1 12 29935
1 587 2564
1 1153 6987
1 1715 1807
2 583 494
SQL> alter system kill session '583, 494, 2';
alter system kill session '583, 494, 2'
ORA-00026: missing or invalid session ID
Изречението „You can find the instance ID by querying the GV$ tables“ не носи много полезна информация. Тук някой може да си помисли, че описанието на грешка ORA-00026 в същата тази документация ще е полезно. Ето колко е полезно:
ORA-00026: missing or invalid session ID
Cause: Missing or invalid session ID string for ALTER SYSTEM KILL SESSION.
Action: Retry with a valid session ID.
Човек веднага се сеща какъв е проблема, нали 🙂
Чак ме е яд как не ми блесна веднага: следвайки синтаксиса от първите два параметъра (SID и Serial#), съвсем логично е, че третият параметър се задава с @ (кльомба/маймунка). Няма нужда това да се пише в документацията – то е толкова естествено…
SQL> alter system kill session '583,494,@2';
alter system kill session '583,494,@2'
ORA-00031: session marked for kill
SQL> select inst_id, sid, serial#
2 from gv$session
3 where username = 'YAVOR'
4 and program not like '%PZ99%';
INST_ID SID SERIAL#
---------- ---------- ----------
1 12 29935
1 587 2564
1 1153 6987
1 1715 1807
P.S.: И в 11.2 е така