昨天中秋節,本該是團圓的好日子,苦逼的運維我還要值班(哈哈,吐槽一下)本覺得會沒有啥事,誰知道比較重要的一臺Oracle服務器忽然報警,CPU 2個core都飆到100%,load average也比較高,以下圖:sql
AWS CloudWatch也能夠看出來CPU長期使用率100%數據庫
從圖可得:系統us比較高,sy基本能夠忽略,Memory和IO都已經檢查過,不存在瓶頸,根據以往經驗,極有多是Oracle數據庫有SQL在長時間運行,而且沒有釋放,登陸到數據庫查看,能夠看到sid爲410,408,404進程執行的都是同一個SQL,bash
SYS@xxxxxx>SELECT b.sid oracleID, b.username, b.serial#, spid, paddr, b.machine, c.sql_text FROM v$process a, v$session b, v$sqlarea c WHERE a.addr = b.paddr AND b.sql_hash_value = c.hash_value; ORACLEID USERNAME SERIAL# SPID PADDR MACHINE ---------- ------------------------------ ---------- ------------------------ ---------------- ---------------------------------------------------------------- SQL_TEXT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 410 PRERNAP2 371 16743 00000002DEC84E60 Prernap2-mbr with cte as(select distinct weekdate, week_month, week_year, SHIPTO, BUYERPARTNUMBER, dense_rank() over(partition by week_year,SHIPTO, BUYERPARTNUMBER, week_month order by weekdate) as rank_week FROM (Select weekdate, to_char(weekdate, 'MM') as week_month, to_char(weekdate, 'YYYY') as week_year, SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by weekdate), cte1 as (select foreca stdate,forecast_month, forecast_year, shipto, buyerpartnumber from (select to_date(forecastdate, 'YYYYMMDD') as forecastdate, TO_CHAR(to_date(forecastdate, 'YYYYMMDD'), 'MM' ) as forecast_month, TO_C HAR(to_date(forecastdate, 'YYYYMMDD'), 'YYYY' ) as forecast_year,SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by forecastdate ), cte2 as (select cte.shipto, cte.buyerpartnumber,ct e.week_month, cte.week_year, max(rank_week) as max_week from cte group by cte.shipto, cte.buyerpartnumber,cte.week_month, cte.week_year), cte4 as (select cte2.*, cte1.forecast_month, cte1.forecast_y 408 PRERNAP21163 15129 00000002DEC916A0 Prernap2-mbr with cte as(select distinct weekdate, week_month, week_year, SHIPTO, BUYERPARTNUMBER, dense_rank() over(partition by week_year,SHIPTO, BUYERPARTNUMBER, week_month order by weekdate) as rank_week FROM (Select weekdate, to_char(weekdate, 'MM') as week_month, to_char(weekdate, 'YYYY') as week_year, SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by weekdate), cte1 as (select foreca stdate,forecast_month, forecast_year, shipto, buyerpartnumber from (select to_date(forecastdate, 'YYYYMMDD') as forecastdate, TO_CHAR(to_date(forecastdate, 'YYYYMMDD'), 'MM' ) as forecast_month, TO_C HAR(to_date(forecastdate, 'YYYYMMDD'), 'YYYY' ) as forecast_year,SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by forecastdate ), cte2 as (select cte.shipto, cte.buyerpartnumber,ct e.week_month, cte.week_year, max(rank_week) as max_week from cte group by cte.shipto, cte.buyerpartnumber,cte.week_month, cte.week_year), cte4 as (select cte2.*, cte1.forecast_month, cte1.forecast_y 18 PRERNAP2 311 19710 00000002DEC948B0 Prernap2-mbr with cte as(select distinct weekdate, week_month, week_year, SHIPTO, BUYERPARTNUMBER, dense_rank() over(partition by week_year,SHIPTO, BUYERPARTNUMBER, week_month order by weekdate) as rank_week FROM (Select weekdate, to_char(weekdate, 'MM') as week_month, to_char(weekdate, 'YYYY') as week_year, SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by weekdate), cte1 as (select foreca stdate,forecast_month, forecast_year, shipto, buyerpartnumber from (select to_date(forecastdate, 'YYYYMMDD') as forecastdate, TO_CHAR(to_date(forecastdate, 'YYYYMMDD'), 'MM' ) as forecast_month, TO_C HAR(to_date(forecastdate, 'YYYYMMDD'), 'YYYY' ) as forecast_year,SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by forecastdate ), cte2 as (select cte.shipto, cte.buyerpartnumber,ct e.week_month, cte.week_year, max(rank_week) as max_week from cte group by cte.shipto, cte.buyerpartnumber,cte.week_month, cte.week_year), cte4 as (select cte2.*, cte1.forecast_month, cte1.forecast_y 404 PRERNAP2 665 21911 00000002DEC95960 Prernap2-mbr with cte as( select distinct weekdate, week_month, week_year, SHIPTO, BUYERPARTNUMBER, dense_rank() over(partition by week_year,SHIPTO, BUYERPARTNUMBER, week_month order by weekdate) as rank_week FROM (Select weekdate, to_char(weekdate, 'MM') as week_month, to_char(weekdate, 'YYYY') as week_year, SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by weekdate ), cte1 as ( select for ecastdate,forecast_month, forecast_year, shipto, buyerpartnumber from (select to_date(forecastdate, 'YYYYMMDD') as forecastdate, TO_CHAR(to_date(forecastdate, 'YYYYMMDD'), 'MM' ) as forecast_month, T O_CHAR(to_date(forecastdate, 'YYYYMMDD'), 'YYYY' ) as forecast_year,SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by forecastdate ), cte2 as ( select cte.shipto, cte.buyerpartnumbe r,cte.week_month, cte.week_year, max(rank_week) as max_week , cte1.forecast_month, cte1.forecast_year from cte inner join cte1 on cte1.forecast_year>=cte.week_year and cte.shipto = cte1.shipto and c 22 SYS 447 23888 00000002DEC96A10 ec2-admart-01 SELECT b.sid oracleID, b.username, b.serial#, spid,paddr, b.machine,c.sql_text FROM v$process a, v$session b, v$sqlarea c WHERE a.addr = b.paddrAND b.sq l_hash_value = c.hash_value 387 PRERNAP2 313 24261 00000002DEC97AC0 Prernap2-mbr with cte as( select distinct weekdate, week_month, week_year, SHIPTO, BUYERPARTNUMBER, dense_rank() over(partition by week_year,SHIPTO, BUYERPARTNUMBER, week_month order by weekdate) as rank_week FROM (Select weekdate, to_char(weekdate, 'MM') as week_month, to_char(weekdate, 'YYYY') as week_year, SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by weekdate ), cte1 as ( select for ecastdate,forecast_month, forecast_year, shipto, buyerpartnumber from (select to_date(forecastdate, 'YYYYMMDD') as forecastdate, TO_CHAR(to_date(forecastdate, 'YYYYMMDD'), 'MM' ) as forecast_month, T O_CHAR(to_date(forecastdate, 'YYYYMMDD'), 'YYYY' ) as forecast_year,SHIPTO, BUYERPARTNUMBER from AUTO.ford_forecast_details ) order by forecastdate ), cte2 as ( select cte.shipto, cte.buyerpartnumbe r,cte.week_month, cte.week_year, max(rank_week) as max_week , cte1.forecast_month, cte1.forecast_year from cte inner join cte1 on cte1.forecast_year>=cte.week_year and cte.shipto = cte1.shipto and c 6 rows selected. SYS@xxxxxx>select b.sid,b.serial#,b.machine,b.terminal,b.program,b.process,b.status from v$lock a, v$session b where a.SID = b.SID and username is not null and username not in ('SYS','SYSTEM'); SID SERIAL# MACHINE TERMINAL PROGRAM PROCESS STATUS ---------- ---------- ---------------------------------------------------------------- ------------------------------ ------------------------------------------------ ------------------------ -------- 387 313 Prernap2-mbr unknown SQL Developer 6246 ACTIVE 387 313 Prernap2-mbr unknown SQL Developer 6246 ACTIVE 404 665 Prernap2-mbr unknown SQL Developer 4145 ACTIVE 387 313 Prernap2-mbr unknown SQL Developer 6246 ACTIVE 387 313 Prernap2-mbr unknown SQL Developer 6246 ACTIVE 408 1163 Prernap2-mbr unknown SQL Developer 3377 ACTIVE 387 313 Prernap2-mbr unknown SQL Developer 6246 ACTIVE 387 313 Prernap2-mbr unknown SQL Developer 6246 ACTIVE 404 665 Prernap2-mbr unknown SQL Developer 4145 ACTIVE 408 1163 Prernap2-mbr unknown SQL Developer 3377 ACTIVE 410 371 Prernap2-mbr unknown SQL Developer 5691 ACTIVE 18 311 Prernap2-mbr unknown SQL Developer 1497 ACTIVE 20 221 Prernap2-mbr unknown SQL Developer 4689 ACTIVE 20 221 Prernap2-mbr unknown SQL Developer 4689 ACTIVE 387 313 Prernap2-mbr unknown SQL Developer 6246 ACTIVE 15 rows selected. SYS@xxxxxx>select sid, username, blocking_session from v$session where blocking_session is not null; SID USERNAME BLOCKING_SESSION ---------- ------------------------------ ---------------- 18 PRERNAP2 408 387 PRERNAP2 404 410 PRERNAP2 408 SYS@xxxxxx>select sid, serial#, username from v$session where sid='410'; SID SERIAL# USERNAME ---------- ---------- ------------------------------ 410 371 PRERNAP2
解決方法服務器
找到開發人員,詢問緣由,獲得的反饋是在測試幾條SQL(我擦,居然在生產環境測試SQL,哎,一點敬畏之心都沒有,可怕!)session
kill掉blocked的進程,釋放資源,再這麼跑下去,系統隨時可能崩潰,最後去優化一下的SQL,再去執行oracle
alter system kill session '410,371';
運維
......其餘幾個進程同理幹掉便可ide