A Case about cursor_sharing=FORCE can introduce a execute plan stale

今天一位同事带着非常忐忑的心情来找我,棋牌项目的ORACLE数据库负载过高。

我连上服务器一看,果然,LOAD 100多。IOWAIT非常低。

再TOP一下,发现ACTIVE进程非常多,单个消耗CPU在20%左右。

然后这位同事跟我描述了一下,今天上了一个推广的活动,可能导致业务量猛增,我开始怀疑是正常的业务请求。

--- 此处省略1000字。

于是开始抓STATSPACK报告,不过LOAD 100多抓起来非常呛。

最终发现以下SQL消耗CPU过多。

因为开启了cursor_sharing=FORCE,这条SQL执行计划被锁定了(后面会有处理办法)。

  Elapsed                Elap per            CPU                        Old
  Time (s)   Executions  Exec (s)  %Total   Time (s)  Physical Reads Hash Value
---------- ------------ ---------- ------ ---------- --------------- ----------
 353348.79       29,044      12.17   87.6   29731.62               0 1523025606
select *     from CAC_xxxxxx     where      :"SY
S_B_0" = :"SYS_B_1"             and        GAME_ID = :1
    and        SKY_ID = :2            and START_TIME >(sysDate -
 :"SYS_B_2")      and (TASK_STATUS = :"SYS_B_3" or TASK_STATUS =
 -:"SYS_B_4")        order by START_TIME desc

于是去看一看执行计划 : 

Plan hash value: 4233498801 

----------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                       | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                            |     1 |    95 |    62   (2)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE ITERATOR           |                            |     1 |    95 |    62   (2)| 00:00:01 |    27 |   KEY |
|   2 |   SORT ORDER BY                     |                            |     1 |    95 |    62   (2)| 00:00:01 |       |       |
|*  3 |    TABLE ACCESS BY LOCAL INDEX ROWID| CAC_xxxxxx |     1 |    95 |    61   (0)| 00:00:01 |    27 |   KEY |
|*  4 |     INDEX RANGE SCAN                | IDX_ACH_SKY_ID             |     6 |       |    55   (0)| 00:00:01 |    27 |   KEY |
----------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   3 - filter(("TASK_STATUS"=(-1) OR "TASK_STATUS"=1) AND "START_TIME">SYSDATE@!-1 AND "GAME_ID"=1)
   4 - access("SKY_ID"=1)

17 rows selected.

从现象上来看,执行计划是对的。

因为cursor_sharing=FORCE,执行计划固化。

为了保险起见,还是对这个表收集了一把统计信息

EXEC DBMS_STATS.GATHER_table_STATS (OWNNAME => 'username',TABNAME =>'CAC_XXXXXX',METHOD_OPT => 'FOR ALL',estimate_percent=>5,cascade => true);

收集完后,数据库负载当然还是那么高滴。

现在要做得是把执行计划解固。

SQL> alter system flush shared_pool;

缓存的执行计划随着shared_pool清空而清空。

清空后立刻见效:

oracle@db-digoal-> vmstat -n 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
112  1      0 3957260 286444 18216008    0    0    51    58 1593 8418 100  0  0  0  0
93  3      0 3955432 286444 18217096    0    0  1175   993 1660 9244 99  0  0  0  0
74  2      0 3951096 286444 18220176    0    0  3311  2090 1980 10706 99  0  0  0  0
62  5      0 3904224 286444 18264240    0    0 44602   193 2713 20304 97  1  1  1  0
 4  3      0 3830140 286444 18329288    0    0 66340 73856 11196 67220 54  5 34  6  0
 2  3      0 3660048 286448 18493348    0    0 164539  1067 11295 67007 19  6 69  7  0
10  5      0 3494580 286448 18653152    0    0 159327  2159 9271 35820 10  4 77  9  0
 7  3      0 3375788 286448 18765216    0    0 112467  8500 12912 36616 14  5 70 12  0
 0  2      0 3223936 286448 18911064    0    0 146187  2815 12425 40537 10  4 76 10  0
 0  5      0 3057604 286448 19024216    0    0 112646 304645 9411 19671  5  4 81 10  0

CPU过高在数据库里面其实是一个比较经典的案例,有硬解析造成的,有执行计划不优造成的等等。

这次也不例外,归根结底就是执行计划的问题。

时间: 2024-09-12 03:55:59

A Case about cursor_sharing=FORCE can introduce a execute plan stale的相关文章

由cursor_sharing=force导致的ora-600错误

1.在alert_lxdb.log日志中报600错误 Errors in file /u01/app/oracle/admin/lxdb/udump/lxdb_ora_50379.trc: ORA-00600: internal error code, arguments: [kkslhsh1], [101], [], [], [], [], [], [] 注意这个问题可能会导致产生非常大的trc 文件而导致 文件系统满! 2.本问题的产生根本原因: 设置了 cursor_sharing = f

[20150513]函数索引与CURSOR_SHARING=FORCE

[20150513]函数索引与CURSOR_SHARING=FORCE.txt --经常awr报表,大量听到的建议是你们的应用没有使用绑定变量.国内的许多项目这个问题更加严重,我敢打赌国内80%甚至更高的比例在 --应用中没有绑定变量(OLTP系统). --如果一个新项目我只要看一下程序使用绑定变量的情况,就知道这个项目是垃圾还是豆腐渣工程.到目前为止我接触的项目仅仅有1个做 --的稍微好一点. --如果不修改代码,一个最简单的方式就是修改参数CURSOR_SHARING = FORCE(补充一

[20130313]cursor_sharing=force的问题.txt

[20130313]cursor_sharing=force的问题.txt 前一阵子,我把生产系统的cursor_sharing设置为force, 大概按照链接: http://space.itpub.net/267265/viewspace-754003 我发现一个奇怪的问题,自己在测试环境重复测试看看. 1.建立测试环境: SQL> select * from v$version where rownum BANNER ------------------------------------

补充:小心设置cursor_sharing=force参数

转载自:http://www.itpub.net/351520,2.html摘自:expert one-on-one oracle  (P554)設置cussor_sharing=force之後,會有以下的情況: • Optimizer related issues – CURSOR_SHARING will remove all character string and numeric constants from the query; the optimizer will have less

小心设置cursor_sharing=force参数

原文:http://www.itpub.net/339204.html 我们公司的数据库,开发商没有很好地使用绑定变量,我星期天我打开了这个参数,想看看结果如何,结果出现严重的问题,今天早上忙呼一阵. 1.执行像如下的sql语句,CPU的使用率会上升到100%.无法使用oracle的命令删除回话,在unix下使用kill杀掉进程.windows就没有这么幸运,只能重启oracle服务. SELECT a.exp_alias "名称", b.supply "供应商",

ANNOUNCEMENT: Deprecating the cursor_sharing = ‘SIMILAR’

ANNOUNCEMENT: Deprecating the cursor_sharing = 'SIMILAR' setting [ID 1169017.1] Applies to:Oracle Server - Enterprise Edition - Version: 11.1.0.6 to 11.2.0.2 - Release: 11.1 to 11.2Information in this document applies to any platform. What is being a

[20160517]11GR2Cursor_Sharing=force的bug

[20160517]11GR2Cursor_Sharing=force的bug.txt --链接https://jonathanlewis.wordpress.com/2016/05/16/cursor_sharing-problem/,重复测试: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING         VERSION    BANNER ------------------- ---------- --------------------------

20170330cursor_sharing=force改变显示宽度

[20170330]参数cursor_sharing=force改变显示宽度.txt --//前几天遇到的问题,链接http://www.itpub.net/thread-2085766-1-1.html --//开始以为是11.2.0.3特有的问题,下班后才知道这个问题可能来自参数cursor_sharing=force,实际上我扫描alert文件才发现是这个 --//问题.感谢zergduan的提醒,应该从参数之类入手检查.实际上当时看到这个修改马上明白这个问题(我前几天修改了这个参数全局有

[20140802]cursor_sharing=similar.txt

[20140802]cursor_sharing=similar.txt --晚上看了http://www.dbaxiaoyu.com/archives/2248,在 cursor_sharing='similar'的情况下,会出现N多子光标(如果查询字段有直方 --图的情况下).实际上oracle在以后的版本会淘汰调cursor_sharing=similar的情况. SCOTT@test01p> @ver BANNER