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

Commit6cead41

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 parent6b93fcd commit6cead41

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
@@ -12489,9 +12489,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1248912489
appendPQExpBuffer(q, "FOR TYPE %s USING %s",
1249012490
opcintype,
1249112491
fmtId(amname));
12492-
if (strlen(opcfamilyname) > 0 &&
12493-
(strcmp(opcfamilyname, opcinfo->dobj.name) != 0 ||
12494-
strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0))
12492+
if (strlen(opcfamilyname) > 0)
1249512493
{
1249612494
appendPQExpBufferStr(q, " FAMILY ");
1249712495
if (strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0)
@@ -12777,15 +12775,6 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1277712775
if (!opfinfo->dobj.dump || dopt->dataOnly)
1277812776
return;
1277912777

12780-
/*
12781-
* We want to dump the opfamily only if (1) it contains "loose" operators
12782-
* or functions, or (2) it contains an opclass with a different name or
12783-
* owner. Otherwise it's sufficient to let it be created during creation
12784-
* of the contained opclass, and not dumping it improves portability of
12785-
* the dump. Since we have to fetch the loose operators/funcs anyway, do
12786-
* that first.
12787-
*/
12788-
1278912778
query = createPQExpBuffer();
1279012779
q = createPQExpBuffer();
1279112780
delq = createPQExpBuffer();
@@ -12868,40 +12857,6 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1286812857

1286912858
res_procs = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
1287012859

12871-
if (PQntuples(res_ops) == 0 && PQntuples(res_procs) == 0)
12872-
{
12873-
/* No loose members, so check contained opclasses */
12874-
resetPQExpBuffer(query);
12875-
12876-
appendPQExpBuffer(query, "SELECT 1 "
12877-
"FROM pg_catalog.pg_opclass c, pg_catalog.pg_opfamily f, pg_catalog.pg_depend "
12878-
"WHERE f.oid = '%u'::pg_catalog.oid "
12879-
"AND refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
12880-
"AND refobjid = f.oid "
12881-
"AND classid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
12882-
"AND objid = c.oid "
12883-
"AND (opcname != opfname OR opcnamespace != opfnamespace OR opcowner != opfowner) "
12884-
"LIMIT 1",
12885-
opfinfo->dobj.catId.oid);
12886-
12887-
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
12888-
12889-
if (PQntuples(res) == 0)
12890-
{
12891-
/* no need to dump it, so bail out */
12892-
PQclear(res);
12893-
PQclear(res_ops);
12894-
PQclear(res_procs);
12895-
destroyPQExpBuffer(query);
12896-
destroyPQExpBuffer(q);
12897-
destroyPQExpBuffer(delq);
12898-
destroyPQExpBuffer(labelq);
12899-
return;
12900-
}
12901-
12902-
PQclear(res);
12903-
}
12904-
1290512860
/* Get additional fields from the pg_opfamily row */
1290612861
resetPQExpBuffer(query);
1290712862

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp