From 9dcf1bdc80094097b1c8a795ef67b8e1cd6b9e50 Mon Sep 17 00:00:00 2001 From: Narek Galstyan Date: Mon, 10 Jun 2024 21:16:32 -0700 Subject: [PATCH] Fix init_fork WAL-logging on unlogged indexes (#591) Currently pgvector does not create any WAL records for unlogged tables Postgres assumes INIT_FORK of unlogged tables is persistent and uses it to reset the table index to its default empty state after a server crash. This patch makes INIT_FORK of unlogged table WAL-tracked, which ensures an unlogged table is usable after a crash-restart --- src/hnswbuild.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hnswbuild.c b/src/hnswbuild.c index ee94ed9..dcfb2bd 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -1121,8 +1121,8 @@ BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, BuildGraph(buildstate, forkNum); - if (RelationNeedsWAL(index)) - log_newpage_range(index, forkNum, 0, RelationGetNumberOfBlocks(index), true); + if (RelationNeedsWAL(index) || forkNum == INIT_FORKNUM) + log_newpage_range(index, forkNum, 0, RelationGetNumberOfBlocksInFork(index, forkNum), true); FreeBuildState(buildstate); }