Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHLql-006Q6U-Vv for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Nov 2024 11:41:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tHLqh-00G4LB-Ui for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Nov 2024 11:41:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHLqh-00G4L3-KK for pgsql-hackers@lists.postgresql.org; Sat, 30 Nov 2024 11:41:20 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tHLqf-000JFv-R1 for pgsql-hackers@lists.postgresql.org; Sat, 30 Nov 2024 11:41:20 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-434a2f3bae4so24869005e9.3 for ; Sat, 30 Nov 2024 03:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732966877; x=1733571677; darn=lists.postgresql.org; h=user-agent:content-disposition:mime-version:subject:to:from:date :sender:message-id:from:to:cc:subject:date:message-id:reply-to; bh=R6vdB80TJx6T1h9R5X9rt6+rGy8vWCMUCQqjVjEBE+c=; b=R/a6jReK6UBhpOlwXN7NGFTjUgcJd+DFDlHKlBRumT0+qyCukMj0lzveepdDWKk+j7 Q+b3PX9HosDlYCt21l3yTa3EftYI5PMzeCKMFw0HtHXct2HURgMA7goe5PaPRRTJ9tVd 4tPNSFn+H8RBHoqcCJAhHe8aZTlYfQ95oUz0HsbaLV6Fz38IegbV3fVwH9DQLV5WkjlT ixbkTiY7ajAMLpIAsXDQEA1ZuB7roBoZLiDrEGPQ62PuUsgs5i50jY/DJ8ea+m2MeIWg YThaXTsGA1AAQLjZUdRhsIdv1ZqBPjfX4ytQ3+oDdRIhmjV69nQi/MO8F+k1lKn+DXb/ iy6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732966877; x=1733571677; h=user-agent:content-disposition:mime-version:subject:to:from:date :sender:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=R6vdB80TJx6T1h9R5X9rt6+rGy8vWCMUCQqjVjEBE+c=; b=m+dfZhJP01WZ8SCRETkj1uIvMP8FyUJO7zXrSTpWOImnhj9JiKT+WcN+0VLIFmX8Ni e/v96vZx4gHwaDa8W21H/cyGS4q19QIVjSkuZbSo0N/zLWLtIUtXxwnaVNhEVjuH0d6x TQvg2HteiLhzh23YKrFnoAK8X8gRxJalp2F3z/hU5uh66fems8QQq6XS23K5cXHTJmix 3STP6rGWtfX0lvl7Xoh9OEliZgoooLX+n7VFE4iOw806NJQ/zDq8ftBZ8yzVR5KOTzSf Da6JDKgB7m+A1sPVgZi0KVwTJf8blEi2EJ4Ah9kcUvvW5j4tajBmvjzyPihNnDR9K3+7 VPfw== X-Gm-Message-State: AOJu0YxmkHqrYwDiXpgvwVeCyVx2lxY6QJyEOyUO9u/eBpkg+yeKsNdR wxzavz3Z0zlNG/2AxuYhTOfEk3y+G35GmFYLVQCkZkectjPBAymYtEtDcA== X-Gm-Gg: ASbGncuFQCUPK5+K6xXxgSOYa60o/xa5GKJRVUqCHeJDo4gNWAM3jl5ubD1JtSjWlRm xCycVLRxd8o5nhTvJdCciDr7Du42BO3nfQ25qE9cK6y523rKft0SDst+CQ61cfNtMGcGzR+cC7E n+pyY6HhDctvraWnNOs3pKbcxloh5C6cDC1X2D2AcuAjcwIODwXLZr2lpD+6KnYTCYAl5bv6BZe 9I/rLVv6ZHUdOpbfs4aZvFEI2jq6086ST1G35YWiLNiYjp3sJmsLvvSHJlnnW7Qc+XcJ6NAcaL2 geHmiiHW X-Google-Smtp-Source: AGHT+IHQgNdveTlu5HmP13vauW1qu7DLZPaVtNJbSyOK3fuqOghjrbYxJrYJonN/iq3EFqGZ6KaH9Q== X-Received: by 2002:a05:600c:3b9e:b0:434:a4a6:5212 with SMTP id 5b1f17b1804b1-434a9d483a2mr155610425e9.0.1732966876775; Sat, 30 Nov 2024 03:41:16 -0800 (PST) Received: from lightning.caipicrew.dd-dns.de ([2001:a61:ae5:5f01:dd42:6945:ab0a:6c93]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434aa763a59sm114565005e9.11.2024.11.30.03.41.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Nov 2024 03:41:16 -0800 (PST) Message-ID: <674af9dc.050a0220.268e1c.4048@mx.google.com> X-Google-Original-Message-ID: <20241130114115.GB1150@caipicrew.dd-dns.de;lightning.caipicrew.dd-dns.de> Sender: Michael Banck Received: from mbanck by lightning.caipicrew.dd-dns.de with local (Exim 4.92) (envelope-from ) id 1tHLqd-0006ZD-A1 for pgsql-hackers@lists.postgresql.org; Sat, 30 Nov 2024 12:41:15 +0100 Date: Sat, 30 Nov 2024 12:41:15 +0100 From: Michael Banck To: pgsql-hackers@lists.postgresql.org Subject: [patch] Make "invalid record length at : expected at least 24, got 0" message less scary MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="qDbXVdCdHGoSgWSk" Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, we had another case on irc today were a user saw Postgres doing crash recovery due to an unclean shutdown and was very worried about a "invalid record length at : expected at least 24, got 0" message and went on to reindex all databases. This is also a frequent hit on Stack Overflow etc. AFAICT this is a normal message in case the record length is 0 and we have reached end of WAL. So I propose to treat a length of 0 as a special case and emit a less-scary message. Up until 9.4 we did have a message "record with zero length at ", but 2c03216d831 ("Revamp the WAL record format") removed it. I propose to reinstate it, see attached patch. I guess it would be even nicer if we could hint here that we likely reached end-of-WAL, but the helper function report_invalid_record() does not take an errhint and I guess we are too deep into the WAL reader machinery to check for an end-of-WAL condition at that spot. Michael --qDbXVdCdHGoSgWSk Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Re-introduce-less-scary-message-for-possible-end-.patch" From 015a9bfb2bd57f37f7c9601e9014d7560b76c21d Mon Sep 17 00:00:00 2001 From: Michael Banck Date: Sat, 30 Nov 2024 11:51:34 +0100 Subject: [PATCH v1] Re-introduce less scary message for possible end-of-WAL invalid record. A lot of users are worried about messages like "invalid record length at : expected at least 24, got 0" even though for the case of "got 0" this usually just means that we have reached the end of WAL. So make that case less scary by re-introducing a "record with zero length at " message for it. This message was there up until version 9.4, but got removed during a large WAL record format revamp in 2c03216d831. --- src/backend/access/transam/xlogreader.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 0c5e040a94..43ec295ee7 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -662,6 +662,14 @@ restart: } else { + /* Record length is zero. */ + if (total_len == 0) + { + report_invalid_record(state, + "record with zero length at %X/%X", + LSN_FORMAT_ARGS(RecPtr)); + goto err; + } /* There may be no next page if it's too small. */ if (total_len < SizeOfXLogRecord) { @@ -1128,6 +1136,13 @@ ValidXLogRecordHeader(XLogReaderState *state, XLogRecPtr RecPtr, XLogRecPtr PrevRecPtr, XLogRecord *record, bool randAccess) { + if (record->xl_tot_len == 0) + { + report_invalid_record(state, + "record with zero length at %X/%X", + LSN_FORMAT_ARGS(RecPtr)); + return false; + } if (record->xl_tot_len < SizeOfXLogRecord) { report_invalid_record(state, -- 2.39.5 --qDbXVdCdHGoSgWSk--