WAIT EVENT · BUFFER缓冲区
BufferBufferPin
等待获得缓冲区上的独占销。
Waiting to acquire an exclusive pin on a buffer
缓冲区 引入 9.6(机制起点) 于 19 移除 1 次变动 实测触发图谱档案
版本轨迹
相对 PostgreSQL 17 无变化。
各版本描述
相邻版本里类型、名称与英文描述都相同的合并成一段,旧的在前。中文取自图谱或本站手册译文,没有译文的只给英文原文。
-
9.612
BufferPinBufferPin曾用名等待获取缓冲区上的钉住。
Waiting to acquire a pin on a buffer.
-
1318
BufferPinBufferPin曾用名等待获得缓冲区上的独占销。
Waiting to acquire an exclusive pin on a buffer
触发机制
WAIT_EVENT_BUFFER_PIN 位于 src/backend/storage/buffer/bufmgr.c:5819,是经 grep 核验的报告路径。公共身份/资源映射位于 src/backend/utils/activity/wait_event_names.txt:286。探针覆盖的操作是:等待获取 buffer 上的独占 pin。缓冲区管理器需要独占 pin,但另一个后端仍在同一共享缓冲区上持有 pin;当前后端会休眠到最后一个冲突 pin 被释放。
WAIT_EVENT_BUFFER_PIN at src/backend/storage/buffer/bufmgr.c:5819 is the grep-verified reporting path. The public identity/resource is mapped at src/backend/utils/activity/wait_event_names.txt:286. The instrumented operation is: Waiting to acquire an exclusive pin on a buffer. The buffer manager needs an exclusive pin, but another backend still holds a pin on the same shared buffer. It sleeps until the last conflicting pin is released.
通常正常
扫描或索引维护期间,孤立的亚秒级样本可能正常。
An isolated sub-second sample can occur during scans or index maintenance.
值得警惕
等待超过一秒就值得怀疑,尤其要检查游标或空闲事务是否持续钉住页面。
Treat a wait beyond one second as suspicious, especially when a cursor or idle transaction may keep the page pinned.
诊断 SQL
直接在 psql 里跑;标注的是语句里用到的视图与列所要求的最低版本。
正在等待 BufferPin/BufferPin 的会话Sessions waiting on BufferPin/BufferPin
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 = 'BufferPin'
AND wait_event = 'BufferPin'
ORDER BY query_age DESC NULLS LAST;
当前 BufferPin 等待分布Current BufferPin 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 = 'BufferPin'
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 = 'BufferPin'
AND a.wait_event = 'BufferPin'
ORDER BY a.pid, l.granted, l.locktype, l.mode;
处置步骤
- 保全等待查询与关系上下文。
- 查找访问同一关系的长游标与 idle in transaction 会话。
- 确认最安全的持有者或维护受害者后再取消。
英文原文
- Preserve the waiting query and relation context.
- Find long cursors and idle-in-transaction sessions touching the same relation.
- Cancel only after identifying the safest holder or maintenance victim.
相关参数与指标
waiting_sessionswait_event_share
源码证据
图谱在各版本源码树里核对到的位置,新的在前。「触发点」是真正上报等待事件的调用处,「目录定义」只说明这个名字在枚举里存在。
PostgreSQL 18REL_18_6
-
src/backend/storage/buffer/bufmgr.c:5819WAIT_EVENT_BUFFER_PIN触发点实测触发ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN); -
src/backend/utils/activity/wait_event_names.txt:286BUFFER_PIN目录定义实测触发BUFFER_PIN "Waiting to acquire an exclusive pin on a buffer."
演化历史
相邻两个大版本之间的差异,新的在前。版本号链到该版的变动清单。
-
PostgreSQL 19 ← 18 移除此事件
该版起不再存在
-
PostgreSQL 13 ← 12 描述更新
描述措辞更新
等待获得缓冲区上的独占销。
描述前后对照
Waiting to acquire a pin on a buffer. Waiting to acquire an exclusive pin on a buffer. -
PostgreSQL 9.6 新增此事件
9.6 引入等待事件机制,此为本事件的首个版本
等待获取缓冲区上的钉住。
同类事件
| 事件 | 引入 | 版本变动 | 最近变动 |
|---|---|---|---|
BufferCleanup
|
19 | — | |
| 等待获取缓冲区上的排他 pin。如果另一个进程持有一个尚未关闭的游标,且该游标最近一次读取的数据来自这个缓冲区,缓冲区 pin 等待可能会持续较长时间。 | 现存 | ||
BufferExclusive
|
19 | 201 次 | |
| 等待获取缓冲区上的排他锁。 | 现存 | ||
BufferPin档案
|
9.6起点 | 131 次 | |
| 等待获取 buffer 上的独占 pin。 | 于 19 移除 | ||
BufferShared
|
19 | — | |
| 等待获取缓冲区上的共享锁。 | 现存 | ||
BufferShareExclusive
|
19 | — | |
| 等待获取缓冲区上的共享排他锁。 | 现存 | ||