Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUct6-0001Nz-PS for pgsql-general@arkaria.postgresql.org; Thu, 28 Dec 2017 18:26:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUct6-00014u-5G for pgsql-general@arkaria.postgresql.org; Thu, 28 Dec 2017 18:26:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eUct5-00014k-Qp for pgsql-general@lists.postgresql.org; Thu, 28 Dec 2017 18:26:39 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eUct3-00056I-6T for pgsql-general@lists.postgresql.org; Thu, 28 Dec 2017 18:26:38 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 3B7E85F795; Thu, 28 Dec 2017 13:26:36 -0500 (EST) Date: Thu, 28 Dec 2017 13:26:36 -0500 From: Stephen Frost To: Brent Wood Cc: Edson Carlos Ericksson Richter , "pgsql-general@lists.postgresql.org" Subject: Re: Does PostgreSQL check database integrity at startup? Message-ID: <20171228182636.GG4628@tamriel.snowman.net> References: <20171227213314.GY4628@tamriel.snowman.net> <20171227215204.nucxo7b2ssmyznip@alvherre.pgsql> <20171228121651.GZ4628@tamriel.snowman.net> <42cda197-fead-a7e5-a7e2-750d98bc4eb2@simkorp.com.br> <743808611.5608368.1514484408822@mail.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="55wyIat2y2jWjLQg" Content-Disposition: inline In-Reply-To: <743808611.5608368.1514484408822@mail.yahoo.com> User-Agent: Mutt/1.5.21 (2010-09-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --55wyIat2y2jWjLQg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings Brent, * Brent Wood (pcreso@yahoo.com) wrote: > A tool to calculate a checksum of sorts based on the table (file) content= would provide a better surety of duplication than simply checking file siz= e - like differently vacuumed tables in each copy could have the same conte= nt but be different file sizes.=20 PG has support for checksums and there are tools out there to validate that the checksum is correct for all pages which have one, but that wouldn't help in this case because the file is zero'd out (and a zero'd out file is actually a valid file in a PG data directory). Also, the files on the primary and the replica actually can be different when looked at with a complete-file checksum due to hint bits being set differently (at least, possibly other ways too). That doesn't make them invalid or incorrect though. Rather than trying to compare a running primary to a running replica, such a check to verify that the files backed up during a backup have the same checksum as the files being restored from that backup can be done, and that *is* done in at least some of the PG backup tools already (pgBackRest has an independent manifest that it stores for each backup which contains the checksum of each file as-backed-up, and it verifies that checksum when performing a restore to make sure that the backed up file wasn't corrupted in place, other tools hopefully have similar). > I do wonder though - given the order of records in a table (file) is not = necessarily identical (or is it?) event this may be problematic. Perhaps a = checksum based on the result of a query output ordered by primary key could= work? The order of records in a *file* should be the same in the heap on the primary as they are on the replica, but that doesn't mean the contents of those files will be exactly the same (as mentioned above, hint bits can differ). We used to have cases where the indexes could also be different, but I believe that was changed so they should match. I've used the approach of doing a checksum across the results of an ordered query to compare between systems and that generally does work, but it's a bit tricky if you're trying to compare a table that's heavily modified- you need to determine the point in the WAL stream that you're at on the primary when you run the query and then replay the replica to that point in the WAL and then run the query on the replica, otherwise you could end up with differences that are just because of the ongoing transactions being run to update the table. Thanks! Stephen --55wyIat2y2jWjLQg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaRTdbAAoJEO1sijiDR2RVfZgQAJmJQ0+JvGnnv0L6MfyXbCwy cIlK59YcSaFyxL3v2ofhe7e5FQkVhHkVf5EgvVuEGVk9WXS7f0/UWFr+28ULH136 4TyrfUrL7vCA2DXSz2ectFV8Db7mKtXKYcl+rjU+NLsfT5u8NClL1WZVUzjUBG4o ANsRLxEvyYXgQQGvaLtKI/bwcmVuYugdTwmQi2zsBVnvEi1A8sklAWFWWT5XU7Qr dTZ57qHBAC9sNbidQd820pf3C9oJGwX4JjRw8YgP/xtz1HW74q+iHH47s4aBOPQ4 8ItMLlJHe9KelyKbVDp+CyCI8lHOyQhyOS5/5XcpUdY+1VxK0srLNJrcgJdLF/zB +1NRiR0li9E3RF8WdKVur1dplo2H0sf9k4MrPNKAmYZIRzwdCf9HP/qILhPecuWG tdCaxlua1idgOhebBihZwDP9cA6XgLSyhDyGOC3vJS7721qHc828hR3yta6CMNo9 oCpsb5AK9G4o1bvDv1SVA4boGzfv9WNU/IxAM/6JFniS7Wu0pwIveCyTbBkbUbUI Aqdd+TSNGctvAn5Cv80ItIslJepuzmSFa9q/rUiTkEDpp39wgkNBcUOblGy8N50i oPRfYqMbMdbpBE8D/3Szwpd0mhwV4l+At2Aq2jynhFxBE3BbbHO029FNbRPT3C3f ztkHI9YcwLF18rzmyMgW =iyHq -----END PGP SIGNATURE----- --55wyIat2y2jWjLQg--