From 2ee26322351de334f033091cc62cd451a8db66da Mon Sep 17 00:00:00 2001 From: Antonin Houska Date: Tue, 25 Jun 2024 12:19:08 +0200 Subject: [PATCH] Fixed locking of TOAST indexes. Problem introduced by commit aceb16a18a. --- pg_squeeze.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pg_squeeze.c b/pg_squeeze.c index f82e360..39d5166 100644 --- a/pg_squeeze.c +++ b/pg_squeeze.c @@ -3219,10 +3219,11 @@ swap_toast_names(Oid relid1, Oid toastrelid1, Oid relid2, Oid toastrelid2) snprintf(name, NAMEDATALEN, "pg_toast_%u_index_", relid1); #if PG_VERSION_NUM < 130000 + /* NoLock as RenameRelationInternal() did not release its lock. */ toastidxid = get_toast_index(toastrelid2); #else - /* NoLock as RenameRelationInternal() did not release its lock. */ - toastidxid = toast_get_valid_index(toastrelid2, NoLock); + /* TOAST relation is locked, but not its indexes. */ + toastidxid = toast_get_valid_index(toastrelid2, AccessExclusiveLock); #endif /* * Pass is_index=false so that even the index is locked in @@ -3240,9 +3241,11 @@ swap_toast_names(Oid relid1, Oid toastrelid1, Oid relid2, Oid toastrelid2) RenameRelationInternal(toastrelid1, name, true, false); /* NoLock as RenameRelationInternal() did not release its lock. */ #if PG_VERSION_NUM < 130000 + /* NoLock as RenameRelationInternal() did not release its lock. */ toastidxid = get_toast_index(toastrelid1); #else - toastidxid = toast_get_valid_index(toastrelid1, NoLock); + /* TOAST relation is locked, but not its indexes. */ + toastidxid = toast_get_valid_index(toastrelid1, AccessExclusiveLock); #endif snprintf(name, NAMEDATALEN, "pg_toast_%u_index", relid1); RenameRelationInternal(toastidxid, name, true, false);