首页 > 开发 > 综合 > 正文

彻底搞清楚library cache lock的成因和解决方法(一)

2024-07-21 02:11:40
字体:
来源:转载
供稿:网友

最大的网站源码资源下载站,


问题描述:
接到应用人员的报告,说是在任何对表csnoz629926699966的操作都会hang,包括desc csnoz629926699966,
例如:

[email protected]_dc02:/ora9i > sqlplus pubuser/pubuser

sql*plus: release 9.2.0.4.0 - production on mon jan 10 10:11:06 2005

copyright (c) 1982, 2002, oracle corporation.  all rights reserved.


connected to:
oracle9i enterprise edition release 9.2.0.4.0 - 64bit production
with the partitioning and real application clusters options
jserver release 9.2.0.4.0 - production

sql> conn pubuser/pubuser
connected.
sql> desc csnoz629926699966

。。。

这个进程 hang 了

。。。

 

询问了一下之前有无特别的操作,业务人员说很久以前执行了脚本,但是该教本运行很久都没有结果,然后他就退出了会话,再之后,就出现了上面的情况。脚本内容如下:
$ cat csnoz629926699966.sh
#!/bin/sh
sqlplus pubuser/[email protected] << eof  #use your username/password

create table csnoz629926699966 as select * from csnoz62992266cs
where mid not in ( select mid from [email protected] where servid='020999011964' and status in ('a','b','s'));

exit;
$
$
$
$

解决过程:
[email protected]_dc02:/ora9i > sqlplus "/ as sysdba"

sql*plus: release 9.2.0.4.0 - production on mon jan 10 10:19:13 2005

copyright (c) 1982, 2002, oracle corporation.  all rights reserved.


connected to:
oracle9i enterprise edition release 9.2.0.4.0 - 64bit production
with the partitioning and real application clusters options
jserver release 9.2.0.4.0 - production

sql> select * from v$lock where block=1;

no rows selected

sql> /

no rows selected

sql> /

no rows selected

sql>
我们看到目前没有锁的信息

sql> select xidusn, object_id, session_id, locked_mode from v$locked_object;

。。。   

 xidusn  object_id session_id locked_mode
---------- ---------- ---------- -----------
        14         18         37           3

。。。

sql> /

。。。   

 xidusn  object_id session_id locked_mode
---------- ---------- ---------- -----------
        14         18         37           3

。。。

sql> /

。。。   

 xidusn  object_id session_id locked_mode
---------- ---------- ---------- -----------
        14         18         37           3

。。。

sql>
查找 v$locked_object,我们发现了一个可疑的会话,sid 37:

sql> select object_name,owner,object_type from dba_objects where object_id=18;

。。。 。。。

object_name                    owner                          object_type
------------------------------ ------------------------------ ------------------
obj$                           sys                            table

 

。。。 。。。

sql>

奇怪怎么一直有这个锁??
初步猜测是由于sid为37的会话执行了上面的ddl语句,并在语句未完成前异常退出,
造成了所有访问那个(ddl语句中涉及到的)对象的进程都hang了。


接下来我们看看等待事件:
sql> select event,sid,p1,p2,p3 from v$session_wait where event not like 'sql*%' and event not like 'rdbms%';

event                                                                    p1         p2        sid
---------------------------------------------------------------- ---------- ---------- ----------
pmon timer                                                              300          0          1
ges remote message                                                       32          0          4
gcs remote message                                                       64          0          5
gcs remote message                                                       64          0          7
smon timer                                                              300          0         19
library cache lock                                               1.3835e+19 1.3835e+19         30
wakeup time manager                                                       0          0         22

7 rows selected.

sql> /

event                                                                    p1         p2        sid
---------------------------------------------------------------- ---------- ---------- ----------
pmon timer                                                              300          0          1
ges remote message                                                       32          0          4
gcs remote message                                                       64          0          5
gcs remote message                                                       64          0          7
smon timer                                                              300          0         19
library cache lock                                               1.3835e+19 1.3835e+19         30
wakeup time manager                                                       0          0         22

7 rows selected.

sql> /

event                                                                    p1         p2        sid
---------------------------------------------------------------- ---------- ---------- ----------
pmon timer                                                              300          0          1
ges remote message                                                       32          0          4
gcs remote message                                                       64          0          5
gcs remote message                                                       64          0          7
smon timer                                                              300          0         19
library cache lock                                               1.3835e+19 1.3835e+19         30
wakeup time manager                                                       0          0         22

7 rows selected.

sql> /

event                                                                    p1         p2        sid
---------------------------------------------------------------- ---------- ---------- ----------
pmon timer                                                              300          0          1
ges remote message                                                       32          0          4
gcs remote message                                                       64          0          5
gcs remote message                                                       64          0          7
smon timer                                                              300          0         19
library cache lock                                               1.3835e+19 1.3835e+19         30
wakeup time manager                                                       0          0         22

7 rows selected.

sql>


我们注意到下面的事件:
event                                                                    p1         p2        sid
---------------------------------------------------------------- ---------- ---------- ----------
。。。

library cache lock                                               1.3835e+19 1.3835e+19         30

。。。

p1 是句柄地址(handle address),也就是'library cache lock'发生的地址。
p2 是一个状态对象,在这里,它表示在对象上加载的锁的地址(lock address)。
p1 和 p2都是科学计数发表示的10进制数。

这些信息再次证实了上面的猜测,sid 37阻塞了sid 30。

找出这两个可疑进程的sid和serial,然后对他们设置10046事件:
sql> select sid,serial# from v$session where sid in (30,37);

       sid    serial#
---------- ----------
        30      24167
        37       2707

sql> exec dbms_system.set_ev(30,24167,10046,12,'');

pl/sql procedure successfully completed.

sql> exec dbms_system.set_ev(37,2707,10046,12,'');

pl/sql procedure successfully completed.

sql>

跟踪期间咱们再次测试一下,看看有没有其他线索。


新开一个进程,找出其sid, serial和spid等信息:
[email protected]_dc01:/ora9i > sqlplus pubuser/pubuser                                                                                 

sql*plus: release 9.2.0.4.0 - production on mon jan 10 11:36:25 2005

copyright (c) 1982, 2002, oracle corporation.  all rights reserved.


connected to:
oracle9i enterprise edition release 9.2.0.4.0 - 64bit production
with the partitioning and real application clusters options
jserver release 9.2.0.4.0 - production

sql> select distinct sid from v$mystat;

       sid
----------
        33

sql> select sid,serial# from v$session where sid=33;

       sid    serial#
---------- ----------
        33       6639

sql> select spid,pid from v$process where addr=(select paddr from v$session where sid=37);

spid                pid
------------ ----------
20552                26

sql> select spid,pid from v$process where addr=(select paddr from v$session where sid=30);

spid                pid
------------ ----------
22580                28

sql> show parameter dump

name                                 type        value
------------------------------------ ----------- ------------------------------
background_core_dump                 string      partial
background_dump_dest                 string      /ora9i/app/oracle/admin/csmisc
                                                 /bdump
core_dump_dest                       string      /ora9i/app/oracle/admin/csmisc
                                                 /cdump
max_dump_file_size                   string      unlimited
shadow_core_dump                     string      partial
user_dump_dest                       string      /ora9i/app/oracle/admin/csmisc
                                                 /udump
sql>       


然后,再尝试对 csnoz629926699966 表进行操作
sql> desc csnoz629926699966

。。。

还是hang住了。

 

于是中断这个操作(ctrl + c):

sql> desc csnoz629926699966
error:
ora-01013: user requested cancel of current operation

 

sql> select tname from tab where tname='csnoz629926699966';

no rows selected

sql>
查看pubuser用户下的这个表,居然不存在!!


进一步证实了前面的猜测,也就是说会话37阻塞了其他所有操作表csnoz629926699966的会话,造成了进程的hang,当然,包括上面的sid 30和sid 33的ddl语句

现在,我们结束10046的事件跟踪:
sql> exec dbms_system.set_ev(30,24167,0,0,'');

pl/sql procedure successfully completed.

sql> exec dbms_system.set_ev(37,2707,0,0,'');

pl/sql procedure successfully completed.

sql>


根据上面记录的信息,我们知道这两个会话产生的跟踪信息分别为:
sid为30的会话,产生的跟踪文件为:/ora9i/app/oracle/admin/csmisc/udump/csmisc2_ora_22580.trc
sid为37的会话,产生的跟踪文件为:/ora9i/app/oracle/admin/csmisc/udump/csmisc2_ora_20552.trc

 

看看trace文件:
[email protected]_dc02:/ora9i > cd /ora9i/app/oracle/admin/csmisc/udump
[email protected]_dc02:/ora9i/app/oracle/admin/csmisc/udump > ll -tlc
total 4432
-rw-r-----   1 ora9i      dba         332995 jan 10 12:00 csmisc2_ora_22580.trc
-rw-r-----   1 ora9i      dba           3168 jan 10 11:59 csmisc2_ora_20552.trc
-rw-r-----   1 ora9i      dba         407133 jan  7 15:10 csmisc2_ora_2708.trc
-rw-r-----   1 ora9i      dba            640 jan  7 14:48 csmisc2_ora_835.trc
-rw-r-----   1 ora9i      dba           1590 dec 30 22:50 csmisc2_ora_16244.trc
-rw-r-----   1 ora9i      dba        1308403 dec 30 22:44 csmisc2_ora_16033.trc
-rw-r-----   1 ora9i      dba            616 dec 28 14:16 csmisc2_ora_2176.trc
-rw-r-----   1 ora9i      dba            644 dec  8 18:22 csmisc2_ora_21083.trc
[email protected]_dc02:/ora9i/app/oracle/admin/csmisc/udump > mailx -s "csmisc2_ora_22580.trc" [email protected] < csmisc2_ora_22580.trc
[email protected]_dc02:/ora9i/app/oracle/admin/csmisc/udump > mailx -s "csmisc2_ora_20552.trc" [email protected] < csmisc2_ora_20552.trc
[email protected]_dc02:/ora9i/app/oracle/admin/csmisc/udump > exit

sql>

我们看到sid为30的会话,产生的跟踪文件(csmisc2_ora_22580.trc)为的主要内容是:
/ora9i/app/oracle/admin/csmisc/udump/csmisc2_ora_22580.trc
oracle9i enterprise edition release 9.2.0.4.0 - 64bit production
with the partitioning and real application clusters options
jserver release 9.2.0.4.0 - production
oracle_home = /ora9i/app/oracle/product/920
system name: hp-ux
node name: cs_dc02
release: b.11.11
version: u
machine: 9000/800
instance name: csmisc2
redo thread mounted by this instance: 2
oracle process number: 28
unix process pid: 22580, image: [email protected]_dc02 (tns v1-v3)

*** 2005-01-10 11:31:49.416
*** session id:(30.24167) 2005-01-10 11:31:49.354
wait #0: nam='library cache lock' ela= 507258 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 505686 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507678 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507595 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507880 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507317 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507703 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507683 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 508265 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507100 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507684 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 505889 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507731 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507650 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507604 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301
wait #0: nam='library cache lock' ela= 507698 p1=-4611686013547141416 p2=-4611686013691716064 p3=1301

。。。 。。。


我们看到sid 30的跟踪文件中的等待事件就是在v$session_wait中看到的'library cache lock' .

 

再看看sid为37的会话,产生的跟踪文件(csmisc2_ora_20552.trc)为的主要内容是:
oracle9i enterprise edition release 9.2.0.4.0 - 64bit production
with the partitioning and real application clusters options
jserver release 9.2.0.4.0 - production
oracle_home = /ora9i/app/oracle/product/920
system name: hp-ux
node name: cs_dc02
release: b.11.11
version: u
machine: 9000/800
instance name: csmisc2
redo thread mounted by this instance: 2
oracle process number: 26
unix process pid: 20552, image: [email protected]_dc02 (tns v1-v3)

*** 2005-01-10 11:33:22.702
*** session id:(37.2707) 2005-01-10 11:33:22.690
wait #1: nam='sql*net message to dblink' ela= 4 p1=675562835 p2=1 p3=0
*** 2005-01-10 11:35:07.452
wait #1: nam='sql*net message from dblink' ela= 102293555 p1=675562835 p2=1 p3=0
wait #1: nam='sql*net message to dblink' ela= 3 p1=675562835 p2=1 p3=0
*** 2005-01-10 11:36:55.980
wait #1: nam='sql*net message from dblink' ela= 105969709 p1=675562835 p2=1 p3=0
wait #1: nam='sql*net message to dblink' ela= 4 p1=675562835 p2=1 p3=0
*** 2005-01-10 11:39:05.416
wait #1: nam='sql*net message from dblink' ela= 126390826 p1=675562835 p2=1 p3=0
wait #1: nam='sql*net message to dblink' ela= 4 p1=675562835 p2=1 p3=0
*** 2005-01-10 11:41:12.878
wait #1: nam='sql*net message from dblink' ela= 124461520 p1=675562835 p2=1 p3=0
wait #1: nam='sql*net message to dblink' ela= 4 p1=675562835 p2=1 p3=0
*** 2005-01-10 11:43:01.285
wait #1: nam='sql*net message from dblink' ela= 105859385 p1=675562835 p2=1 p3=0
wait #1: nam='sql*net message to dblink' ela= 4 p1=675562835 p2=1 p3=0
*** 2005-01-10 11:44:48.200
wait #1: nam='sql*net message from dblink' ela= 104397696 p1=675562835 p2=1 p3=0
wait #1: nam='sql*net message to dblink' ela= 4 p1=675562835 p2=1 p3=0


。。。 。。。

 

现在我们来dump 系统状态(systemstate),看看更详细的信息。

首先简单的介绍一下 event systemstate。
很多人把 systemstate 事件理解为dump发生的那一刻的系统内所有进程的信息,这是个错误的概念,事实上,
转储 system state 产生的跟踪文件是从dump那一刻开始到dump任务完成之间一段事件内的系统内所有进程的信息。

dump systemstate产生的跟踪文件包含了系统中所有进程的进程状态等信息。每个进程对应跟踪文件中的一段内容,反映该进程的状态信息,包括进程信息,会话信息,enqueues信息(主要是lock的信息),缓冲区的信息和该进程在sga区中持有的(held)对象的状态等信息。

那么通常在什么情况下使用systemstate比较合适呢?
 oracle推荐的使用systemstate事件的几种情况是:
数据库 hang 住了 数据库很慢 进程正在hang 数据库出现某些错误 资源争用
dump systemstate的语法为:
    alter session set events 'immediate trace name systemstate level 10';

也可以使用oradebug实现这个功能
    oradebug dump systemstate level 10

如果希望在数据库发生某种错误时除非systemstate事件,可以在参数文件(spfile或者pfile)中设置event参数,
例如,当系统发生死锁(出现ora-00060错误)时dump systemstate:
    event = "60 trace name systemstate level 10"
 

言归正传,我们dump系统状态:
sql> alter session set events 'immediate trace name systemstate level 8';

session altered.

sql> host
[email protected]_dc02:/ora9i >cd /ora9i/app/oracle/admin/csmisc/udump
[email protected]_dc02:/ora9i/app/oracle/admin/csmisc/udump > ll -ctl
-rw-r-----   1 ora9i      dba        1070863 jan 10 13:02 csmisc2_ora_22580.trc
-rw-r-----   1 ora9i      dba        1345368 jan 10 13:01 csmisc2_ora_22568.trc
-rwxrwxrwx   1 ora9i      dba          44114 jan 10 12:52 ass1015.awk
-rw-r-----   1 ora9i      dba         407133 jan  7 15:10 csmisc2_ora_2708.trc
-rw-r-----   1 ora9i      dba            640 jan  7 14:48 csmisc2_ora_835.trc
-rw-r-----   1 ora9i      dba           1590 dec 30 22:50 csmisc2_ora_16244.trc
-rw-r-----   1 ora9i      dba        1308403 dec 30 22:44 csmisc2_ora_16033.trc
-rw-r-----   1 ora9i      dba            616 dec 28 14:16 csmisc2_ora_2176.trc
-rw-r-----   1 ora9i      dba            644 dec  8 18:22 csmisc2_ora_21083.trc
[email protected]_dc02:/ora9i/app/oracle/admin/csmisc/udump >
[email protected]_dc02:/ora9i/app/oracle/admin/csmisc/udump > mailx -s "22568" [email protected] < csmisc2_ora_22568.trc

这个跟踪文件很大(因为它包含了所有进程的信息),那么我们从哪里开始看起呢?

首先,通过在跟踪文件中查找字符串"waiting for 'library cache lock'",我们找到了被阻塞进程的信息:

process 28: ----------------被阻塞的oracle进程,这里process 28对应了v$process中的pid的值,
    也就是说我们可以根据这一信息在v$process和v$session找到被阻塞的会话的信息
  ----------------------------------------
  so: c000000109c83bf0, type: 2, owner: 0000000000000000, flag: init/-/-/0x00
  (process) oracle pid=28, calls cur/top: c00000010b277890/c00000010b277890, flag: (0) -
            int error: 0, call error: 0, sess error: 0, txn error 0
  (post info) last post received: 17 24 6
              last post received-location: ksusig
              last process to post me: c000000109c840f8 25 0
              last post sent: 0 0 15
              last post sent-location: ksasnd
              last process posted by me: c000000109c7ff90 1 6
    (latch info) wait_event=0 bits=0
    process group: default, pseudo proc: c000000109eefda0
    o/s info: user: ora9i, term: pts/th, ospid: 22580  ----------------该进程的操作系统进程号,对应于v$process中的spid
    osd pid info: unix process pid: 22580, image: [email protected]_dc02 (tns v1-v3)
    ----------------------------------------
    so: c000000109f02c68, type: 4, owner: c000000109c83bf0, flag: init/-/-/0x00
    (session) trans: 0000000000000000, creator: c000000109c83bf0, flag: (100041) usr/- bsy/-/-/-/-/-
              did: 0002-001c-00000192, short-term did: 0000-0000-00000000
              txn branch: 0000000000000000
              oct: 0, prv: 0, sql: c00000011f8ea068, psql: c00000011f8ea068, user: 50/pubuser
    o/s info: user: ora9i, term: , ospid: 22536, machine: cs_dc02
              program: [email protected]_dc02 (tns v1-v3)
    application name: sql*plus, hash value=3669949024
    waiting for 'library cache lock' blocking sess=0x0 seq=18589 wait_time=0
                handle address=c000000122e2a6d8, lock address=c00000011a449e20, 100*mode+namespace=515

。。。 。。。

    so: c00000010b277890, type: 3, owner: c000000109c83bf0, flag: init/-/-/0x00
    (call) sess: cur c000000109f02c68, rec 0, usr c000000109f02c68; depth: 0
      ----------------------------------------
      so: c00000011a449e20, type: 51, owner: c00000010b277890, flag: init/-/-/0x00
      library object lock: lock=c00000011a449e20 handle=c000000122e2a6d8 request=s
      call pin=0000000000000000 session pin=0000000000000000
      htl=c00000011a449e90[c00000011a4bc350,c00000011a4bc350] htb=c00000011a4bc350
      user=c000000109f02c68 session=c000000109f02c68 count=0 flags=[00] savepoint=463
      the rest of the object was already dumped

。。。 。。。

 

请注意下面的信息:
    waiting for 'library cache lock' blocking sess=0x0 seq=18589 wait_time=0
                handle address=c000000122e2a6d8, lock address=c00000011a449e20, 100*mode+namespace=515

这段信息告诉我们oracle pid为 28的进程(process 28),正在等待'library cache lock' ,通过‘handle address=c000000122e2a6d8’我们可以找到阻塞它的会话的oracle pid信息。

还要注意这段信息:
      library object lock: lock=c00000011a449e20 handle=c000000122e2a6d8 request=s
      call pin=0000000000000000 session pin=0000000000000000
      htl=c00000011a449e90[c00000011a4bc350,c00000011a4bc350] htb=c00000011a4bc350
      user=c000000109f02c68 session=c000000109f02c68 count=0 flags=[00] savepoint=463

这里就是阻塞process 28进程的会话的信息。

简单的记住这个依据的要点是:

waiting session的'handle address'的值对应于blocking session的'handle'的值。


回过头来,看看这个值,它应于上面我们在v$session_wait中看到的p1和p2的值:
sql> select to_number('c000000122e2a6d8','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') from dual;

to_number('c000000122e2a6d8','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
----------------------------------------------------------------
                                                      1.3835e+19

sql>      

问题的成因已经基本上明确了,这里推荐两种解决问题的方法:
方法1,根据 c000000122e2a6d8 地址,我们可以得到当前在library cache中相应的锁信息:              
sql> l
  1  select inst_id,user_name,kglnaobj,kgllksnm,kgllkuse,kgllkses,kgllkmod,kgllkreq,kgllkpns,kgllkhdl
  2* from x$kgllk where kgllkhdl = 'c000000122e2a6d8' order by kgllksnm,kglnaobj
sql> /

   inst_id user_name     kglnaobj                 kgllksnm kgllkuse         kgllkses       kgllkmod   kgllkreq kgllkpns         kgllkhdl
---------- ------------- ---------------------- ---------- ---------------- ---------------- ---------- ---------- ---------------- ----------------
         2 pubuser       csnoz629926699966              30 c000000109f02c68 c000000109f02c68      0          2 00               c000000122e2a6d8
         2 pubuser       csnoz629926699966              37 c000000108c99e28 c000000108c99e28      3          0 00               c000000122e2a6d8

sql> 

按照oracle推荐的做法,我们现在应该使用'alter system kill session'命令kill掉sid 37,
结果得到了ora-00031错误:
sql> alter system kill session '37,2707';

alter system kill session '37,2707'
*
error at line 1:
ora-00031: session marked for kill

sql>

检查sid 37的状态:
sql> set linesize 150
sql> col program for a50
sql> select sid,serial#,status,username,program from v$session where sid=37;

       sid    serial# status   username                       program
---------- ---------- -------- ------------------------------ --------------------------------------------------
        37       2707 killed   pubuser                        [email protected]_dc02 (tns v1-v3)

sql>
再次证实了我们最初的想法—— 有人在执行了某个需要运行很久的ddl(多数是语句效率低,当然不排除遭遇bug的可能),
然后没等语句结束就异常退出了会话。

这个例子中我们在上面的跟踪文件已经找到了该会话对应的操作系统进程(spid),如果在其他情况下,我们如何找到这种状态为'killed'
的操作系统进程号(spid)呢?
下面给出了一个方法,可以借鉴:
sql> l
  1  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)
  4  from x$ksupr x,v$session s
  5  where s.paddr(+)=x.addr
  6  and bitand(ksspaflg,1)!=0
  7* and s.sid=37
sql> /

username                       status   addr               ksllapsc   ksllapsn ksllaspo       ksllid1r ks d
------------------------------ -------- ---------------- ---------- ---------- ------------ ---------- -- -
pubuser                        killed   c000000109c831e0         41         15 16243                17

sql>


x$ksupr.addr列的值对应了v$process 中的addr的值,知道了这个spid的地址,找到这个操作系统进程(spid)就简单了,例如:
sql> select spid,pid from v$process where addr='c000000109c831e0';

spid                pid
------------ ----------
20552                26

sql>

现在,我们只需要在操作系统上 kill 操作系统进程20552就可以了:
[email protected]_dc02:/ora9i > ps -ef | grep 20552
   ora9i 20552     1  0  jan  8  ?         0:01 oraclecsmisc2 (local=no)
   ora9i 14742 14740  0 17:19:02 pts/ti    0:00 grep 20552
[email protected]_dc02:/ora9i > kill -9 20552
[email protected]_dc02:/ora9i > ps -ef | grep 20552
   ora9i 14966 14964  0 17:40:01 pts/ti    0:00 grep 20552
[email protected]_dc02:/ora9i >


再来检查一下sid 37的信息,我们看到这个会话是真的被kill掉了,
[email protected]_dc02:/ora9i > exit

sql> select sid,serial#,status,username,program from v$session where sid=37;

no rows selected

sql> l
  1  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)
  4  from x$ksupr x,v$session s
  5  where s.paddr(+)=x.addr
  6  and bitand(ksspaflg,1)!=0
  7* and s.sid=37
sql> /

no rows selected

sql>

回到刚才hang住的会话,它已经恢复了正常操作,
并且我们已经得到了'ora-04043: object csnoz629926699966 does not exist'这个正常的信息:
sql> desc csnoz629926699966

 


error:
ora-04043: object csnoz629926699966 does not exist


sql>

在开一个会话,测试一把:
[email protected]_dc02:/ora9i > sqlplus pubuser/pubuser

sql*plus: release 9.2.0.4.0 - production on mon jan 10 17:42:16 2005

copyright (c) 1982, 2002, oracle corporation.  all rights reserved.


connected to:
oracle9i enterprise edition release 9.2.0.4.0 - 64bit production
with the partitioning and real application clusters options
jserver release 9.2.0.4.0 - production

sql> set timing on
sql> desc csnoz629926699966
error:
ora-04043: object csnoz629926699966 does not exist


sql>
当发出命令'desc csnoz629926699966'的时候,我们看到系统立刻返回了ora-04043: object csnoz629926699966 does not exist'信息,问题就此解决了。


这里,简单的介绍一下x$kgllk,这个基表保存了库缓存中对象的锁的信息,它对于解决这类问题特别有用,其名称的含义如下:
  [k]ernel layer                                                               
    [g]eneric layer                                                            
      [l]ibrary cache manager  ( defined and mapped from kqlf )                
        object locks                                                           
          x$kgllk - object [l]oc[k]s                                           

kglnaobj 列包含了在librarky cache中的对象上执行命令的语句的前80个字符(其实从这里我们也可以大大缩小范围了)
x$kgllk.kgllkuse 和 x$kgllk.kgllkses 对应于跟踪文件中的owner的值
x$kgllk.kgllkadr
x$kgllk.kgllkhdl 对应于跟踪文件中的handle的值(handle=c000000122e2a6d8),也就是'library cache lock'的地址
x$kgllk.kgllkpns 对应于跟踪文件中的session pin的值
x$kgllk.kgllkspn对应于跟踪文件中的savepoint的值

我们再来看一下更全面的信息:
sql> set linesize 2000
sql> select * from x$kgllk where kgllkhdl = 'c000000122e2a6d8' order by kgllksnm,kglnaobj                          
  2  /

addr                   indx    inst_id kgllkadr         kgllkuse         kgllkses           kgllksnm kgllkhdl         kgllkpnc         kgllkpns       kgllkcnt   kgllkmod   kgllkreq   kgllkflg   kgllkspn kgllkhtb           kglnahsh kglhdpar           kglhdnsp user_name                  kglnaobj
---------------- ---------- ---------- ---------------- ---------------- ---------------- ---------- ---------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------------- ---------- ------------------------------ ------------------------------------------------------------
800003fb0007e4d0         33          2 c00000011a449e20 c000000109f02c68 c000000109f02c68         30 c000000122e2a6d8 00               00                    0          0          2          0        463 c00000011a4bc350 3990848181 c000000122e2a6d8          1 pubuser                            csnoz629926699966
800003fb0007e5b0         34          2 c00000011a44a150 c000000108c99e28 c000000108c99e28         37 c000000122e2a6d8 00               00                    1          3          0          0        179 c00000011a4bb328 3990848181 c000000122e2a6d8          1 pubuser                            csnoz629926699966

sql> set linesize 100
sql> l
  1* select * from x$kgllk where kgllkhdl = 'c000000122e2a6d8' order by kgllksnm,kglnaobj
sql> /

addr                   indx    inst_id kgllkadr         kgllkuse         kgllkses           kgllksnm
---------------- ---------- ---------- ---------------- ---------------- ---------------- ----------
kgllkhdl         kgllkpnc         kgllkpns           kgllkcnt   kgllkmod   kgllkreq   kgllkflg
---------------- ---------------- ---------------- ---------- ---------- ---------- ----------
  kgllkspn kgllkhtb           kglnahsh kglhdpar           kglhdnsp user_name
---------- ---------------- ---------- ---------------- ---------- ------------------------------
kglnaobj
------------------------------------------------------------
800003fb0007e4d0         33          2 c00000011a449e20 c000000109f02c68 c000000109f02c68         30
c000000122e2a6d8 00               00                        0          0          2          0
       463 c00000011a4bc350 3990848181 c000000122e2a6d8          1 pubuser
csnoz629926699966

800003fb0007e5b0         34          2 c00000011a44a150 c000000108c99e28 c000000108c99e28         37
c000000122e2a6d8 00               00                        1          3          0          0
       179 c00000011a4bb328 3990848181 c000000122e2a6d8          1 pubuser
csnoz629926699966


sql>


 

 

————待续————
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表