On Sat, Oct 26, 2024 at 12:43:44AM -0700, Masahiko Sawada wrote:
> I got the following assertion failure from an autovaucum worker:
> 
> 2024-10-26 00:32:03.685 PDT [830672] LOG:  autovacuum: dropping orphan
> temp table "postgres.pg_temp_0.hoge"
> TRAP: failed Assert("HaveRegisteredOrActiveSnapshot()"), File:
> "index.c", Line: 2345, PID: 830672

IMHO the best way to handle this is to just unconditionally push a snapshot
in this code path instead of making assumptions about what callers will do.

-- 
nathan
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 9162b9f81a..74d0f3097e 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2336,13 +2336,9 @@ index_drop(Oid indexId, bool concurrent, bool 
concurrent_lock_mode)
 
        /*
         * Updating pg_index might involve TOAST table access, so ensure we 
have a
-        * valid snapshot.  We only expect to get here without a snapshot in the
-        * concurrent path.
+        * valid snapshot.
         */
-       if (concurrent)
-               PushActiveSnapshot(GetTransactionSnapshot());
-       else
-               Assert(HaveRegisteredOrActiveSnapshot());
+       PushActiveSnapshot(GetTransactionSnapshot());
 
        /*
         * fix INDEX relation, and check for expressional index
@@ -2361,8 +2357,7 @@ index_drop(Oid indexId, bool concurrent, bool 
concurrent_lock_mode)
        ReleaseSysCache(tuple);
        table_close(indexRelation, RowExclusiveLock);
 
-       if (concurrent)
-               PopActiveSnapshot();
+       PopActiveSnapshot();
 
        /*
         * if it has any expression columns, we might have stored statistics 
about

Reply via email to