Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMI1I-000490-J9 for pgsql-general@arkaria.postgresql.org; Tue, 16 Mar 2021 22:18:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lMI1G-0007ut-IP for pgsql-general@arkaria.postgresql.org; Tue, 16 Mar 2021 22:18:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMI1F-0007um-0S for pgsql-general@lists.postgresql.org; Tue, 16 Mar 2021 22:18:30 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMI1B-0005nh-KB for pgsql-general@postgresql.org; Tue, 16 Mar 2021 22:18:28 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 70AC65C00D5; Tue, 16 Mar 2021 18:18:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 16 Mar 2021 18:18:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=8pS7K2fntq4xDzqHe1UzhCr9kHR LN33utdSf46efCM8=; b=L/Pm4vYAXVyaCMTaX0kxlFOSORAlMwITs8/pyrh/40c fMk8sEAO0UvW5M4cuwH1QsBXVfpQjwwfEzi8zSh3tpYfFXRVeTxQ+2rcvgbPV4/I BF14mtG7MbSy/9j/M7Nv9l/23pw2tI6Gl7+OwbR1/3jZNMtHIPXg8ZzkRGgrgdVr jz2O8lSnvgWHPMX4EKqD2AR3JpAqpzrQwjhFIMgwnqF23JVV70CfljT8BSMJmThV Ylauq1vGDaSzGJrOKA4j6fZWHe6VKXoVtBQT6hsmEGHr9yJt/jIbzRGl5yUAxCnr uGT3WHtkE0oYsGgv1K7FrJNH3cSFhmwWIzmILlrJ9KQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=8pS7K2 fntq4xDzqHe1UzhCr9kHRLN33utdSf46efCM8=; b=N8cqVt/vtE+IjGCwfvCUlr EX1zuQEhcwBbFmsPbR1KJhxtT1QMfMyOis94lEiOo5u+Qv4cwXgU6bb2FLucMR9s FvEiHQYYCstOQcBAHA6A9KiGXjTbJZkC7UqqeTH65eoyuU/JdPI5klu5dG6CCHCm Satr7XSf+A3ylsgpOS/oYvdyJGWGJzJ51hdzx34ZPS/efqe/0tqgQQbLzZ4KfnGb gyJu4RYNd3iD2OX7IAh+W2PJroQ9hdCsmhgnEgx/SaeEMTurnuNoWcKG3+zOKm5+ yK1P4M4pcnn8Apxk2HHvgss0BJbqW3O7L8Iaek3i3RTOL9/aFxjkwxx1RrzuTM4g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefvddgudeiudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredt tddunecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepvedtgfekudduueevteefgefg jeduvddtteeuhfelueffueekiefhjefgieegudelnecukfhppeduuddurddutddvrdduke dtrddukeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id 4F364108005C; Tue, 16 Mar 2021 18:18:19 -0400 (EDT) Date: Wed, 17 Mar 2021 07:18:15 +0900 From: Michael Paquier To: Andrus Cc: Thomas Munro , Niels Jespersen , Tom Lane , Laurenz Albe , pgsql-general Subject: Re: SV: Log files polluted with permission denied error messages after every 10 seconds Message-ID: References: <1881481.1615240712@sss.pgh.pa.us> <94330326-5fa0-279a-937c-c4806e1fcd5a@hot.ee> <2586bd2e-77d4-e3e2-2f30-d5c83f52f001@hot.ee> <2b675d25-e86c-ea29-b02e-6bad5d55fbe3@hot.ee> <22ec98b1-cc2f-8e6a-f1d7-ee528237f2fb@hot.ee> <78e6daee-0323-752d-c142-263a80154e18@hot.ee> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ygl9RjIGmGq0kxiL" Content-Disposition: inline In-Reply-To: <78e6daee-0323-752d-c142-263a80154e18@hot.ee> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ygl9RjIGmGq0kxiL Content-Type: multipart/mixed; boundary="8DZamL9ESyk4Ky4k" Content-Disposition: inline --8DZamL9ESyk4Ky4k Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 16, 2021 at 01:59:07PM +0200, Andrus wrote: > I have two Windows 2019 servers. In Intel Xeon Cold 6226R server it occurs > after every 10 seconds. Last logs: >=20 > 2021-03-16 13:48:12 EET=A0=A0=A0=A0 checkpointer LOG:=A0 could not rename= file > "pg_wal/000000010000001100000097": Permission denied > 2021-03-16 13:48:22 EET=A0=A0=A0=A0 checkpointer LOG:=A0 could not rename= file > "pg_wal/000000010000001100000098": Permission denied > 2021-03-16 13:48:32 EET=A0=A0=A0=A0 checkpointer LOG:=A0 could not rename= file > "pg_wal/000000010000001100000099": Permission denied > 2021-03-16 13:48:42 EET=A0=A0=A0=A0 checkpointer LOG:=A0 could not rename= file > "pg_wal/00000001000000110000009A": Permission denied > 2021-03-16 13:48:52 EET=A0=A0=A0=A0 checkpointer LOG:=A0 could not rename= file > "pg_wal/00000001000000110000009D": Permission denied > 2021-03-16 13:49:02 EET=A0=A0=A0=A0 checkpointer LOG:=A0 could not rename= file > "pg_wal/0000000100000011000000A0": Permission denied >=20 > So It should be probably reproducible in any Windows 2019 server. Those ten seconds are coming from RemoveXlogFile(), where pgrename() loops 100 times for 100ms before giving up. So something holding up the file's handle prevents the removal to happen. Attached is the patch that should be tested, based on the suspected commit. There are actually two scenarios to worry about: - Check that the code of 13.2 compiled manually is enough to see the failure. - Check that once the patch attached is applied makes the failure go away. I am trying on my side to reproduce the problem in a more reliable way. One thing I saw breaking in my setup is archive_command, where it was not able to archive a segment with a simple copy, failing with the same error as yours. In one of those servers, do you have in pg_wal/ some files named xlogtemp.N? N is an integer that would be the PID of the process that generated it. -- Michael --8DZamL9ESyk4Ky4k Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Revert-Remove-HAVE_WORKING_LINK.patch" Content-Transfer-Encoding: quoted-printable =46rom 961f9a03d4c27220c33e88402d5ef274424a0ab2 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Wed, 17 Mar 2021 07:12:35 +0900 Subject: [PATCH] Revert "Remove HAVE_WORKING_LINK" This reverts commit aaa3aeddee51dd0058d38469907865052706a590. --- src/include/pg_config_manual.h | 7 +++++++ src/include/storage/fd.h | 2 +- src/backend/access/transam/timeline.c | 4 ++-- src/backend/access/transam/xlog.c | 4 ++-- src/backend/storage/file/fd.c | 21 ++++++++++++++++----- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h index 8f3ec6bde1..966da99742 100644 --- a/src/include/pg_config_manual.h +++ b/src/include/pg_config_manual.h @@ -135,6 +135,13 @@ #define EXEC_BACKEND #endif =20 +/* + * 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/include/storage/fd.h b/src/include/storage/fd.h index 8cd125d7df..2085c62b41 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -157,7 +157,7 @@ extern void fsync_fname(const char *fname, bool isdir); extern int fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm= , int elevel); extern int durable_rename(const char *oldfile, const char *newfile, int lo= glevel); extern int durable_unlink(const char *fname, int loglevel); -extern int durable_rename_excl(const char *oldfile, const char *newfile, i= nt loglevel); +extern int durable_link_or_rename(const char *oldfile, const char *newfile= , int loglevel); extern void SyncDataDirectory(void); extern int data_sync_elevel(int elevel); =20 diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/tra= nsam/timeline.c index e6a29d9a9b..27d70ff869 100644 --- a/src/backend/access/transam/timeline.c +++ b/src/backend/access/transam/timeline.c @@ -446,7 +446,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID pare= ntTLI, * Perform the rename using link if available, paranoidly trying to avoid * overwriting an existing file (there shouldn't be one). */ - durable_rename_excl(tmppath, path, ERROR); + durable_link_or_rename(tmppath, path, ERROR); =20 /* The history file can be archived immediately. */ if (XLogArchivingActive()) @@ -524,7 +524,7 @@ writeTimeLineHistoryFile(TimeLineID tli, char *content,= int size) * Perform the rename using link if available, paranoidly trying to avoid * overwriting an existing file (there shouldn't be one). */ - durable_rename_excl(tmppath, path, ERROR); + durable_link_or_rename(tmppath, path, ERROR); } =20 /* diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam= /xlog.c index 7daa7c43ad..82e070e431 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -3624,11 +3624,11 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmpp= ath, * Perform the rename using link if available, paranoidly trying to avoid * overwriting an existing file (there shouldn't be one). */ - if (durable_rename_excl(tmppath, path, LOG) !=3D 0) + if (durable_link_or_rename(tmppath, path, LOG) !=3D 0) { if (use_lock) LWLockRelease(ControlFileLock); - /* durable_rename_excl already emitted log message */ + /* durable_link_or_rename already emitted log message */ return false; } =20 diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index e5950b0726..ba92ceaf65 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -767,11 +767,10 @@ durable_unlink(const char *fname, int elevel) } =20 /* - * durable_rename_excl -- rename a file in a durable manner, without - * overwriting an existing target file + * durable_link_or_rename -- rename a file in a durable manner. * - * Similar to durable_rename(), except that this routine will fail if the - * target file already exists. + * Similar to durable_rename(), except that this routine tries (but does n= ot + * guarantee) not to overwrite the target file. * * Note that a crash in an unfortunate moment can leave you with two links= to * the target file. @@ -782,7 +781,7 @@ durable_unlink(const char *fname, int elevel) * valid upon return. */ int -durable_rename_excl(const char *oldfile, const char *newfile, int elevel) +durable_link_or_rename(const char *oldfile, const char *newfile, int eleve= l) { /* * Ensure that, if we crash directly after the rename/link, a file with @@ -791,6 +790,7 @@ durable_rename_excl(const char *oldfile, const char *ne= wfile, int elevel) if (fsync_fname_ext(oldfile, false, false, elevel) !=3D 0) return -1; =20 +#ifdef HAVE_WORKING_LINK if (link(oldfile, newfile) < 0) { ereport(elevel, @@ -800,6 +800,17 @@ durable_rename_excl(const char *oldfile, const char *n= ewfile, 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 =20 /* * Make change persistent in case of an OS crash, both the new entry and --=20 2.30.2 --8DZamL9ESyk4Ky4k-- --ygl9RjIGmGq0kxiL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmBRLqcACgkQnvQgOdby QH0A+w//fSmKG5rqVv0LBIXcooc7cjDZHVUlmfepqn92Z+XDDiWevnq4dQWuaGwC QqHKSQdJhAxKk02+OQmnB8G4dUgVFAuM4YWC/NbO6VqNP8kYjDOQs5Upr971nOf+ 5TCzwwTAHpQvJXIaUvReKTw8S6T5rzhoCLHCJAKVTcwACWcElpiXxAqJ68kYf1i/ ah06a4N0eikume1OKyo8juOP0onvktN+pIm4F5BJ4llGd5I7DVjPUFN5snqc2Ofy r+sTwpFyqqLgmNImMigvC9PVfJDpsRNZu2aElK3pnVVlVFwGmgAcTWsG2QcrHtbm frbbN+NuljytbXftriO7uvBhXiGNTBIbVIjLtfPkKEv9o65UxU/5TjO5MbjsgL5n swefU4jk2c5eLAgqf/4YmDO3r55YzvRRZ+ZliZeBdzJg9CZTYMs32O3zdq/wUIuS y/G4xHnC/lMw+Gf5Qoej7Jf6aLKdF6+dxo4Gw6PItwkjTfV6Z3MkOeZ5MvtVl2FM 2dmlX0OVF838VAHjFXfIQzYMMJJc/jvuSjA8/ZI5AIza6M5xTHLm0TzV00jHGMso FnbLDFO7Ihs5Zf37s1KbY2GOJBZnkhGyQYtF0Zv2ZGIKdiR/jSk8w4bZbkwzS802 C0i99/ciQFRJ8UMCb14UnSDq+IGh3TYhHsv0OaHNU28U5hg3l9c= =mSbn -----END PGP SIGNATURE----- --ygl9RjIGmGq0kxiL--