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 1n9ji6-0006PF-VQ for pgsql-admin@arkaria.postgresql.org; Tue, 18 Jan 2022 08:19:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n9ji5-0000Un-Jj for pgsql-admin@arkaria.postgresql.org; Tue, 18 Jan 2022 08:19:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9ji4-0000Ue-QA for pgsql-admin@lists.postgresql.org; Tue, 18 Jan 2022 08:19:21 +0000 Received: from admin.sibptus.ru ([2001:19f0:5001:21dc::10]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n9jhx-00045A-VM for pgsql-admin@lists.postgresql.org; Tue, 18 Jan 2022 08:19:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sibptus.ru; s=20181118; h=In-Reply-To:Message-ID:Subject:To:From:Date; bh=YpxjY70ylsOzAa57t0VGIHmqUwT0FEyRlKcUV4QGPYY=; b=odOnQG21erKzpiGTiPdkQx/q/W 4DlZIu66U/CteczP9Vj9SBZ4fcUYEiCPg/xzotfwStR4PplhXYB1H/rZrK9b4g/zuik4LmPMWsx0Q es+7R5Abp8Ky7HopW9Jjcmm+24uzkb7uN7KDfvZOu6rOX+ziNnR9+9uHaTdOZUGOjGWc=; Received: from vas by admin.sibptus.ru with local (Exim 4.95 (FreeBSD)) (envelope-from ) id 1n9jhv-000BgV-1U; Tue, 18 Jan 2022 08:19:11 +0000 Date: Tue, 18 Jan 2022 08:19:11 +0000 From: Victor Sudakov To: Tom Lane Cc: pgsql-admin@lists.postgresql.org, Ron Subject: Re: Large number of partitions of a table Message-ID: References: <3919502.1642393668@sss.pgh.pa.us> <671340a5-1960-e5dc-1d09-4b7f36cda2c8@gmail.com> <254601.1642480213@sss.pgh.pa.us> <268771.1642489687@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <268771.1642489687@sss.pgh.pa.us> X-PGP-Key: http://admin.sibptus.ru/~vas/ X-PGP-Fingerprint: 10E3 1171 1273 E007 C2E9 3532 0DA4 F259 9B5E C634 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tom Lane wrote: > Victor Sudakov writes: > > Tom Lane wrote: > >> 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. > > > Why should "SELECT COUNT(*) FROM t" ever consume more than work_mem > > even if t has 10000 partitions? > > Sure, COUNT(*)'s runtime memory consumption is negligible. > But you're not thinking about overhead --- specifically, > > 1. 10000 relcache entries for the base tables. > > 2. If you have N indexes per table, N*10000 relcache entries for > the indexes. (The planner will probably have looked at all those > indexes, even if it didn't find any use for them.) > > 3. 10000 SeqScan plan nodes and associated rangetable entries, > > 4. Likewise, 10000 instances of executor per-node state. > > 5. 10000 lock table entries (both shared and local lock tables). > > 6. Probably a few per-relation things I didn't think of. I see your point about all that query-related stuff. I hope the testing of queries in a staging environment should help to detect such situations. What about the system catalogs however? Will the extra 10000 tables and 500000 indexes negatively impact the performance of the system catalogs? Are there any caveats you could think of? > > Basically, this is likely to work until it doesn't ... Oh, this can be said about many things beyond the very trivial. Unless there are immediately visible and well-known limitations, I would risk it. -- Victor Sudakov VAS4-RIPE http://vas.tomsk.ru/ 2:5005/49@fidonet