Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb0f639

Browse files
committed
Fix pg_dump so pg_upgrade'ing an extension with simple opfamilies works.
As reported by Michael Feld, pg_upgrade'ing an installation havingextensions with operator families that contain just a single operator classfailed to reproduce the extension membership of those operator families.This caused no immediate ill effects, but would create problems when latertrying to do a plain dump and restore, because the seemingly-not-part-of-the-extension operator families would appear separately in the pg_dumpoutput, and then would conflict with the families created by loading theextension. This has been broken ever since extensions were introduced,and many of the standard contrib extensions are affected, so it's a bitastonishing nobody complained before.The cause of the problem is a perhaps-ill-considered decision to omitsuch operator families from pg_dump's output on the grounds that theCREATE OPERATOR CLASS commands could recreate them, and having explicitCREATE OPERATOR FAMILY commands would impede loading the dump script intopre-8.3 servers. Whatever the merits of that decision when 8.3 was beingwritten, it looks like a poor tradeoff now. We can fix the pg_upgradeproblem simply by removing that code, so that the operator families aredumped explicitly (and then will be properly made to be part of theirextensions).Although this fixes the behavior of future pg_upgrade runs, it does nothingto clean up existing installations that may have improperly-linked operatorfamilies. Given the small number of complaints to date, maybe we don'tneed to worry about providing an automated solution for that; anyone whoneeds to clean it up can do so with manual "ALTER EXTENSION ADD OPERATORFAMILY" commands, or even just ignore the duplicate-opfamily errors theyget during a pg_restore. In any case we need this fix.Back-patch to all supported branches.Discussion: <20228.1460575691@sss.pgh.pa.us>
1 parent079013f commitfb0f639

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11522,9 +11522,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1152211522
appendPQExpBuffer(q,"FOR TYPE %s USING %s",
1152311523
opcintype,
1152411524
fmtId(amname));
11525-
if (strlen(opcfamilyname)>0&&
11526-
(strcmp(opcfamilyname,opcinfo->dobj.name)!=0||
11527-
strcmp(opcfamilynsp,opcinfo->dobj.namespace->dobj.name)!=0))
11525+
if (strlen(opcfamilyname)>0)
1152811526
{
1152911527
appendPQExpBufferStr(q," FAMILY ");
1153011528
if (strcmp(opcfamilynsp,opcinfo->dobj.namespace->dobj.name)!=0)
@@ -11808,15 +11806,6 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1180811806
if (!opfinfo->dobj.dump||dopt->dataOnly)
1180911807
return;
1181011808

11811-
/*
11812-
* We want to dump the opfamily only if (1) it contains "loose" operators
11813-
* or functions, or (2) it contains an opclass with a different name or
11814-
* owner. Otherwise it's sufficient to let it be created during creation
11815-
* of the contained opclass, and not dumping it improves portability of
11816-
* the dump. Since we have to fetch the loose operators/funcs anyway, do
11817-
* that first.
11818-
*/
11819-
1182011809
query=createPQExpBuffer();
1182111810
q=createPQExpBuffer();
1182211811
delq=createPQExpBuffer();
@@ -11899,40 +11888,6 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1189911888

1190011889
res_procs=ExecuteSqlQuery(fout,query->data,PGRES_TUPLES_OK);
1190111890

11902-
if (PQntuples(res_ops)==0&&PQntuples(res_procs)==0)
11903-
{
11904-
/* No loose members, so check contained opclasses */
11905-
resetPQExpBuffer(query);
11906-
11907-
appendPQExpBuffer(query,"SELECT 1 "
11908-
"FROM pg_catalog.pg_opclass c, pg_catalog.pg_opfamily f, pg_catalog.pg_depend "
11909-
"WHERE f.oid = '%u'::pg_catalog.oid "
11910-
"AND refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
11911-
"AND refobjid = f.oid "
11912-
"AND classid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
11913-
"AND objid = c.oid "
11914-
"AND (opcname != opfname OR opcnamespace != opfnamespace OR opcowner != opfowner) "
11915-
"LIMIT 1",
11916-
opfinfo->dobj.catId.oid);
11917-
11918-
res=ExecuteSqlQuery(fout,query->data,PGRES_TUPLES_OK);
11919-
11920-
if (PQntuples(res)==0)
11921-
{
11922-
/* no need to dump it, so bail out */
11923-
PQclear(res);
11924-
PQclear(res_ops);
11925-
PQclear(res_procs);
11926-
destroyPQExpBuffer(query);
11927-
destroyPQExpBuffer(q);
11928-
destroyPQExpBuffer(delq);
11929-
destroyPQExpBuffer(labelq);
11930-
return;
11931-
}
11932-
11933-
PQclear(res);
11934-
}
11935-
1193611891
/* Get additional fields from the pg_opfamily row */
1193711892
resetPQExpBuffer(query);
1193811893

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp