aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2020-05-15 16:50:34 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2020-05-15 16:50:34 -0400
commit242dfcbafac592a3f097ec2e4e36fe1b739f7f29 (patch)
treeb9d594f4b90b63094f8a6951a811789e74c5a5f6 /src
parent5da14938f7bfb96b648ee3c47e7ea2afca5bcc4a (diff)
downloadpostgresql-242dfcbafac592a3f097ec2e4e36fe1b739f7f29.tar.gz
postgresql-242dfcbafac592a3f097ec2e4e36fe1b739f7f29.zip
Avoid killing btree items that are already dead
_bt_killitems marks btree items dead when a scan leaves the page where they live, but it does so with only share lock (to improve concurrency). This was historicall okay, since killing a dead item has no consequences. However, with the advent of data checksums and wal_log_hints, this action incurs a WAL full-page-image record of the page. Multiple concurrent processes would write the same page several times, leading to WAL bloat. The probability of this happening can be reduced by only killing items if they're not already dead, so change the code to do that. The problem could eliminated completely by having _bt_killitems upgrade to exclusive lock upon seeing a killable item, but that would reduce concurrency so it's considered a cure worse than the disease. Backpatch all the way back to 9.5, since wal_log_hints was introduced in 9.4. Author: Masahiko Sawada <masahiko.sawada@2ndquadrant.com> Discussion: https://postgr.es/m/CA+fd4k6PeRj2CkzapWNrERkja5G0-6D-YQiKfbukJV+qZGFZ_Q@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/nbtree/nbtutils.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 84b391ce038..1429ac8b63e 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -1854,7 +1854,15 @@ _bt_killitems(IndexScanDesc scan)
else if (ItemPointerEquals(&ituple->t_tid, &kitem->heapTid))
killtuple = true;
- if (killtuple)
+ /*
+ * Mark index item as dead, if it isn't already. Since this
+ * happens while holding a buffer lock possibly in shared mode,
+ * it's possible that multiple processes attempt to do this
+ * simultaneously, leading to multiple full-page images being
+ * set to WAL (if wal_log_hints or data checksums are enabled),
+ * which is undesirable.
+ */
+ if (killtuple && !ItemIdIsDead(iid))
{
/* found the item/all posting list items */
ItemIdMarkDead(iid);