aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2023-07-04 17:57:03 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2023-07-04 17:57:03 +0300
commit4b4798e1384ce12e19a558708e66c829276cf8d7 (patch)
treec474302d17c86c879818287bc3c5c0090a8788d5
parent657f5f223e8fd9aa12d8d9fc473faecc267b9b7a (diff)
downloadpostgresql-4b4798e1384ce12e19a558708e66c829276cf8d7.tar.gz
postgresql-4b4798e1384ce12e19a558708e66c829276cf8d7.zip
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" error. To fix, register an fsync request in mdcreate(), like we do for mdwrite(). Per discussion, we probably should also fsync the containing directory after creating a new file. But that's a separate and much wider issue. Backpatch to all supported versions. Reviewed-by: Andres Freund, Thomas Munro Discussion: https://www.postgresql.org/message-id/d47d8122-415e-425c-d0a2-e0160829702d%40iki.fi
-rw-r--r--src/backend/storage/smgr/md.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 30dbc02f823..fdecbad1709 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);
}
/*