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.94.2) (envelope-from ) id 1vFsdL-002stI-51 for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 11:21:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFsdK-002JLN-0e for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 11:21:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFsdJ-002JK8-Er for pgsql-hackers@lists.postgresql.org; Mon, 03 Nov 2025 11:21:56 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vFsdG-005Cob-20 for pgsql-hackers@lists.postgresql.org; Mon, 03 Nov 2025 11:21:55 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 934021D00053 for ; Mon, 3 Nov 2025 06:21:53 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 03 Nov 2025 06:21:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to; s=fm1; t=1762168913; x=1762255313; bh=wb384ob8ac hUwfVBn0Q4Q1g05TgMNh++O5XDHV6930Y=; b=Md2GY+3Uq/1JoKiDjAwTLkaX7z f67LehOh3/+/29bwLWlGU3mVYq/DRbjqTTfZwHzN2FWecyOHReoSgHP4GLBHr888 QEUFvn2uPUXMKTTBEiD9qn8a6w8BY6fRIO3+rcgZ3pBAvMzqnMAIcXDXppGgkOXk 4wHEanU/WcE6lxpYkePAfoWg8nrdvtqg75q0mdmAxtE20ATSBf9vqTt5Ai2yQDBB qDl1exq9jyKEyF/myIFo2Xt8FrkEYh1beRZaJbYqgh/4pEAnJtFm+AvFyNcuzyNs V6jS6L2wPL5kAL7BA313zQ3xsMlvcQpl2uIWdxIMcFNkuMnd26jd2BAusamA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1762168913; x=1762255313; bh=wb384ob8achUwfVBn0Q4Q1g05TgMNh++O5X DHV6930Y=; b=2o65Cz7f74Z7qxx4oWsGNDKjbjmJDdJUPVW/jlouAZ//TyxOB5c ZA+k4nH2TJSdAu59dMPJ/uC6YMhhPReVL7xx0usprWlYkjdBphChUcL3MOCjgI9c D06Q7Bit9dMG8/lox/zKd90e2KPXmcJVbYNtsZxSo+6H7S+2O7xeo2bvxmgMUPOC 3g+W9/3DrpTMcuFNyTsslZ7dmLtkouyFHfP7V4OuBkNMaKEriY+XF1HBrgpHm/tY LNR+l/VMoECyTva0FxxCc/m7dXG04Y6mJYsi72p2tscrB/fTX76aDQjppeBCRpQe qOGATvdIBQCGcNpoArROdq6jpcMS2UVAXBw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddujeektddtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvffukfggtggugfesmhekreertddtjeenucfhrhhomheplmhlvhgrrhhoucfj vghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtffrrg htthgvrhhnpeefveegkedttdeiueegtefgkedvgeevudegveeukeejtdejveejtefhfeeu jeeggeenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsehk uhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuth dprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgv shhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 3 Nov 2025 06:21:53 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1762168910; bh=2nz6LnIM7aOG5FGN7AqDWURGdnVhA7ZbhdJ4fZBo/rw=; h=Date:From:To:Subject:From; b=t8D9hov42tSGgj99v/RpmBGHCm00fCCMtnYzfP/6Mt3CytTnzpOe6v/JbF0fkGOQI Hfy0ym9zYI1hzItuERAzq8asBLZsyBiri0lIe+qLqBfxemDnH5/WJxk56lxYXSBXuT TxZ2ZVgzZKNjlCaW8SA4GQzDfXQX2hxFZhwqJRomPo3CC/VJhSSrTQf/G73DLgRC0B PWaieashyJT/8hT3S+0xPLqCIt14xby4AIQwLR8WwYE3stjOfkhrrb1D12HznJfMBO DjAPaeUbhTyYN/5VkUCUTBubUOL1GBba2clWSIvsaxzsXHi75wcdwt1p90bLzeU5Sm ZOT4Nq7tj+3Bg== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id 9098A76; Mon, 03 Nov 2025 13:21:50 +0200 (EET) Date: Mon, 3 Nov 2025 12:21:50 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Pg Hackers Subject: BRIN autosummarization lacking a snapshot Message-ID: <202511031106.h4fwyuyui6fz@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="y3erep2biy2c2i25" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --y3erep2biy2c2i25 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit If you have a BRIN index with autosummarize=on, and it's based on a function that requires a snapshot, autovacuum will simply error out when trying to summarize a range. Here's a reproducer: create table journal (d timestamp); create function packdate(d timestamp) returns text as $$ begin return to_char(d, 'yyyymm'); end; $$ language plpgsql returns null on null input immutable; create index on journal using brin (packdate(d)) with (autosummarize = on, pages_per_range = 1); Now insert some data, insert into journal select generate_series(timestamp '2025-01-01', '2025-12-31', '1 day'); and wait for autovacuum to fire. You'll get an error like 2025-11-03 12:17:42.263 CET [536755] ERROR: cannot execute SQL without an outer snapshot or portal This patch fixes it. I haven't given much thought to adding a good way to test this yet ... -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Someone said that it is at least an order of magnitude more work to do production software than a prototype. I think he is wrong by at least an order of magnitude." (Brian Kernighan) --y3erep2biy2c2i25 Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Brin-autosummarization-may-need-a-snapshot.patch" Content-Transfer-Encoding: 8bit From e0f81d98b08512f540300a0c3061480b62917b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Mon, 3 Nov 2025 12:20:22 +0100 Subject: [PATCH] Brin autosummarization may need a snapshot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's possible to define BRIN indexes on functions that require a snapshot to run, but the autosummarization feature introduced by commit 7526e10224f0 fails to provide one. Repair. Author: Álvaro Herrera Reported-by: Giovanni Fabris Reported-by: Arthur Nascimento Backpatch-through: 13 Discussion: https://postgr.es/m/202511031106.h4fwyuyui6fz@alvherre.pgsql --- src/backend/postmaster/autovacuum.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 23cca675f00..2d10ee22377 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -2596,7 +2596,9 @@ deleted: workitem->avw_active = true; LWLockRelease(AutovacuumLock); + PushActiveSnapshot(GetTransactionSnapshot()); perform_work_item(workitem); + PopActiveSnapshot(); /* * Check for config changes before acquiring lock for further jobs. -- 2.47.3 --y3erep2biy2c2i25--