Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f6155-00025Y-Ph for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Apr 2018 21:45:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f6154-00040Y-FN for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Apr 2018 21:45:34 +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 1f6154-00040O-8L for pgsql-hackers@lists.postgresql.org; Tue, 10 Apr 2018 21:45:34 +0000 Received: from mail.thelabyrinth.net ([45.56.70.56]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f614n-0002Oy-NX for pgsql-hackers@postgresql.org; Tue, 10 Apr 2018 21:45:33 +0000 Received: from Davids-MacBook.local (50-195-93-134-static.hfc.comcastbusiness.net [50.195.93.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dsteele) by mail.thelabyrinth.net (Postfix) with ESMTPSA id D644154669; Tue, 10 Apr 2018 21:45:14 +0000 (UTC) Subject: Re: pgsql: Validate page level checksums in base backups To: Tomas Vondra , Magnus Hagander , Michael Banck Cc: Alvaro Herrera , Tom Lane , Andres Freund , PostgreSQL-development References: <20180404121930.GE20852@nighthawk.caipicrew.dd-dns.de> <20180404134732.tsxx2osvooolxy24@alvherre.pgsql> <20180404182247.GG20852@nighthawk.caipicrew.dd-dns.de> <20180405124113.GH20852@nighthawk.caipicrew.dd-dns.de> From: David Steele Message-ID: Date: Tue, 10 Apr 2018 17:45:12 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/10/18 5:24 PM, Tomas Vondra wrote: > > I think there's a bug in sendFile(). We do check checksums on all pages > that pass this LSN check: > > /* > * Only check pages which have not been modified since the > * start of the base backup. Otherwise, they might have been > * written only halfway and the checksum would not be valid. > * However, replaying WAL would reinstate the correct page in > * this case. > */ > if (PageGetLSN(page) < startptr) > { > ... > } > > Now, imagine the page is new, i.e. all-zeroes. That means the LSN is 0/0 > too, and we'll try to verify the checksum - but we actually do not set > checksums on empty pages. > > So I think it should be something like this: > > if ((!PageIsNew(page)) && (PageGetLSN(page) < startptr)) > { > ... > } > > It might be worth verifying that the page is actually all-zeroes (and > not just with corrupted pd_upper value. Not sure it's worth it. > > I've found this by fairly trivial stress testing - running pgbench and > pg_basebackup in a loop. It was failing pretty reliably (~75% of runs). > With the proposed change I see no further failures. Good catch, Tomas! I should have seen this since I had the same issue when I implemented this feature in pgBackRest. Anyway, I agree that your fix looks correct. Thanks, -- -David david@pgmasters.net