首页 > 数据库 > Oracle > cursor:pin S wait on X
关于library cache里的一些基本对象,基本原理在这就不赘述了 嘿嘿。我们来说说cursor pin s wait on X
Library Cache handle
我们对Library cache中所有对象的访问是通过利用library cache handle来实现的,也就是说我们想要访问library cache object,我们必须先找到library cache handle。Library cache handle指向library cache object,它包含了
l
i
brary object
的名字,命名空间,时间戳,引用列表,
lock对象以及pin对象的列表信息等等。Library cache handle也被library cache用来记录哪个用户在这个这个handle上有lock,或者是哪个用户正在等待获得这个lock。那么这里我们也知道了library cache lock是发生在handle上的。
当一个进程请求library cache object, library cache manager就会应用一个hash算法,从而得到一个hash值,根据相应的hash值到相应的hash bucket中去寻找。这里的hash算法原理与buffer cache中快速定位block的原理是一样的。如果library cache object在内存中,那么这个library cache handle就会被找到。有时候,当shared pool不够大,library cache handle会保留在内存中,然而library cache heap由于内存不足被age out,这个时候我们请求的object heap就会被重载。最坏的情况下,library cache handle在内存中没有找到,这个时候就必须分配一个新的library cache handle,同时object heap也会被加载到内存中。
Library Cache Object
Library Cache Object是由一些独立的heap所组成,前面说了Library cache handle指向Library cache Object,其实handle是指向第一个heap,这个heap 我们就称之为heap 0。Heap 0记录了指向其他heap的指针信息。
select name,gets,misses,sleeps from v$latch where name like '%library%';
Library Cache lock有3中模式:
Share(S): 当读取一个library cache object的时候获得
Exclusive(X): 当创建/修改一个library cache object的时候获得
Null(N): 用来确保对象依赖性
Library Cache pin有2种模式:
Share(S): 读取
object heap Exclusive(X):修改object heap
所以这里的cursor pin S wait on X 就是读(pin S)在等待修改(pin X)的情况,那么这说明了肯定有相同的sql在同时执行,不要然只有cursor pin S 或者cursor pin X。还有library cache 中有秀逗的object就是说,oracle不知道这些sql能否编译成功也要申请一块内存去编译。这样也会有pin X的。
--------------------------------------
--------------------------------------
Top 5 Timed Events
| Event | Waits | Time(s) | Avg Wait(ms) | % Total Call Time | Wait Class |
|---|---|---|---|---|---|
| CPU time | 10,061 | 76.0 | |||
| cursor: pin S wait on X | 254,229 | 2,485 | 10 | 18.8 | Concurrency |
| db file sequential read | 148,935 | 428 | 3 | 3.2 | User I/O |
| direct path read | 159,372 | 123 | 1 | .9 | User I/O |
| gc cr multi block request | 195,173 | 59 | 0 | .4 | Cluster |
"Pct Misses" should be very low
| Namespace | Get Requests | Pct Miss | Pin Requests | Pct Miss | Reloads | Invali- dations |
|---|---|---|---|---|---|---|
| BODY | 674 | 1.63 | 2,474 | 2.75 | 53 | 0 |
| CLUSTER | 329 | 2.13 | 431 | 2.78 | 5 | 0 |
| INDEX | 45 | 51.11 | 133 | 18.05 | 1 | 0 |
| SQL AREA | 170,513 | 29.10 | 745,128 | 11.40 | 6,190 | 1,978 |
| TABLE/PROCEDURE | 72,027 | 1.22 | 389,103 | 2.27 | 4,134 | 0 |
| TRIGGER | 2,819 | 0.46 | 8,335 | 0.61 | 37 | 0 |
Back to Library Cache Statistics
6190次还算是有些高,这个reload现象就是大sql文本进来和硬解析sql,同时有shared pool扩张的现象。
Cache Sizes
|
|
Begin | End |
|
|
|---|---|---|---|---|
| Buffer Cache: | 22,288M | 22,128M | Std Block Size: | 8K |
| Shared Pool Size: | 2,128M | 2,288M | Log Buffer: | 14,288K |
shared pool 在变大,
Oracle只有在万不得已的情况下才会去resize pool
Total time in database user-calls (DB Time): 13235.7s
Statistics including the word "background" measure background process time, and so do not contribute to the DB time statistic
Ordered by % or DB time desc, Statistic name
Only Statements with Sharable Memory greater than 1048576 are displayed
Time Model Statistics
Statistic Name
Time (s)
% of DB Time
DB CPU
10,060.63
76.01
parse time elapsed
8,461.29
63.93
sql execute elapsed time
6,271.82
47.39
hard parse elapsed time
5,951.34
44.96
hard parse (sharing criteria) elapsed time
18.15
0.14
PL/SQL execution elapsed time
15.16
0.11
hard parse (bind mismatch) elapsed time
8.31
0.06
failed parse elapsed time
3.53
0.03
PL/SQL compilation elapsed time
2.92
0.02
sequence load elapsed time
2.24
0.02
connection management call elapsed time
0.65
0.00
repeated bind elapsed time
0.26
0.00
DB time
13,235.66
background elapsed time
157.59
background cpu time
136.26
SQL ordered by Sharable Memory
一个sql 占用空间大1.02483463M
Sharable Mem (b)
Executions
% Total
SQL Id
SQL Module
SQL Text
1,074,722
2
0.04
67p9d6rhbhg80
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,722
2
0.04
b2r48c8mwv1pw
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,720
1
0.04
2rbxdyjc2kh98
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,718
1
0.04
76t18q2v1vsbm
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,718
1
0.04
fn52y3mx8wmhq
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,716
2
0.04
2cxfzr2xb0vnz
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,716
2
0.04
ahf940uh6qn6h
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,716
1
0.04
g7qnp8s33tym4
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,714
2
0.04
ay3p6x0ku8ps9
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,633
2
0.04
42j1ccmvt0qxc
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,632
2
0.04
g2uzmn9xm99bc
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,618
5
0.04
5mabhc2tpu1yk
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,618
3
0.04
67b1kczyhay73
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,617
3
0.04
42yjwfxb387ky
JDBC Thin Client
select * from (select "GAMS_AS...
1,074,617
2
0.04
fs2w84hjrk0sy
JDBC Thin Client
select * from (select "GAMS_AS...
latch: shared pool
Shared pool latch用来保护共享池的结构,在分配,释放共享池空间的时候就会获得该latch,那么在这个案例中,由于共享池太小,在对一个新的SQL
进行硬解析的时候需要age-out某些对象,为新对象腾出空间,那么reload对象释放空间的过程就需要获得
shared pool latch。当然了,在进行硬解析,也需要获得一个shared pool latch因为硬解析需要申请分配shared pool空间,而分配空间的时候就需要获得该latch。
参考: http://blog.csdn.net/robinson1988/article/details/6037925
--------再看个例子-------
Top 5 Timed Events
| Event | Waits | Time(s) | Avg Wait(ms) | % Total Call Time | Wait Class |
|---|---|---|---|---|---|
| gc buffer busy | 3,467,943 | 180,613 | 52 | 29.9 | Cluster |
| latch: row cache objects | 12,231,684 | 165,729 | 14 | 27.4 | Concurrency |
| enq: TX - index contention | 376,343 | 92,751 | 246 | 15.4 | Concurrency |
| buffer busy waits | 522,812 | 54,652 | 105 | 9.0 | Concurrency |
| gc cr block 2-way | 3,406,206 | 22,579 | 7 | 3.7 | Cluster |
对于oracle数据库中的latch,如果进程无法获得某个latch,那么会进行自旋,我们称为spin,经过一段时间后再次申请获得该latch,如果仍然无法获得,那么继续进行自旋状态,每次的时间间隔逐渐增加,以此类推。如果spin次数达到_spin_count(默认为2000,当前该系统为4000)之后,仍然无法获得该latch,那么该进程将进行sleep状态,经过一段时间后,该进程将被唤醒,继续申请获得该latch,每sleep 1次,Sleeps指标的值加1. spin和sleep的区别是spin消耗cpu,sleep不消耗cpu
| Cache | Get Requests | Pct Miss | Scan Reqs | Pct Miss | Mod Reqs | Final Usage |
|---|---|---|---|---|---|---|
| dc_awr_control | 42 | 2.38 | 0 |
|
1 | 1 |
| dc_database_links | 508 | 0.00 | 0 |
|
0 | 2 |
| dc_files | 26,978 | 0.00 | 0 |
|
0 | 329 |
| dc_global_oids | 1,052 | 0.00 | 0 |
|
0 | 83 |
| dc_histogram_data | 2,066 | 1.55 | 0 |
|
0 | 4,712 |
| dc_histogram_defs | 2,747 | 2.91 | 0 |
|
0 | 4,469 |
| dc_object_grants | 30 | 0.00 | 0 |
|
0 | 39 |
| dc_object_ids | 5,670 | 0.76 | 0 |
|
0 | 2,237 |
| dc_objects | 2,683 | 1.75 | 0 |
|
12 | 1,357 |
| dc_profiles | 260 | 0.00 | 0 |
|
0 | 1 |
| dc_rollback_segments | 46,605,094 | 0.00 | 0 |
|
620 | 1,237 |
| dc_segments | 7,324 | 5.20 | 0 |
|
450 | 2,246 |
| dc_sequences | 5,953 | 71.41 | 0 |
|
5,953 | 9 |
| dc_tablespace_quotas | 417 | 6.71 | 0 |
|
417 | 18 |
| dc_tablespaces | 118,147 | 0.00 | 0 |
|
0 | 87 |
| dc_usernames | 3,064 | 0.00 | 0 |
|
0 | 54 |
| dc_users | 22,432 | 0.00 | 0 |
|
0 | 81 |
| outstanding_alerts | 534 | 95.88 | 0 |
|
12 | 13 |
Back to Dictionary Cache Statistics
Back to Top
buffer busy waits不单单是数据块上的,
| Class | Waits | Total Wait Time (s) | Avg Time (ms) |
|---|---|---|---|
| data block | 2,231,323 | 196,045 | 88 |
| undo header | 1,120,177 | 14,488 | 13 |
| undo block | 306,896 | 4,050 | 13 |
| 2nd level bmb | 2,300 | 26 | 11 |
| 1st level bmb | 514 | 3 | 6 |
| segment header | 118 | 1 | 6 |
| system undo header | 4 | 0 | 20 |
| file header block | 1 | 0 | 0 |
| system undo block | 1 | 0 | 0 |
Back to Wait Statistics
Back to Top
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29990276/viewspace-1629560/ ,如需转载,请注明出处,否则将追究法律责任。