Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8EtO-0003sW-GS for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Oct 2018 01:26:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g8EtM-0005Fb-58 for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Oct 2018 01:26:56 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8EtL-0005FU-UJ for pgsql-hackers@lists.postgresql.org; Fri, 05 Oct 2018 01:26:55 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8EtI-0005r7-E6 for pgsql-hackers@postgresql.org; Fri, 05 Oct 2018 01:26:55 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 109AD2102F; Thu, 4 Oct 2018 21:26:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 04 Oct 2018 21:26:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:mime-version:content-type; s= fm2; bh=YXCiEKm3hblwKhXSszVVJJeY0AfGVodhUX4qKZ5yZ04=; b=e5NRw1gZ IvAhcUa97R+GRwuoqg+9gOxd4LveJ3nCRE2/MRkEUiIXpR5k2CkRfkyMSC681BVh u/B53Qv19r63Acnhm5xqXPQC9VB9CsVf9exikmIXO6PA85aYYE7a7peazAbUR5GK 3wcLSrMvM4hhaHdC1GyySYJg50wXSrbxSG4/wRRsVXq/BdchBNICFxlSz2qqy0j1 vayO+j4azthmekdLwJQqT4nkBUOCzVn76A/RhOdckzNYwuyprvNyM8G6OkNLD8aA SnwExq0YUXqO1k3lGcU8KLlijg2baAsqLGzEOC5DzIBzcmhbbdby3qyxRL7MMTzH /dtsWYczJ0j0pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=YXCiEKm3hblwKhXSszVVJJeY0AfGV odhUX4qKZ5yZ04=; b=CznE32ESZdUZvvBquOepQlrXKdIrFJjQ3vTG/z7OZSY8m iB6aNhLCeGzysAJC52Lu/irH5A6DtLm405SXs7+3PfgNmaIiFigoV1GjHxec97Pc 1vTHc3hxw0JpJRnPPGND5PjKmdLzTesi0f9s4TJj8y61arC/hOOXDq/73P/p3Geh mlK2wDA1Cgs+SmQFRYpqKDVfS3dX06nzRse46XJmBDx6vnoOU5hXqy6eQW/nZZXD BvFLHjlHN/6XAe+JxQAhe0wpB9iu7PnjAEPjcaz4sSbK+1Ebe0bNozleJmns/7/J 9sZmnJM6fY9hNVBs0fzXQa8QDY4AMkusj3vwOawvQ== X-ME-Sender: X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 44CE4102E2; Thu, 4 Oct 2018 21:26:47 -0400 (EDT) Date: Fri, 5 Oct 2018 10:26:45 +0900 From: Michael Paquier To: Postgres hackers Cc: Magnus Hagander , Michael Banck Subject: TAP tests for pg_verify_checksums Message-ID: <20181005012645.GE1629@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="TeJTyD9hb8KJN2Jy" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --TeJTyD9hb8KJN2Jy Content-Type: multipart/mixed; boundary="vmttodhTwj0NAgWp" Content-Disposition: inline --vmttodhTwj0NAgWp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, The topic of $subject has been discussed a bit times, resulting in a couple of patches on the way: https://www.postgresql.org/message-id/20180830200258.GG15446@paquier.xyz https://www.postgresql.org/message-id/CABUevEzEKrwPeGK2o-OV4z2MjfT6Cu8cLfA-v1S1j4z8x7WJjg@mail.gmail.com However nothing has actually happened. Based on the previous feedback, attached is an updated patch to do the actual job. Magnus Hagander and Michael Banck need to be credited as authors, as this patch is roughly a merge of what they proposed. Thoughts? -- Michael --vmttodhTwj0NAgWp Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="verify-checksums-tap-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/initdb/t/001_initdb.pl b/src/bin/initdb/t/001_initdb.pl index 5dc629fd5e..610887e5d4 100644 --- a/src/bin/initdb/t/001_initdb.pl +++ b/src/bin/initdb/t/001_initdb.pl @@ -8,7 +8,7 @@ use Fcntl ':mode'; use File::stat qw{lstat}; use PostgresNode; use TestLib; -use Test::More tests =3D> 18; +use Test::More tests =3D> 21; =20 my $tempdir =3D TestLib::tempdir; my $xlogdir =3D "$tempdir/pgxlog"; @@ -58,6 +58,12 @@ mkdir $datadir; "check PGDATA permissions"); } } + +# Control file should tell that data checksums are disabled by default. +command_like(['pg_controldata', $datadir], + qr/Data page checksum version:.*0/, + 'checksums are disabled in control file'); + command_ok([ 'initdb', '-S', $datadir ], 'sync only'); command_fails([ 'initdb', $datadir ], 'existing data directory'); =20 diff --git a/src/bin/pg_verify_checksums/.gitignore b/src/bin/pg_verify_che= cksums/.gitignore index d1dcdaf0dd..0e5e569a54 100644 --- a/src/bin/pg_verify_checksums/.gitignore +++ b/src/bin/pg_verify_checksums/.gitignore @@ -1 +1,3 @@ /pg_verify_checksums + +/tmp_check/ diff --git a/src/bin/pg_verify_checksums/Makefile b/src/bin/pg_verify_check= sums/Makefile index d16261571f..cfe4ab1b8b 100644 --- a/src/bin/pg_verify_checksums/Makefile +++ b/src/bin/pg_verify_checksums/Makefile @@ -34,3 +34,9 @@ uninstall: clean distclean maintainer-clean: rm -f pg_verify_checksums$(X) $(OBJS) rm -rf tmp_check + +check: + $(prove_check) + +installcheck: + $(prove_installcheck) diff --git a/src/bin/pg_verify_checksums/t/001_basic.pl b/src/bin/pg_verify= _checksums/t/001_basic.pl new file mode 100644 index 0000000000..1fa2e12db2 --- /dev/null +++ b/src/bin/pg_verify_checksums/t/001_basic.pl @@ -0,0 +1,8 @@ +use strict; +use warnings; +use TestLib; +use Test::More tests =3D> 8; + +program_help_ok('pg_verify_checksums'); +program_version_ok('pg_verify_checksums'); +program_options_handling_ok('pg_verify_checksums'); diff --git a/src/bin/pg_verify_checksums/t/002_actions.pl b/src/bin/pg_veri= fy_checksums/t/002_actions.pl new file mode 100644 index 0000000000..7423595181 --- /dev/null +++ b/src/bin/pg_verify_checksums/t/002_actions.pl @@ -0,0 +1,52 @@ +# Do basic sanity checks supported by pg_verify_checksums using +# an initialized cluster. + +use strict; +use warnings; +use PostgresNode; +use TestLib; +use Test::More tests =3D> 8; + +# Initialize node with checksums enabled. +my $node =3D get_new_node('node_checksum'); +$node->init(extra =3D> ['--data-checksums']); +my $pgdata =3D $node->data_dir; + +# Control file should know that checksums are disabled. +command_like(['pg_controldata', $pgdata], + qr/Data page checksum version:.*1/, + 'checksums enabled in control file'); + +# Checksums pass on a newly-created cluster +command_ok(['pg_verify_checksums', '-D', $pgdata], + "checksum checks done and passing"); + +# Checks cannot happen for an online cluster +$node->start; +command_fails(['pg_verify_checksums', '-D', $pgdata], + "checksum checks not done"); + +# Create table to corrupt and get its relfilenode +$node->safe_psql('postgres', + "SELECT a INTO corrupt1 FROM generate_series(1,10000) AS a; + ALTER TABLE corrupt1 SET (autovacuum_enabled=3Dfalse);"); + +my $file_corrupted =3D $node->safe_psql('postgres', + "SELECT pg_relation_filepath('corrupt1')"); + +# Set page header and block size +my $pageheader_size =3D 24; +my $block_size =3D $node->safe_psql('postgres', 'SHOW block_size;'); +$node->stop; + +# Time to create a corruption +open my $file, '+<', "$pgdata/$file_corrupted"; +seek($file, $pageheader_size, 0); +syswrite($file, '\0\0\0\0\0\0\0\0\0'); +close $file; + +$node->command_checks_all([ 'pg_verify_checksums', '-D', $pgdata], + 1, + [qr/Bad checksums: 1/s], + [qr/checksum verification failed/s], + 'pg_checksums reports checksum mismatch'); --vmttodhTwj0NAgWp-- --TeJTyD9hb8KJN2Jy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlu2vdUACgkQnvQgOdby QH1Rag//d45x0j6m6MpYmjuCUTLs6g/dw50p+KcnMuT9HPQnH3/J8bmiLsNDYI1Y u802tVjwo9BNuiZYt5NgqsnF+LEIdrMB4hZRWJQ1Yn8oDPo3aKeKQ/oMTeCvtnv/ +c2waOpS5vl24ficcotyup+eDzBpnZqSiSItThj6dLs/ijjgbMh6MZTxzBi+y24e PKlBUypWQ60TX0i1awvW5Q5vvJHMpQ7bNLCWX8rQAwU11SB0J6psFXya1g9+Kr+P mouowoXXyCNr9evCpfhwjB2mzaWp5WCt+kIEXsUaNixQJQwBFaY9Ny3QfzZl2Fw7 jtCgY2EGGOocp/HSbyjJJkaRenHKulmohPakMPg+5pj5ilyqrJ9Vd+h99q5UJ81I SXtav/Ffq/kQcc5bVxcLcY3h3Pcuq/jPTbrLeZ9EOfh0/Zrc8mIgpBsClR5I72IM 2rvnk1v5hJ2rvkkm2/U2k6lJ+h6E9EhUa5ViU6rGv9gmQYHlOSihof1fq/h5CaIf xeRB9eeDtOI6zYi/c0gJTPqsqiAZVrHpQ1fAHfcSRS3MGRDFBoiIPk4xN3uMvlhO fuF802hnTyS73b342nZpXHKKAwq+3d8OJRdA8qtNPyGQ7TNtYdIhNHIq2bs+s3+E OMmm+DDhMsvjNDRE04c7YWb+PIAhxBjHuxTIXfFyd08TPREt+9g= =kN/8 -----END PGP SIGNATURE----- --TeJTyD9hb8KJN2Jy--