Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> I suppose pg_describe_object can be used on the contents of pg_shdepend
> to detect it. I'm less sure what to do to correct it -- delete the
> bogus entries and regenerate them with some bulk query?
Seems that what copyTemplateDependencies wants to do can easily be
modeled by a SQL query, assuming you know which DB was cloned to
which other one, and that the source's shdeps didn't change since
then. However, I'm not sure how we can get rid of existing bogus
entries, especially if we'd like to preserve not-bogus ones
(which very likely have gotten added to the destination DB since
it was created).
On the whole I'm afraid that people messing with this manually are
likely to do more harm than good. pg_shdepend entries that don't
match any object probably won't cause a problem, and the lack of
protection against untimely dropping a role is unlikely to be much
of an issue for a role you're referencing in a template database.
So I suspect that practical issues will be rare. We're fortunate
that cloning a nonempty template database is rare already.
BTW, I think there is an additional bug in copyTemplateDependencies:
I do not see it initializing slot->tts_isnull[] anywhere. It
probably accidentally works (at least in devel builds) because we zero
that memory somewhere else, but surely this code shouldn't assume that?
regards, tom lane