pgsql: Ensure that creation of an empty relfile is fsync'd at checkpoin

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Ensure that creation of an empty relfile is fsync'd at checkpoin
Date: 2023-07-04 15:31:31
Message-ID: E1qGi03-001tAY-G1@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e24c02e4d258f8cc0305f5ec6708bceb57403276

Modified Files
--------------
src/backend/storage/smgr/md.c | 3 +++
1 file changed, 3 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2023-07-04 15:38:43 pgsql: Fix assertion failure in snapshot building
Previous Message Peter Eisentraut 2023-07-04 12:45:08 pgsql: Remove incidental md5() function uses from several tests