summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2025-12-18 15:08:48 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2025-12-18 15:08:48 +0200
commit951b60f7abdcdeb37f2d73ad4822f278d2687c1c (patch)
tree028732aab31ee74a24643711f602030f8efdb463
parentb47c50e5667b489bec3affb55ecdf4e9c306ca2d (diff)
Do not emit WAL for unlogged BRIN indexes
Operations on unlogged relations should not be WAL-logged. The brin_initialize_empty_new_buffer() function didn't get the memo. The function is only called when a concurrent update to a brin page uses up space that we're just about to insert to, which makes it pretty hard to hit. If you do manage to hit it, a full-page WAL record is erroneously emitted for the unlogged index. If you then crash, crash recovery will fail on that record with an error like this: FATAL: could not create file "base/5/32819": File exists Author: Kirill Reshke <reshkekirill@gmail.com> Discussion: https://www.postgresql.org/message-id/CALdSSPhpZXVFnWjwEBNcySx_vXtXHwB2g99gE6rK0uRJm-3GgQ@mail.gmail.com Backpatch-through: 14
-rw-r--r--src/backend/access/brin/brin_pageops.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/backend/access/brin/brin_pageops.c b/src/backend/access/brin/brin_pageops.c
index 91a5ba163f2..c80b87da3d2 100644
--- a/src/backend/access/brin/brin_pageops.c
+++ b/src/backend/access/brin/brin_pageops.c
@@ -891,7 +891,11 @@ brin_initialize_empty_new_buffer(Relation idxrel, Buffer buffer)
page = BufferGetPage(buffer);
brin_page_init(page, BRIN_PAGETYPE_REGULAR);
MarkBufferDirty(buffer);
- log_newpage_buffer(buffer, true);
+
+ /* XLOG stuff */
+ if (RelationNeedsWAL(idxrel))
+ log_newpage_buffer(buffer, true);
+
END_CRIT_SECTION();
/*