找出 alter system kill session ‘sid,serial#’ kill 掉的数据库会话对应进程

当我们使用alter system kill session ‘sid,serial#’ 在数据库中kill掉某个会话的时候,如果你观察仔细会发现v$session.paddr发生了改变,从而是的不能直接通过关联v$process.add找出spid,然后进行其他操作.本文提供三种方法找该种情况下spid的方法.
数据库版本

SQL> select * from v$version;

BANNER

-----------------------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production

PL/SQL Release 11.2.0.3.0 - Production

CORE    11.2.0.3.0      Production

TNS for Linux: Version 11.2.0.3.0 - Production

NLSRTL Version 11.2.0.3.0 - Production

会话1

SQL> select sid, SERIAL#,paddr from v$session where

  2  sid=(select sid from v$mystat where rownum=1);

       SID    SERIAL# PADDR

---------- ---------- --------

       133         53 35FE16F4

会话2

SQL> select sid, SERIAL#,paddr from v$session where

  2  sid=(select sid from v$mystat where rownum=1);

       SID    SERIAL# PADDR

---------- ---------- --------

       143         21 35FE2D3C

会话3

SQL> alter system kill session ‘133,53‘;

System altered.

SQL> alter system kill session ‘143,21‘;

System altered.

SQL> select sid, SERIAL#,paddr,status from v$session where sid in(133,143);

       SID    SERIAL# PADDR    STATUS

---------- ---------- -------- ----------------

       133         53 3547A3F4 KILLED

       143         21 3547A3F4 KILLED

证明alter system kill session后,v$session中的paddr发生了改变,这个时候如果需要找出原来的spid,不能使用v$session.paddr和v$process.addr关联获得

找出kill掉的spid方法1

SQL> select spid, program from v$process

  2      where program!= ‘PSEUDO‘

  3      and addr not in (select paddr from v$session)

  4      and addr not in (select paddr from v$bgprocess)

  5      and addr not in (select paddr from v$shared_server);

SPID                                             PROGRAM

------------------------------------------------ ------------------------------

14260                                            [email protected] (L001)

14256                                            [email protected] (L000)

15300                                            [email protected] (TNS V1-V3)

14179                                            [email protected] (D000)

15318                                            [email protected] (TNS V1-V3)

14252                                            [email protected] (N000)

SQL> !ps -ef|grep 15300|grep -v grep

oracle   15300 14052  0 03:22 ?        00:00:00 oracleora11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

SQL> !ps -ef|grep 15318|grep -v grep

oracle   15318 15315  0 03:22 ?        00:00:00 oracleora11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

找出kill 掉的spid 方法2

SQL> SELECT s.username,s.status,

  2  x.ADDR,x.KSLLAPSC,x.KSLLAPSN,x.KSLLASPO,x.KSLLID1R,x.KSLLRTYP,

  3  decode(bitand (x.ksuprflg,2),0,null,1)

  FROM x$ksupr x,v$session s

  WHERE s.paddr(+)=x.addr

  and bitand(ksspaflg,1)!=0;

USERNAME   STATUS           ADDR       KSLLAPSC   KSLLAPSN KSLLASPO                   KSLLID1R KSLL DE

---------- ---------------- -------- ---------- ---------- ------------------------ ---------- ---- --

           ACTIVE           35FD5990          6         26 14121                             0      1

           ACTIVE           35FD6FD8          1         69 14055                             0      1

           ACTIVE           35FD8620          1         69 14055                             0      1

           ACTIVE           35FD9C68          1         69 14055                             0      1

           ACTIVE           35FDB2B0          8         27 15300                             0      1

           ACTIVE           35FDC8F8         12         36 15300                             0      1

           ACTIVE           35FDDF40          1         69 14055                             0      1

           ACTIVE           35FDF588          1         69 14055                             0      1

           ACTIVE           35FE3860          7         26 14236                             0      1

           ACTIVE           35FE4EA8          1         69 14224                             0      1

           ACTIVE           35FE64F0         63          2 14311                           377 EV   1

           ACTIVE           35FEA7C8          3         26 14155                           258 EV   1

           ACTIVE           35FE9180         59          2 14248                           378 EV   1

           ACTIVE           35FE9CA4         12          2 14603                             0      1

           ACTIVE           35FD64B4          1         69 14055                             0      1

           ACTIVE           35FD7AFC          2         27 14055                             0      1

           ACTIVE           35FD9144          2         27 15300                             0      1

           ACTIVE           35FDA78C          3         26 14171                             0      1

           ACTIVE           35FDBDD4         17          2 15255                             0      1

           ACTIVE           35FDD41C         22         26 14155                             0      1

           ACTIVE           35FDEA64         52         26 14155                             0      1

           ACTIVE           35FE4384          1         69 14224                             0      1

           ACTIVE           35FE59CC          1         69 14224                             0      1

           ACTIVE           35FEB2EC          2          2 14248                             0      1

           ACTIVE           35FEC934         11         26 14121                             0      1

SYS        ACTIVE           35FEF5C4          4         16 14117                             0

                            35FE0BD0          1         69 14055                             0

                            35FE865C          1         69 14117                             0

                            35FE7B38          1         69 14117                             0

                            35FE16F4          1         26 14155                             0

                            35FD4E6C          0          0                                   0

                            35FE00AC          2        279 14117                             0

                            35FE2D3C          0          0                                   0

                            35FE7014          2        335 14117                             0

--挑选username和status为null的会话

SQL> select spid,program from v$process where addr in (

  ‘35FE0BD0‘,

  ‘35FE865C‘,

  ‘35FE7B38‘,

  ‘35FE16F4‘,

  ‘35FD4E6C‘,

  ‘35FE00AC‘,

  ‘35FE2D3C‘,

  ‘35FE7014‘

 10  );

SPID                                             PROGRAM

------------------------------------------------ ------------------------------

                                                 PSEUDO

14179                                            [email protected] (D000)

14183                                            [email protected] (S000)

15300                                            [email protected] (TNS V1-V3)

15318                                            [email protected] (TNS V1-V3)

14252                                            [email protected] (N000)

14256                                            [email protected] (L000)

14260                                            [email protected] (L001)

8 rows selected.

--同样可以发现spid 15300和15318的进程已经在数据库中被kill掉

找出kill掉的spid方法3(11g特有)

SQL> select  spid,program  from v$process where addr in

  2  (select creator_addr from v$session where sid in(133,143));

SPID                                             PROGRAM

------------------------------------------------ ------------------------------

15300                                            [email protected] (TNS V1-V3)

15318                                            [email protected] (TNS V1-V3)

找出kill掉的spid方法4(11g特有)

SQL> select * from V$DETACHED_SESSION;

      INDX PG_NAME                                                             SID    SERIAL#        PID

---------- ------------------------------------------------------------ ---------- ---------- ----------

         0 DEFAULT                                                             143         21         21

         1 DEFAULT                                                             133         53         19

SQL> select spid,program from v$process where pid in(21,19);

SPID                                             PROGRAM

------------------------------------------------ ------------------------------

15300                                            [email protected] (TNS V1-V3)

15318                                            [email protected] (TNS V1-V3)

原文地址:https://www.cnblogs.com/liang545621/p/9410711.html

时间: 2024-11-06 21:30:30

找出 alter system kill session ‘sid,serial#’ kill 掉的数据库会话对应进程的相关文章

oracle for update锁表资源释放之kill -9和alter system kill session 'sid,serial#';

通过for update锁表,通过操作系统方式和oracle方式终止进程方式 --查询需要终止进程的情况,包括操作系统进程 select proc.sPID, sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked_mode from v$locked_object lo, dba_objects ao, v$session sess,v$process proc where a

如何查找僵尸进程并Kill之,杀不掉的要查看父进程并杀之

用ps和grep命令寻找僵尸进程 #ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' 命令注解: -A 参数列出所有进程 -o 自定义输出字段 我们设定显示字段为 stat(状态), ppid(进程父id), pid(进程id),cmd(命令)这四个参数 因为状态为 z或者Z的进程为僵尸进程,所以我们使用grep抓取stat状态为zZ进程 运行结果参考如下 Z 12334 12339 /path/cmd 这时,我们可以使用 kill -HUP 12339来杀

Oracle中Kill session的研究(转 出自eagle)

itpub link: http://www.itpub.net/235873.html 我们知道,在Oracle数据库中,可以通过kill session的方式来终止一个进程,其基本语法结构为: alter system kill session 'sid,serial#' ; 被kill掉的session,状态会被标记为killed,Oracle会在该用户下一次touch时清除该进程. 我们发现当一个session被kill掉以后,该session的paddr被修改,如果有多个session

oracle kill session

kill session 是DBA经常碰到的事情之一.如果kill 掉了不该kill 的session,则具有破坏性,因此尽可能的避免这样的错误发生.同时也应当注意,如果kill 的session属于Oracle 后台进程,则容易导致数据库实例宕机. 通常情况下,并不需要从操作系统级别杀掉Oracle会话进程,但并非总是如此,下面的描述中给出了在Oracle级别杀掉会话以及操作系统级别杀掉进程.一.获得需要kill session的信息(使用V$SESSION 和 GV$SESSION视图) S

Oracle中Kill session

我们知道,在Oracle数据库中,可以通过kill session的方式来终止一个进程,其基本语法结构为: alter system kill session 'sid,serial#' ; 被kill掉的session,状态会被标记为killed,Oracle会在该用户下一次touch时清除该进程. 我们发现当一个session被kill掉以后,该session的paddr被修改,如果有多个session被kill,那么多个session的paddr都被更改为相同的进程地址: SQL> sel

【翻译自mos文章】在RAC database中怎么独立于instance来kill session?

来源于: How to Kill a Session on RAC Database In Instance Independent Fashion. (文档 ID 869777.1) 适用于: Oracle Database - Enterprise Edition - Version 11.1.0.6 and later Information in this document applies to any platform. 目标: 你可以在RAC database中来kill sessi

alter database和alter system和alter session的区别

1.system是实例级,database是数据库级,session是会话级. 2.关于这三个级别个更改大致如下 数据库级(比较大)> 实例级 > 会话级(仅针对当前对话) 3.相关属性 "alter session set *****=****"  //对当前会话有效 "alter system set *****=****"   //是永久(系统)有效 "alter database set *****=****"  //一般是改

tomcat端口被占用,如何找出并kill

开始-运行-cmd,输入netstat -ano即可看到所有端口占用情况. 加入要想知道谁占用了我们的端口8080,输入以下命令 C:\Documents and Settings\Administrator>netstat -aon|findstr "8080" TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       1596 端口被进程号为1596的程序占用 继续执行以下命令 C:\taskli

ORA-00031: session marked for kill 处理Oracle中杀不掉的锁

一些ORACLE中的进程被杀掉后,状态被置为"killed",但是锁定的资源很长时间不释放,有时实在没办法,只好重启数据库.现在提供一种方法解决这种问题,那就是在ORACLE中杀不掉的,在OS一级再杀. 1.下面的语句用来查询哪些对象被锁: select object_name,machine,s.sid,s.serial# from v$locked_object l,dba_objects o ,v$session swhere l.object_id = o.object_id