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 1tkPq2-003iGW-RK for pgsql-performance@arkaria.postgresql.org; Tue, 18 Feb 2025 15:48:47 +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 1tkPpz-00BcA0-3E for pgsql-performance@arkaria.postgresql.org; Tue, 18 Feb 2025 15:48:43 +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 1tkPpy-00Bc9p-KB for pgsql-performance@lists.postgresql.org; Tue, 18 Feb 2025 15:48:42 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tkPpw-001Xj7-2B for pgsql-performance@lists.postgresql.org; Tue, 18 Feb 2025 15:48:41 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5fcd50841f4so1117830eaf.0 for ; Tue, 18 Feb 2025 07:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739893719; x=1740498519; 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=ACO9Sq8pSB67MGLsqYkT2z9LCfHw7F46KxjIYspE500=; b=fF9ncKhbH7UFIEAc7E64mfsIFjQzbCt6HghHgz8bqjohq8tBr4FfQYHGAVSY6wIxys 6ASdjOX1Yq0Fr9B1RpX4ntXQzj1lJOFae1VFJa+qBL7G2xqOifaqacjYMqchN/taz3Dw 80VXiR6M6HIDUi2JHYDVtiLgp+RHhPjku1LKG3fnQD/3pYRV3gpxqT/dkuHk7WEFUl3T Ya/2dxnDVKgiP8HzTz+6ffGdBIrSSF/yxYV6dIMEJRdJwzeTp9qYJI4Rh6iz8XUoeq8B 8o0/iUjYSdj+hNKPo9ZXjFJ3XXBO8oiFPwMAz1T+XqfYD/c0hNfXtS/o/+3pLku88XJQ wuZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739893719; x=1740498519; 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=ACO9Sq8pSB67MGLsqYkT2z9LCfHw7F46KxjIYspE500=; b=Ey4NKOC6LWjajagG9kkacLW5grfuZLAJcUx5/sBDDYNbLZ8XS1EHXalooHj7Lywq7m e3cc5KUGg1ikV22qLKGUYCbnyueIjNRCHFKeacFP8PhxYSzGVLoE3SeR1/ExGrbeSJ9L psO/9Hq11NW7nyx4tIJ28zm0HPRDBHFSXY/HUsYno4AO3kW0f4JHv9al8tCl44tgRWRq g3Nijp8BU9HpXAX/abtNjmpKDgPjBh6hKNO/XwlEhM2bOginkc6QZZBbVyz3GdHc05Yb 7Skdx0H7/Y0H56d++2P1SOk/HgZ19JXEDxqhScEirmjnKuzbOZbci2XitOfNEBMQc3WQ 9SIA== X-Gm-Message-State: AOJu0Yy/0DaXLcdbBDEa1kf+C5x5mjOIwiRN0cmxgqrJN6tKm60OuvIi MXzqYgTxUX6meztrE5FZ6QK5wta7xnHy5JdhW59PCwq2wYHbePkul9oZmbjEvTM+0Gl/AZsn+0o JVbJXzO1LD2N9uGTjLIb83F97xEc= X-Gm-Gg: ASbGncv5rXX4foR4aoSCu4yLHTPPWHp/yyPOP75oKlLpqtW27gI9jIO2lBdQJqDda/f 7s1XFsBbxGb7ppnVUwBjUe3421oDkOyS+xYAhBLH4zkAmmmZtniVbT0SViL8Ly6i5hAKyOZY= X-Google-Smtp-Source: AGHT+IEFoZXQykfZSdsnr2ZD57dIHEGyvIyVuhbajLXS5tTlG2hynV+4mPiY1OJaUTQluckpOz+ShOmTl1P6Q2CPp4w= X-Received: by 2002:a05:6808:13c3:b0:3f4:c17:440a with SMTP id 5614622812f47-3f40c174630mr1214370b6e.28.1739893718735; Tue, 18 Feb 2025 07:48:38 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: bruno vieira da silva Date: Tue, 18 Feb 2025 10:48:26 -0500 X-Gm-Features: AWEUYZk8tN3mI0mn-L50Mx7ZFifX_VQmXe64h2k9srQM_jPpV4ubD6ygmoC4NnY 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="0000000000000d641d062e6c93cc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000000d641d062e6c93cc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, Your explanation aligns with the idea I had that having more shared_buffers and connection pooling are very important in the context of the partitioned tables. Thanks. Regards. On Tue, Feb 18, 2025 at 7:16=E2=80=AFAM David Rowley = wrote: > On Tue, 18 Feb 2025 at 09:18, bruno vieira da silva > wrote: > > > > Hello, I did a more comprehensive test with a different number of > partitions and I found this: > > > > Summary buffers usage for the first call vs second call on the same > session. > > > > Query 200, 100, 50, and 10 partitions: > > 200 Partitions: 12,828 (100MB) > > 100 Partitions: 9,329 (72MB) > > 50 Partitions: 3,305 (25MB) > > 10 Partitions: 875 (7MB) > > > > Same query on the same session: > > 200 Partitions: 205 (1.6MB) > > 100 Partitions: 5 (40KB) > > 50 Partitions: 5 (40KB) > > 10 Partitions: 5 (40KB) > > > > I did test on PG 17.3 no relevant changes. > > > > Question is, does it make sense? > > I didn't analyze this in great detail, but nothing looks too > surprising to me. I get roughly the same numbers on the latest git > master branch as you've shown above. > > A PostgreSQL backend will cache various metadata about relations the > first time they're accessed in a backend. Building those caches > requires accessing the system catalogue tables. I expect the majority > of the buffer accesses are for those tables. If you're curious about > what's being accessed and have a fresh test instance handy, you could > use strace to see which buffers are being read. You'll need to ensure > the shared buffers are not caching anything. Restarting PostgreSQL > should clear those out sufficiently. You can translate the filenodes > back into relation names by using a query such as: select relname from > pg_class where pg_relation_filenode(oid)=3D1259; > > If this is causing you problems then maybe a connection pooler would > help you. With one of those, the backend will live longer than just 1 > query. You could also perhaps revisit your partition count to see if > the number you've chosen gives you the best performance. It's very > common for people to over-partition and not properly consider the > overheads of partitioning. > > David > --=20 Bruno Vieira da Silva --0000000000000d641d062e6c93cc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello, Your=C2=A0explanation aligns with the idea I had th= at having more shared_buffers and connection pooling are very important in = the context of the partitioned tables.=C2=A0

Thanks.=C2= =A0Regards.=C2=A0

On Tue, Feb 18, 2025 at 7:16= =E2=80=AFAM David Rowley <dgrowl= eyml@gmail.com> wrote:
On Tue, 18 Feb 2025 at 09:18, bruno vieira da silva
<brunogiovs@gm= ail.com> wrote:
>
> Hello, I did a more comprehensive test with a different number of part= itions and I found this:
>
> Summary buffers usage for the first call vs second call on the same se= ssion.
>
> Query 200, 100, 50, and 10 partitions:
> 200 Partitions: 12,828 (100MB)
> 100 Partitions:=C2=A0 9,329 (72MB)
>=C2=A0 50 Partitions:=C2=A0 3,305 (25MB)
>=C2=A0 10 Partitions:=C2=A0 =C2=A0 875 (7MB)
>
> Same query on the same session:
> 200 Partitions:=C2=A0 =C2=A0 205 (1.6MB)
> 100 Partitions:=C2=A0 =C2=A0 =C2=A0 5 (40KB)
> 50=C2=A0 Partitions:=C2=A0 =C2=A0 =C2=A0 5 (40KB)
> 10=C2=A0 Partitions:=C2=A0 =C2=A0 =C2=A0 5 (40KB)
>
> I did test on PG 17.3 no relevant changes.
>
> Question is, does it make sense?

I didn't analyze this in great detail, but nothing looks too
surprising to me. I get roughly the same numbers on the latest git
master branch as you've shown above.

A PostgreSQL backend will cache various metadata about relations the
first time they're accessed in a backend.=C2=A0 Building those caches requires accessing the system catalogue tables. I expect the majority
of the buffer accesses are for those tables. If you're curious about what's being accessed and have a fresh test instance handy, you could use strace to see which buffers are being read. You'll need to ensure the shared buffers are not caching anything. Restarting PostgreSQL
should clear those out sufficiently. You can translate the filenodes
back into relation names by using a query such as: select relname from
pg_class where pg_relation_filenode(oid)=3D1259;

If this is causing you problems then maybe a connection pooler would
help you. With one of those, the backend will live longer than just 1
query. You could also perhaps revisit your partition count to see if
the number you've chosen gives you the best performance. It's very<= br> common for people to over-partition and not properly consider the
overheads of partitioning.

David


--
Bruno Vieira da Silva
--0000000000000d641d062e6c93cc--