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 1f60vO-0001U7-RU for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Apr 2018 21:35:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f60vN-0003HF-Pz for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Apr 2018 21:35:33 +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 1f60vN-0003Gz-IN for pgsql-hackers@lists.postgresql.org; Tue, 10 Apr 2018 21:35:33 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f60vF-0002AG-Ds for pgsql-hackers@postgresql.org; Tue, 10 Apr 2018 21:35:33 +0000 Received: by mail-wm0-x234.google.com with SMTP id t67so163749wmt.0 for ; Tue, 10 Apr 2018 14:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=6MXE0cK0kAnBht4eHLLMouen6nJnoWhuBJN0MWDf8c8=; b=mkMigujYfQJ84f22IvSXlmzJ0sP1oXidVoknmx+2iGlEYRe6mKg2i0zl4QRJGFssh/ AN+E88mk68U2lTKkSBMHLgRrS7HXF3gWmIiypz7vWWNmSlacQp0Lc5dUqQzTDCGTbIHc Z94QvxWtTyF+Sbc6Jim/xcX1NMOfs2NKi2j38p2YEkbjzoRLXQb/R5383Thqrq/LUalc KgRbMvNih3JeFPEV9+VPDcq0b/FV/Yo3Srt1K3eKKWiOlQE+cRR8vRrSHscf7t4h3C8i Dha0oeC2JFQIrB0xXDQOYVR3JTR300324fjeDLzJA5nM2ZBRJv+Xdc++xiyYJBM6qvlZ vOdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=6MXE0cK0kAnBht4eHLLMouen6nJnoWhuBJN0MWDf8c8=; b=Qnb28iqw6jVC57OLwo+0irSzehez2qSKt/LuLcazxpF77Rhacm6QNnpxPLaRc3waeH RUC50z211g6FtPeUflHBbEjE3rLPApDTyjouHe7xo88X4j9oJC+mPzVsXP7kSWJ45Loj S9HrnTk+vARIICDMkFuURK570nLyEg2DGeXlfc8sCyo/6rZpeZmFEzhIis06h7OyvB9o FRRYbn0OcNd9kmHHPmfHc33+rBek0gemx2YGLUevDfdmCjnKbDp4STkbENoMkrwbfwc2 gy9xEYF4k1Ku+RMAgjYugOZ12xzrLKgZp9Rn4TzhMBC7MgtBsQokjA6gNiSmAheyPr4T sIug== X-Gm-Message-State: ALQs6tDPUcpF21R8x773mYBUxW5FYQachZEjpUA8auVb/xmvSEstmzV1 04qE3w9GoK5VmRxhb+8xy6pxEl3KhIi+ckqvxABTo9B2JnMDOCAEzcTobyvQp9s3MqWSsn3pAhR wlCCSiUwWpAhfC2PA6oKYmQsuYZeWzflBhkTCTp/l8AKGcsMQwiEPeVWNsSccZ+LtBo2RWOR0cs yDDt4xALvI X-Google-Smtp-Source: AIpwx49zBwseJcaXSJXU7wHwSFz9jkuiYBqgyxf2QQWWtUHqyih9uQroqHU/tthyCxCKPDDMEkw+/Q== X-Received: by 10.28.131.211 with SMTP id f202mr728128wmd.20.1523396123701; Tue, 10 Apr 2018 14:35:23 -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 o63sm2579639wmb.4.2018.04.10.14.35.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 14:35:23 -0700 (PDT) Subject: Re: pgsql: Validate page level checksums in base backups From: Tomas Vondra 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> Message-ID: <500ab687-d588-020a-0e23-bfec853aac9c@2ndquadrant.com> Date: Tue, 10 Apr 2018 23:35:21 +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 On 04/10/2018 11:24 PM, Tomas Vondra wrote: > 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. > BTW pg_verify_checksums needs the same fix. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services