动态性能视图v$lock访问很慢的解决办法
现象如下:我在OA生产库上执行如下语句,要3分钟左右猜出结果,但是我在其他生产库上执行结果几乎是秒出,会是什么原因?
我担心的原因,如果哪天出现session阻塞,那我岂不是要完蛋,阻塞session查不出来,kill不掉,到时估计就只能重启应用或者数据库了(PS:之前就出现过一次,不过当时并未将注意力放在这个上面)
SQL> select sid,lmode,type,request,block from v$lock where type in ('TX','TM') order by 1,3;
SID LMODE TY REQUEST BLOCK
---------- ---------- -- ---------- ----------
9 6 TX 0 2
634 6 TX 0 2
1899 6 TX 0 2
2847 6 TX 0 2
3155 6 TX 0 2
3313 6 TX 0 2
3461 6 TX 0 2
5186 6 TX 0 2
5360 6 TX 0 2
6764 6 TX 0 2
8186 3 TM 0 2
SID LMODE TY REQUEST BLOCK
---------- ---------- -- ---------- ----------
8186 6 TX 0 2
9107 6 TX 0 2
13 rows selected.
这结果出来要3分多钟
分析下语句的执行计划
SQL> set linesize 150;
SQL> select sid,lmode,type,request,block from v$lock where type in ('TX','TM') order by 1,3;
Execution Plan
----------------------------------------------------------
Plan hash value: 3010872788
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 105 | 2 (100)| 00:00:01 |
| 1 | SORT ORDER BY | | 1 | 105 | 2 (100)| 00:00:01 |
|* 2 | HASH JOIN | | 1 | 105 | 1 (100)| 00:00:01 |
| 3 | MERGE JOIN CARTESIAN | | 1 | 54 | 0 (0)| 00:00:01 |
|* 4 | FIXED TABLE FULL | X$KSUSE | 1 | 32 | 0 (0)| 00:00:01 |
| 5 | BUFFER SORT | | 1 | 22 | 0 (0)| 00:00:01 |
|* 6 | FIXED TABLE FULL | X$KSQRS | 1 | 22 | 0 (0)| 00:00:01 |
| 7 | VIEW | GV$_LOCK | 10 | 510 | 0 (0)| 00:00:01 |
| 8 | UNION-ALL | | | | | |
|* 9 | FILTER | | | | | |
| 10 | VIEW | GV$_LOCK1 | 2 | 102 | 0 (0)| 00:00:01 |
| 11 | UNION-ALL | | | | | |
|* 12 | FIXED TABLE FULL| X$KDNSSF | 1 | 77 | 0 (0)| 00:00:01 |
|* 13 | FIXED TABLE FULL| X$KSQEQ | 1 | 77 | 0 (0)| 00:00:01 |
|* 14 | FIXED TABLE FULL | X$KTADM | 1 | 77 | 0 (0)| 00:00:01 |
|* 15 | FIXED TABLE FULL | X$KTATRFIL | 1 | 77 | 0 (0)| 00:00:01 |
|* 16 | FIXED TABLE FULL | X$KTATRFSL | 1 | 77 | 0 (0)| 00:00:01 |
|* 17 | FIXED TABLE FULL | X$KTATL | 1 | 77 | 0 (0)| 00:00:01 |
|* 18 | FIXED TABLE FULL | X$KTSTUSC | 1 | 77 | 0 (0)| 00:00:01 |
|* 19 | FIXED TABLE FULL | X$KTSTUSS | 1 | 77 | 0 (0)| 00:00:01 |
|* 20 | FIXED TABLE FULL | X$KTSTUSG | 1 | 77 | 0 (0)| 00:00:01 |
|* 21 | FIXED TABLE FULL | X$KTCXB | 1 | 77 | 0 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("SADDR"="S"."ADDR" AND TO_CHAR(USERENV('INSTANCE'))||RAWTOHEX("R
ADDR")=TO_CHAR("R"."INST_ID")||RAWTOHEX("R"."ADDR"))
4 - filter("S"."INST_ID"=USERENV('INSTANCE'))
6 - filter("R"."KSQRSIDT"='TM' OR "R"."KSQRSIDT"='TX')
9 - filter(USERENV('INSTANCE') IS NOT NULL)
12 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
13 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
14 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
15 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
16 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
17 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
18 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
19 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
20 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSOBFLG",1)<>0)
21 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND
"INST_ID"=USERENV('INSTANCE') AND BITAND("KSSPAFLG",1)<>0)
做level12的10046事件
SQL> alter session set events '10046 trace name context forever, level 12';
Session altered.
SQL> select sid,lmode,type,request,block from v$lock where type in ('TX','TM') order by 1,3;
SID LMODE TY REQUEST BLOCK
---------- ---------- -- ---------- ----------
634 6 TX 0 2
2847 6 TX 0 2
3461 6 TX 0 2
3631 6 TM 0 2
5186 6 TX 0 2
5829 6 TX 0 2
6458 6 TX 0 2
9426 6 TX 0 2
8 rows selected.
SQL> alter session set events '10046 trace name context off';
Session altered.
tkprof出来的trace文件
TKPROF: Release 11.2.0.3.0 - Development on Fri Mar 1 13:54:30 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Trace file: oaprod1_ora_16214.trc
Sort options: default
********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************
SQL ID: c4ghdvdm6vbfv Plan Hash: 3010872788
select sid,lmode,type,request,block
from
v$lock where type in ('TX','TM') order by 1,3
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.02 0.02 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 310.83 402.58 952800 0 8 8
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 310.86 402.60 952800 0 8 8
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
8 8 8 SORT ORDER BY (cr=0 pr=952800 pw=952800 time=402582277 us cost=2 size=105 card=1)
8 8 8 HASH JOIN (cr=0 pr=952800 pw=952800 time=382540704 us cost=1 size=105 card=1)
134180992 134180992 134180992 MERGE JOIN CARTESIAN (cr=0 pr=0 pw=0 time=107803810 us cost=0 size=54 card=1)
10048 10048 10048 FIXED TABLE FULL X$KSUSE (cr=0 pr=0 pw=0 time=145542 us cost=0 size=32 card=1)
134180992 134180992 134180992 BUFFER SORT (cr=0 pr=0 pw=0 time=51017140 us cost=0 size=22 card=1)
13354 13354 13354 FIXED TABLE FULL X$KSQRS (cr=0 pr=0 pw=0 time=26869 us cost=0 size=22 card=1)
480 480 480 VIEW GV$_LOCK (cr=0 pr=0 pw=0 time=18205 us cost=0 size=510 card=10)
480 480 480 UNION-ALL (cr=0 pr=0 pw=0 time=18081 us)
472 472 472 FILTER (cr=0 pr=0 pw=0 time=17267 us)
472 472 472 VIEW GV$_LOCK1 (cr=0 pr=0 pw=0 time=17139 us cost=0 size=102 card=2)
472 472 472 UNION-ALL (cr=0 pr=0 pw=0 time=16784 us)
0 0 0 FIXED TABLE FULL X$KDNSSF (cr=0 pr=0 pw=0 time=12111 us cost=0 size=77 card=1)
472 472 472 FIXED TABLE FULL X$KSQEQ (cr=0 pr=0 pw=0 time=4068 us cost=0 size=77 card=1)
0 0 0 FIXED TABLE FULL X$KTADM (cr=0 pr=0 pw=0 time=108012 us cost=0 size=77 card=1)
0 0 0 FIXED TABLE FULL X$KTATRFIL (cr=0 pr=0 pw=0 time=29 us cost=0 size=77 card=1)
0 0 0 FIXED TABLE FULL X$KTATRFSL (cr=0 pr=0 pw=0 time=12 us cost=0 size=77 card=1)
0 0 0 FIXED TABLE FULL X$KTATL (cr=0 pr=0 pw=0 time=150 us cost=0 size=77 card=1)
0 0 0 FIXED TABLE FULL X$KTSTUSC (cr=0 pr=0 pw=0 time=452 us cost=0 size=77 card=1)
0 0 0 FIXED TABLE FULL X$KTSTUSS (cr=0 pr=0 pw=0 time=172 us cost=0 size=77 card=1)
0 0 0 FIXED TABLE FULL X$KTSTUSG (cr=0 pr=0 pw=0 time=169 us cost=0 size=77 card=1)
8 8 8 FIXED TABLE FULL X$KTCXB (cr=0 pr=0 pw=0 time=63711 us cost=0 size=77 card=1)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
asynch descriptor resize 174 0.00 0.00
Disk file operations I/O 1 0.00 0.00
CSS initialization 2 0.02 0.02
CSS operation: action 2 0.01 0.02
CSS operation: query 6 0.00 0.00
direct path write temp 30839 0.51 29.56
direct path read temp 63516 0.26 64.82
SQL*Net message from client 2 80.46 80.46
********************************************************************************
SQL ID: 06nvwn223659v Plan Hash: 0
alter session set events '10046 trace name context off'
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Parsing user id: SYS
********************************************************************************
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.02 0.02 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 310.83 402.58 952800 0 8 8
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 6 310.86 402.60 952800 0 8 8
Misses in library cache during parse: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 3 0.00 0.00
SQL*Net message from client 3 80.46 102.99
asynch descriptor resize 174 0.00 0.00
Disk file operations I/O 1 0.00 0.00
CSS initialization 2 0.02 0.02
CSS operation: action 2 0.01 0.02
CSS operation: query 6 0.00 0.00
direct path write temp 30839 0.51 29.56
direct path read temp 63516 0.26 64.82
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 0 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
********************************************************************************
Trace file: oaprod1_ora_16214.trc
Trace file compatibility: 11.1.0.7
Sort options: default
1 session in tracefile.
2 user SQL statements in trace file.
0 internal SQL statements in trace file.
2 SQL statements in trace file.
2 unique SQL statements in trace file.
95414 lines in trace file.
483 elapsed seconds in trace file.
从上面分析来看竟然有大量的读,有些不可思议,找不到原因只好去support.oracle.com发SR寻求帮助
oracle给了回复如下:
这个问题是由于oracle没有对fixed object进行stats收集.
请执行以后命令收集fixed object的统计个息, 再测试一下这个问题.
SQL> exec DBMS_STATS.gather_fixed_objects_stats();
或者,
在查询上加个/*+rule*/的hint再测试一下.
select /*+rule*/ sid,lmode,type,request,block from v$lock where type in ('TX','TM') order by 1,3;
至此问题已经基本结果,v$lock查询时间正常
转载于:https://blog.51cto.com/yeluyide/1144367
动态性能视图v$lock访问很慢的解决办法相关推荐
- Oracle 动态性能视图 (x$, v$, gv$, v_$, gv_$)
sys : x$(内存对象))--->v$(内存对象)---->v_$(view)----->v$(public sysnonym) 一. 动态性能视图 1.1 动态性能图 动态性 ...
- Oracle 原理 : 动态性能视图和数据字典
Oracle 的数据字典包含了两部分:数据字典表和数据字典视图.数据字典基本表是由$ORACLE_HOME\RDBMS\ADMIN\sql.bsq这文件所创建.表名大多以$结尾,属于sys用户,放在S ...
- DM7 常用动态性能视图及使用方法
DM7 常用动态性能视图及使用方法 前言 一.视图分类 二.常用视图用法 1.v$BUFFERPOOL 2.v$CACHEITEM 3.v$CACHEPLN 4.v$CKPT_HISTORY 5.v$ ...
- oracle 条件动态视图,oracle最重要的9个动态性能视图
oracle最重要的9个动态性能视图 v$session v$session_wait (在10g里功能被整合,凑合算1个吧.) v$process v$sql v$sqltext v$bh (更宁愿 ...
- Oracle 9i学习日志(9)--数据字典与动态性能视图及练习
一.数据字典 不仅是每个Oracle数据库的核心组件之一,也是所有数据库用户重要的信息资源:描述数据与对象的数据:包含只读的表和视图:存储在系统表空间:所有者为sys:由Oracle server维护 ...
- ORACLE常用的动态性能视图
V$FIXED_TABLE用于列出所有可用的动态性能视图和动态性能表. V$INSTANCE用于获取当前例程的详细信息. V$SGA用于取得SGA更详细的信息. V$PARAMETER用于取得初始化参 ...
- 十三、oracle 数据字典和动态性能视图
一.概念 数据字典是oracle数据库中最重要的组成部分,它提供了数据库的一些系统信息. 动态性能视图记载了例程启动后的相关信息. 二.数据字典 1).数据字典记录了数据库的系统信息,它是只读表和视图 ...
- oracle 查看动态性能视图,oracle常用动态性能视图
今天通过视频学习,和网上搜索总结了一些oracle 常用的动态性能视图和大家分享 要查看oralce有哪些可用的动态性能视图可以看v$fixed_table 1.关于数据库/实例的动态性能视图 v$d ...
- oracle报错查询动态视图,oracle基表和动态性能视图
1. 数据字典是oracle数据库中最重要的组成部分,它提供了数据库的一些系统信息.它是只读表和视图的集合,所有者为sys用户.用户自能在数据字典上执行查询操作,而维护和修改是由系统自动完成的. 数据 ...
最新文章
- 解决Jetty Maven Plugin:Please initialize the log4j system properly(转)
- 在DataGrid(WebControl)中处理DropDownList事件的补充说明
- 福建2020年3月计算机二级报名时间,福建2020年3月计算机等级考试报名时间
- ACM/ICPC2014鞍山现场赛E hdu5074Hatsune Miku
- 字符串不替代_使用第三方库demjson解析不规范的json字符串
- Android HTTP必知必会
- 2.1.3 计算机网络之编码与调制
- Android 中的LayoutInflater的理解
- Servlet使用适配器模式进行增删改查案例(DeptDaoImpl.java)
- Java笔记-为客户端及服务端创建公私钥的密钥库
- spring邮件发送(转)
- linux readelf,readelf命令常用参数介绍
- 单相电机正反转接线图_单相电机正反转原理及接线图(多图)
- minic 动作句型处理
- 合唱队形(线性DP)
- 计算机课艺术字四周型怎么弄,Word.文档中艺术字环绕方式四周型怎么设置
- 更改bootstrap工具提示-tooltip
- Prometheus监控实战系列十七:探针监控
- 你不知道的CS模式的进程管理工具,状态监测、项目启停一目了然!
- S60手机使用putty进行ssh登录