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 1tmkVh-00ADeb-Ex for pgsql-performance@arkaria.postgresql.org; Tue, 25 Feb 2025 02:17: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 1tmkVg-00C9ho-Et for pgsql-performance@arkaria.postgresql.org; Tue, 25 Feb 2025 02:17:24 +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 1tmkVg-00C9gx-0y for pgsql-performance@lists.postgresql.org; Tue, 25 Feb 2025 02:17:24 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tmkVd-000eMo-15 for pgsql-performance@lists.postgresql.org; Tue, 25 Feb 2025 02:17:23 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3f41706d768so3017183b6e.1 for ; Mon, 24 Feb 2025 18:17:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740449839; x=1741054639; 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=FkV43pT4fy2ugAhBRNdunXsZLlW5ifp7FnXJ90ZEn+8=; b=WFUpPI65+ATznzs3GJHUhQkM8YP7EFkkmisur+eDFtpffrdQIO8DQWOHL1IxwhaEl7 1BjmrqA29ktXG6X7lak40taOiafZRA3+M6zQNmCLxHikZ1MQmed4Gk7w4t2NE6quTnej GS/T6L2zMu/h80ZFGIMN98g2bG23OLtdzil1Cg00qb6mCtfdWU4T65VaV+d6WcV6pegG PXZCsqfc7ZS6pdAr6BqB8z0LvCCwMVtVsfqeGGw7qqY6/yKESUP3K7XB/t3Bj7yhqL2s a+jl16Uk/7weJmTLMEHgfjOxyP14faPH1CkVQ+0wuFkguX8PzsSROQo7o8Ut1iaSiHla LoFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740449839; x=1741054639; 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=FkV43pT4fy2ugAhBRNdunXsZLlW5ifp7FnXJ90ZEn+8=; b=JF/NZi1xIgPsm8XwRVpk/dAcSQjhSUupeo+AgAMo36NPeLkg2Fcd0gV4xDC0ebUWmI wp0uuvL2dO+NOTt9feTresXTNXhqOp6tXmsDb9hgtaUcRhPhfa7dxRnCRabSn6CDz4Rv 3O0JgGAqM8mBY9YeOBnEu2PxAbPT/ZqcxUJ+1qmE8WWXn91RlE83HAqNNgkeXMXFSk2L DDhJTQQV8r1RlqdxjmYnJC4K56VWJhnK+bhKeEushnWvCWNrEE6VvWkkzx7YRLXwPKPX lX0y/0OLOTLCpt9VDfw/bAr8qLBHo4InjeNnYF6Lt0ouHLvMhNv2pX70dh0FOS+2WCL3 qkBA== X-Forwarded-Encrypted: i=1; AJvYcCUQlwUhvB9yph1UG6pydnS05Ojb1wSVt9ChKDWBjFTU+QJNxA7SuAUaXPsG6GgP884c4EYSm6yritdoSeq5NtZfvQ==@lists.postgresql.org X-Gm-Message-State: AOJu0YzxpM32YNuVmhPVHurEHXXuvsyEh2l5snTZIAw6KIEUb1HLiVLU xoP31OnkCR268Yd+2Vtb3hlKA84fu3hZKFV7DtBKgRHFcjugofzxIuQ3cuG+MVtZRInptcvmL/J vLi5I9Qx7qIXv8BqF+xOng7zrCA== X-Gm-Gg: ASbGncskm2fz7JrjFUOSLsnHDles8I3RWjDaLwUQ/V8F/TCnx5qj47OF6jo417kMi1G T2YyjsOvRI5WNQJ8cJSSRTX82wRQzVAxHAxU4/XDhoDqRptSF09kkyvmPk0gsrVc/kGpsu1DxoN v7M6qZWrw= X-Google-Smtp-Source: AGHT+IF0dsBbzxJbKTypnwyJEmFxfbujJ+UkoL3AkoFNBZPze/56ACrJZPLKENWyPeavxh9hTHl6cX+5XbcV4Zqjtes= X-Received: by 2002:a05:6808:3a17:b0:3f3:adab:2012 with SMTP id 5614622812f47-3f419f6d9f8mr16289370b6e.15.1740449839571; Mon, 24 Feb 2025 18:17:19 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Lincoln Swaine-Moore Date: Mon, 24 Feb 2025 18:17:08 -0800 X-Gm-Features: AWEUYZnSUTYSU366tDkc02RtVi5cNlUIR_dfdyo-K_9psnbeN6zbvevYQHeYZtg Message-ID: Subject: Re: Unfortunate Nested Loop + Missing Autovacuum To: Jeff Janes Cc: Andrei Lepikhov , pgsql-performance@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000006feab1062eee0e58" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006feab1062eee0e58 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks Jeff for the response--I did end up just analyzing the tables manually, as a stopgap. Resource consumption was a non-issue as you predicted (and plan was corrected, though estimates were still slightly awkward). With respect to the blocking of the autovacuum/analyze: no it shouldn't be the case that those are running frequently in our case. Ditto re: database restarts--this is out of my control because it would be DigitalOcean's doing, but I don't see any evidence of it. Nor anything amiss in \dt+, unfortunately. I'll try to figure out if I can get access to the logs to search for cancellations. Do you happen to know what that would look like if I'm grep-ing for it? And do you have any other guesses about possible explanations? Thanks again for your help. Lincoln On Sun, Feb 23, 2025 at 6:09=E2=80=AFPM Jeff Janes w= rote: > On Sun, Feb 23, 2025 at 5:49=E2=80=AFPM Lincoln Swaine-Moore < > lswainemoore@gmail.com> wrote: > >> 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 prod= uction 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 m= eantime. >> But that may be false or avoidable. >> > > The default setting of vacuum_cost_delay is zero, while the default > setting of autovacuum_vacuum_cost_delay is 2ms (or 20ms, depending on the > software version). So you can give a manual run the same resource > consumption as an autorun just by changing vacuum_cost_delay in that > session so that it has the same value as autovacuum_vacuum_cost_delay. > Also, if you just do ANALYZE (rather than VACUUM ANALYZE) the resource > usage should be rather modest anyway. > > Another difference is that autovac will cancel itself if it detects it is > blocking something else, while a manual vac/analyze operation will not > do that. Normal operations (DML) don't block against vacuum anyway, only > things like index creation or partition maintenance do that. But if thos= e > types of operation are frequent, then doing a manual VACUUM or ANALYZE > could indeed gum things up. Also, if those operations are frequent, it > could explain the missing autovac. If every auto attempt gets cancelled > before it completes, then it will never complete. pg_stat_user_tables > doesn't reflect cancelled vacuum or analyze so those will go missing. (Y= ou > should see mentions of cancelled autovac operations in the log file thoug= h.) > > Database restarts will also interrupt vacuums. So if your database is > shutdown and restarted regularly (for cold back-ups, or just out of some > misguided belief that restarting occasionally is a good practise) and the > period between restarts is shorter than how long it would take autovac to > run, this could also explain the lack of completed autovacs. Also, if a > table qualifies for both auto vacuum and auto analyze, the vacuum is done > first. So even if auto analyze would be fast by itself, it still won't > complete if auto vacuum is slow and never gets to finish. > > It is possible to override your vacuum settings on a per-table basis. So > another possible explanation for the missing autovacs is that those two > tables have been specifically configured to disable autovacuum on them an= d > only them. If you use psql, \dt+ (but not regular \dt) will show such > customizations. I'm sure other tools also have ways to detect this, but = I > don't know what those ways are off the top of my head. > > Cheers, > > Jeff > --=20 Lincoln Swaine-Moore --0000000000006feab1062eee0e58 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Jeff for the response--I did end up just analyzing = the tables manually, as a stopgap. Resource consumption was a non-issue as = you predicted (and plan was corrected, though estimates were still slightly= awkward).

With respect to the blocking of the autovacuu= m/analyze: no it shouldn't be the case that those=C2=A0are running freq= uently in our case. Ditto re: database restarts--this is out of my control = because it would be DigitalOcean's doing, but I don't see any evide= nce of it. Nor anything amiss in \dt+, unfortunately.

<= div>I'll try to figure out if I can get access to the logs to search fo= r cancellations. Do you happen=C2=A0to know what that would look like if I&= #39;m grep-ing for it? And do you have any other guesses about possible exp= lanations?

Thanks again for your help.
<= br>
Lincoln



On Sun, Feb 23, 2025 at 6:09=E2=80=AFPM Jeff Janes <jeff.janes@gmail.com> wrote:
On Sun, Feb 23, 2025 at 5:49=E2=80=AFPM Lincoln Swaine-Moore <lswainemoore@gmail.com= > wrote:
Thanks for the reply! I tried the = analysis on our much shorter staging table and it did change the plan. I ha= ven=E2=80=99t tried it on the production ones because my understanding is t= hat the autovacuum process is gentler with resource consumption and I didn= =E2=80=99t want to gum things up in the meantime. But that may be false or = avoidable.=C2=A0

The default setting = of=C2=A0vacuum_cost_delay is zero, while the default setting of=C2=A0autova= cuum_vacuum_cost_delay is 2ms (or 20ms, depending on the software version).= =C2=A0 So you can give a manual run the=C2=A0same resource consumption as a= n autorun just by changing vacuum_cost_delay in that session so that it has= the same value as autovacuum_vacuum_cost_delay.=C2=A0 Also, if you just do= ANALYZE (rather than VACUUM ANALYZE) the resource usage should be rather= =C2=A0modest anyway.

Another difference is that au= tovac will cancel itself if it detects it is blocking something=C2=A0else, = while a manual vac/analyze operation will not do=C2=A0that.=C2=A0 Normal op= erations (DML) don't block against vacuum anyway, only things like inde= x creation or partition maintenance=C2=A0do that.=C2=A0 But if those types = of operation are frequent, then doing a manual VACUUM or ANALYZE could inde= ed gum things up.=C2=A0 Also, if those operations are frequent, it could ex= plain the missing autovac.=C2=A0 If every auto attempt gets cancelled befor= e it completes, then it will never complete.=C2=A0=C2=A0pg_stat_user_tables doesn't reflect cancelled vacuum or a= nalyze so those=C2=A0will go missing.=C2=A0 (You should see mentions of can= celled autovac operations in the log file though.)

Database restarts will also interrupt vacuums.=C2=A0 So if your datab= ase is shutdown and restarted regularly (for cold back-ups, or just out of = some misguided belief that restarting occasionally is a good practise) and = the period between restarts is shorter than how long it would take autovac = to run, this could also explain the lack of completed autovacs.=C2=A0 Also,= if a table qualifies for both auto vacuum and auto analyze, the vacuum is = done first.=C2=A0 So even if auto analyze would be fast=C2=A0by itself, it = still won't complete if auto vacuum is slow and never gets to finish.

It is possible to override your vacuum setti= ngs on a per-table basis.=C2=A0 So another possible=C2=A0explanation for th= e missing autovacs is that those two tables have been specifically configur= ed to disable autovacuum on them and only them.=C2=A0 If you use psql, \dt+= (but not regular \dt) will show such customizations.=C2=A0 I'm sure ot= her tools also have ways to detect this, but I don't know what those wa= ys are off the top of my head.

Cheers,
<= br>
Jeff


--
Lincoln Swaine-Moore
--0000000000006feab1062eee0e58--