Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b3bc63e

Browse files
committed
Fix pg_dump's handling of extension-member casts and languages.
pg_dump has some heuristic rules for whether to dump casts and procedural languages, since it's not all that easy to distinguish built-in ones from user-defined ones. However, we should not apply those rules to objects that belong to an extension, but just use the perfectly well-defined rules for what to do with extension member objects. Otherwise we might mistakenly lose extension member objects during a binary upgrade (which is the only time that we'd want to dump extension members).
1 parent e728701 commit b3bc63e

File tree

1 file changed

+52
-35
lines changed

1 file changed

+52
-35
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8252,6 +8252,9 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo)
82528252
* For some backwards compatibility with the older behavior, we forcibly
82538253
* dump a PL if its handler function (and validator if any) are in a
82548254
* dumpable namespace. That case is not checked here.
8255+
*
8256+
* Also, if the PL belongs to an extension, we do not use this heuristic.
8257+
* That case isn't checked here either.
82558258
*/
82568259
static bool
82578260
shouldDumpProcLangs(void)
@@ -8316,13 +8319,22 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
83168319
* If the functions are dumpable then emit a traditional CREATE LANGUAGE
83178320
* with parameters. Otherwise, dump only if shouldDumpProcLangs() says to
83188321
* dump it.
8322+
*
8323+
* However, for a language that belongs to an extension, we must not use
8324+
* the shouldDumpProcLangs heuristic, but just dump the language iff we're
8325+
* told to (via dobj.dump). Generally the support functions will belong
8326+
* to the same extension and so have the same dump flags ... if they don't,
8327+
* this might not work terribly nicely.
83198328
*/
83208329
useParams = (funcInfo != NULL &&
83218330
(inlineInfo != NULL || !OidIsValid(plang->laninline)) &&
83228331
(validatorInfo != NULL || !OidIsValid(plang->lanvalidator)));
83238332

8324-
if (!useParams && !shouldDumpProcLangs())
8325-
return;
8333+
if (!plang->dobj.ext_member)
8334+
{
8335+
if (!useParams && !shouldDumpProcLangs())
8336+
return;
8337+
}
83268338

83278339
defqry = createPQExpBuffer();
83288340
delqry = createPQExpBuffer();
@@ -9013,13 +9025,12 @@ dumpCast(Archive *fout, CastInfo *cast)
90139025
PQExpBuffer delqry;
90149026
PQExpBuffer labelq;
90159027
FuncInfo *funcInfo = NULL;
9016-
TypeInfo *sourceInfo;
9017-
TypeInfo *targetInfo;
90189028

90199029
/* Skip if not to be dumped */
90209030
if (!cast->dobj.dump || dataOnly)
90219031
return;
90229032

9033+
/* Cannot dump if we don't have the cast function's info */
90239034
if (OidIsValid(cast->castfunc))
90249035
{
90259036
funcInfo = findFuncByOid(cast->castfunc);
@@ -9032,43 +9043,49 @@ dumpCast(Archive *fout, CastInfo *cast)
90329043
* objects (the conversion function and the two data types) are not
90339044
* builtin AND if all of the non-builtin objects are included in the dump.
90349045
* Builtin meaning, the namespace name does not start with "pg_".
9046+
*
9047+
* However, for a cast that belongs to an extension, we must not use this
9048+
* heuristic, but just dump the cast iff we're told to (via dobj.dump).
90359049
*/
9036-
sourceInfo = findTypeByOid(cast->castsource);
9037-
targetInfo = findTypeByOid(cast->casttarget);
9050+
if (!cast->dobj.ext_member)
9051+
{
9052+
TypeInfo *sourceInfo = findTypeByOid(cast->castsource);
9053+
TypeInfo *targetInfo = findTypeByOid(cast->casttarget);
90389054

9039-
if (sourceInfo == NULL || targetInfo == NULL)
9040-
return;
9055+
if (sourceInfo == NULL || targetInfo == NULL)
9056+
return;
90419057

9042-
/*
9043-
* Skip this cast if all objects are from pg_
9044-
*/
9045-
if ((funcInfo == NULL ||
9046-
strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) == 0) &&
9047-
strncmp(sourceInfo->dobj.namespace->dobj.name, "pg_", 3) == 0 &&
9048-
strncmp(targetInfo->dobj.namespace->dobj.name, "pg_", 3) == 0)
9049-
return;
9058+
/*
9059+
* Skip this cast if all objects are from pg_
9060+
*/
9061+
if ((funcInfo == NULL ||
9062+
strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) == 0) &&
9063+
strncmp(sourceInfo->dobj.namespace->dobj.name, "pg_", 3) == 0 &&
9064+
strncmp(targetInfo->dobj.namespace->dobj.name, "pg_", 3) == 0)
9065+
return;
90509066

9051-
/*
9052-
* Skip cast if function isn't from pg_ and is not to be dumped.
9053-
*/
9054-
if (funcInfo &&
9055-
strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
9056-
!funcInfo->dobj.dump)
9057-
return;
9067+
/*
9068+
* Skip cast if function isn't from pg_ and is not to be dumped.
9069+
*/
9070+
if (funcInfo &&
9071+
strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
9072+
!funcInfo->dobj.dump)
9073+
return;
90589074

9059-
/*
9060-
* Same for the source type
9061-
*/
9062-
if (strncmp(sourceInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
9063-
!sourceInfo->dobj.dump)
9064-
return;
9075+
/*
9076+
* Same for the source type
9077+
*/
9078+
if (strncmp(sourceInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
9079+
!sourceInfo->dobj.dump)
9080+
return;
90659081

9066-
/*
9067-
* and the target type.
9068-
*/
9069-
if (strncmp(targetInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
9070-
!targetInfo->dobj.dump)
9071-
return;
9082+
/*
9083+
* and the target type.
9084+
*/
9085+
if (strncmp(targetInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
9086+
!targetInfo->dobj.dump)
9087+
return;
9088+
}
90729089

90739090
/* Make sure we are in proper schema (needed for getFormattedTypeName) */
90749091
selectSourceSchema("pg_catalog");

0 commit comments

Comments
 (0)