From 704ded2d7abb145e8d8c7a4d90fe6835f3e66318 Mon Sep 17 00:00:00 2001 From: Aman Ganapathy Date: Thu, 3 Dec 2026 18:51:21 +0000 Subject: [PATCH v2 1/2] Fix ALTER COLUMN TYPE when a dependent object is dropped concurrently. RememberAllDependentForRebuilding() looks up the objects that depend on the column without locking them. Views, OWNED BY sequences and publication WHERE clauses can be dropped without a lock on the table, so if one is dropped after its pg_depend entry was found, the lookup fails with an internal error such as "could not find tuple for rule". Skip such objects: once dropped, they no longer depend on the column. Discussion: https://postgr.es/m/19968-d24000922918f552@postgresql.org --- src/backend/commands/tablecmds.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 9755943..162df9a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16225,6 +16225,9 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, { char relKind = get_rel_relkind(foundObject.objectId); + if (relKind == '\0') + break; + if (relKind == RELKIND_INDEX || relKind == RELKIND_PARTITIONED_INDEX) { @@ -16281,12 +16284,18 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, * function bodies. FIXME someday. */ if (subtype == AT_AlterColumnType) + { + char *objdesc = getObjectDescription(&foundObject, true); + + if (objdesc == NULL) + break; + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot alter type of a column used by a view or rule"), errdetail("%s depends on column \"%s\".", - getObjectDescription(&foundObject, false), - colName))); + objdesc, colName))); + } break; case TriggerRelationId: @@ -16379,12 +16388,18 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype, * clause. Same issues as above. FIXME someday. */ if (subtype == AT_AlterColumnType) + { + char *objdesc = getObjectDescription(&foundObject, true); + + if (objdesc == NULL) + break; + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot alter type of a column used by a publication WHERE clause"), errdetail("%s depends on column \"%s\".", - getObjectDescription(&foundObject, false), - colName))); + objdesc, colName))); + } break; default: -- 2.47.3