]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
During heap rebuild, lock any TOAST index until end of transaction.
authorNoah Misch <noah@leadboat.com>
Sat, 21 Mar 2020 16:38:26 +0000 (09:38 -0700)
committerNoah Misch <noah@leadboat.com>
Sat, 21 Mar 2020 16:38:30 +0000 (09:38 -0700)
swap_relation_files() calls toast_get_valid_index() to find and lock
this index, just before swapping with the rebuilt TOAST index.  The
latter function releases the lock before returning.  Potential for
mischief is low; a concurrent session can issue ALTER INDEX ... SET
(fillfactor = ...), which is not alarming.  Nonetheless, changing
pg_class.relfilenode without a lock is unconventional.  Back-patch to
9.5 (all supported versions), because another fix needs this.

Discussion: https://postgr.es/m/20191226001521.GA1772687@rfd.leadboat.com

src/backend/access/heap/tuptoaster.c
src/backend/commands/cluster.c

index 55d6e91d1c3882f48e13c2b422758ae6e9a636c5..3a9d2ff38ed6a1b4267228a396c1fed92a041ce2 100644 (file)
@@ -1436,8 +1436,8 @@ toast_get_valid_index(Oid toastoid, LOCKMODE lock)
        validIndexOid = RelationGetRelid(toastidxs[validIndex]);
 
        /* Close the toast relation and all its indexes */
-       toast_close_indexes(toastidxs, num_indexes, lock);
-       table_close(toastrel, lock);
+       toast_close_indexes(toastidxs, num_indexes, NoLock);
+       table_close(toastrel, NoLock);
 
        return validIndexOid;
 }
index ebaec4f8dd9e9b3935d0134ec3547e390e26b620..c7fda21634dec5f6ee1636b2dac2e60d03d49b97 100644 (file)
@@ -1490,7 +1490,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
 
                        /* Get the associated valid index to be renamed */
                        toastidx = toast_get_valid_index(newrel->rd_rel->reltoastrelid,
-                                                                                        AccessShareLock);
+                                                                                        NoLock);
 
                        /* rename the toast table ... */
                        snprintf(NewToastName, NAMEDATALEN, "pg_toast_%u",