{"Entry":{"collection":"waitevent","key":"lwlock/WALInsert","name":"WALInsert","aliases":["WALInsert","wal_insert"],"metadata":{"aliases":["WALInsert","wal_insert"],"changed_in":["10","13"],"changes":[{"from":"9.6","moved":{"from":"LWLockTranche","to":"LWLock"},"renamed":null,"reworded":null,"status":"changed","to":"10"},{"from":"12","moved":null,"renamed":{"from":"wal_insert","to":"WALInsert"},"reworded":{"from":"Waiting to insert WAL into a memory buffer.","to":"Waiting to insert WAL data into a memory buffer."},"status":"changed","to":"13"}],"content_hash":"e0efc3e2c6e90e157d80f3a9eca5b6d6e904030c5b727b33277958fba4bdc91b","dossier":{"actions":{"en":["Rank statements by WAL generation and call rate.","Check checkpoint/full-page-image timing and concurrent writer count.","Batch tiny writes, reduce needless index churn, and address WAL write latency."],"zh":["按 WAL 生成量与调用频率排序语句。","检查检查点/全页镜像时机与并发写会话数量。","批量合并微小写入、减少无效索引抖动，并处理 WAL 写延迟。"]},"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 = 'LWLock'\n  AND wait_event = 'WALInsert'\nORDER BY query_age DESC NULLS LAST;","title":"Sessions waiting on LWLock/WALInsert","title_zh":"正在等待 LWLock/WALInsert 的会话"},{"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 = 'LWLock'\nGROUP BY wait_event\nORDER BY waiting_sessions DESC, wait_event;","title":"Current LWLock cohort","title_zh":"当前 LWLock 等待分布"},{"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 = 'LWLock'\n  AND a.wait_event = 'WALInsert'\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":"18.6"},"gucs":["wal_buffers","full_page_writes","checkpoint_timeout"],"incident_pattern":{"en":"A fan-out job issues many single-row commits immediately after a checkpoint; full-page images and writer concurrency turn WAL insertion into the bottleneck.","zh":"扇出任务在检查点后立即发起大量单行提交，全页镜像与写并发共同让 WAL 插入成为瓶颈。"},"mechanism":{"en":"A backend must hold one of the WAL insertion locks while reserving and copying a WAL record into shared WAL buffers. High concurrent WAL producers can queue when insertion critical sections lengthen.","zh":"后端在共享 WAL 缓冲区中预留空间并复制 WAL 记录时，必须持有一个 WAL insertion lock。并发 WAL 生产者很多、插入临界区变长时，会在此排队。"},"metrics":["waiting_sessions","wait_event_share","wal_bytes","wal_fpi","statement_wal_bytes"],"normal":{"en":"Transient waits are normal during concurrent writes and commit bursts.","zh":"并发写入与提交突发期间的瞬时等待很正常。"},"official_descriptions":{"13":"Waiting to insert WAL data into a memory buffer.","14":"Waiting to insert WAL data into a memory buffer.","15":"Waiting to insert WAL data into a memory buffer.","16":"Waiting to insert WAL data into a memory buffer.","17":"Waiting to insert WAL data into a memory buffer","18":"Waiting to insert WAL data into a memory buffer"},"record_kind":"event","source_locations":[{"commit":"724edf9bde9d356724ad384a2e196edc3c9f80f7","excerpt":"immed = LWLockAcquire(\u0026WALInsertLocks[MyLockNo].l.lock, LW_EXCLUSIVE);","grep_pattern":"WALInsert","grep_verified":true,"kind":"resource_path","line":1399,"major":18,"path":"src/backend/access/transam/xlog.c","status":"dynamic_trigger","symbol":"WALInsert","tag":"REL_18_6","url":"https://github.com/postgres/postgres/blob/REL_18_6/src/backend/access/transam/xlog.c#L1399","version":"18.6"},{"commit":"724edf9bde9d356724ad384a2e196edc3c9f80f7","excerpt":"pgstat_report_wait_start(PG_WAIT_LWLOCK | lock-\u003etranche);","grep_pattern":"pgstat_report_wait_start","grep_verified":true,"kind":"generic_reporter","line":739,"major":18,"path":"src/backend/storage/lmgr/lwlock.c","status":"dynamic_trigger","symbol":"pgstat_report_wait_start","tag":"REL_18_6","url":"https://github.com/postgres/postgres/blob/REL_18_6/src/backend/storage/lmgr/lwlock.c#L739","version":"18.6"},{"commit":"724edf9bde9d356724ad384a2e196edc3c9f80f7","excerpt":"WALInsert\t\"Waiting to insert WAL data into a memory buffer.\"","grep_pattern":"WALInsert","grep_verified":true,"kind":"catalog_definition","line":372,"major":18,"path":"src/backend/utils/activity/wait_event_names.txt","status":"dynamic_trigger","symbol":"WALInsert","tag":"REL_18_6","url":"https://github.com/postgres/postgres/blob/REL_18_6/src/backend/utils/activity/wait_event_names.txt#L372","version":"18.6"}],"source_status":"dynamic_trigger","trouble":{"en":"A recurring foreground pile-up indicates WAL insertion has become a serialization point, often with very high write concurrency, full-page images, or slow buffer turnover.","zh":"前台会话反复堆积说明 WAL 插入已成为串行点，常伴随极高写并发、全页镜像或缓冲区换页过慢。"}},"first_version":"9.6","has_dossier":true,"imported_at":"2026-09-27T17:57:33.078663+08:00","key":"lwlock/walinsert","last_version":"20","name":"WALInsert","position":284,"present_in":["9.6","10","11","12","13","14","15","16","17","18","19","20"],"slug":"wal-insert","source_rev":"english-manuals:6f53460de64633c12562e6563c384e3a4002da0934ed929ea9233374a36c4f49","summary":"Waiting to insert WAL data into a memory buffer.","summary_zh":"","type":"LWLock","type_slug":"lwlock","type_variants":["LWLock","LWLockTranche"]}},"Definition":{"Collection":"waitevent","Key":"lwlock/WALInsert","SourceDatabase":"center","Version":"18","SourceTable":"waitevent","SourceKey":"lwlock/walinsert","SourceRevision":"english-manuals:6f53460de64633c12562e6563c384e3a4002da0934ed929ea9233374a36c4f49","Facts":{"description":"Waiting to insert WAL data into a memory buffer.","description_zh":"","doc":{"anchor":"WAIT-EVENT-LWLOCK-TABLE","file":"monitoring-stats.html","lang":"en","sha256":"aa979eed08627fbf715a9d792094a162a73671db5af810f3ab2aad3e073d5722","slug":"18"},"lang":"en","name":"WALInsert","source":"english-manual","type":"LWLock","zh_from":""},"ManualEvidence":{"doc":{"anchor":"WAIT-EVENT-LWLOCK-TABLE","file":"monitoring-stats.html","lang":"en","sha256":"aa979eed08627fbf715a9d792094a162a73671db5af810f3ab2aad3e073d5722","slug":"18"}},"MeasuredEvidence":{}},"Text":{"Collection":"waitevent","Key":"lwlock/WALInsert","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"WALInsert","Summary":"等待将WAL数据插入内存缓冲区。","BodyHTML":"\u003cp\u003e等待将WAL数据插入内存缓冲区。\u003c/p\u003e","SourceRevision":"2026-08-31@34d13c8","ContentHash":"48c5a2c7ed71f55240992f2cc4150a2188adcb5f0e8674580351d8459df0e3a3","Payload":{"description_zh":"等待将WAL数据插入内存缓冲区。","zh_from":"doc"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
