postgres.git / summary / log / commit / refs

commit    4b6d096a0f99d684db60a9f99aef851ebe0a5fa3
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Thu Dec 18 13:08:48 2025 +0000
First released in: 14.21, 15.16, 16.12, 17.8, 18.2

    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


src/backend/access/brin/brin_pageops.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/access/brin/brin_pageops.c b/src/backend/access/brin/brin_pageops.c index b69217c1ec6..92d467c6b57 100644 --- a/src/backend/access/brin/brin_pageops.c +++ b/src/backend/access/brin/brin_pageops.c @@ -893,7 +893,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(); /* [parent: a3e7bbd410d4]