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 1oiT2C-0000nF-C4 for pgsql-general@arkaria.postgresql.org; Wed, 12 Oct 2022 04:07:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oiT2B-0005qH-6N for pgsql-general@arkaria.postgresql.org; Wed, 12 Oct 2022 04:07:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiT2A-0005q4-SD for pgsql-general@lists.postgresql.org; Wed, 12 Oct 2022 04:07:54 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oiT28-0006hs-Ke for pgsql-general@lists.postgresql.org; Wed, 12 Oct 2022 04:07:53 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1322d768ba7so18252783fac.5 for ; Tue, 11 Oct 2022 21:07:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ZVI+rn8inA/hdduyRjzBDG0A5txHnh1Y/YXwprqhVGE=; b=hXUIZ1WX6mBRYrzJecjYGEmJdA58hk9s8Njv3XqAQ3d1flnRP7I1DQbtKiEGILjBKo aykpGMiWqtIFBA21UWx4jLSvLhOO0SmCT4Xd4AdC3CzVc0aQBpsh0mqgMw4Mdp/LG5da 9mx1ErRtFp+NWZ9B+sVp3FuxUMlQRu0CJMoTRxjXyY5GoGVaZX8QdWfkGTHALf0kxrnz BeB0Gh3cYCakjKw3AObZ8fWIopSsFTt0qN9aRLRT37awFRHOgxlp0sTABQ1bFaTiSqav V1D/vovtAwGDqzXC3HNWlRsfGLbyMRZyl+Mq6JsHO1xopqwT5OZgLDy9yVlq2RnpRCad E8AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZVI+rn8inA/hdduyRjzBDG0A5txHnh1Y/YXwprqhVGE=; b=ylKhgIUT5em4cETq46AuVFT/ugBzoFlLYbmOdmTokrbKdPdy/nnOBIcoyq0JlECeK3 PDjcZQBtImnfr5cqAKX/Spi0SNrqtUwm0FOUl+2pS/6I1kH9WzwkFOSh9PnXULS3/9BG /Uuur1khs3hvJjiWL+8OXgslXWnSaWKhqXB2Utmb/VUuK6ojipC9A4HkpHJmvPJfREwp wfEtnzESrnxCcTfeL+oP2whKbqKH4FG2tL8WrAhh+72NvORmyFFTerTWw7tn4U4ELGsE xQ8YF0edmBZYSBR6ufl1ioP/XKgjn3TkwNEnz0U8s/qRlsijXwN3flnbIWD3tcDkfHoG IGiw== X-Gm-Message-State: ACrzQf2QDGtRAx68enoQnLPpqC8zT6I/VLyTqXatQELnNg8LPUi2B8hq WwhEIEPhAxPcMVMxEWZgj0xt++cyGcs= X-Google-Smtp-Source: AMsMyM7KRPPI3dIyKloDaPXXHiaT8fo3PFKEgcZaqmcayuNoC51cA8e0aUGqTmH3cBdMcab70eGfNg== X-Received: by 2002:a05:6870:a2c7:b0:131:d098:9e37 with SMTP id w7-20020a056870a2c700b00131d0989e37mr1406776oak.152.1665547671653; Tue, 11 Oct 2022 21:07:51 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id g11-20020a4ac4cb000000b00480646ecd45sm543540ooq.48.2022.10.11.21.07.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Oct 2022 21:07:51 -0700 (PDT) Message-ID: <1cb7ac0e-fbd9-909d-a43d-a8ec1d481632@gmail.com> Date: Tue, 11 Oct 2022 23:07:50 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: Weird planner issue on a standby Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <418848.1665505048@sss.pgh.pa.us> <20221011162736.cd2h5ajdbhtwdc4l@alvherre.pgsql> <20221012033502.cxdq4nnwcntatf4v@jrouhaud> From: Ron In-Reply-To: <20221012033502.cxdq4nnwcntatf4v@jrouhaud> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/11/22 22:35, Julien Rouhaud wrote: > 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. Would EXPLAIN (VERBOSE, COSTS, FORMAT JSON) run on both nodes help show any differences? -- Angular momentum makes the world go 'round.