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 1n9plh-00059m-1e for pgsql-admin@arkaria.postgresql.org; Tue, 18 Jan 2022 14:47:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n9plf-0002Pg-Uj for pgsql-admin@arkaria.postgresql.org; Tue, 18 Jan 2022 14:47:27 +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 1n9plf-0002PW-IZ for pgsql-admin@lists.postgresql.org; Tue, 18 Jan 2022 14:47:27 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n9pla-0002qY-Gi for pgsql-admin@lists.postgresql.org; Tue, 18 Jan 2022 14:47:26 +0000 Received: by mail-oi1-x22f.google.com with SMTP id q186so28773206oih.8 for ; Tue, 18 Jan 2022 06:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=COid7N4GcEee5KCpDT+cQ2JRswMuzhr2WYWICbqQ5og=; b=SkNwsAP+fNe1CmEUlDTZoyrVpazHU/eDTDUpMtm0rh2UNuMAegiy0itwb+PyWOh5jO zMTecyx5EeYq0Ln6b/1JlYL0qsgFz55WCwpKfkgGXy25um7Nf4L6n93cqRlntKJfPUi9 BKFqw+JZdDHel/ij2QTWsoLKRF7gGcXMec1vGmBgJ2ONPFSZMjzVeAL2ewasCggvRaTJ R7FJ/glIYgisFcLdOTolKbmB/nGWhukyy9vITrfqL5qCmojoDfCzas0a+3vePRKRn//I HmHxzRsuoUmlqWidXguz7Hdrq49C9+/Mw7Fmuw29BJV3W+PhHIWepdg3R20ZTvZSSK4k IiqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=COid7N4GcEee5KCpDT+cQ2JRswMuzhr2WYWICbqQ5og=; b=xY5P7yD1L08j0kcMRdlchL9arRslRoP5Ii0ZQOUM5piPssrvD52p9Eh8cFsozauZaJ lCcIc5WhOBG5N9jkyeHD3WtZrqoc3Egvz2nkxTZouvdfc3ywYJqZZnW8SiXg6GkTDjA+ Z1cOKydezL1DPf3nKWXibdsl+E/T7rB3ihywkOV9tdQVmXFbO+NlXNs/sFO2GOVvYN4k Wsiqfstt98eSgBvb4XSlZ9T0AuJJtVrUAMRB/fUDioy2ROTRNv4jSlDUtHQRvO3vPldh 2CFYTLw3Ksf/HTTrHY9qXFE1JaPerm3/YPK8St5PaR+rQRU/apuYiQgvFUJpRRQHAbT6 c6RA== X-Gm-Message-State: AOAM530k7dq9it2Nu+q3lNztRkjuwp39HBWyF6zBJJGu4tsnQoX2EHmv Mew9U0/6cAXLXXQ4g9A2IyMDJRXAU9s= X-Google-Smtp-Source: ABdhPJwSjDt+GcriKzKFMWu9XRwKfjl5QEFCmKJPaeOlekEoQV0HnIafTcZ2eFrG2h3xS9+crldD0g== X-Received: by 2002:aca:f241:: with SMTP id q62mr8449497oih.64.1642517241726; Tue, 18 Jan 2022 06:47:21 -0800 (PST) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id y2sm7327677otq.27.2022.01.18.06.47.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jan 2022 06:47:21 -0800 (PST) Subject: Re: Large number of partitions of a table To: pgsql-admin@lists.postgresql.org 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> From: Ron Message-ID: Date: Tue, 18 Jan 2022 08:47:20 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/18/22 2:19 AM, Victor Sudakov wrote: > 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? EXPLAIN plans are going to be hilariously gigantic, which means that query planning would take a loooong time,  And the query planner (in v12, at least) can generate some pretty bad plans in partitioned tables; I bet there are edge cases in the QP code that don't work well with 10000 partitions and 50000 indices. -- Angular momentum makes the world go 'round.