alter system disconnect/kill session 'sid,serial#';

yxyup發表於2007-03-18

alter system disconnect 'sid,serial#';

1.session 1

SQL> conn yxy
Enter password:
Connected.
SQL> select * from t;

NUM
----------
1

SQL> update t set num=2 where num=1;

1 row updated.

2.session 2

SQL> select sid,serial#,username from v$session where type='USER';

SID SERIAL# USERNAME
---------- ---------- ------------------------------
10 1
11 1
15 21625 SYS
20 9893 YXY

SQL> select a.sid,a.serial#,a.username,b.spid from v$session a,v$process b where a.paddr=b.addr and a.sid=20;

SID SERIAL# USERNAME SPID
---------- ---------- ------------------------------ ------------
20 9907 YXY 27596


SQL> alter system disconnect session '20,9907' immediate;

System altered.


SQL> host
[oracle@restore ~]$ ps -ef | grep 27596
oracle 27596 27594 0 20:01:30 ? 0:00 oracleoramdb (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27693 27690 0 20:06:38 pts/ta 0:00 grep 27596

3.session 1

SQL> r
1* update t set num=2 where num=1
update t set num=2 where num=1
*
ERROR at line 1:
ORA-00028: your session has been killed

SQL> exit
[oracle@restore ~]$

4.session 2

[oracle@restore ~]$ ps -ef | grep 27596
oracle 27697 27690 0 20:06:47 pts/ta 0:00 grep 27596
[oracle@restore ~]$ ps -ef | grep 27596
[oracle@restore ~]$ ps -ef | grep 27596
oracle 27771 27690 1 20:06:51 pts/ta 0:00 grep 27596

alter system kill session 'sid,serial#';

1.session 1

SQL> update t set num=2 where num=1;

1 row updated.


2.session 2
SQL> select a.sid,a.serial#,a.username,b.spid from v$session a,v$process b where a.paddr=b.addr and a.sid=20;

SID SERIAL# USERNAME SPID
---------- ---------- ------------------------------ ------------
20 9939 YXY 27887


SQL> alter system kill session '20,9939' immediate;

System altered.


SQL> host
[oracle@restore ~]$ ps -ef | grep 27887
oracle 27974 27972 0 20:19:13 pts/ta 0:00 grep 27887
oracle 27887 27871 0 20:15:54 ? 0:00 oracleoramdb (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
[oracle@restore ~]$ ps -ef | grep 27887
oracle 27887 27871 0 20:15:54 ? 0:00 oracleoramdb (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 27976 27972 0 20:19:24 pts/ta 0:00 grep 27887


2.session 1

SQL> r
1* update t set num=2 where num=1
update t set num=2 where num=1
*
ERROR at line 1:
ORA-00028: your session has been killed


SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.5.0 - Production
[oracle@restore ~]$ sqlplus /nolog

SQL*Plus: Release 9.2.0.5.0 - Production on Sat Mar 17 20:20:02 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> conn yxy
Enter password:
Connected.
SQL> select * from t;

NUM
----------
1

3.session 2

[oracle@restore ~]$ ps -ef | grep 27887
oracle 27979 27972 0 20:19:41 pts/ta 0:00 grep 27887


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7364032/viewspace-17458/,如需轉載,請註明出處,否則將追究法律責任。

相關文章