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 1f60kw-0000iG-Ru for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Apr 2018 21:24:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f60kv-0004p2-HS for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Apr 2018 21:24:45 +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.89) (envelope-from ) id 1f60ku-0004os-Vz for pgsql-hackers@lists.postgresql.org; Tue, 10 Apr 2018 21:24:45 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f60kr-0002v9-CK for pgsql-hackers@postgresql.org; Tue, 10 Apr 2018 21:24:43 +0000 Received: by mail-wm0-x22b.google.com with SMTP id r82so115855wme.0 for ; Tue, 10 Apr 2018 14:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=XTtjGchSRanfuk9kMQDYqp5dAkB5HLUWymcC23OGZ2g=; b=zb8DwD7RsDudQ1S0QaHbSoDXWw5cUpD6TyNEJYhJcmPZYlZv9I5sCki3yII0mIykGg hLQqSCzeRZRVJZaoZg5zIAqorfJ19ixOEpmZU9j9HbzgYiYaPvuEPJustau6KnPoEF33 pmvTJVQ5r/Jcj2DD0zESnI50T3k2s0cs98J5HqObipIHnHEa5yafLTJQpJWsF8wsNcHo TngbeuzgSgiCFoq/bBFttxeegeHOeGSTYlc0/9m6hFZEKs9BQuhEmXbVfXJW48Vu/uZo fucf8Tbu3QJlDWt/EPUoIma4WgYAUmCkWt+4ndf+gILOUOxYkNZCdEOoU/N7s3oFnX6x oDlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=XTtjGchSRanfuk9kMQDYqp5dAkB5HLUWymcC23OGZ2g=; b=ONlh3Vq9aIdnE7uV4CK5ugVhGpOqI2tS0bLAIPtAr4zOc6JYezfaU5STtDxq94JAa+ RaN10TtrOMUojxdR7wdIBT03/46ICujyUu4DTRz6WPvfdKsESXNKOcoIOECKlc/5PaT3 ELOso4LF/Q0pBT1KxwD7tTc6WTdPucoNnFNL5uxeVcbr73FAeW+UikN8ke175jsVsyed Pcnv/VClVhDRUCr1eWRKexIs1cnedJks+DumlttSA0G2DHQRkMR5r0kUg4eL0CVjOO8p 2bLP++EoPgxi5tvt4JQJn4SGYwyoKI0MBbNOowgOlgbqakjc7j3Sspl20F5KuVX40Y+7 k98w== X-Gm-Message-State: ALQs6tD1K0jZiEWOq61E84c0HWDVZdtnFiIAb3fgZnK0VWsy+ql2PUku aNUehsfXhhPPeeSMnmKCqUra1TpWEFFwxihxVT1rfoVJuKM6tqEfmyW4KsxPILyCeFHK92isiEE pth9UV+5sbCMHj5IgiElXdaJckyZNooN0tVCtdzefA76VbQAkW44Djv/gCRmzJ2nzkd85XEoLCY 52CD2kJiLb X-Google-Smtp-Source: AIpwx48+sHbsqK9QhPNJoXPLdoex0DxXaef/FIOVtG7DwesxbdQ5kavU1Kxy2gj/4YGIgS8ZT1kIBQ== X-Received: by 10.28.91.209 with SMTP id p200mr648817wmb.11.1523395478480; Tue, 10 Apr 2018 14:24:38 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id p25sm1859360wmi.14.2018.04.10.14.24.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 14:24:37 -0700 (PDT) Subject: Re: pgsql: Validate page level checksums in base backups To: Magnus Hagander , Michael Banck Cc: Alvaro Herrera , Tom Lane , Andres Freund , David Steele , 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: Tomas Vondra Message-ID: Date: Tue, 10 Apr 2018 23:24:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, 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. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services