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 1wvuL8-001cEp-1I for pgsql-bugs@arkaria.postgresql.org; Mon, 17 Aug 2026 10:13:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wvuL4-009PS9-2T for pgsql-bugs@arkaria.postgresql.org; Mon, 17 Aug 2026 10:13:07 +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 1wvuL4-009PS1-1e for pgsql-bugs@lists.postgresql.org; Mon, 17 Aug 2026 10:13:07 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wvuL2-00000001CFl-2Yri for pgsql-bugs@lists.postgresql.org; Mon, 17 Aug 2026 10:13:07 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-39c9452244aso24608391fa.3 for ; Mon, 17 Aug 2026 03:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786961583; x=1787566383; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:to:subject:from :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=5SS0jnxKIpBWpz/zKsps24Ja3aPrknXF/zdDblvM6wI=; b=AiKTtRemAo/EJq+OVgb2UD/176CvoMQ9q3xcNbUbwrSvjRz+xvPUwMmmnn1aM57fE1 2F2/dT2ZG3DGjMccArgahJAcSnCUsLvGUYD7CC7T6xFB0Ikj4iWMI5jcs0w/DxDWdPsd 82eAc70+jEg7JABcnwwdH8lZlmv301pRCGXGriYUDj8ItKMacT7eAnbqvwSij6PhvWB0 8ZlkwejQE8quiQrwmsq2B4nqgY+UAKcgZG1h+hbJZgid3a8JW8rb8QazgAwvH3M2YZth nkygD+FwsMEJ22Zd3A3fcdvYrSjX+mRZh2PTCVMqQVEVGgSBiCWYBcGVbettoaGIeeFB eBrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786961583; x=1787566383; h=content-transfer-encoding:content-type:to:subject:from :content-language:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5SS0jnxKIpBWpz/zKsps24Ja3aPrknXF/zdDblvM6wI=; b=YsrAo96YBceZImTq/oo9aS+mV7o+Cy0WnMiRFrQmextgy4CIeYrQsh+dcY3lNFh0x9 j2AFlPKYzoS71QjxdQlxULeNRhVcXqoYvKhwKZ8xbtVTr5L+2E5A4e8Bw3yYhKsQ/NEm yUO5GD8hYX2ugzRwqF0GePl8is+rFPvjDDR1kNaGDZxuWlHA5akMqDOa2wYlQpuE8UrV ZJt4swDCE0PS3jv6IUZpfOxddx199Vm25Oa+50p9Jjrh53b2ECqmUG0Y4+75HncCAyHg WRTodVHSmcZ9oS1l3UTb+s5/tokbXLlO88MuGThhlS0qGKo34dGQ/cL7SoPvDYOQguUX gZuQ== X-Gm-Message-State: AOJu0Yw39IHkMvzejHmHh7FVVntOjDMn3b8DZArbOhJ6MILRkBLw0Kg3 +ux4Yi9dWHjroWqpxHpd/sNcCQIFkbG1Is/Fply3WlyD++KAdbNT/mgNUi0ytVvMyUU= X-Gm-Gg: AR+sD12ncLGyDbfdDB4R85IxoBprU4RACPaMuxGwp3EadD++AjAJ9qecXMlHke6l/L+ Thnaxl4xslou5NoYcESnaYzmSIJ8napYshUTYYHFKXa31C4CPfD/RxPrNZhjgSKYtH6dpFtfJkd fyc1rDwe5LWJ0PE7IT2TfJrIE06O8qxe9bOzTobQeaujdvuSc8lIc1be4IZ+olaBaqK46vlZhMg Z6trKML+uVo0DR8SEizgYFgvSBpuycI7eMbYhkQV9cySB9fSt7KG0pQC4pT2PIUMzOkNgLOBGxA F6INEsmbHyoDYJPaLV83++FsxRiIrjd+pDvhd4QZNeRSl1sitUNyG9ACx3kC36gIKVowWWCjAh3 N1oomTjxdAugzpiPuYDlW9Ds5x4BxitYz7OmJohUBXRyUsT2RWP2Z1GAPS11ORdn5p4R61qAlVJ vgFv+8047ewi2X8IzenBzWGXubdP31TMJo3wH2K6Q+eu29H69hbHr5q4FxdTNZsXhuWPVkH7UNc XCpEXJ6K+1fcZbD2/QyOjbEFsEfZg== X-Received: by 2002:a05:651c:a204:20b0:39b:2ff8:64ae with SMTP id 38308e7fff4ca-3a1323db330mr13985261fa.9.1786961582701; Mon, 17 Aug 2026 03:13:02 -0700 (PDT) Received: from [192.168.1.107] (95-27-196-180.broadband.corbina.ru. [95.27.196.180]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3a16b1a98dfsm3258201fa.21.2026.08.17.03.13.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Aug 2026 03:13:02 -0700 (PDT) Message-ID: <2bbe2557-83a1-443e-bde8-a3c25c6ac29a@gmail.com> Date: Mon, 17 Aug 2026 13:13:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Oleg Gurev Subject: Autovacuum and vacuum spoil reltuples statistics on nontruncated relation To: pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello. Looks like I've got similar bug as was described in this thread: https://www.postgresql.org/message-id/flat/3dec196d-72a6-447f-ad2e-f2668f2907a9%40oss.nttdata.com#b83f0d78023e8980ec4ac0e5568b9f9d Autovacuum continue to spoil reltuple statistics when vacuum_truncate is off and long transaction is going. ============================================================== Reproduction: Start cluster with GUC "vacuum_truncate = off". (since REL_18) ============================================================== Sesson 1: CREATE TABLE t AS SELECT i FROM generate_series(1, 50000) i; begin; SELECT txid_current(); ============================================================== Session 2: DELETE from t WHERE i > 40000; SELECT to_char(now(), 'HH24:MI:SS'), c.relname, c.relpages, c.reltuples, st.n_live_tup, st.autovacuum_count, st.autoanalyze_count, age(c.relfrozenxid) FROM pg_class c, pg_stat_all_tables st WHERE c.oid = st.relid AND c.relname = 't' \watch 1 ============================================================== reltuples and reltuples will start to decrease. My investigation led me to vac_estimate_reltuples() function and page density calculation. Here we rely on uniform distribution of tuples over all pages. But without truncation this led us to mistake on counting new tuples count. If we don't run long transaction - autovacuum perform one shot on 't' doing vacuum and analyze. So it helps to see correct statistics unless we run vacuum t; manually... The key issue is than vac_estimate_reltuples() rely on total pages number. And pages counted by deviding relation file size by BLOCKSZ. I didn't found any "cheap" solution on this case. Probably, someone can help. workaround: vacuum analyze t; can fixup statisctics and tell autovacuum don't touch this relation. But any manual "vacuum t;" will break statisctics again. vacuum full t; solve the problem by the cost of truncation.