Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tmKmr-005v2F-Vk for pgsql-performance@arkaria.postgresql.org; Sun, 23 Feb 2025 22:49:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tmKmp-00Dk2M-JY for pgsql-performance@arkaria.postgresql.org; Sun, 23 Feb 2025 22:49:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tmKmp-00Dk28-7L for pgsql-performance@lists.postgresql.org; Sun, 23 Feb 2025 22:49:23 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tmKmk-000OzW-34 for pgsql-performance@lists.postgresql.org; Sun, 23 Feb 2025 22:49:21 +0000 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5fd0c7be155so1746607eaf.1 for ; Sun, 23 Feb 2025 14:49:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740350957; x=1740955757; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=x5cWHGSLlPJfTxgpuynkRwc47n/pSz3NNLDqpvQi/cE=; b=nqrIn16Z95dzyv5YSlNOVVGFJ7mObsafF2w4tHI2210ld/y0Cq/ngDMJWNxNCPjtPB lkjdWP/G9lcU3KjcrU67Fj4A+Ie2TCSu6/n/6NspATYYCmzL+mYmmOYd48eALiD2FUPb oOSzTX7TXmQCcmARZaFkNlt8gn1vRiGE5Jg8oYCSUe0ITlVPTr9QMsd1lKsttjDZgMkP RQ+/oLovu+czeOgbJo0OjlAcqVSpsgkWdwuwqb3Q4xy7meH900hcaMZfpvXCglxtH38F mdx4OdvuVmZoGEWznKhF4Pdb1M3Mf6MEtw4nUHA29YmDbxOsYTznN3M6wsaaWb25RZ+l bmEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740350957; x=1740955757; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x5cWHGSLlPJfTxgpuynkRwc47n/pSz3NNLDqpvQi/cE=; b=BOYJ38qQXw1a3NVEoCzpiQzt58I/N1VjN/REVoDFAE4AyJZ1gaqN3FLJmKmdvBQ8ML 56ghKHYaDZiNexcBX2UuIAm5sRrBXBIBCYvezK4FFykcqPOfVRj0KHz7r97NQlxTi2nj UmnhYS6L4w7eABQRHGUL/s8U7r6s5Yun3h1ARm+Cp/1hqXL+F9oa2paTf3DW8UTNXDr8 Di6eYFe/sqK2SwcLTIHUlDzgQLrCboCX02ag/SfDt02Ra/L/v3gKAgX/DLDmhvFbvNti LPL+1tUNhPYPrkGpLJDN/1JGZuWe5QpBb2vrIEtiE22gV01ZxKQyfnGNES3W/qfW/X3K 5xhQ== X-Gm-Message-State: AOJu0YwVJnqlhjkBPwBZVbEnQ9jSsfxTT7f+O1SoZ54b14xN7/Wc0KrS xt49w4H0Xl4aEEVrOyTS2qODNQybo3OFY619qhe4R7B3ZRGL+SiiPjEh+KPHNfwEOukf6ia0uvL AEWoo0zGf9f6WRZCqmorBmX+U5g== X-Gm-Gg: ASbGncuhZdO8J0YeVEwr6SSB8BUnK1yzqwfcsBfrt11mn1w8hz9FcMDOC27rRTZScaz 79eZRAmsQN+B5bqf5SZ6SteuwuP/ADMa62lEYbG71meP1f7tlN0WJT7yaH+DSoGOyDSAm4L8uaL Sm2wLH+g== X-Google-Smtp-Source: AGHT+IEDHuIaJCirCnXWU48V4CuZcH4vFNgJ2G29gaRuXSG0tdWflWwsg4/2FEx2NwV+ArJ071WwYEfv63LHf+fWKr4= X-Received: by 2002:a05:6820:8412:b0:5fc:e6c5:27a3 with SMTP id 006d021491bc7-5fd0af9117bmr10016021eaf.4.1740350957263; Sun, 23 Feb 2025 14:49:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Lincoln Swaine-Moore Date: Sun, 23 Feb 2025 14:49:06 -0800 X-Gm-Features: AWEUYZlPjPJMH7XJJPKnv-ikI0UJ6TQ4OmJ2rdY4OrfC2fiD2XYN_HirbIeHDiA Message-ID: Subject: Re: Unfortunate Nested Loop + Missing Autovacuum To: Andrei Lepikhov Cc: pgsql-performance@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000097a1e9062ed708c8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000097a1e9062ed708c8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the reply! I tried the analysis on our much shorter staging table and it did change the plan. I haven=E2=80=99t tried it on the product= ion ones because my understanding is that the autovacuum process is gentler with resource consumption and I didn=E2=80=99t want to gum things up in the mean= time. But that may be false or avoidable. Unfortunately the insertions are not batched=E2=80=94they arrive in a fairl= y steady stream. Given that, and the fact that we=E2=80=99re talking about the behav= ior of the daemon, I=E2=80=99m not sure how to provide a reproduction (though woul= d be game if you had pointers). I could in theory make a job analyze these tables on a regular cadence, though I guess that feels like I=E2=80=99d be = stepping on autovacuum=E2=80=99s toes. Would be happy to read over similar reports if you could steer me toward them. Thanks again for your help. Lincoln Swaine-Moore On Sat, Feb 22, 2025 at 00:37 Andrei Lepikhov wrote: > On 22/2/2025 00:46, Lincoln Swaine-Moore wrote: > > So, obviously there's a statistics problem, which led me to realize tha= t > > actually these tables have *never* been autovacuumed/analyzed according > > to pg_stat_user_tables. > > I'm using a managed database which makes it a little tricky to debug, > > but all my settings > > (autovacuum/autovacuum_vacuum_threshold/autovacuum_analyze_threshold/ > > autovacuum_vacuum_insert_threshold) are default, > > and I can see that other tables have been vacuumed recently. > I know a couple of reports related to this kind of behaviour and > different solutions to resolve it. But first, if you execute the ANALYZE > command on these problematic tables, does it fix your issue? May you > live with manual vacuum analysis each time after batch insertion? > If not, may you provide a synthetic reproduction of the case? > > -- > regards, Andrei Lepikhov > --00000000000097a1e9062ed708c8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for the reply! I tried the analysis on our much sh= orter staging table and it did change the plan. I haven=E2=80=99t tried it = on the production ones because my understanding is that the autovacuum proc= ess is gentler with resource consumption and I didn=E2=80=99t want to gum t= hings up in the meantime. But that may be false or avoidable.=C2=A0

Unfortunately the insertions ar= e not batched=E2=80=94they arrive in a fairly steady stream. Given that, an= d the fact that we=E2=80=99re talking about the behavior of the daemon, I= =E2=80=99m not sure how to provide a reproduction (though would be game if = you had pointers). I could in theory make a job analyze these tables on a r= egular cadence, though I guess that feels like I=E2=80=99d be stepping on a= utovacuum=E2=80=99s toes.

Would be happy to read over similar reports if you could steer me toward = them.

Thanks again for y= our help.=C2=A0

=
Lincoln Swaine-Moore


On Sat, Feb 22, 2025 at 00:37 Andrei Lepikhov <lepihov@gmail.com> wrote:
= On 22/2/2025 00:46, Lincoln Swaine-Moore wrote:
> So, obviously there's a statistics problem, which led me to realiz= e that
> actually these tables have *never* been autovacuumed/analyzed accordin= g
> to pg_stat_user_tables.
> I'm using a managed database which makes it a little tricky to deb= ug,
> but all my settings
> (autovacuum/autovacuum_vacuum_threshold/autovacuum_analyze_threshold/ =
> autovacuum_vacuum_insert_threshold) are default,
> and I can see that other tables have been vacuumed recently.
I know a couple of reports related to this kind of behaviour and
different solutions to resolve it. But first, if you execute the ANALYZE command on these problematic tables, does it fix your issue? May you
live with manual vacuum analysis each time after batch insertion?
If not, may you provide a synthetic reproduction of the case?

--
regards, Andrei Lepikhov
--00000000000097a1e9062ed708c8--