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 1tYRIb-00Aqzx-Q2 for pgsql-performance@arkaria.postgresql.org; Thu, 16 Jan 2025 14:56:46 +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 1tYRIa-00EIFe-HE for pgsql-performance@arkaria.postgresql.org; Thu, 16 Jan 2025 14:56:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tYRIa-00EIBp-2I for pgsql-performance@lists.postgresql.org; Thu, 16 Jan 2025 14:56:44 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tYRIZ-000j9k-0K for pgsql-performance@lists.postgresql.org; Thu, 16 Jan 2025 14:56:43 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-2a3d8857a2bso564277fac.1 for ; Thu, 16 Jan 2025 06:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737039402; x=1737644202; 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=0ZYTb0Sl2HLagfWzDg5U2bDRx+NTnlvHndP5zw158TI=; b=KnpnalMxUDTorMqtKMzekj0RW41H25GOuiQrSqqrozkGzyKKZSA3qTBUPza82ueAov 3FB3A9mm9ifNPfW/b+TSQ00Td8tBKMAyx/WCxBhFEZl7iOVN7bzeAdyo9KCClnKb+Q6P lfF7OYSsseFlKc0jaMJwM6oquntndw0exxX4w0HR1WE+D2s0mugzcsfKHlMnfuyW9MoD Y63WGL7SwVbJNoYPgv6kDFQducAkeUymholTgSzREFcKk/FzH/7Hc1IYwYAoABj/O2Gm 4BGU/myHBaNc+/NeaWu04sw28PH+cGCGF1N4H0mCvCULvHwAf2NpMX2QvpHzQp+zV5D1 BpNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737039402; x=1737644202; 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=0ZYTb0Sl2HLagfWzDg5U2bDRx+NTnlvHndP5zw158TI=; b=ZtNV98Q77kG/mKgo7MFGTxZsczaTblL6bmTf46Y5SmX+EfNknBxS0msdDEgOj3Gf1P czrCqQ4UYTzLnHrEbBV3STxFBroJPkIlnCJwiDwIZPHBbPNXs0TTkbtAMYLNeX/tmNga +l97ASeQK/CuMHiJiel24uysl9elCd2MkKSytE4VfchTbld6GJCrlg5kxvNSqjx1o9DT FKvwxcwPXZnSDg3MQR3CRWq5MqyPbqDhU9R79Wwp7vsO/E/BZMRkoT4+HOl15w1eZiO0 8jtxBh0UrUmb0qHgbnD/mQT7NqiDOKfxnIsL/WISVzvNe2rE0Le66gJovy7szsOuZzS0 KWzg== X-Gm-Message-State: AOJu0YyxXQlqwto1DcfqfR6/MeuJVhi4bUt0CdvjY6iVjrzZhLvDMC3r UU0zAaODE/iGZrbLC7hBE5lTQY2Z9IJHti3RsQl2HffKyS9efGAq623v/b55wp00tOcLp9KRsJx LWAhBCc9/zA0hfnAkcaMohbRd28E= X-Gm-Gg: ASbGncvZJtkuXyXHRgVgeO0WoItuOg7YpB2IX8QadWVA0d6LJ9T2PhbSMVKFDaKSUo5 UQJF/1ZR9+rnlhTp/Zq8ViV6OvX8IqMAFkDYXaO3E X-Google-Smtp-Source: AGHT+IGs45ZEd/UX6rcagx5H/hLPL+OYG2GxCFgdyXf1PuGcUuBQd0wo9oxCANQRob9ljEPuu69MO7KWpHPmqAuiCCg= X-Received: by 2002:a05:6870:6ecc:b0:29e:6c6a:e7e7 with SMTP id 586e51a60fabf-2aa06739035mr17889685fac.21.1737039401903; Thu, 16 Jan 2025 06:56:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: bruno vieira da silva Date: Thu, 16 Jan 2025 09:56:31 -0500 X-Gm-Features: AbW1kvYzVT1IlbybbvTEa3bJbpTgL0bIdaq7jQUbMzk6tdeL99q6YVPCIEUWnho Message-ID: Subject: Re: Query planning read a large amount of buffers for partitioned tables To: David Rowley Cc: pgsql-performance@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000082ef80062bd40034" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000082ef80062bd40034 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, Thanks David. this pg test deployment. anyways I did a vacuum full on the db. and the number of buffers read increased a bit. On Wed, Jan 15, 2025 at 3:01=E2=80=AFPM David Rowley = wrote: > On Thu, 16 Jan 2025 at 07:29, bruno vieira da silva > wrote: > > On pg 17 now we have better visibility on the I/O required during query > planning. > > so, as part of an ongoing design work for table partitioning I was > analyzing the performance implications of having more or less partitions. > > In one of my tests of a table with 200 partitions using explain showed = a > large amount of buffers read during planning. around 12k buffers. > > That's a suspiciously high number of buffers. > > > I observed that query planning seems to have a caching mechanism as > subsequent similar queries require only a fraction of buffers read during > query planning. > > However, this "caching" seems to be per session as if I end the client > session and I reconnect the same query execution will require again to re= ad > 12k buffer for query planning. > > > > Does pg have any mechanism to mitigate this issue ( new sessions need t= o > read a large amount of buffers for query planning) ? or should I mitigate > this issue by the use of connection pooling. > > How is this caching done? Is there a way to have viability on its usage= ? > Where is it stored? > > The caching is for relation meta-data and for various catalogue data. > This is stored in local session hash tables. The caching is done > lazily the first time something is looked up after the session starts. > If you're doing very little work before ending the session, then > you'll pay this overhead much more often than you would if you were to > do more work in each session. A connection pooler would help you do > that, otherwise it would need to be a redesign of how you're > connecting to Postgres from your application. > > There's no easy way from EXPLAIN to see which tables or catalogue > tables the IO is occurring on, however, you might want to try looking > at pg_statio_all_tables directly before and after the query that's > causing the 12k buffer accesses and then look at what's changed. > > I suspect if you're accessing 12k buffers to run EXPLAIN that you have > some auto-vacuum starvation issues. Is auto-vacuum enabled and > running? If you look at pg_stat_activity, do you see autovacuum > running? It's possible that it's running but not configured to run > quickly enough to keep up with demand. Alternatively, it may be > keeping up now, but at some point in the past, it might not have been > and you have some bloat either in an index or in a catalogue table as > a result. > > David > --=20 Bruno Vieira da Silva --00000000000082ef80062bd40034 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello, Thanks David.

t= his pg test deployment. anyways I did a vacuum=C2=A0full on the db. and the= number of buffers read increased a bit.=C2=A0


On Wed, Jan 15, 2025 at 3:01=E2=80=AFPM David Rowley &l= t;dgrowleyml@gmail.com> wrot= e:
On Thu, 16 Ja= n 2025 at 07:29, bruno vieira da silva
<brunogiovs@gm= ail.com> wrote:
> On pg 17 now we have better visibility on the I/O required during quer= y planning.
> so, as part of an ongoing design work for table partitioning I was ana= lyzing the performance implications of having more or less partitions.
> In one of my tests of a table with 200 partitions using explain showed= a large amount of buffers read during planning. around 12k buffers.

That's a suspiciously high number of buffers.

> I observed that query planning seems to have a caching mechanism as su= bsequent similar queries require only a fraction of buffers read during que= ry planning.
> However, this "caching" seems to be per session as if I end = the client session and I reconnect the same query execution will require ag= ain to read 12k buffer for query planning.
>
> Does pg have any mechanism to mitigate this issue ( new sessions need = to read a large amount of buffers for query planning) ? or should I mitigat= e this issue by the use of connection pooling.
> How is this caching done? Is there a way to have viability on its usag= e? Where is it stored?

The caching is for relation meta-data and for various catalogue data.
This is stored in local session hash tables. The caching is done
lazily the first time something is looked up after the session starts.
If you're doing very little work before ending the session, then
you'll pay this overhead much more often than you would if you were to<= br> do more work in each session. A connection pooler would help you do
that, otherwise it would need to be a redesign of how you're
connecting to Postgres from your application.

There's no easy way from EXPLAIN to see which tables or catalogue
tables the IO is occurring on, however, you might want to try looking
at pg_statio_all_tables directly before and after the query that's
causing the 12k buffer accesses and then look at what's changed.

I suspect if you're accessing 12k buffers to run EXPLAIN that you have<= br> some auto-vacuum starvation issues. Is auto-vacuum enabled and
running? If you look at pg_stat_activity, do you see autovacuum
running? It's possible that it's running but not configured to run<= br> quickly enough to keep up with demand.=C2=A0 Alternatively, it may be
keeping up now, but at some point in the past, it might not have been
and you have some bloat either in an index or in a catalogue table as
a result.

David


--
Bruno Vieira da Silva
--00000000000082ef80062bd40034--