public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: Robert Haas <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: Daniel Gustafsson <[email protected]>
Cc: Kyotaro Horiguchi <[email protected]>
Cc: [email protected]
Cc: Ibrar Ahmed <[email protected]>
Cc: [email protected]
Cc: hlinnaka <[email protected]>
Cc: Masahiko Sawada <[email protected]>
Cc: [email protected] <[email protected]>
Cc: Daniel Wood <[email protected]>
Subject: Re: Corruption during WAL replay
Date: Fri, 25 Mar 2022 11:50:48 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+TgmobXjkeptO-rNiOrq8zjUK2QusXKGgsRL-fqPCL0umc+3Q@mail.gmail.com>
References: <CA+Tgmoa_TAJsUnFWzTevg=FzgXFyiHLJAY_L-jMDA=mH=ytysg@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<CA+Tgmoa=1a+A_gK4gqBf7ypK9NyY5bo--Wqc7Wp3xm8fjsrUOQ@mail.gmail.com>
<[email protected]>
<CA+TgmoaH=6MJtcqN44geA6uQqt1PCHg-2UvehScAxSmsUm4KVA@mail.gmail.com>
<[email protected]>
<CA+TgmobXjkeptO-rNiOrq8zjUK2QusXKGgsRL-fqPCL0umc+3Q@mail.gmail.com>
Robert Haas <[email protected]> writes:
> ... It's not
> like a 16-bit checksum was state-of-the-art even when we introduced
> it. We just did it because we had 2 bytes that we could repurpose
> relatively painlessly, and not any larger number. And that's still the
> case today, so at least in the short term we will have to choose some
> other solution to this problem.
Indeed. I propose the attached, which also fixes the unsafe use
of seek() alongside syswrite(), directly contrary to what "man perlfunc"
says to do.
regards, tom lane
Attachments:
[text/x-diff] make-checksum-corruption-more-reliable.patch (1.4K, ../[email protected]/2-make-checksum-corruption-more-reliable.patch)
download | inline diff:
diff --git a/src/bin/pg_checksums/t/002_actions.pl b/src/bin/pg_checksums/t/002_actions.pl
index 62c608eaf6..8c70453a45 100644
--- a/src/bin/pg_checksums/t/002_actions.pl
+++ b/src/bin/pg_checksums/t/002_actions.pl
@@ -24,6 +24,7 @@ sub check_relation_corruption
my $tablespace = shift;
my $pgdata = $node->data_dir;
+ # Create table and discover its filesystem location.
$node->safe_psql(
'postgres',
"CREATE TABLE $table AS SELECT a FROM generate_series(1,10000) AS a;
@@ -37,9 +38,6 @@ sub check_relation_corruption
my $relfilenode_corrupted = $node->safe_psql('postgres',
"SELECT relfilenode FROM pg_class WHERE relname = '$table';");
- # Set page header and block size
- my $pageheader_size = 24;
- my $block_size = $node->safe_psql('postgres', 'SHOW block_size;');
$node->stop;
# Checksums are correct for single relfilenode as the table is not
@@ -55,8 +53,12 @@ sub check_relation_corruption
# Time to create some corruption
open my $file, '+<', "$pgdata/$file_corrupted";
- seek($file, $pageheader_size, SEEK_SET);
- syswrite($file, "\0\0\0\0\0\0\0\0\0");
+ my $pageheader;
+ sysread($file, $pageheader, 24) or die "sysread failed";
+ # This inverts the pd_checksum field (only); see struct PageHeaderData
+ $pageheader ^= "\0\0\0\0\0\0\0\0\xff\xff";
+ sysseek($file, 0, 0) or die "sysseek failed";
+ syswrite($file, $pageheader) or die "syswrite failed";
close $file;
# Checksum checks on single relfilenode fail
view thread (92+ messages) latest in thread
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: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Corruption during WAL replay
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox