Skip to content

Commit d9d5e1b

Browse files
committed
Make getObjectDescription robust against dangling amproc type links.
Yoran Heling reported a case where a data type could be dropped while references to its OID remain behind in pg_amproc. This causes getObjectDescription to fail, which blocks dropping the operator family (since our DROP code likes to construct descriptions of everything it's dropping). The proper fix for this requires adding more pg_depend entries. But to allow DROP to go through with already-corrupt catalogs, tweak getObjectDescription to print "???" for the type instead of failing when it processes such an entry. I changed the logic for pg_amop similarly, for consistency, although it is not known that the problem can manifest in pg_amop. Per report from Yoran Heling. Back-patch to all supported branches (although the problem may be unreachable in v13). Discussion: https://postgr.es/m/Z1MVCOh1hprjK5Sf@gmai021
1 parent 5882a4b commit d9d5e1b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/backend/catalog/objectaddress.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -3237,15 +3237,23 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok)
32373237
initStringInfo(&opfam);
32383238
getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
32393239

3240+
/*
3241+
* We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3242+
* completely if the type links are dangling, which is a form
3243+
* of catalog corruption that could occur due to old bugs.
3244+
*/
3245+
32403246
/*------
32413247
translator: %d is the operator strategy (a number), the
32423248
first two %s's are data type names, the third %s is the
32433249
description of the operator family, and the last %s is the
32443250
textual form of the operator with arguments. */
32453251
appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
32463252
amopForm->amopstrategy,
3247-
format_type_be(amopForm->amoplefttype),
3248-
format_type_be(amopForm->amoprighttype),
3253+
format_type_extended(amopForm->amoplefttype,
3254+
-1, FORMAT_TYPE_ALLOW_INVALID),
3255+
format_type_extended(amopForm->amoprighttype,
3256+
-1, FORMAT_TYPE_ALLOW_INVALID),
32493257
opfam.data,
32503258
format_operator(amopForm->amopopr));
32513259

@@ -3294,15 +3302,23 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok)
32943302
initStringInfo(&opfam);
32953303
getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
32963304

3305+
/*
3306+
* We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3307+
* completely if the type links are dangling, which is a form
3308+
* of catalog corruption that could occur due to old bugs.
3309+
*/
3310+
32973311
/*------
32983312
translator: %d is the function number, the first two %s's
32993313
are data type names, the third %s is the description of the
33003314
operator family, and the last %s is the textual form of the
33013315
function with arguments. */
33023316
appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
33033317
amprocForm->amprocnum,
3304-
format_type_be(amprocForm->amproclefttype),
3305-
format_type_be(amprocForm->amprocrighttype),
3318+
format_type_extended(amprocForm->amproclefttype,
3319+
-1, FORMAT_TYPE_ALLOW_INVALID),
3320+
format_type_extended(amprocForm->amprocrighttype,
3321+
-1, FORMAT_TYPE_ALLOW_INVALID),
33063322
opfam.data,
33073323
format_procedure(amprocForm->amproc));
33083324

0 commit comments

Comments
 (0)