Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9g8S-0005xm-IB for pgsql-admin@arkaria.postgresql.org; Tue, 18 Jan 2022 04:30:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n9g8Q-0008KT-UQ for pgsql-admin@arkaria.postgresql.org; Tue, 18 Jan 2022 04:30:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9g8Q-0008KJ-Jv for pgsql-admin@lists.postgresql.org; Tue, 18 Jan 2022 04:30:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9g8O-0006O1-2U for pgsql-admin@lists.postgresql.org; Tue, 18 Jan 2022 04:30:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 20I4UDBD254602; Mon, 17 Jan 2022 23:30:13 -0500 From: Tom Lane To: Victor Sudakov cc: pgsql-admin@lists.postgresql.org, Ron Subject: Re: Large number of partitions of a table In-reply-to: References: <3919502.1642393668@sss.pgh.pa.us> <671340a5-1960-e5dc-1d09-4b7f36cda2c8@gmail.com> Comments: In-reply-to Victor Sudakov message dated "Tue, 18 Jan 2022 02:54:43 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <254600.1642480213.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 17 Jan 2022 23:30:13 -0500 Message-ID: <254601.1642480213@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Victor Sudakov writes: > What's the worst thing to happen if someone runs "SELECT COUNT(*) FROM t= " where t has 10000 partitions? > 1. The backend will crash? Well, yeah, actually. An ill-advised query will blow out your backend's memory consumption, potentially leading to a SIGKILL from the dreaded OOM killer[1] (if you're on Linux), resulting in a backend crash and cluster restart. On other platforms, you will likely end up in swap purgatory, which is actually worse because it destroys the whole platform's responsiveness and there may not be any easy way to get out of it. > 2. The whole cluster will crash? Not unless the OOM killer decides to kill the postmaster. That's been seen to happen :-( but I think recent kernels have gotten better about targeting the misbehaving backend not its parent process. (Once upon a time they deliberately targeted the parent, which is the main reason for the advice in [1] to disable the OOM killer.) > 3. Only this particular query (spanning multiple partitions) will be ver= y slow? Guaranteed. > 4. ? You could run the shared lock table to full or nearly full, causing concurrent queries to fail all the while your SELECT COUNT(*) is leisurely proceeding towards completion. > Also, what if it is not a SELECT but an UPDATE query spanning multiple p= artitions? Does it make any difference? On v14, no. Before that, you have the O(N^2) planner issues I mentioned upthread. All of these things can be worked around, but you have to ask yourself if the benefits you get from using more rather than fewer partitions are worth fighting these sorts of fires. regards, tom lane [1] https://www.postgresql.org/docs/current/kernel-resources.html#LINUX-ME= MORY-OVERCOMMIT