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 1i2Kqy-0002iO-Hz for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Aug 2019 19:40:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i2Kqw-00029S-EN for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Aug 2019 19:40:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2Kqv-000297-5r for pgsql-hackers@lists.postgresql.org; Mon, 26 Aug 2019 19:40:34 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2Kqr-00079z-4i for pgsql-hackers@postgresql.org; Mon, 26 Aug 2019 19:40:32 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id E0835210DC; Mon, 26 Aug 2019 15:40:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 26 Aug 2019 15:40:26 -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=0wAMob ecqRqMTWJG4kt2n4P6/H4VUDGCIMOnwOmDUgA=; b=nSkK68wePJGso82lFbS6KX 6enZ+vZAQYT2iCb09j1KY+PzcYSfHBoGAXNAyGZEi0Qe4O+3nh6N9VWJ657kv6mu zrdNtar6Opq/nMxbqOxOTSJbqty0vix/zhdWN/z3B2OfKN5c9qYEsbEHy5TRBxIi 1JFkADiLIxb152mpKkUYhoqFJbCKNN2ka/GI6iwEY5uDbj7BEIJt+4sjOsfzutk5 T4ZyeUG1aXAuywB8IG+KtwjCD8yjBn5gZELRW0ll5QSAXOLocWqM4QDB+py2bujE r8en1M1HXSeBnU/l02dKCw0QxuePbt/r7yY3cFQ+e2QThhWRgBriGXymuIVjwrOg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudehgedgudegtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhfhokffffgggjggtsehmtderredtfeehnecuhfhrohhmpefrvght vghrucfgihhsvghnthhrrghuthcuoehpvghtvghrrdgvihhsvghnthhrrghuthesvdhnug hquhgrughrrghnthdrtghomheqnecuffhomhgrihhnpedvnhguqhhurggurhgrnhhtrdgt ohhmnecukfhppeelfedrvdegvddrgedtrddvtddvnecurfgrrhgrmhepmhgrihhlfhhroh hmpehpvghtvghrrdgvihhsvghnthhrrghuthesvdhnughquhgrughrrghnthdrtghomhen ucevlhhushhtvghrufhiiigvpedt 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 5E3C58005A; Mon, 26 Aug 2019 15:40:25 -0400 (EDT) Subject: Re: fix "Success" error messages To: Michael Paquier , Shawn Debnath References: <5de61b6b-8be9-7771-0048-860328efe027@2ndquadrant.com> <20190618161319.GA5285@f01898859afd.ant.amazon.com> <20190619025155.GD17450@paquier.xyz> Cc: pgsql-hackers From: Peter Eisentraut Openpgp: preference=signencrypt Autocrypt: addr=peter.eisentraut@2ndquadrant.com; prefer-encrypt=mutual; keydata= xsFNBFUUt6kBEADZd9NNTBJbHmAXXJgPGOdd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PxceA0wA2rSWZSjxLdKxvyGTj9vsCjaDu13rABEBAAHCwV8E 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: <36d38542-63e9-b73c-09fe-bd5e32e06066@2ndquadrant.com> Date: Mon, 26 Aug 2019 21:40:23 +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: <20190619025155.GD17450@paquier.xyz> Content-Type: multipart/mixed; boundary="------------893F683A237131F02D66269A" 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. --------------893F683A237131F02D66269A Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 2019-06-19 04:51, Michael Paquier wrote: > On Tue, Jun 18, 2019 at 09:13:19AM -0700, Shawn Debnath wrote: >>> case SLRU_WRITE_FAILED: >>> ereport(ERROR, >>> (errcode_for_file_access(), >>> errmsg("could not access status of transaction %u", xid), >>> - errdetail("Could not write to file \"%s\" at offset %u: %m.", >>> - path, offset))); >>> + errno == 0 >>> + ? errdetail("Short write to file \"%s\" at offset %u.", path, offset) >>> + : errdetail("Could not write to file \"%s\" at offset %u: %m.", >>> + path, offset))); > > There is no point to call errcode_for_file_access() if we know that > errno is 0. Not a big deal, still.. The last time I looked at that, > the best way I could think of would be to replace slru_errcause with a > proper error string generated at error time. Perhaps the partial > read/write case does not justify this extra facility. I don't know. > At least that would be more flexible. Here is an updated patch set that rearranges this a bit according to your suggestions, and also fixes some similar issues in pg_checksums. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------893F683A237131F02D66269A Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="v2-0001-Better-error-messages-for-short-reads-writes-in-S.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="v2-0001-Better-error-messages-for-short-reads-writes-in-S.pa"; filename*1="tch" From d1d306f80c53a59b67823ae044bf85a2718ea94e Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 26 Aug 2019 21:37:10 +0200 Subject: [PATCH v2 1/2] Better error messages for short reads/writes in SLRU This avoids getting a Could not read from file ...: Success. for a short read or write (since errno is not set in that case). Instead, report a more specific error messages. --- src/backend/access/transam/slru.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c index 0fbcb4e6fe..e38f9199dd 100644 --- a/src/backend/access/transam/slru.c +++ b/src/backend/access/transam/slru.c @@ -920,18 +920,29 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid) path, offset))); break; case SLRU_READ_FAILED: - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not access status of transaction %u", xid), - errdetail("Could not read from file \"%s\" at offset %u: %m.", - path, offset))); + if (errno) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not access status of transaction %u", xid), + errdetail("Could not read from file \"%s\" at offset %u: %m.", + path, offset))); + else + ereport(ERROR, + (errmsg("could not access status of transaction %u", xid), + errdetail("Could not read from file \"%s\" at offset %u: read too few bytes.", path, offset))); break; case SLRU_WRITE_FAILED: - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not access status of transaction %u", xid), - errdetail("Could not write to file \"%s\" at offset %u: %m.", - path, offset))); + if (errno) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not access status of transaction %u", xid), + errdetail("Could not write to file \"%s\" at offset %u: %m.", + path, offset))); + else + ereport(ERROR, + (errmsg("could not access status of transaction %u", xid), + errdetail("Could not write to file \"%s\" at offset %u: wrote too few bytes.", + path, offset))); break; case SLRU_FSYNC_FAILED: ereport(data_sync_elevel(ERROR), base-commit: acb96eb7d294a003a9392cdd445630ef137d9918 -- 2.22.0 --------------893F683A237131F02D66269A Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="v2-0002-pg_checksums-Handle-read-and-write-returns-correc.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="v2-0002-pg_checksums-Handle-read-and-write-returns-correc.pa"; filename*1="tch" From 89fe3678ef9443fc56a8ebfc3657ad06f5585bf5 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 26 Aug 2019 21:37:50 +0200 Subject: [PATCH v2 2/2] pg_checksums: Handle read and write returns correctly The read() return was not checking for errors, the write() return was not checking for short writes. --- src/bin/pg_checksums/pg_checksums.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c index 8c00ec9a3b..40619be0fa 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c @@ -196,7 +196,13 @@ scan_file(const char *fn, BlockNumber segmentno) if (r == 0) break; - if (r != BLCKSZ) + else if (r < 0) + { + pg_log_error("could not read block %u in file \"%s\": %m", + blockno, fn); + exit(1); + } + else if (r != BLCKSZ) { pg_log_error("could not read block %u in file \"%s\": read %d of %d", blockno, fn, r, BLCKSZ); @@ -222,6 +228,8 @@ scan_file(const char *fn, BlockNumber segmentno) } else if (mode == PG_MODE_ENABLE) { + int w; + /* Set checksum in page header */ header->pd_checksum = csum; @@ -233,10 +241,15 @@ scan_file(const char *fn, BlockNumber segmentno) } /* Write block with checksum */ - if (write(f, buf.data, BLCKSZ) != BLCKSZ) + w = write(f, buf.data, BLCKSZ); + if (w != BLCKSZ) { - pg_log_error("could not write block %u in file \"%s\": %m", - blockno, fn); + if (w < 0) + pg_log_error("could not write block %u in file \"%s\": %m", + blockno, fn); + else + pg_log_error("could not write block %u in file \"%s\": wrote %d of %d", + blockno, fn, w, BLCKSZ); exit(1); } } -- 2.22.0 --------------893F683A237131F02D66269A--