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.96) (envelope-from ) id 1w7x7t-0004Ee-0L for pgsql-general@arkaria.postgresql.org; Wed, 01 Apr 2026 15:05:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7x7q-000oxc-1h for pgsql-general@arkaria.postgresql.org; Wed, 01 Apr 2026 15:04:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w7x7q-000oxT-0O for pgsql-general@lists.postgresql.org; Wed, 01 Apr 2026 15:04:58 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7x7n-0000000022n-3WkE for pgsql-general@postgresql.org; Wed, 01 Apr 2026 15:04:58 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-7927261a3acso34429557b3.0 for ; Wed, 01 Apr 2026 08:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775055894; cv=none; d=google.com; s=arc-20240605; b=ZQ+GE6IG3VQu+knxbL+EKca4oh0YCCDk7UifMiKMF7FCJE8qcZB9kyUdaiOXYdIcE8 o/1XKDKMhSKSiqaHeEmZthKsUHuxKI9H/hXDzBLFIk9oeoreZuXAuP1dVt615p4NORRu OtAt6faBbqNm+KV3OE/1TumLKRgDGMMvILITJvgiGn15kuddlbtE1hWsH3tN7sXwE6jx WEEmZh4W6wJSPktBGYRWYzTHp8/0azQBD7wtVVkHduKxqShGpg+dN2QDTmCgGnm+YuUv 65prc+vCYD58WXGsLAWgpri2vUTRZ/m2wIRtBZ03hREFk3qPlcz2a4eMFspDh0odUOnl ZR+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=CK9gpXEWRSVZl0LrB1a2p+vjlnD0JHRw8BHI+G99TQ4=; fh=BVuptWvcqVGjpLXAcHdZy0e0PQa6XH8krFkuQRq3g8I=; b=LajhTAHjkYTZ+4LNGFM1rwCCI4/wgy/fhN99Fybg+lanxu71Wd7dwIJkSM9Gdfa8Ld rbfmHIOphXYhHAZuC6yBmbDH3Mu1KOjQpW+ayIGk3UFPDeRBfP0C+cyeoVLjp3GU+aw/ bTXLm+BHOWSM/vYSxsR6fdS1yvOwbTto0Wqb1heEjsJle9vqAAnF884RDghZNu4BRdm2 fQg/oJEfmFapfJBuraQzeGRCDLiJN3T4DzgAZ8sqUAjpNs2s1qsQ4a9+1cZ+LRzkkW5F pa0bIaerIwrzDy36GlcJTZcX+FN24VTqljk+RnkzsLc1TMTsNmR06w/qO6mZ8Qt3NDLA sfBQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775055894; x=1775660694; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=CK9gpXEWRSVZl0LrB1a2p+vjlnD0JHRw8BHI+G99TQ4=; b=c4k3T/HSv5960TExkA8mRVuKBj7QSMduldQEkw3aXgnO3tW4uKZeuQgcV4TghCb6kO 6HZDN9l3HXoHY3hKppX6jdhiRHyJT7GFSzGB4tmrI+9m+npPuQOIZEmr8G+dNw/RmPW7 nGUK53Ks9hMd98VBQJLA9VwDL4MG5vf0Z7TTHEd77CwtXupAOD5iSqIUjgsHVwn73U/T 9lrL1TJlVxcqEazIwFcG1jG2Jszso2m+8iNc361wR35N1TCjfN0MlIjjdte80twgIEfT DX2tI0M5jhozf7eHx6u3EgAf+UtMaPB8XHCbtXkNJGJHLRfNou0t7OgXp4hx2Iu7WjwI Glsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775055894; x=1775660694; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CK9gpXEWRSVZl0LrB1a2p+vjlnD0JHRw8BHI+G99TQ4=; b=oQxY884MRJ/QTPpFl/D0FAbV0WNve6IYozrWcAfXOtS4bKd7o4HzQ+oApStTLvHEZy VAQiajDO2mLa7VLZ4li+RZFxEVo8A97kgUqbpStJVvSfW4JtQZbdz27z3oyQgcdbz1Dy P5PqUR/aBnybxllhybPJ4uP1VX2tpqICNfC+u4xmzUjBHvPE8RRwuM3+3HMGS3lrV29g t0Ot+RA34iKhca7lgkVgM2xiLxEJ7LPG7Ro5HVsw4MjVwf4/JB6ye1KqDZvV0bVFK5jy cBeFpwI+mcV3Urs7DuJVzlvvs1yVnUyo4PQIBo7BHYfmsey8iAZyRbhk0m9+K8c725lo mYkA== X-Gm-Message-State: AOJu0YwHdd7yLrdCtpzZYm4ia6EjFhVgZVOH0BG9Eb37iKrreUYzCXF2 gKEER5xmoAGZqCSH18ZEhCshyYSd90BJBydOS1xvPT7A/2EXZCyY1+/eCx2ucnnGPSy1D8luxEK UWGRorjckBCSejhDDrq2pg8cEgkl1iYuJKW5j X-Gm-Gg: ATEYQzwhMfCTNYP9/IgqwboEMZ3yFjqoivOsEpiH/hBRDjRP+lPNkgABYHaZIThT0wS EViRXHO7AIao2n4mfWfhgSMFbevyBRmFHHrXVdz2H4FhNoat3wDSG1zhuP40sWUo0XZ2l/JSf3A KmmgRwtM2WKiXM4uR8iBq/NUlmxXXkFK/YSeprmxR37QTZaOCWs6qf+toFH78XgWvwl4tp8rUC1 LwDCMD8jBNhqJIjbcKox0ZbTYxfjLzBiRyUuSepYXMzetqVherYAzvS4UPVlkwLT3EfJaijVTJV 3Cv3StTXgZrjIJyIhs6snoBZtCxRjivKcKXo X-Received: by 2002:a05:690c:698b:b0:7a2:9a26:d3d0 with SMTP id 00721157ae682-7a29a26d764mr23161477b3.47.1775055894086; Wed, 01 Apr 2026 08:04:54 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?Q?Gabriel_S=C3=A1nchez?= Date: Wed, 1 Apr 2026 11:04:43 -0400 X-Gm-Features: AQROBzBnRFAJ7BGNGPMFAl80ZcGzVM45lFpD_Ay0Nmit9PivOv0AO4A5iRYY7g4 Message-ID: Subject: Speeding up ANALYZE on large partitioned tables To: Postgres General Content-Type: multipart/alternative; boundary="00000000000006091d064e6768be" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000006091d064e6768be Content-Type: text/plain; charset="UTF-8" Hi PostgreSQL community, I have a database with several very large tables (for example, 86 GB) that are partitioned by year, sub-partitioned by month, and sub-sub-partitioned by day. Each day a new partition is added, and that partition is immediately ANALYZEd by my process. However I noticed that sometimes the query plans for queries on the top-level partitioned table don't make much sense, and I read in the documentation that ANALYEing the leaf partitions doesn't update the statistics of the parent and grandparent tables. So I have to run ANALYZE on the top-level table, and when I do that the query plan makes more sense. But it takes quite a while to ANALYZE the 86 GB table with hundreds of sub-sub=partitions, because that ANALYZE triggers an ANALYZE on each partition down the tree. Since leaf tables are always ANALYZED when created, isn't there a way to update the statistics of the parent and grandparent tables based on the statistics already calculated for the partitions? Maybe with an ANALYZE ONLY [top-level table]? Thanks, Gabriel --00000000000006091d064e6768be Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi PostgreSQL community,

I h= ave a database=C2=A0with several very large tables (for example, 86 GB) tha= t are partitioned by year, sub-partitioned by month, and sub-sub-partitione= d by day. Each day a new partition is added, and that partition is immediat= ely ANALYZEd by my process.=C2=A0

However I notice= d that sometimes the query plans for queries on the top-level partitioned t= able don't make much sense, and I read in the documentation that ANALYE= ing=C2=A0the leaf partitions doesn't update the statistics of the paren= t and grandparent tables. So I have to run ANALYZE on the top-level table, = and when I do that the query plan makes more sense. But it takes quite a wh= ile to ANALYZE the 86 GB table with hundreds of sub-sub=3Dpartitions, becau= se that ANALYZE triggers an ANALYZE on each partition down the tree. Since = leaf tables are always ANALYZED when created, isn't there a way to upda= te the statistics of the parent and grandparent tables based on the statist= ics already calculated for the partitions? Maybe with an ANALYZE ONLY [top-= level table]?

Thanks,
Gabriel
=
--00000000000006091d064e6768be--