v2-0001-Ensure-that-creation-of-an-empty-relfile-is-fsync.patch

application/octet-stream

Filename: v2-0001-Ensure-that-creation-of-an-empty-relfile-is-fsync.patch
Type: application/octet-stream
Part: 0
Message: Re: Creation of an empty table is not fsync'd at checkpoint

Patch

Format: format-patch
Series: patch v2-0001
Subject: Ensure that creation of an empty relfile is fsync'd at checkpoint.
File+
src/backend/storage/smgr/md.c 3 0
From ddafa47befc614d4964833c1a4c85459151182fc Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Thu, 27 Jan 2022 19:52:37 +0200
Subject: [PATCH v2] Ensure that creation of an empty relfile is fsync'd at
 checkpoint.

If you create a table and don't insert any data into it, the relation file
is never fsync'd. You don't lose data, because an empty table doesn't have
any data to begin with, but if you crash and lose the file, subsequent
operations on the table will fail with "could not open file" erorr.

To fix, register an fsync request in mdcreate(), like we do for mdwrite().
---
 src/backend/storage/smgr/md.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 30dbc02f82..fdecbad170 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -239,6 +239,9 @@ mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
 	mdfd = &reln->md_seg_fds[forknum][0];
 	mdfd->mdfd_vfd = fd;
 	mdfd->mdfd_segno = 0;
+
+	if (!SmgrIsTemp(reln))
+		register_dirty_segment(reln, forknum, mdfd);
 }
 
 /*
-- 
2.32.1 (Apple Git-133)