Skip to content

Commit 89c29c0

Browse files
committed
Fix corner case for binary upgrade: extension functions in pg_catalog.
Normally, pg_dump summarily excludes functions in pg_catalog from consideration. However, some extensions may create functions in pg_catalog (adminpack already does that, and extensions for procedural languages will likely do it too). In binary-upgrade mode, we have to dump such functions, or the extension will be incomplete after upgrading. Per experimentation with adminpack.
1 parent 8b25575 commit 89c29c0

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,7 +3462,10 @@ getAggregates(int *numAggs)
34623462
/* Make sure we are in proper schema */
34633463
selectSourceSchema("pg_catalog");
34643464

3465-
/* find all user-defined aggregates */
3465+
/*
3466+
* Find all user-defined aggregates. See comment in getFuncs() for the
3467+
* rationale behind the filtering logic.
3468+
*/
34663469

34673470
if (g_fout->remoteVersion >= 80200)
34683471
{
@@ -3471,11 +3474,20 @@ getAggregates(int *numAggs)
34713474
"pronargs, proargtypes, "
34723475
"(%s proowner) AS rolname, "
34733476
"proacl AS aggacl "
3474-
"FROM pg_proc "
3475-
"WHERE proisagg "
3476-
"AND pronamespace != "
3477-
"(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
3477+
"FROM pg_proc p "
3478+
"WHERE proisagg AND ("
3479+
"pronamespace != "
3480+
"(SELECT oid FROM pg_namespace "
3481+
"WHERE nspname = 'pg_catalog')",
34783482
username_subquery);
3483+
if (binary_upgrade && g_fout->remoteVersion >= 90100)
3484+
appendPQExpBuffer(query,
3485+
" OR EXISTS(SELECT 1 FROM pg_depend WHERE "
3486+
"classid = 'pg_proc'::regclass AND "
3487+
"objid = p.oid AND "
3488+
"refclassid = 'pg_extension'::regclass AND "
3489+
"deptype = 'e')");
3490+
appendPQExpBuffer(query, ")");
34793491
}
34803492
else if (g_fout->remoteVersion >= 70300)
34813493
{
@@ -3608,7 +3620,14 @@ getFuncs(int *numFuncs)
36083620
/* Make sure we are in proper schema */
36093621
selectSourceSchema("pg_catalog");
36103622

3611-
/* find all user-defined funcs */
3623+
/*
3624+
* Find all user-defined functions. Normally we can exclude functions
3625+
* in pg_catalog, which is worth doing since there are several thousand
3626+
* of 'em. However, there are some extensions that create functions in
3627+
* pg_catalog. In normal dumps we can still ignore those --- but in
3628+
* binary-upgrade mode, we must dump the member objects of the extension,
3629+
* so be sure to fetch any such functions.
3630+
*/
36123631

36133632
if (g_fout->remoteVersion >= 70300)
36143633
{
@@ -3617,12 +3636,20 @@ getFuncs(int *numFuncs)
36173636
"pronargs, proargtypes, prorettype, proacl, "
36183637
"pronamespace, "
36193638
"(%s proowner) AS rolname "
3620-
"FROM pg_proc "
3621-
"WHERE NOT proisagg "
3622-
"AND pronamespace != "
3639+
"FROM pg_proc p "
3640+
"WHERE NOT proisagg AND ("
3641+
"pronamespace != "
36233642
"(SELECT oid FROM pg_namespace "
36243643
"WHERE nspname = 'pg_catalog')",
36253644
username_subquery);
3645+
if (binary_upgrade && g_fout->remoteVersion >= 90100)
3646+
appendPQExpBuffer(query,
3647+
" OR EXISTS(SELECT 1 FROM pg_depend WHERE "
3648+
"classid = 'pg_proc'::regclass AND "
3649+
"objid = p.oid AND "
3650+
"refclassid = 'pg_extension'::regclass AND "
3651+
"deptype = 'e')");
3652+
appendPQExpBuffer(query, ")");
36263653
}
36273654
else if (g_fout->remoteVersion >= 70100)
36283655
{
@@ -13319,6 +13346,8 @@ getExtensionMembership(ExtensionInfo extinfo[], int numExtensions)
1331913346
*/
1332013347
if (!binary_upgrade)
1332113348
dobj->dump = false;
13349+
else
13350+
dobj->dump = refdobj->dump;
1332213351
}
1332313352

1332413353
PQclear(res);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy