This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
数据库日志,可以发现出现过 ORA-600[504]错误,这个错误正是由 Bug“ORA-600 [504] DURING SHUTDOWN OR ALTER SYSTEM FLUSH SHARED_POOL[ID 428226.1]”引起的,Bug 号为 5508574。而将_KGHDSIDX_COUNT 这个隐含参
数设为 1,正是一个解决此 Bug 的临时方案。那么这个参数的影响在哪里呢?
由于每个 Shared Pool 子池由一个 shared pool latch 来保护,那么如果将这个参数
设置为 1,将会只有一个 shared pool latch,在高并发的情况下,shared pool latch
Oracle DBA 手记 3——数据库性能优化与内部原理解析 283
的争用将非常严重。而在 4GB 这么大的 shared pool 时,默认情况下有 7 个子池,
那么 shared pool patch 的争用将会少得多。 对于上面提到的 Bug 5508574,检查数据库已经安装的补丁,发现对应的补丁已
下面的信息: Process global information: process: 0x51a2dce8, call: 0x51b465e4, xact: (nil), curses: 0x51b2a4b8, usrses: 0x51b2a4b8 ---------------------------------------- SO: 0x51a2dce8, type: 2, owner: (nil), flag: INIT/-/-/0x00 (process) Oracle pid=15, calls cur/top: 0x51b465e4/0x51b465e4, flag: (0) - int error: 0, call error: 0, sess error: 0, txn error 0 (post info) last post received: 110 0 4 last post received-location: kslpsr last process to post me: 51a2a904 1 6 last post sent: 0 0 24 last post sent-location: ksasnd last process posted by me: 51a2a904 1 6 (latch info) wait_event=0 bits=20 Location from where call was made: kghupr1: Chunk Header Context saved from call: 1306572176 waiting for 200999bc Child shared pool level=7 child#=1 Location from where latch is held: kghupr1: Chunk Header Context saved from call: 1299065692 state=busy, wlstate=free waiters [orapid (seconds since: put on list, posted, alive check)]: 10 (54, 1304393092, 54) 11 (54, 1304393092, 54) 24 (15, 1304393092, 15) 15 (6, 1304393092, 6) waiter count=4 gotten 35138 times wait, failed first 502 sleeps 5 gotten 0 times nowait, failed: 0 on wait list for 200999bc holding (efd=3) 4f7c75f8 Child library cache level=5 child#=1 Location from where latch is held: kgllkdl: child: no lock handle: latch Context saved from call: 2
Oracle DBA 手记 3——数据库性能优化与内部原理解析 287
state=busy, wlstate=free
从 waiting for 200999bc Child shared pool level=7 child#=1 和 holding (efd=3) 4f7c75f8 Child library cache level=5 child#=1 可以看到,进程的确是在持有了 library cache latch 的同时去请求 shared pool latch。
[oracle@xty ~]$ gdb -p 4763 GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5) Copyright (C) 2009 Free Software Foundation, Inc. ...省略部分输出... Reading symbols from /lib/libnss_files.so.2...(no debugging symbols found)...done. Loaded symbols for /lib/libnss_files.so.2 0x0059b402 in __kernel_vsyscall ()
(4)在 gdb 中,在 latch 的获取和释放的函数上设置断点: (gdb) b kslgpl Breakpoint 1 at 0x8339fca (gdb) b kslgetsl Breakpoint 2 at 0x833a2d5 (gdb) b kslgpl Breakpoint 3 at 0x83473bf (gdb) b kslg2c Breakpoint 4 at 0x8347886 (gdb) b kslg2csl Breakpoint 5 at 0x834794e (gdb) b kslgprl Breakpoint 6 at 0x8346186 (gdb) Note: breakpoint 6 also set at pc 0x8346186. Breakpoint 7 at 0x8346186 (gdb) b kslfre Breakpoint 8 at 0x833c05d (gdb) b kslf2c Breakpoint 9 at 0x8347a1e (gdb) b kslfpl Breakpoint 10 at 0x8347812 (gdb) b kslfal Breakpoint 11 at 0x833fbca (gdb) b kslfpl0 Breakpoint 12 at 0x834766d (gdb)
注:最后几个函数只是猜测跟 latch 有关……latch 的请求和释放所调用的函数主要为
kslgetl、kslgetsl 和 kslfre。 (gdb) c Continuing.
(5)在 sqlplus 中执行 SQL: SQL> select * from t where object_id=10000;
正如预期的那样,会话 hang 住。这是因为运行到了 gdb 设置的断点。 (6)在 gdb 中可以看到:
Breakpoint 2, 0x0833a2d5 in kslgetsl () (gdb) info f Stack level 0, frame at 0xbfd3fb08:
隐含参数与 Library Cache、Shared Pool Latch 原理—— 一次由隐含参数引起性能问题的处理
288
eip = 0x833a2d5 in kslgetsl; saved eip 0x84257e1 called by frame at 0xbfd3fb44 Arglist at 0xbfd3fb00, args: Locals at 0xbfd3fb00, Previous frame's sp is 0xbfd3fb08 Saved registers: ebp at 0xbfd3fb00, eip at 0xbfd3fb04 (gdb) x /10x 0xbfd3fb00 0xbfd3fb00: 0xbfd3fb3c 0x084257e1 0x51b4c38c 0x00000001 0xbfd3fb10: 0x51b11738 0x00000058 0x00000008 0x00000002 0xbfd3fb20: 0x0d099c40 0x0d099d3c
0x51b4c38c 这是一个地址,从 v$latch 和 v$latch_children 中可以查到正是 session idle bit latch。
(7)在 gdb 中继续: (gdb) c Continuing. Breakpoint 8, 0x0833c05d in kslfre () (gdb) info f Stack level 0, frame at 0xbfd3fb18: eip = 0x833c05d in kslfre; saved eip 0x842581a called by frame at 0xbfd3fb44 Arglist at 0xbfd3fb10, args: Locals at 0xbfd3fb10, Previous frame's sp is 0xbfd3fb18 Saved registers: ebp at 0xbfd3fb10, eip at 0xbfd3fb14 (gdb) x /10x 0xbfd3fb10 0xbfd3fb10: 0xbfd3fb3c 0x0842581a 0x51b4c38c 0x00000002 0xbfd3fb20: 0x0d099c40 0x0d099d3c 0x0d099c40 0x00000002 0xbfd3fb30: 0x00000000 0x517a7090 (gdb) c Continuing. ----下面很重要----- Breakpoint 1, 0x08339fca in kslgetl () (gdb) x /10x $ebp+8 0xbfd3ecc0: 0x4f7c7594 0x00000001 0x00000001 0x00000a57 0xbfd3ecd0: 0x0af275ca 0x00000000 0x0dcfdcc0 0x0d045860 0xbfd3ece0: 0xbfd3ed58 0x0b20fc09 (gdb) c Continuing. Breakpoint 8, 0x0833c05d in kslfre () (gdb) x /10x $ebp+8 0xbfd3ed64: 0x4f7c7594 0x00000000 0x10010040 0x0d045860 0xbfd3ed74: 0xbfd3ef10 0x0b1f5d10 0x0d099c40 0x4f7c7594 0xbfd3ed84: 0x00000000 0x00000008 (gdb) c Continuing. Breakpoint 1, 0x08339fca in kslgetl () (gdb) x /10x $ebp+8 0xbfd3ecc0: 0x4f7c7594 0x00000001 0x00000001 0x00000a57 0xbfd3ecd0: 0x0af275ca 0x00000000 0x0dcfdcc0 0x0d045860 0xbfd3ece0: 0xbfd3ed58 0x0b20fc09 (gdb) c Continuing. Breakpoint 1, 0x08339fca in kslgetl () (gdb) x /10x $ebp+8 0xbfd3eb50: 0x200999bc 0x00000001 0x00000000 0x000009de 0xbfd3eb60: 0x0d099c40 0x0000000f 0x0c3c3ec0 0x0d045860 0xbfd3eb70: 0xbfd3ec10 0x0af3983b (gdb) c Continuing. Breakpoint 8, 0x0833c05d in kslfre () (gdb) x /10x $ebp+8 0xbfd3eb6c: 0x200999bc 0x0d099c40 0x2001d310 0x0d045860 0xbfd3eb7c: 0xbfd3ec10 0x0af390a8 0x0d099c40 0x200999bc
Oracle DBA 手记 3——数据库性能优化与内部原理解析 289
0xbfd3eb8c: 0xbfd3ebe8 0x00000164 (gdb) c Continuing. Breakpoint 8, 0x0833c05d in kslfre () (gdb) x /10x $ebp+8 0xbfd3ed64: 0x4f7c7594 0x00000000 0x10010040 0x0d045860 0xbfd3ed74: 0xbfd3ef10 0x0b1f58e6 0x0d099c40 0x4f7c7594 0xbfd3ed84: 0x00000000 0x00000008 (gdb) quit A debugging session is active. Inferior 1 [process 4763] will be detached.
同时可以从数据库中查到: SQL> select addr,latch#,child#,level#,name from v$latch_children where name in ('library cache','shared pool'); ADDR LATCH# CHILD# LEVEL# NAME -------- ---------- ---------- ---------- -------------------------------------------------- 4F7C75F8 217 1 5 library cache 4F7C7594 217 2 5 library cache 4F7C7530 217 3 5 library cache 200999BC 216 1 7 shared pool 20099A20 216 2 7 shared pool 20099A84 216 3 7 shared pool 20099AE8 216 4 7 shared pool 20099B4C 216 5 7 shared pool 20099BB0 216 6 7 shared pool 20099C14 216 7 7 shared pool