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 1tkMWa-003ChL-3Q for pgsql-performance@arkaria.postgresql.org; Tue, 18 Feb 2025 12:16:28 +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 1tkMWY-009gQr-7I for pgsql-performance@arkaria.postgresql.org; Tue, 18 Feb 2025 12:16:26 +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 1tkMWX-009gQj-TS for pgsql-performance@lists.postgresql.org; Tue, 18 Feb 2025 12:16:25 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tkMWW-001VjK-0b for pgsql-performance@lists.postgresql.org; Tue, 18 Feb 2025 12:16:25 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-5452c2805bcso4196270e87.2 for ; Tue, 18 Feb 2025 04:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739880982; x=1740485782; 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=SSGa5DDugP5LqPgXF9rT9uNwL6tVyJmExX/ZTFBCncY=; b=WD0kuZ2Kom0AldgHksM3eRi3Yb1aouGGqfdWFhIqHnWPUdGDlGaNO5AxUeuwDWhwcL lXtUKdnkhwpJ8lo3+rO1aTnkXu8ueK3kfTBuSuHXEjpHwxkU2+IrzeGY7zAe0Nxnr0xD oN5VOLteboqvnXro6d5ihP6a8voZxTXx7V6pIUrSpScT+v/aUcWNOFhd2Ta/Q/aWuahQ HAbBp8CtrZZ6MRnNZzyNNz0sOLmjITpuUNqNPdfhdS0ZNvr7+Ace1rIHLI7/gp39p1+D 7hLwO0eblvnu5ViTq6oE1NyvGe9DL5mU+BEqX0bHW3+OQEkG95ghgaXkKcKfdEKdR7nU myOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739880982; x=1740485782; 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=SSGa5DDugP5LqPgXF9rT9uNwL6tVyJmExX/ZTFBCncY=; b=c4/SS1F4ycPOvMk3PR23gAMFjhx8e98NA5M2Is59xzxMkQsJ+X0TqtN1KJ7OPTj9x4 6XRCdtIClPmVCJXjmERPBu469J87fgQhuA4XtyVUWkxvPqXUJmPPGxsS7df3naqHh2EE zlf/bm0iyzRL3T+pBbzb2adFCUzKiG4F5eYnIfxziUaeKaa+3cFbf6UAMrXOZ0cjgZlJ SNETeGxauPn447Oddz6dZWcGWK/KhuF2CFfDudVwabBRkLDmfNtlKVNSDuS1Xl2F6lXX aV45KrTod+BQRE6xhaod0FXuJ9OqleydGBlOm/0tEKSTGUPqSCa/oHaz7XmBJXY9N2xV +UYQ== X-Gm-Message-State: AOJu0Yy6mlrKMwkx5EC6++Z+U7NG6d8lZ/g2a6vmt6O6A6l60sa1AlFJ mOlEYQJakDVU6OdrE7qchD58aUj5qkF0fG6QM9QRudceFWWuD+U/xqenvuOQPfQ5Lh2noOGV0iB XJJ5NpR71RFcz26iFuXoN2C3zRzFt5AQf X-Gm-Gg: ASbGnctsC6IOnPlyRzLlqBLLU83yekIzhpqKv1TCKaePkfvDd2OVpYxPPU6p6iv+Dmm 9WqjCB/wLDIzoxY6NCPSNB9CYI39SxpEqFQW0dSXuy04aYTMU+L1DlFHJnsQJ0l1NEG9P31H6Nw jnE1napXXWAZAL/EUofe7xvObKryIqkzU= X-Google-Smtp-Source: AGHT+IERji6n9Rz3/kMYr3IrUnw5KtftpHCt1SMkkQHOTG/eBUAhwsW7Zw/TyStZ44MookFnK5FT5fvHS+cluu//eW0= X-Received: by 2002:a05:6512:1592:b0:545:ea9:1a1f with SMTP id 2adb3069b0e04-5452fe5c770mr3975022e87.25.1739880982189; Tue, 18 Feb 2025 04:16:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Wed, 19 Feb 2025 01:16:09 +1300 X-Gm-Features: AWEUYZnglUvN3Lm3616UgI9dmgbj3Cd5f6S2tXCFwDoe0HVJ5g9Yq6EDYxSvoPA Message-ID: Subject: Re: Query planning read a large amount of buffers for partitioned tables To: bruno vieira da silva Cc: pgsql-performance@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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)=1259; 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