DBAtlas · 数据库运维图谱

查看主要等待事件

Oracle

SELECT event, total_waits, time_waited, ROUND(time_waited/100,2) AS sec_waited
FROM v$system_event
WHERE wait_class <> 'Idle'
ORDER BY time_waited DESC
FETCH FIRST 20 ROWS ONLY;
-- For real-time analysis: v$active_session_history (ASH)

v$system_event 给出累计等待事件;v$active_session_history 给出最近几分钟的活动会话采样(需要 Diagnostics Pack 许可)。

PostgreSQL

SELECT wait_event_type, wait_event, count(*)
FROM pg_stat_activity
WHERE wait_event IS NOT NULL AND state = 'active'
GROUP BY 1, 2
ORDER BY 3 DESC;

pg_stat_activity 显示当前等待状态;反复采样(轮询)可揭示最频繁的等待事件。

MySQL

SELECT event_name, count_star, sum_timer_wait,
       ROUND(sum_timer_wait/1000000000000, 2) AS sec_waited
FROM performance_schema.events_waits_summary_global_by_event_name
WHERE count_star > 0
ORDER BY sum_timer_wait DESC
LIMIT 20;

events_waits_summary_global_by_event_name 给出每个事件的总等待时间(以皮秒为单位);必须启用等待 instrument。

SQL Server

SELECT wait_type, waiting_tasks_count, wait_time_ms,
       signal_wait_time_ms, wait_time_ms - signal_wait_time_ms AS resource_wait_ms
FROM sys.dm_os_wait_stats
WHERE wait_time_ms > 0
ORDER BY wait_time_ms DESC;

sys.dm_os_wait_stats 显示自实例启动以来的累计等待类型;可用 DBCC SQLPERF 重置。

MongoDB

db.serverStatus().wiredTiger.concurrentTransactions
// For general waits/congestion:
// db.serverStatus().globalLock  and  db.serverStatus().wiredTiger.cache

WiredTiger 没有传统的等待事件;concurrentTransactions(tickets)耗尽、globalLock.currentQueue 和缓存压力表明存在拥塞。

Redis

CONFIG SET latency-monitor-threshold 100
LATENCY LATEST
LATENCY HISTORY command
# For the slowest commands: SLOWLOG GET 10

设置 latency monitor 阈值后,LATENCY LATEST/HISTORY 会报告造成最大延迟的事件。

Elasticsearch

GET _nodes/hot_threads

_nodes/hot_threads 给出 CPU 消耗最高的线程的堆栈跟踪,从而揭示瓶颈。

在 DBAtlas 中打开 →