WAIT EVENT · ACTIVITY空闲等待
ActivityRecoveryWalStream
流恢复期间,在启动进程主循环等待WAL到达。
Waiting in main loop of startup process for WAL to arrive, during streaming recovery
空闲等待 引入 10 现存至 20 devel 1 次变动 实测触发图谱档案
版本轨迹
相对 PostgreSQL 17 无变化。
各版本描述
相邻版本里类型、名称与英文描述都相同的合并成一段,旧的在前。中文取自图谱或本站手册译文,没有译文的只给英文原文。
-
1012
ActivityRecoveryWalStream在恢复期间,若所有来源(本地、归档或流)都没有可用的 WAL 数据,则在重新尝试获取 WAL 数据前等待。
Waiting when WAL data is not available from any kind of sources (local, archive or stream) before trying again to retrieve WAL data, at recovery.
-
1320
ActivityRecoveryWalStream流恢复期间,在启动进程主循环等待WAL到达。
Waiting in main loop of startup process for WAL to arrive, during streaming recovery.
触发机制
WAIT_EVENT_RECOVERY_WAL_STREAM 位于 src/backend/access/transam/xlogrecovery.c:4038,是经 grep 核验的报告路径。公共身份/资源映射位于 src/backend/utils/activity/wait_event_names.txt:64。探针覆盖的操作是:流式恢复期间,在 startup 进程的主循环中等待 WAL 到达。RecoveryWalStream 后台路径在主循环暂时无事可做、进入 latch wait 前报告此事件;信号、计时器或新工作会唤醒进程并进入下一轮循环。
WAIT_EVENT_RECOVERY_WAL_STREAM at src/backend/access/transam/xlogrecovery.c:4038 is the grep-verified reporting path. The public identity/resource is mapped at src/backend/utils/activity/wait_event_names.txt:64. The instrumented operation is: Waiting in main loop of startup process for WAL to arrive, during streaming recovery. The RecoveryWalStream background path reports this event around its latch wait when its main loop has no immediate work. A signal, timeout, or new work clears the sleep and the process loops again.
通常正常
对匹配的后台进程而言,这通常是预期空闲。
This is normally expected idleness for the matching background process.
值得警惕
只有工作队列、关闭或故障切换时限没有推进但进程一直停在这里,或事件出现在不匹配的后端类型上时,才需要调查。
Investigate only when queued work or a shutdown/failover deadline is not advancing while the process remains here, or when the event appears on an unexpected backend type.
诊断 SQL
直接在 psql 里跑;标注的是语句里用到的视图与列所要求的最低版本。
正在等待 Activity/RecoveryWalStream 的会话Sessions waiting on Activity/RecoveryWalStream
PG ≥ 13SELECT pid, backend_type, usename, datname, application_name,
state, now() - query_start AS query_age,
now() - xact_start AS xact_age,
wait_event_type, wait_event,
pg_blocking_pids(pid) AS blocking_pids,
left(query, 160) AS query
FROM pg_stat_activity
WHERE wait_event_type = 'Activity'
AND wait_event = 'RecoveryWalStream'
ORDER BY query_age DESC NULLS LAST;
当前 Activity 等待分布Current Activity cohort
PG ≥ 13SELECT wait_event, count(*) AS waiting_sessions,
count(*) FILTER (WHERE state = 'active') AS active_waiters,
max(now() - query_start) AS oldest_query
FROM pg_stat_activity
WHERE wait_event_type = 'Activity'
GROUP BY wait_event
ORDER BY waiting_sessions DESC, wait_event;
这些会话的锁与关系上下文Lock and relation context for these sessions
PG ≥ 13SELECT a.pid, l.locktype, l.mode, l.granted, l.fastpath,
d.datname, n.nspname, c.relname,
l.page, l.tuple, l.virtualxid, l.transactionid,
l.classid, l.objid, l.objsubid
FROM pg_stat_activity AS a
LEFT JOIN pg_locks AS l ON l.pid = a.pid
LEFT JOIN pg_database AS d ON d.oid = l.database
LEFT JOIN pg_class AS c
ON c.oid = l.relation
AND l.database = (
SELECT oid FROM pg_database WHERE datname = current_database()
)
LEFT JOIN pg_namespace AS n ON n.oid = c.relnamespace
WHERE a.wait_event_type = 'Activity'
AND a.wait_event = 'RecoveryWalStream'
ORDER BY a.pid, l.granted, l.locktype, l.mode;
处置步骤
- 先与 backend_type 对照。
- 检查该进程专属的积压与最后进展时间。
- 修复缺失的工作信号或停滞的上游阶段,不要终止正常空闲的 worker。
英文原文
- Match the row to backend_type.
- Inspect the process-specific backlog and last-progress timestamp.
- Fix the missing work signal or stalled upstream phase; do not kill a normally idle worker.
相关参数与指标
wal_bufferssynchronous_commit
waiting_sessionswait_event_sharewal_byteswal_write_time
源码证据
图谱在各版本源码树里核对到的位置,新的在前。「触发点」是真正上报等待事件的调用处,「目录定义」只说明这个名字在枚举里存在。
PostgreSQL 18REL_18_6
-
src/backend/access/transam/xlogrecovery.c:4038WAIT_EVENT_RECOVERY_WAL_STREAM触发点实测触发WAIT_EVENT_RECOVERY_WAL_STREAM); -
src/backend/utils/activity/wait_event_names.txt:64RECOVERY_WAL_STREAM目录定义实测触发RECOVERY_WAL_STREAM "Waiting in main loop of startup process for WAL to arrive, during streaming recovery."
演化历史
相邻两个大版本之间的差异,新的在前。版本号链到该版的变动清单。
-
PostgreSQL 13 ← 12 描述更新
描述措辞更新
流恢复期间,在启动进程主循环等待WAL到达。
描述前后对照
Waiting when WAL data is not available from any kind of sources (local, archive or stream) before trying again to retrieve WAL data, at recovery. Waiting in main loop of startup process for WAL to arrive, during streaming recovery. -
PostgreSQL 10 ← 9.6 新增此事件
该版起出现
在恢复期间,若所有来源(本地、归档或流)都没有可用的 WAL 数据,则在重新尝试获取 WAL 数据前等待。
同类事件
| 事件 | 引入 | 版本变动 | 最近变动 |
|---|---|---|---|
ArchiverMain档案
|
10 | 131 次 | |
| 在 archiver 进程的主循环中等待。 | 现存 | ||
AutovacuumMain档案
|
10 | 171 次 | |
在 autovacuum launcher 进程的主循环中等待。曾用名 AutoVacuumMain |
现存 | ||
BgwriterHibernate档案
|
10 | 171 次 | |
在后台写入器进程休眠时等待。曾用名 BgWriterHibernate |
现存 | ||
BgwriterMain档案
|
10 | 172 次 | |
在后台写入器进程的主循环中等待。曾用名 BgWriterMain |
现存 | ||
CheckpointerMain档案
|
10 | — | |
| 在 checkpointer 进程的主循环中等待。 | 现存 | ||
CheckpointerShutdown档案
|
18 | — | |
| 等待 checkpointer 进程终止。 | 现存 | ||
IoWorkerMain档案
|
18 | — | |
| 在 I/O worker 进程的主循环中等待。 | 现存 | ||
LogicalApplyMain档案
|
10 | 131 次 | |
| 在逻辑复制 apply 进程的主循环中等待。 | 现存 | ||
LogicalLauncherMain档案
|
10 | 131 次 | |
| 在逻辑复制 launcher 进程的主循环中等待。 | 现存 | ||
LogicalParallelApplyMain档案
|
16 | — | |
| 在逻辑复制并行 apply 进程的主循环中等待。 | 现存 | ||
PgStatMain档案
|
10 | 131 次 | |
| 在统计收集器进程的主循环中等待。 | 于 15 移除 | ||
RecoveryWalAll
|
10 | — | |
| 在恢复期间等待来自流的 WAL。 | 于 13 移除 | ||
RecoveryWalStream档案
|
10 | 131 次 | |
| 流式恢复期间,在 startup 进程的主循环中等待 WAL 到达。 | 现存 | ||
ReplicationSlotsyncMain档案
|
17 | 191 次 | |
| 在复制槽同步 worker 的主循环中等待。 | 现存 | ||
ReplicationSlotsyncShutdown档案
|
17 | — | |
| 等待复制槽同步 worker 停止运行。 | 现存 | ||
SysloggerMain档案
|
10 | 171 次 | |
在 syslogger 进程的主循环中等待。曾用名 SysLoggerMain |
现存 | ||
WalReceiverMain档案
|
10 | — | |
| 在 WAL receiver 进程的主循环中等待。 | 现存 | ||
WalSenderMain档案
|
10 | — | |
| 在 WAL sender 进程的主循环中等待。 | 现存 | ||
WalSummarizerWal档案
|
17 | — | |
| 在 WAL summarizer 中等待生成更多 WAL。 | 现存 | ||
WalWriterMain档案
|
10 | — | |
| 在 WAL writer 进程的主循环中等待。 | 现存 | ||