Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eUIFK-0006FV-3B for pgsql-general@arkaria.postgresql.org; Wed, 27 Dec 2017 20:24:14 +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 1eUIFJ-0001DM-A7 for pgsql-general@arkaria.postgresql.org; Wed, 27 Dec 2017 20:24:13 +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.84_2) (envelope-from ) id 1eUIFJ-0001DD-2U for pgsql-general@lists.postgresql.org; Wed, 27 Dec 2017 20:24:13 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eUIFE-0004eG-Ss for pgsql-general@lists.postgresql.org; Wed, 27 Dec 2017 20:24:12 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 6AFFF5F795; Wed, 27 Dec 2017 15:24:07 -0500 (EST) Date: Wed, 27 Dec 2017 15:24:07 -0500 From: Stephen Frost To: Alvaro Herrera Cc: Edson Carlos Ericksson Richter , pgsql-general@lists.postgresql.org Subject: Re: Does PostgreSQL check database integrity at startup? Message-ID: <20171227202407.GX4628@tamriel.snowman.net> References: <20171227170213.GW4628@tamriel.snowman.net> <20171227201116.bl23m2g3hr6y2wlw@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ycIGp/o1m9c3Zth7" Content-Disposition: inline In-Reply-To: <20171227201116.bl23m2g3hr6y2wlw@alvherre.pgsql> User-Agent: Mutt/1.5.21 (2010-09-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ycIGp/o1m9c3Zth7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Alvaro, * Alvaro Herrera (alvherre@alvh.no-ip.org) wrote: > Stephen Frost wrote: >=20 > > It's entirely unclear to me what the problem being complained about in > > this thread actually is. >=20 > As Edson explained, a relfilenode in the standby server is zero bytes > long when it is not that size in the primary server, and it corresponds > to a persistent table. I don't have any satisfactory explanation for > that. Somehow I missed the discussion of it being zero bytes for a long time after it's non-zero on the primary (I take the to main that it's longer than whatever checkpoint timeout is set to..?). That does sound like there might be an actual issue/bug here. > > Given the thread subject, if someone actually wanted to do a database > > integrity check before startup, they could use pgBackRest to perform a > > backup with a CRC-enabled database and at least verify that all of the > > checksums are valid. >=20 > That's not a complete solution, because a zero-byte file does not > contain any CRC. CRCs may detect some problems, but they will not > detect this particular kind of corruption. I agree that we can certainly have bugs which will cause corruption that's not detectable by our CRCs. Validating CRCs is just checking for one kind of corruption; using amcheck would provide another level, though it's unclear if that would help in this specific case if it's really just files on the standby (but not the primary) being zero-length long after they should be written out. > > We could possibly look into adding some set of additional checks for > > files which can't actually be zero-byte, perhaps.. I know we have some > > other one-off checks already. >=20 > Some possibilities, from the realm of haven't-had-coffee-yet-after-lunch: >=20 > * the length of the FSM fork can let you infer something about the > length that the main fork ought to have. Maybe the VM fork too? not sure. > (Easy to check: just some math on the size of the FSM/VM forks) I was just chatting with David over lunch specifically about checking that the number of forks was valid and looking at their lengths also makes sense, but the VM is only created/updated based on VACUUM runs, so checking that is a bit tricky. David has ideas about how to handle various races when it comes to forks (in particular by building a manifest once and then seeing if anything in the relation has changed since the manifest was built- if so, assume that WAL has the necessary info and if not then raise a flag) but it's all a bit tricky when the system is running. We might be able to do more checks if we're serious about supporting pre-startup checks though. We were also thinking about having a set of catalog tables that must not be zero and checking for those. > * the largest block number in any item pointer in any index of a table > can tell you what's the latest page that should appear in the table. > (Expensive: need to scan the indexes completely) This is something that I'd expect amcheck to handle; I'm not sure it makes sense to invent something else. David and I have chatted a little bit a while ago about trying to incorporate amcheck but it's rather complicated and not something we plan to do in the near-term. Still, it does seem like it'd be a nice capability to have. I wish it was possible to do off-line though. Of course, a user could do a restore and then run amcheck on the result themselves. Thanks! Stephen --ycIGp/o1m9c3Zth7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaRAFmAAoJEO1sijiDR2RVQ+EP/A0k6pJlVn7Xa8c8mn7Z2R9z 9+W8b8EAkWKJnx09NjOfluSwfsIxjkFtlLPjMmM773y1YDxXma3h+rCXf2Dwq3Dp ajOm1fw1pdbrK7tj8L25BRfuhOH9slvDSgaxjE9goMC9cA3+YuxROfY29v1YWYuQ gj5Wqnr8VXy7PYIR60hN6RDWW6e3vzrpSX82EM8pb8CzRH+W+3sDberNLyhBu9Xw C968iBNKy8taOFLkoz6Oq+XfMfd9/jWuet5+KqRhNCGGnHZ79bVwjO42M5BFxO7r nIYcYQoFWP87rAYLKoBUIckP5RehUiJ2ag/2ekdsTfJA0IHnhj7oK8j3iafdy/nl RNCFT3m4ReV73AEC2BQl75B0RMo3nMRCRqLExIoV6GlEk/oJScKWkc2WaZd9A8Kg 5MV4+NtQ/vufnyIN+3y3jTGnY+3p3AJJbaKsUiO7KQfD/SU30pF9FWAWN/IDVx1e +8XC1GCpNI5dtEcd1syAeEHEO61W3T7EbDAvLSXqxFJTI61OJ548wpNuywd2maM9 4xaVZnGH6gh6ElBc9Hid6/jKMWXfJmGnlpLsIxLifUxtge/e1HCpXsNjksru29wg XT0pcH4coF+raF5Zs1WMMfT/GNlp/hIPHpcL6XXqoF+36WCTcCfvenlsPaufnPRL N0cP0FrwbdvfXqrlTLSJ =07w8 -----END PGP SIGNATURE----- --ycIGp/o1m9c3Zth7--