Oracle 优化 - CPU 问题

  • 作为 OLTP 应用,一般不太有 CPU 问题,比较少 - 毕竟大多数问题都是 IO 引起;但是偶尔也会有。
  • 问题判断
    • 很简单 - OS 出现 CPU 很高的问题,持续高于 90%
    • 应用可能会表现慢
  • 问题调查和解决
    • 硬件
    • 消耗 CPU 的 SQLs
    • 限制消耗 CPU 的 SQLs
  • 硬件
    • 根据经验和具体情况增加新的 CPUs,曾经很难,在目前虚拟化普遍使用的情况下,不再是太大的困扰。
  • 消耗 CPU 的 SQLs
    • AWR report 里面的 SQL ordered by CPU Time 会明确的告诉原因。比如下面红色的 SQL ID 69vuwhdz0jw51消耗了 Oracle 57% 的 CPU.
    • 这个 SQL 每次执行 0.22 秒 CPU, 实际耗时 (Elapsed Time / Executions = 0.5 秒左右);再结合具体的 SQL, 没有优化的余地,那么需要 要么修改代码减少调用次数,要么修改代码简化 SQL

SQL ordered by CPU Time

    • Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code.
    • % Total is the CPU Time divided into the Total CPU Time times 100
    • Total CPU Time (s): 56,812
    • Captured SQL account for 79.1% of Total
    • Total CPU Time (s): 56,812
    • Captured PL/SQL account for 0.9% of Total
CPU Time (s)Elapsed Time (s)ExecutionsCPU per Exec (s)% Total% Total DB TimeSQL IdSQL ModuleSQL Text
32,59596,381149,4760.2257.3747.4269vuwhdz0jw51JDBC Thin Client 
1,9405,45119010.213.412.6847y171y2nuvy9JDBC Thin Client 
1,2323,8165,7170.222.171.883x365dut1trbzJDBC Thin Client 
1,0133,1474,7220.211.781.558vmfr11dt6bb7JDBC Thin Client 
9082,7924,2250.211.601.379kxdmwbytzsbsJDBC Thin Client 
8482,1394511.881.491.059zv8ryyqzjudhJDBC Thin Client 
5641,6512,5300.220.990.81bdd9ay1mz8x22JDBC Thin Client 
5581,6372,5320.220.980.811pfxcnwp9ydw9JDBC Thin Client 
5561,6332,5320.220.980.80dwysa8fbxz8duJDBC Thin Client 
5001,4962,2880.220.880.7457jgy744z6rq3JDBC Thin Client 

    • 也可以使用下面的 SQLs 来更细的分析 TOP CPU SQLs.
  • 按照 CPU 总耗时排序 (执行次数 X 每次的 CPU 耗时)

select a.SQL_ID,c.username, CPU_TIME*0.000001 cpu_time_secs,
ELAPSED_TIME*0.000001 elapsed_time_secs,round(ELAPSED_TIME*0.000001/nvl(nullif(executions,0),1)) Elap_per_Exec,
executions,ROWS_PROCESSED,b.piece line#,b.sql_text
from v$sql a, v$sqltext b,dba_users c
where
a.address=b.address
and
(
ELAPSED_TIME*0.000001>10
or executions  > 1000
)
and executions>0
and c.user_id=a.PARSING_USER_ID
order by CPU_TIME,a.HASH_VALUE, b.piece asc

  • 按照 SQL 单次执行的CPU 耗时排序

    select c.username,CPU_TIME*0.000001 cpu_time_secs,
        ELAPSED_TIME*0.000001 elapsed_time_secs,
        round(ELAPSED_TIME*0.000001/nvl(nullif(executions,0),1)) Elap_per_Exec,
        executions,LAST_LOAD_TIME,
        b.piece line#,
        b.sql_text sql_text
from v$sql a, v$sqltext b, dba_users c
where
a.address=b.address
and
(
ELAPSED_TIME*0.000001>10
or executions  > 1000
)
and executions>0
and c.user_id=a.PARSING_USER_ID
order by Elap_per_Exec,ELAPSED_TIME,CPU_TIME,a.HASH_VALUE, b.piece asc;

 

  • 资源限制 - 终止 CPU 耗时超过一定阀值的 SQL

Create resource limit to limit SQLs which run more than 5 minutes.
alter system set resource_limit =true scope=both; (Oracle restart required to take effect)
create profile cpu_limit_3_min limit cpu_per_call 30000;  (time is in 100ths of a second)
alter user XXXX  profile cpu_limit_5_min; (change the user to use the profile)

转载于:https://www.cnblogs.com/tang88seng/p/Oracle_CPU.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值