Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiSWV-0006On-Ph for pgsql-general@arkaria.postgresql.org; Wed, 12 Oct 2022 03:35:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oiSWU-000278-Ip for pgsql-general@arkaria.postgresql.org; Wed, 12 Oct 2022 03:35:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiSWU-00026y-6H for pgsql-general@lists.postgresql.org; Wed, 12 Oct 2022 03:35:10 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oiSWS-0001IJ-4L for pgsql-general@postgresql.org; Wed, 12 Oct 2022 03:35:09 +0000 Received: by mail-pj1-x1030.google.com with SMTP id b15so14195511pje.1 for ; Tue, 11 Oct 2022 20:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=zXSblGfpIRVRAULxQqjM6cCFNfNegyfNNEBiQsURWiw=; b=NRjLtQ66nc/Snzg1pGVJg+yEnjdUJMWCu5isHeWqtWa+uFGNUxn2Z2g2M/Da+/gIOv pqBG7eO1KLTV0bifR5/Scazb7wvv2QCN5Snp/I2KIEFODKYH6x3aB3W6ow//4FI/ya4u +HdXgGxsafHkPlzr0Fboce/Qpk3bUdt+QbtST5HOb1g5ni45jODakTPEqlFrAFpMpced /peODR0te6Yv78nQQz43Dy1ceg/z98E9hnWwFrGKeyURULl+DIiO/Qop5Txwaaa7FvQP B7C7vbVo1m5hp1sQ2WHIn/mc7Yk9vxDSq35+hYlswnq59bQXw1pvBbqn2ooC2XvwrgzR dUog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zXSblGfpIRVRAULxQqjM6cCFNfNegyfNNEBiQsURWiw=; b=KkaR8mNjANImZgSHdlA0NIsw3LTdD47HxcbiYBWw39X9W4AWsbAzY5oop79ga9/rrZ v9GMm1mOuBRSu0DeyyTDusjexWBXzZN5NhgoJ0VRnlvqG5Ei8+ArWB4sw3LouCdpexuQ 4MbsAWgWVO0HOJ38CdwBRjcT7nGvEBM8KKLNbS1xNZqLFZtescis6r9DfL5jMmaxCRY/ TMROhCfi7m9ujL8ATPNnuaT7VpV9OCdtlqFTh1+yqn9exTcIcPdfJFgmiN8DiJe6t96a 1KT8T5L8SHvpHtNx0e+xBlfEn3P+UvY6HQs29QjjYyhCGJ9Tdy69LYZbnyIaNws/gLaD +/fg== X-Gm-Message-State: ACrzQf3UgAYthFGKl245LgIE08PkNc1JLOq51wwr7P7wpkfGPcM9bPS7 nDj/+ohU7hpKFumu/DPwsqE= X-Google-Smtp-Source: AMsMyM50dTWTKR03/Q+lcanAZ6+uKwjun4aBqC9SAuFOqtbxXrQkkqIDtV506miXwzErrId8lG+0AQ== X-Received: by 2002:a17:903:4d4:b0:17f:7ecc:88e3 with SMTP id jm20-20020a17090304d400b0017f7ecc88e3mr26363779plb.169.1665545705932; Tue, 11 Oct 2022 20:35:05 -0700 (PDT) Received: from jrouhaud (2001-b011-1006-dfce-d424-3032-86f5-3872.dynamic-ip6.hinet.net. [2001:b011:1006:dfce:d424:3032:86f5:3872]) by smtp.gmail.com with ESMTPSA id d14-20020a170902654e00b00181f8523f60sm5570648pln.225.2022.10.11.20.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 20:35:05 -0700 (PDT) Date: Wed, 12 Oct 2022 11:35:02 +0800 From: Julien Rouhaud To: Guillaume Lelarge Cc: Alvaro Herrera , Tom Lane , PostgreSQL General Subject: Re: Weird planner issue on a standby Message-ID: <20221012033502.cxdq4nnwcntatf4v@jrouhaud> References: <418848.1665505048@sss.pgh.pa.us> <20221011162736.cd2h5ajdbhtwdc4l@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Oct 11, 2022 at 07:42:55PM +0200, Guillaume Lelarge wrote: > Le mar. 11 oct. 2022 à 18:27, Alvaro Herrera a > écrit : > > > On 2022-Oct-11, Tom Lane wrote: > > > > > Are there any tables in this query where extremal values of the join > > > key are likely to be in recently-added or recently-dead rows? Does > > > VACUUM'ing on the primary help? > > > > I remember having an hypothesis, upon getting a report of this exact > > problem on a customer system once, that it could be due to killtuple not > > propagating to standbys except by FPIs. I do not remember if we proved > > that true or not. I do not remember observing that tables were being > > read, however. > > > > > Thanks for your answers. > > The last predicate is "and c3>='2020-10-10' and c3<='2022-10-10'. I have no > idea on the actual use of c3 but rows with c3 at '2022-10-10' (which is > yesterday) is much probably recently-added. I can ask my customer if you > want but this looks like a pretty safe bet. > > On the VACUUM question, I didn't say, but we're kind of wondering if it was > lacking a recent-enough VACUUM. So they're doing a VACUUM tonight on the > database (and especially on the 1.6TB table which is part of the query). > I'm kind of skeptical because if the VACUUM wasn't enough on the standby, > it should be the same on the primary. > > Actually, there are two things that really bug me: > * why the difference between primary and both standbys? > * why now? (it worked great before this weekend, and the only thing I know > happened before is a batch delete on sunday... which may be a good-enough > reason for things to get screwed, but once again, why only both standbys?) > > Julien Rouhaud also told me about killtuples, but I have no idea what they > are. I suppose this is different from dead tuples. Anyway, if you can > enlighten me, I'll be happy :) That's an optimisation where an index scan can mark an index entry as dead (LP_DEAD) if if tries to fetch some data from the heap that turns out to be all dead, so further scans won't have to check again (you can grep kill_prior_tuple in the source for more details). As that's a hint bit, it may not be replicated unless you enable wal_log_hints or data_checksums (or write it as a FPI indeed), which could explain discrepancy between primary (after a first slow index scan) and standby nodes. But since your customer recreated their standbys from scratch *after* that delete, all the nodes should have those hint bits set (Guillaume confirmed off-list that they used a fresh BASE_BACKUP). Note that Guillaume also confirmed off-list that the customer has checksums enabled, which means that MarkBufferDirtyHint() should be guaranteed to mark the buffers as dirty, so I'm out of ideas to explain the different behavior on standbys.