Fix snapshot handling bug in recent BRIN fix
authorÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 4 Nov 2025 19:31:43 +0000 (20:31 +0100)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 4 Nov 2025 19:31:43 +0000 (20:31 +0100)
Commit a95e3d84c0e0 added ActiveSnapshot push+pop when processing
work-items (BRIN autosummarization), but forgot to handle the case of
a transaction failing during the run, which drops the snapshot untimely.
Fix by making the pop conditional on an element being actually there.

Author: Álvaro Herrera <alvherre@kurilemu.de>
Backpatch-through: 13
Discussion: https://postgr.es/m/202511041648.nofajnuddmwk@alvherre.pgsql

src/backend/postmaster/autovacuum.c

index 7ed831693415c1081f9a1a75fb87a173d7cffefa..246ac2bec88a4dffa1e0c376d98789cde706217d 100644 (file)
@@ -2682,7 +2682,8 @@ deleted:
 
        PushActiveSnapshot(GetTransactionSnapshot());
        perform_work_item(workitem);
-       PopActiveSnapshot();
+       if (ActiveSnapshotSet())    /* transaction could have aborted */
+           PopActiveSnapshot();
 
        /*
         * Check for config changes before acquiring lock for further jobs.