Ubuntu 上监控 Oracle 性能的可落地方案
一 监控体系与工具选型
二 快速上手的命令行监控
col inst_sid heading "INST_ID|:SID" format a7
col username format a10
col machine format a12
col sql_exec_start heading "SQL|START|D HH:MM:SS" format a11
col sql_id format a13
col sql_text format a40
col event format a33
col wait_sec heading "WAIT|(SEC)" format 99999
set linesize 200
select ses.inst_id||chr(58)||ses.sid as inst_sid,
username,
(sysdate - sql_exec_start) day(1) to second(0) as sql_exec_start,
ses.sql_id,
substr(sql.sql_text,1,40) sql_text,
substr(case time_since_last_wait_micro
when 0 then (case wait_class when 'Idle' then 'IDLE: '||event else event end)
else 'ON CPU' end,1,33) event,
(case time_since_last_wait_micro
when 0 then wait_time_micro
else time_since_last_wait_micro end) /1000000 wait_sec
from gv$session ses, gv$sqlstats sql
where ses.inst_id||chr(58)||ses.sid <> sys_context('USERENV','INSTANCE')||chr(58)||sys_context('USERENV','SID')
and username is not null
and status='ACTIVE'
and ses.sql_id = sql.sql_id (+)
order by sql_exec_start, username, ses.sid, ses.sql_id;
三 图形化与平台化监控
四 关键指标与阈值建议
五 告警与自动化巡检脚本
set linesize 200
col tablespace_name for a30
select tablespace_name, round((used_space/ total_space)*100,2) pct_used
from (
select df.tablespace_name,
sum(fs.bytes) used_space,
sum(df.bytes) total_space
from dba_data_files df,
dba_free_space fs
where df.file_id = fs.file_id(+)
group by df.tablespace_name
)
where round((used_space/ total_space)*100,2) > 80
order by pct_used desc;
-- 超过 5 分钟未提交的会话
select sid, serial#, username, sql_id, last_call_et/60 mins_inactive
from v$session
where status='ACTIVE' and last_call_et > 300
order by mins_inactive desc;