DBAtlas · 数据库运维图谱

查看长时间运行操作的进度

Oracle

SELECT sid, serial#, opname, target, sofar, totalwork,
       ROUND(sofar / NULLIF(totalwork,0) * 100, 2) AS pct_done,
       time_remaining, elapsed_seconds
FROM v$session_longops
WHERE totalwork > 0 AND sofar < totalwork
ORDER BY start_time;

v$session_longops 显示运行超过 6 秒的操作的完成百分比和剩余时间(time_remaining)。

PostgreSQL

SELECT pid, phase, heap_blks_total, heap_blks_scanned,
       ROUND(heap_blks_scanned::numeric / NULLIF(heap_blks_total,0) * 100, 2) AS pct
FROM pg_stat_progress_vacuum;
-- Others: pg_stat_progress_create_index, _cluster, _analyze, _copy, _basebackup

pg_stat_progress_* 视图报告 VACUUM、CREATE INDEX、CLUSTER、ANALYZE 和 COPY 操作的进度。

MySQL

SELECT t.processlist_id, st.event_name, st.work_completed, st.work_estimated,
       ROUND(st.work_completed / NULLIF(st.work_estimated,0) * 100, 2) AS pct
FROM performance_schema.events_stages_current st
JOIN performance_schema.threads t ON t.thread_id = st.thread_id
WHERE st.work_estimated > 0;

启用 stage instrumentation 后,events_stages_current 通过 work_completed/work_estimated 显示进度(如 ALTER TABLE)。

SQL Server

SELECT session_id, command, percent_complete,
       DATEADD(ms, estimated_completion_time, GETDATE()) AS est_finish,
       total_elapsed_time / 1000 AS elapsed_sec
FROM sys.dm_exec_requests
WHERE percent_complete > 0
ORDER BY percent_complete;

sys.dm_exec_requests.percent_complete 给出 BACKUP、RESTORE、DBCC 和索引重建等操作的完成百分比。

MongoDB

db.currentOp({ "active": true, "secs_running": { "$gte": 3 } })

在 db.currentOp 输出中,长时间运行的操作以及索引构建的 'progress' 字段(done/total)显示进度。

Redis

INFO persistence
# Keys: rdb_bgsave_in_progress, aof_rewrite_in_progress, rdb_last_bgsave_status, loading, loading_loaded_perc

INFO persistence 部分报告 RDB/AOF 保存或重写操作是否正在进行以及加载百分比。

Elasticsearch

GET _tasks?detailed=true&actions=*reindex,*update/byquery,*delete/byquery
# For recovery/shard relocation: GET _cat/recovery?v&active_only=true

_tasks?detailed 显示长时间运行任务(reindex、update_by_query)的状态;_cat/recovery 显示活动分片恢复的进度。

在 DBAtlas 中打开 →