{"Entry":{"collection":"waitevent","key":"activity/PgStatMain","name":"PgStatMain","aliases":["PgStatMain"],"metadata":{"aliases":["PgStatMain"],"changed_in":["13"],"changes":[{"from":"9.6","moved":null,"renamed":null,"reworded":null,"status":"added","to":"10"},{"from":"12","moved":null,"renamed":null,"reworded":{"from":"Waiting in main loop of the statistics collector process.","to":"Waiting in main loop of statistics collector process."},"status":"changed","to":"13"},{"from":"14","moved":null,"renamed":null,"reworded":null,"status":"removed","to":"15"}],"content_hash":"4a4e58d91718c65d26a35e5b27c73da8dec2c0a3c2a04dc046ff4cd3a037585e","dossier":{"actions":{"en":["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."],"zh":["先与 backend_type 对照。","检查该进程专属的积压与最后进展时间。","修复缺失的工作信号或停滞的上游阶段，不要终止正常空闲的 worker。"]},"diagnostic_sql":[{"id":"sessions","min_version":"13","sql":"SELECT pid, backend_type, usename, datname, application_name,\n       state, now() - query_start AS query_age,\n       now() - xact_start AS xact_age,\n       wait_event_type, wait_event,\n       pg_blocking_pids(pid) AS blocking_pids,\n       left(query, 160) AS query\nFROM pg_stat_activity\nWHERE wait_event_type = 'Activity'\n  AND wait_event = 'PgStatMain'\nORDER BY query_age DESC NULLS LAST;","title":"Sessions waiting on Activity/PgStatMain","title_zh":"正在等待 Activity/PgStatMain 的会话"},{"id":"cohort","min_version":"13","sql":"SELECT wait_event, count(*) AS waiting_sessions,\n       count(*) FILTER (WHERE state = 'active') AS active_waiters,\n       max(now() - query_start) AS oldest_query\nFROM pg_stat_activity\nWHERE wait_event_type = 'Activity'\nGROUP BY wait_event\nORDER BY waiting_sessions DESC, wait_event;","title":"Current Activity cohort","title_zh":"当前 Activity 等待分布"},{"id":"lock_objects","min_version":"13","sql":"SELECT a.pid, l.locktype, l.mode, l.granted, l.fastpath,\n       d.datname, n.nspname, c.relname,\n       l.page, l.tuple, l.virtualxid, l.transactionid,\n       l.classid, l.objid, l.objsubid\nFROM pg_stat_activity AS a\nLEFT JOIN pg_locks AS l ON l.pid = a.pid\nLEFT JOIN pg_database AS d ON d.oid = l.database\nLEFT JOIN pg_class AS c\n  ON c.oid = l.relation\n AND l.database = (\n       SELECT oid FROM pg_database WHERE datname = current_database()\n     )\nLEFT JOIN pg_namespace AS n ON n.oid = c.relnamespace\nWHERE a.wait_event_type = 'Activity'\n  AND a.wait_event = 'PgStatMain'\nORDER BY a.pid, l.granted, l.locktype, l.mode;","title":"Lock and relation context for these sessions","title_zh":"这些会话的锁与关系上下文"}],"emission":{"status":"active","verified_release":"14.24"},"incident_pattern":{"en":"","zh":""},"mechanism":{"en":"`WAIT_EVENT_PGSTAT_MAIN` at `src/backend/postmaster/pgstat.c:3425` is the grep-verified reporting path. The public identity/resource is mapped at `src/backend/utils/activity/wait_event.c:234`. The instrumented operation is: Waiting in main loop of statistics collector process. The PgStatMain 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.","zh":"`WAIT_EVENT_PGSTAT_MAIN` 位于 `src/backend/postmaster/pgstat.c:3425`，是经 grep 核验的报告路径。公共身份/资源映射位于 `src/backend/utils/activity/wait_event.c:234`。探针覆盖的操作是：在统计收集器进程的主循环中等待。PgStatMain 后台路径在主循环暂时无事可做、进入 latch wait 前报告此事件；信号、计时器或新工作会唤醒进程并进入下一轮循环。"},"metrics":["waiting_sessions","wait_event_share"],"normal":{"en":"This is normally expected idleness for the matching background process.","zh":"对匹配的后台进程而言，这通常是预期空闲。"},"official_descriptions":{"13":"Waiting in main loop of statistics collector process.","14":"Waiting in main loop of statistics collector process."},"record_kind":"event","source_locations":[{"commit":"6b3806732b7c5df06bdd0ed150e8a07b4ad62315","excerpt":"wr = WaitEventSetWait(wes, -1L, \u0026event, 1, WAIT_EVENT_PGSTAT_MAIN);","grep_pattern":"WAIT_EVENT_PGSTAT_MAIN","grep_verified":true,"kind":"trigger","line":3425,"major":14,"path":"src/backend/postmaster/pgstat.c","status":"live_trigger","symbol":"WAIT_EVENT_PGSTAT_MAIN","tag":"REL_14_24","url":"https://github.com/postgres/postgres/blob/REL_14_24/src/backend/postmaster/pgstat.c#L3425","version":"14.24"},{"commit":"6b3806732b7c5df06bdd0ed150e8a07b4ad62315","excerpt":"event_name = \"PgStatMain\";","grep_pattern":"PgStatMain","grep_verified":true,"kind":"catalog_definition","line":234,"major":14,"path":"src/backend/utils/activity/wait_event.c","status":"live_trigger","symbol":"PgStatMain","tag":"REL_14_24","url":"https://github.com/postgres/postgres/blob/REL_14_24/src/backend/utils/activity/wait_event.c#L234","version":"14.24"}],"source_status":"live_trigger","trouble":{"en":"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.","zh":"只有工作队列、关闭或故障切换时限没有推进但进程一直停在这里，或事件出现在不匹配的后端类型上时，才需要调查。"}},"first_version":"10","has_dossier":true,"imported_at":"2026-09-14T21:49:49.863357+08:00","key":"activity/pgstatmain","last_version":"14","name":"PgStatMain","position":10,"present_in":["10","11","12","13","14"],"slug":"pg-stat-main","source_rev":"english-manuals:1d4625d82bb869a4eeb63cc9319bfab01fefb1e6bde88a9e4fb8bb887cd4bddd","summary":"Waiting in main loop of statistics collector process.","summary_zh":"","type":"Activity","type_slug":"activity","type_variants":["Activity"]}},"Definition":{"Collection":"waitevent","Key":"activity/PgStatMain","SourceDatabase":"center","Version":"14","SourceTable":"waitevent","SourceKey":"activity/pgstatmain","SourceRevision":"english-manuals:1d4625d82bb869a4eeb63cc9319bfab01fefb1e6bde88a9e4fb8bb887cd4bddd","Facts":{"description":"Waiting in main loop of statistics collector process.","description_zh":"","doc":{"anchor":"WAIT-EVENT-ACTIVITY-TABLE","file":"monitoring-stats.html","lang":"en","sha256":"1852c6205d68e465d08dd8f75e3b6bfdd4a475ee8d79886e2dcff6bff8e2d243","slug":"14"},"lang":"en","name":"PgStatMain","source":"english-manual","type":"Activity","zh_from":""},"ManualEvidence":{"doc":{"anchor":"WAIT-EVENT-ACTIVITY-TABLE","file":"monitoring-stats.html","lang":"en","sha256":"1852c6205d68e465d08dd8f75e3b6bfdd4a475ee8d79886e2dcff6bff8e2d243","slug":"14"}},"MeasuredEvidence":{}},"Text":{"Collection":"waitevent","Key":"activity/PgStatMain","SourceDatabase":"pgweb","Version":"14","Locale":"zh-Hans","Title":"PgStatMain","Summary":"在统计收集器进程的主循环中等待。","BodyHTML":"\u003cp\u003e在统计收集器进程的主循环中等待。\u003c/p\u003e","SourceRevision":"2026-08-31@34d13c8","ContentHash":"b81784a8df046017c062c087dd6c4c12c9f06c04b5c32ecaf602d4568ac44280","Payload":{"description_zh":"在统计收集器进程的主循环中等待。","zh_from":"doc"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
