pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Magnus Hagander <magnus@hagander.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ярослав Пашинский <yarik97.6@gmail.com>
Cc: Postgres bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #16927: Postgres can`t access WAL files
Date: Sat, 20 Mar 2021 07:32:43 +0900
Message-ID: <YFUmi3diUlqyoL44@paquier.xyz> (raw)
In-Reply-To: <CABUevExwJrT9tAZz0gJKoSc3qLhg3NGsKJH7QWj4BtEK=JHChg@mail.gmail.com>
References: <CADLmTo+AOq2UE3Gr22omfcxhZajqkeGYgWFowKNScOZA1fWVFA@mail.gmail.com>
	<YFM2MRbHZGQ4DsG/@paquier.xyz>
	<CADLmToJJykdGUdKiPkut4mq8oZJ8z4+8d5aSUU9zCtey7yu_9g@mail.gmail.com>
	<YFPMl3TUPXbN127E@paquier.xyz>
	<CADLmTo+GoZ1tuyZxx5uprqSkwqqw3yajry36o-+=N=Jqe=0oZA@mail.gmail.com>
	<YFRglwF+j2RMmbXF@paquier.xyz>
	<CADLmTo+KJoh9+53=7UMfDQALzDEZWXYEUuv3k9YFT4Mo7+0NWQ@mail.gmail.com>
	<YFSMsxc8w2eqUHHR@paquier.xyz>
	<4065519.1616166832@sss.pgh.pa.us>
	<CABUevExwJrT9tAZz0gJKoSc3qLhg3NGsKJH7QWj4BtEK=JHChg@mail.gmail.com>

On Fri, Mar 19, 2021 at 04:19:50PM +0100, Magnus Hagander wrote:
> On Fri, Mar 19, 2021 at 4:14 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Given the evidence that there's a problem, I agree with reverting
>> that.  I'd suggest keeping the cosmetic rename of the function,
>> but we have to put back the Windows-doesn't-HAVE_WORKING_LINK logic.
> 
> +1. I think the indications are definitely clear enough that this has
> to go back in.

No problem from me to keep the rename, and so this leads to the simple
patch attached, then.  Any comments?

>> Grepping in the v12 branch, I find a second use of HAVE_WORKING_LINK
>> in contrib/pg_standby.  But that seems to be in a non-WIN32 code path,
>> so I don't think putting that back is necessary.
> 
> .. and apart front aht I *really* doubt that one has many users,
> especially on Windows :)

Yeah, agreed.
--
Michael

Attachments:

  [text/x-diff] win32-link.patch (1.4K, ../YFUmi3diUlqyoL44@paquier.xyz/2-win32-link.patch)
  download | inline diff:
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index f10ad0acd6..e28c990382 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -135,6 +135,13 @@
 #define EXEC_BACKEND
 #endif
 
+/*
+ * Define this if your operating system supports link()
+ */
+#if !defined(WIN32) && !defined(__CYGWIN__)
+#define HAVE_WORKING_LINK 1
+#endif
+
 /*
  * USE_POSIX_FADVISE controls whether Postgres will attempt to use the
  * posix_fadvise() kernel call.  Usually the automatic configure tests are
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 110ba31517..92b1959648 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -820,6 +820,7 @@ durable_rename_excl(const char *oldfile, const char *newfile, int elevel)
 	if (fsync_fname_ext(oldfile, false, false, elevel) != 0)
 		return -1;
 
+#ifdef HAVE_WORKING_LINK
 	if (link(oldfile, newfile) < 0)
 	{
 		ereport(elevel,
@@ -829,6 +830,17 @@ durable_rename_excl(const char *oldfile, const char *newfile, int elevel)
 		return -1;
 	}
 	unlink(oldfile);
+#else
+	/* XXX: Add racy file existence check? */
+	if (rename(oldfile, newfile) < 0)
+	{
+		ereport(elevel,
+				(errcode_for_file_access(),
+				 errmsg("could not rename file \"%s\" to \"%s\": %m",
+						oldfile, newfile)));
+		return -1;
+	}
+#endif
 
 	/*
 	 * Make change persistent in case of an OS crash, both the new entry and

  [application/pgp-signature] signature.asc (832B, ../YFUmi3diUlqyoL44@paquier.xyz/3-signature.asc)
  download

view thread (29+ messages)  latest in thread

Message-ID: <YFUmi3diUlqyoL44@paquier.xyz>
Permalink:  ../YFUmi3diUlqyoL44@paquier.xyz/
Also on:    postgresql.org/message-id/YFUmi3diUlqyoL44@paquier.xyz

 ·  · 

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-bugs@postgresql.org
  Cc: michael@paquier.xyz, magnus@hagander.net, tgl@sss.pgh.pa.us, yarik97.6@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16927: Postgres can`t access WAL files
  In-Reply-To: <YFUmi3diUlqyoL44@paquier.xyz>

* 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