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 1vXL6K-007ujJ-1I for pgsql-general@arkaria.postgresql.org; Sun, 21 Dec 2025 15:12:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vXL5I-00Botn-1z for pgsql-general@arkaria.postgresql.org; Sun, 21 Dec 2025 15:11:01 +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 1vXL5I-00Botf-0b for pgsql-general@lists.postgresql.org; Sun, 21 Dec 2025 15:11:01 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vXL5D-001vSQ-2e for pgsql-general@postgresql.org; Sun, 21 Dec 2025 15:11:00 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-7c7aee74dceso1238549a34.2 for ; Sun, 21 Dec 2025 07:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766329852; x=1766934652; darn=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=FdYBo2Oe/Ck773t3ZhKfU3KhMFSjvUOX03RN+HKnwWY=; b=GrOs2j2yuTPWqkD+uSO4LgaR+ebo8O1ptGzdObyMoc7DzgM2oVIohk6eDt+eBx9EN5 peG+pAtJD702lqTJEXFgwcbe6k1ABAjqiXbkblWk2K1HuUeuIS1GvuA62h+HxyvPTX1U dl51eCeRXi213ROYmkMFpi2c3Qg2CH4Aky1H9ceK2cwfbN/zebursgRaUGhFJF9GCueu r4axz6eWR3Cy5yKm47m5kV2pKHvDXkHOLxZvPoqHBG1rqXTfmq5R6bxiLEEPvYIpKk+8 uqcsPgUy1V8VSZ2DI1BiWtufd52f7jKDFv20w9+eI0+xTTvz/+s5DN9eibmou08hD/JX vXOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766329852; x=1766934652; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FdYBo2Oe/Ck773t3ZhKfU3KhMFSjvUOX03RN+HKnwWY=; b=jYTheZ9U3h+bqXIQWQ2TfekbhGe9ijlEI27Wh2F6tf8MLIPrJY1LbD2MpXEBDR8AHX SMKwlXPAbrtypA+saAxP++PNcusEXcs3kruikKcPL2ArZ9nZODAIf/uqAXu6t1cYKZ7r TgVDP2Yluxnq+IukuUaH4XULXkVVK0jkwVDX23z1IG2tArRUEQKnzNHN97gALPTX6dft 6DhMxixCo9BPQx2EgeYQIFXivQXBc29Upw/9orv3leHNFovslquuAuyjShSwf/9p7UFs XZ4+191u1gBNYICUS9DLC3ZQMN2H8kHPkgbMHN8J+EWGAGZU4Qc8m8JWQw5dVmMI/kaQ TKaA== X-Forwarded-Encrypted: i=1; AJvYcCWW/9Ep9qXPaUIRG+awVEJtZfAoBy4TNrazs6IT4XIOWQ1ynklwQ7kzzRako/Deo8AUqvBwPC+eyx1Y/QEM@postgresql.org X-Gm-Message-State: AOJu0Yyqir/qYfmlHzuyVenhXQZYLaRRfkXtiMd6cDEsQPFGr9h6W+PW SGohmsyIqEr6Bwi38k2adxuewH9eE4yJek4yPwPqlaD+rblxoIIGrRpw6a2K37JnJ6EFo/FgoWW 1ts/Cl407WtrQlJvh5k+Aw0RW0rJEUAY= X-Gm-Gg: AY/fxX53TxsswXFA/9eyh2cMzuR+4/Sg3NXA9LWmpFJTOvzcQ0JD++YGvzbEZvBYRdB XqOFbyuDeHtjbjHj9WP/g7woBGiwjJ3XFlLiWLsNxxZFuzum+epx3YIC1P6weDHg35yoXeS5upM GXZ4+/xRM2CKfelXvRFH8tAYFlMmKdA0QUvDZfwyczEOYtmYiD02VPfA2V29rahSblB3+y+Mi9n FFYS+Xhuc/gN23vNxVbpImy07jdrIwB9H20P7FWAdDdmVzPuK12k7XWhH6b+d6T55oXcJhT1GUH 7p6GxyC6sn6S2v3ZDbQosWfCIpuCEw== X-Google-Smtp-Source: AGHT+IHnOJ2OPbPyEwcmPWkenC09TY+Tp3VF3fdCNUFI5yDO0OrFVEhIk/mOHOD4IFNQsdzA9gokR83QjtkawuTW6n4= X-Received: by 2002:a05:6820:608:b0:65b:3c3b:69b7 with SMTP id 006d021491bc7-65d0eaa7281mr3378390eaf.39.1766329852506; Sun, 21 Dec 2025 07:10:52 -0800 (PST) MIME-Version: 1.0 References: <87bjjv1v96.fsf@gmail.com> <64ccdcb7b15a17cbf610854e51cd8235c246cca8.camel@cybertec.at> In-Reply-To: <64ccdcb7b15a17cbf610854e51cd8235c246cca8.camel@cybertec.at> From: Greg Sabino Mullane Date: Sun, 21 Dec 2025 10:10:22 -0500 X-Gm-Features: AQt7F2qfFNU12AwaAAMXjNkFnHCMAS1jFsy544MQaeKuea1fW5xEmdcJbb-V3WQ Message-ID: Subject: Re: Dealing with SeqScans when Time-based Partitions Cut Over To: Laurenz Albe Cc: Matthew Planchard , pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="0000000000006a3713064677b781" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006a3713064677b781 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Dec 19, 2025 at 12:42=E2=80=AFPM Laurenz Albe wrote: > I doubt that that is good advice. For one, wrong statistics are not > necessarily better than no statistics. But clearly in this case, "wrong" statistics are better than none. Frankly, any plan is better than the one they are getting (full seq scans). Also, with a time-based highly active partition, we can be very sure that the stats for one partition are going to be similar to another, so doing some "pre-estimation" seems fine with me. At the end of the day, this is a query planner issue, and the goal is to prevent that. The same data will be returned. > Disabling autovacuum is dangerous - and re-enabling it would trigger > another autovacuum, which would undo your efforts. > No, re-enabling it will put it back in the pool of tables that may get vacuumed/analyzed once thresholds are reached. It will not immediately trigger another autovac. > *Not* re-enabling autovacuum is not an option, unless you schedule > explicit VACUUM runs on the partition. > *shrug* Well, for an hourly partition, if the stats you set at the top of the hour are the same as the stats when you analyze at the end of the hour, and give the same plan, analyzing doesn't really matter. If this were a normal table, I might advocate cron-based or insert-based vacuum runs for all the other benefits vacuum provides, but with time-partitioning, the app usually only cares about very recent partitions, and there is little-to-no updating going on. Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support --0000000000006a3713064677b781 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Dec 19, 2025 at 12:42=E2=80=AFPM = Laurenz Albe <laurenz.albe@c= ybertec.at> wrote:
I doubt that that is= good advice.=C2=A0 For one, wrong statistics are not necessarily better th= an no statistics.

But clearly in this case,= "wrong" statistics are better than none. Frankly, any plan is be= tter than the one they are getting (full seq scans). Also, with a time-base= d highly active partition, we can be very sure that the stats for one parti= tion are going to be similar to another, so doing some "pre-estimation= " seems fine with me. At the end of the day, this is a query planner i= ssue, and the goal is to prevent that. The same data will be returned.
=C2=A0
=C2=A0 = Disabling autovacuum is dangerous - and re-enabling it would trigger anothe= r autovacuum, which would undo your efforts.

No, re-enabling it will put it back in the pool of tables that may ge= t vacuumed/analyzed once thresholds are reached. It will not immediately tr= igger another autovac.
=C2=A0
*Not* re-enabling autovacuum is not an option, unless you schedule explicit= VACUUM runs on the partition.

*shrug* = Well, for an hourly partition, if the stats you set at the top of the hour = are the same as the stats when you analyze at the end of the hour,=C2=A0and= give the=C2=A0same plan, analyzing doesn't really matter. If this were= a normal table, I might advocate cron-based or insert-based vacuum=C2=A0ru= ns for all the other benefits vacuum provides, but with time-partitioning, = the app usually only cares about very recent partitions, and there is littl= e-to-no updating going on.

Cheers,
Greg

--
Enterp= rise Postgres Software Products & Tech Support

--0000000000006a3713064677b781--