pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Ensure that creation of an empty relfile is fsync'd at checkpoin
Date: Tue, 04 Jul 2023 15:31:31 +0000
Message-ID: <E1qGi03-001tAg-Ha@gemulon.postgresql.org> (raw)

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_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1b4f1c6f8a6c0b764636f25e17d37d8cab7e82be

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



view thread (7+ messages)  latest in thread

Message-ID: <E1qGi03-001tAg-Ha@gemulon.postgresql.org>
Permalink:  ../E1qGi03-001tAg-Ha@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1qGi03-001tAg-Ha@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Ensure that creation of an empty relfile is fsync'd at checkpoin
  In-Reply-To: <E1qGi03-001tAg-Ha@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox