Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfkTl-0004s7-2O for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Jun 2019 12:23:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfkTj-0004EW-UI for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Jun 2019 12:23:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfkTi-0004DI-QH for pgsql-hackers@lists.postgresql.org; Tue, 25 Jun 2019 12:23:15 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfkTf-0005Js-18 for pgsql-hackers@postgresql.org; Tue, 25 Jun 2019 12:23:13 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 1A7D044D; Tue, 25 Jun 2019 08:23:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 25 Jun 2019 08:23:09 -0400 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=fm3; bh=gfcIQF Mv5wlTPtU+SzNL1PWXRE7UIEdoM4Em2Ee+j88=; b=jNPnMNioHoB7tn6QZI6CTZ OtnEjZ31kdVzbds0B6APYBMPrcZvMjv8j3BtDAdhgQvaXuH0HGLzhUOnv5Fk0Bsw g9YFpIPc5eTY+pRRzvexAVpLrSGd49lWfx+jEZjipGwLyJtGHYSjsRBZCEqcso9C LO12JwegJci+Mo4tz6n7kzYd3mBrMZj2g1hX8bnB7xaaBXRGbojFJcCpdINcbADy 9omNn+QmrcReB3sD7XvC2qKSaKeGmftx+ZsV9uhvtf/pgrTKE7MgC5UBUTOAdunV wuAAqv+YpwqPZ6FtcOqZHe/IYKFJo4nCnASuebvEKRExK4KoKMXx91TwRaorKv8g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudeggdehvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhfhokffffgggjggtsehmtderredtfeehnecuhfhrohhmpefrvghtvghr ucfgihhsvghnthhrrghuthcuoehpvghtvghrrdgvihhsvghnthhrrghuthesvdhnughquh grughrrghnthdrtghomheqnecuffhomhgrihhnpedvnhguqhhurggurhgrnhhtrdgtohhm necukfhppeelfedrvdegvddrgedtrddvtddvnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hpvghtvghrrdgvihhsvghnthhrrghuthesvdhnughquhgrughrrghnthdrtghomhenucev lhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from april.pezone.net (p5df228ca.dip0.t-ipconnect.de [93.242.40.202]) by mail.messagingengine.com (Postfix) with ESMTPA id B3AE78005C; Tue, 25 Jun 2019 08:23:07 -0400 (EDT) Subject: Re: fsync error handling in pg_receivewal, pg_recvlogical To: Michael Paquier References: <9b49fe44-8f3e-eca9-5914-29e9e99030bf@2ndquadrant.com> <20190329130505.GG1954@paquier.xyz> Cc: pgsql-hackers From: Peter Eisentraut Openpgp: preference=signencrypt Autocrypt: addr=peter.eisentraut@2ndquadrant.com; prefer-encrypt=mutual; keydata= xsFNBFUUt6kBEADZd9NNTBJbHmAXXJgPGOdd6Q73l80oifIVgn2tRxP9dYkCf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j9vsCjaDu13rABEBAAHCwV8E GAEIAAkFAlUUt6kCGwwACgkQoZ8SQ+xBJp+HJhAAxmSTsC5y7p9Zu+nnLpucv/h88oEx985e qWeXzQiwM3pfRZS+PdTH9TyzHK0KOgKoAiubk0vt+BrT91D9d0G5kVQaTctAErGBoMkTaZJT XVEcNphiPzysdSqvprjojMp1y7rG8AP+Xd6m0rE1LRnkRRm8HyI8vdXsuLQPITGWXDLMjaNq AOV3BUnzkgtjMuIYw7SCr+12ZOb5dEKvaG4kjC4kaJ/TLbuBhVANcXkC90yp0AOZLs/cB1Dj OAXno/RUUruJ3r27a+pFv768UAi9QWcdw58yPxreMNMLqAgsS9oTHwHfGNWcB2dJ4UW+GMLJ hTf9TjQ2f+N/sIx5XMQ9pYw6CAJMK29qPx6/ZayrPxf22EXf0D3zTwIEZgwfSkynFVwV25L7 awQq60fifdMYheSxq7GbhpsixmcD+e161cCmLIt75YDt5bQ0B1yf7EmxG8n7pGZAOM6LoNsU fkSldba5XVwh8LuN5mK0nQBELGW6Os4TDq4REggLpfcvFC215zpuo0iCGnmE/Bns4nowqUSP u4tkWL+nxW4qgv8wo8HJ52jd79EJ8iqfIBoidBfy9AIUiEUApGQzWPu6yWcI8fY0rN5D+tc+ Yw1Zt6Mm+huYJpgCRsTcfzEcahnBn521CWcWvhW1ff3KFileFMtNmnBBhMncmRKHphtTKEpN 3jI= Organization: 2ndQuadrant Message-ID: <43bba31e-c520-2de0-1b02-5672bc7faf70@2ndquadrant.com> Date: Tue, 25 Jun 2019 14:23:05 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190329130505.GG1954@paquier.xyz> Content-Type: multipart/mixed; boundary="------------FD58F2D0F6ABC7B4E776A847" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------FD58F2D0F6ABC7B4E776A847 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 2019-03-29 14:05, Michael Paquier wrote: > Yes, I think that we are going to need an equivalent of that for all > frontend tools. At various degrees, making sure that a fsync happens > is also important for pg_dump, pg_basebackup, pg_rewind and > pg_checksums so it is not only a problem of the two tools you mention. > It seems to me that the most correct way to have those failures would > be to use directly exit(EXIT_FAILURE) in file_utils.c where > appropriate. Yeah, there is more to do. The reason I'm focusing on these two right now is that they would typically run as a background service, and a clean exit is most important there. In the other cases, the program runs more often in the foreground and you can see error messages. There are also some cases where fsync() failures are intentionally ignored ((void) casts), so some of that would need to be investigated further. Here is a patch to get started. Note that these calls don't go through file_utils.c, so it's a separate issue anyway. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------FD58F2D0F6ABC7B4E776A847 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="0001-Handle-fsync-failures-in-pg_receivewal-and-pg_recvlo.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Handle-fsync-failures-in-pg_receivewal-and-pg_recvlo.pa"; filename*1="tch" From 8f275321775f41d4a46ea6e1b10765c68fe2653d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 25 Jun 2019 14:19:26 +0200 Subject: [PATCH] Handle fsync failures in pg_receivewal and pg_recvlogical It is not safe to simply report an fsync error and continue. We must exit the program instead. --- src/bin/pg_basebackup/pg_recvlogical.c | 4 ++-- src/bin/pg_basebackup/receivelog.c | 12 ++++++------ src/bin/pg_basebackup/walmethods.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index b029118bf6..9d8f8c74f8 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -192,8 +192,8 @@ OutputFsync(TimestampTz now) if (fsync(outfd) != 0) { - pg_log_error("could not fsync file \"%s\": %m", outfile); - return false; + pg_log_fatal("could not fsync file \"%s\": %m", outfile); + exit(2); } return true; diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index 2fd16421aa..81fc1b0a01 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -134,10 +134,10 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint) /* fsync file in case of a previous crash */ if (stream->walmethod->sync(f) != 0) { - pg_log_error("could not fsync existing write-ahead log file \"%s\": %s", + pg_log_fatal("could not fsync existing write-ahead log file \"%s\": %s", fn, stream->walmethod->getlasterror()); stream->walmethod->close(f, CLOSE_UNLINK); - return false; + exit(2); } walfile = f; @@ -763,9 +763,9 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream, { if (stream->walmethod->sync(walfile) != 0) { - pg_log_error("could not fsync file \"%s\": %s", + pg_log_fatal("could not fsync file \"%s\": %s", current_walfile_name, stream->walmethod->getlasterror()); - goto error; + exit(2); } lastFlushPosition = blockpos; @@ -1015,9 +1015,9 @@ ProcessKeepaliveMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len, */ if (stream->walmethod->sync(walfile) != 0) { - pg_log_error("could not fsync file \"%s\": %s", + pg_log_fatal("could not fsync file \"%s\": %s", current_walfile_name, stream->walmethod->getlasterror()); - return false; + exit(2); } lastFlushPosition = blockpos; } diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index 83b520898b..d8abea6dc6 100644 --- a/src/bin/pg_basebackup/walmethods.c +++ b/src/bin/pg_basebackup/walmethods.c @@ -864,7 +864,7 @@ tar_close(Walfile f, WalCloseMethod method) /* Always fsync on close, so the padding gets fsynced */ if (tar_sync(f) < 0) - return -1; + exit(2); /* Clean up and done */ pg_free(tf->pathname); -- 2.22.0 --------------FD58F2D0F6ABC7B4E776A847--