]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Ensure that creation of an empty relfile is fsync'd at checkpoint.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 4 Jul 2023 14:57:03 +0000 (17:57 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 4 Jul 2023 15:08:40 +0000 (18:08 +0300)
commit6377f705cab2f8f3e4017cd9852887906c8ac053
treee0bfb4ac4f80424e9185f4a7e6efc0cebcc4d2f1
parentc2cff443b0b182a07ef4aa17559302ace48c3e62
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
src/backend/storage/smgr/md.c