From 029fa7e97c8219f13b12ebd5026beb5ffd5ba684 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 18 May 2018 17:05:27 -0400 Subject: [PATCH 2/5] Ignore attempts to add TOAST table to shared or catalog tables Running ALTER TABLE on any table will check if a TOAST table needs to be added. On shared tables, this would previously fail, thus effectively disabling ALTER TABLE for those tables. On (non-shared) system catalogs, on the other hand, it would add a TOAST table, even though we don't really want TOAST tables on some system catalogs. In some cases, it would also fail with an error "AccessExclusiveLock required to add toast table.", depending on what locks the ALTER TABLE actions had already taken. So instead, just ignore attempts to add TOAST tables to such tables, outside of bootstrap mode, pretending they don't need one. This allows running ALTER TABLE on such tables without messing up the TOAST situation. (All this still requires allow_system_table_mods, which is independent of this.) --- src/backend/catalog/toasting.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c index 3baaa08238..97a215d2c1 100644 --- a/src/backend/catalog/toasting.c +++ b/src/backend/catalog/toasting.c @@ -17,6 +17,7 @@ #include "access/tuptoaster.h" #include "access/xact.h" #include "catalog/binary_upgrade.h" +#include "catalog/catalog.h" #include "catalog/dependency.h" #include "catalog/heap.h" #include "catalog/index.h" @@ -153,9 +154,10 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, */ shared_relation = rel->rd_rel->relisshared; if (shared_relation && !IsBootstrapProcessingMode()) - ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("shared tables cannot be toasted after initdb"))); + return false; + + if (IsCatalogRelation(rel) && !IsBootstrapProcessingMode()) + return false; /* It's mapped if and only if its parent is, too */ mapped_relation = RelationIsMapped(rel); -- 2.18.0