A discussion over in pgsql-admin led me to realize that there's a
corner case bug in pg_dump for casts that belong to extensions.
Namely, pg_dump has a rather ad-hoc rule for deciding whether to
dump a cast, and that rule could result in not dumping a cast belonging
to an extension (if the extension installs its stuff into pg_catalog).
Normally this wouldn't matter since extension members don't get dumped
anyway; but during a binary upgrade, it would result in loss of the
cast.
I think the correct fix is to only apply the namespace heuristic to
casts that aren't members of extensions. If they are, just obey the
"dobj.dump" flag as-is.
There are some other object types like languages that also have
heuristic dump rules, and may need a similar hack.
Barring objections, I'll go make this change.
regards, tom lane