PQExpBuffer upgrade_buffer, Oid pg_rel_oid);
static void binary_upgrade_set_pg_class_oids(PQExpBuffer upgrade_buffer,
Oid pg_class_oid, bool is_index);
+static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer,
+ DumpableObject *dobj,
+ const char *objlabel);
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
static const char *fmtCopyColumnList(const TableInfo *ti);
static void do_sql_command(PGconn *conn, const char *query);
AssignDumpId(&tdinfo->dobj);
tdinfo->dobj.name = tbinfo->dobj.name;
tdinfo->dobj.namespace = tbinfo->dobj.namespace;
- tdinfo->dobj.dump = true;
tdinfo->tdtable = tbinfo;
tdinfo->oids = oids;
tdinfo->filtercond = NULL; /* might get set later */
destroyPQExpBuffer(upgrade_query);
}
+/*
+ * If the DumpableObject is a member of an extension, add a suitable
+ * ALTER EXTENSION ADD command to the creation commands in upgrade_buffer.
+ */
+static void
+binary_upgrade_extension_member(PQExpBuffer upgrade_buffer,
+ DumpableObject *dobj,
+ const char *objlabel)
+{
+ DumpableObject *extobj = NULL;
+ int i;
+
+ if (!dobj->ext_member)
+ return;
+
+ /*
+ * Find the parent extension. We could avoid this search if we wanted
+ * to add a link field to DumpableObject, but the space costs of that
+ * would be considerable. We assume that member objects could only have
+ * a direct dependency on their own extension, not any others.
+ */
+ for (i = 0; i < dobj->nDeps; i++)
+ {
+ extobj = findObjectByDumpId(dobj->dependencies[i]);
+ if (extobj && extobj->objType == DO_EXTENSION)
+ break;
+ extobj = NULL;
+ }
+ if (extobj == NULL)
+ {
+ write_msg(NULL, "failed to find parent extension for %s", objlabel);
+ exit_nicely();
+ }
+
+ appendPQExpBuffer(upgrade_buffer,
+ "\n-- For binary upgrade, handle extension membership the hard way\n");
+ appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n",
+ fmtId(extobj->name),
+ objlabel);
+}
+
/*
* getNamespaces:
* read all namespaces in the system catalogs and return them in the
int i_oid;
int i_extname;
int i_nspname;
+ int i_extrelocatable;
+ int i_extversion;
int i_extconfig;
int i_extcondition;
selectSourceSchema("pg_catalog");
appendPQExpBuffer(query, "SELECT x.tableoid, x.oid, "
- "x.extname, n.nspname, x.extconfig, x.extcondition "
+ "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
"FROM pg_extension x "
"JOIN pg_namespace n ON n.oid = x.extnamespace");
i_oid = PQfnumber(res, "oid");
i_extname = PQfnumber(res, "extname");
i_nspname = PQfnumber(res, "nspname");
+ i_extrelocatable = PQfnumber(res, "extrelocatable");
+ i_extversion = PQfnumber(res, "extversion");
i_extconfig = PQfnumber(res, "extconfig");
i_extcondition = PQfnumber(res, "extcondition");
AssignDumpId(&extinfo[i].dobj);
extinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_extname));
extinfo[i].namespace = strdup(PQgetvalue(res, i, i_nspname));
+ extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
+ if (PQgetisnull(res, i, i_extversion))
+ extinfo[i].extversion = NULL;
+ else
+ extinfo[i].extversion = strdup(PQgetvalue(res, i, i_extversion));
extinfo[i].extconfig = strdup(PQgetvalue(res, i, i_extconfig));
extinfo[i].extcondition = strdup(PQgetvalue(res, i, i_extcondition));
-
- /* For the moment, all extensions are considered dumpable */
- extinfo->dobj.dump = true;
}
PQclear(res);
else
planginfo[i].lanowner = strdup("");
- /* Assume it should be dumped (getExtensionMembership may override) */
- planginfo[i].dobj.dump = true;
-
if (g_fout->remoteVersion < 70300)
{
/*
castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
- /* Assume it should be dumped (getExtensionMembership may override) */
- castinfo[i].dobj.dump = true;
-
/*
* Try to name cast as concatenation of typnames. This is only used
* for purposes of sorting. If we fail to find either type, the name
{
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
char *qnspname;
/* Skip if not to be dumped */
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
qnspname = strdup(fmtId(nspinfo->dobj.name));
appendPQExpBuffer(q, "CREATE SCHEMA %s;\n", qnspname);
+ appendPQExpBuffer(labelq, "SCHEMA %s", qnspname);
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &nspinfo->dobj, labelq->data);
+
ArchiveEntry(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId,
nspinfo->dobj.name,
NULL, NULL,
NULL, NULL);
/* Dump Schema Comments and Security Labels */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "SCHEMA %s", qnspname);
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, nspinfo->rolname,
nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
NULL, nspinfo->rolname,
nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
{
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
char *qextname;
/* Skip if not to be dumped */
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
qextname = strdup(fmtId(extinfo->dobj.name));
appendPQExpBuffer(delq, "DROP EXTENSION %s;\n", qextname);
- appendPQExpBuffer(q, "CREATE EXTENSION %s WITH SCHEMA %s;\n",
- qextname, fmtId(extinfo->namespace));
+ if (!binary_upgrade)
+ {
+ appendPQExpBuffer(q, "CREATE EXTENSION %s WITH SCHEMA %s;\n",
+ qextname, fmtId(extinfo->namespace));
+ }
+ else
+ {
+ int i;
+ int n;
+
+ appendPQExpBuffer(q, "-- For binary upgrade, create an empty extension and insert objects into it\n");
+ appendPQExpBuffer(q,
+ "SELECT binary_upgrade.create_empty_extension(");
+ appendStringLiteralAH(q, extinfo->dobj.name, fout);
+ appendPQExpBuffer(q, ", ");
+ appendStringLiteralAH(q, extinfo->namespace, fout);
+ appendPQExpBuffer(q, ", ");
+ appendPQExpBuffer(q, "%s, ", extinfo->relocatable ? "true" : "false");
+ if (extinfo->extversion)
+ appendStringLiteralAH(q, extinfo->extversion, fout);
+ else
+ appendPQExpBuffer(q, "NULL");
+ appendPQExpBuffer(q, ", ");
+ /*
+ * Note that we're pushing extconfig (an OID array) back into
+ * pg_extension exactly as-is. This is OK because pg_class OIDs
+ * are preserved in binary upgrade.
+ */
+ if (strlen(extinfo->extconfig) > 2)
+ appendStringLiteralAH(q, extinfo->extconfig, fout);
+ else
+ appendPQExpBuffer(q, "NULL");
+ appendPQExpBuffer(q, ", ");
+ if (strlen(extinfo->extcondition) > 2)
+ appendStringLiteralAH(q, extinfo->extcondition, fout);
+ else
+ appendPQExpBuffer(q, "NULL");
+ appendPQExpBuffer(q, ", ");
+ appendPQExpBuffer(q, "ARRAY[");
+ n = 0;
+ for (i = 0; i < extinfo->dobj.nDeps; i++)
+ {
+ DumpableObject *extobj;
+
+ extobj = findObjectByDumpId(extinfo->dobj.dependencies[i]);
+ if (extobj && extobj->objType == DO_EXTENSION)
+ {
+ if (n++ > 0)
+ appendPQExpBuffer(q, ",");
+ appendStringLiteralAH(q, extobj->name, fout);
+ }
+ }
+ appendPQExpBuffer(q, "]::pg_catalog.text[]");
+ appendPQExpBuffer(q, ");\n");
+ }
+
+ appendPQExpBuffer(labelq, "EXTENSION %s", qextname);
ArchiveEntry(fout, extinfo->dobj.catId, extinfo->dobj.dumpId,
extinfo->dobj.name,
NULL, NULL);
/* Dump Extension Comments and Security Labels */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "EXTENSION %s", qextname);
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, "",
extinfo->dobj.catId, 0, extinfo->dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
NULL, "",
extinfo->dobj.catId, 0, extinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
{
PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer();
+ PQExpBuffer labelq = createPQExpBuffer();
PQExpBuffer query = createPQExpBuffer();
PGresult *res;
int num,
enum_oid);
appendPQExpBuffer(q, "ALTER TYPE %s.",
fmtId(tyinfo->dobj.namespace->dobj.name));
- appendPQExpBuffer(q, "%s ADD ",
+ appendPQExpBuffer(q, "%s ADD VALUE ",
fmtId(tyinfo->dobj.name));
appendStringLiteralAH(q, label, fout);
appendPQExpBuffer(q, ";\n\n");
}
}
+ appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
+
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Type Comments and Security Labels */
- resetPQExpBuffer(q);
-
- appendPQExpBuffer(q, "TYPE %s", fmtId(tyinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
PQclear(res);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(query);
}
{
PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer();
+ PQExpBuffer labelq = createPQExpBuffer();
PQExpBuffer query = createPQExpBuffer();
PGresult *res;
int ntups;
appendPQExpBuffer(q, "\n);\n");
+ appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
+
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Type Comments and Security Labels */
- resetPQExpBuffer(q);
-
- appendPQExpBuffer(q, "TYPE %s", fmtId(tyinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
PQclear(res);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(query);
}
{
PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer();
+ PQExpBuffer labelq = createPQExpBuffer();
PQExpBuffer query = createPQExpBuffer();
PGresult *res;
int ntups;
appendPQExpBuffer(delq, "%s;\n",
fmtId(tyinfo->dobj.name));
+ appendPQExpBuffer(labelq, "DOMAIN %s", fmtId(tyinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
+
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Domain Comments and Security Labels */
- resetPQExpBuffer(q);
-
- appendPQExpBuffer(q, "DOMAIN %s", fmtId(tyinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(query);
}
{
PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer();
+ PQExpBuffer labelq = createPQExpBuffer();
PQExpBuffer query = createPQExpBuffer();
PGresult *res;
int ntups;
appendPQExpBuffer(delq, "%s;\n",
fmtId(tyinfo->dobj.name));
+ appendPQExpBuffer(labelq, "TYPE %s", fmtId(tyinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
+
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name,
/* Dump Type Comments and Security Labels */
- resetPQExpBuffer(q);
-
- appendPQExpBuffer(q, "TYPE %s", fmtId(tyinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
PQclear(res);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(query);
/* Dump any per-column comments */
{
PQExpBuffer defqry;
PQExpBuffer delqry;
+ PQExpBuffer labelq;
bool useParams;
char *qlanname;
char *lanschema;
defqry = createPQExpBuffer();
delqry = createPQExpBuffer();
+ labelq = createPQExpBuffer();
qlanname = strdup(fmtId(plang->dobj.name));
}
appendPQExpBuffer(defqry, ";\n");
+ appendPQExpBuffer(labelq, "LANGUAGE %s", qlanname);
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(defqry, &plang->dobj, labelq->data);
+
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
plang->dobj.name,
lanschema, NULL, plang->lanowner,
NULL, NULL);
/* Dump Proc Lang Comments and Security Labels */
- resetPQExpBuffer(defqry);
- appendPQExpBuffer(defqry, "LANGUAGE %s", qlanname);
- dumpComment(fout, defqry->data,
+ dumpComment(fout, labelq->data,
NULL, "",
plang->dobj.catId, 0, plang->dobj.dumpId);
- dumpSecLabel(fout, defqry->data,
+ dumpSecLabel(fout, labelq->data,
NULL, "",
plang->dobj.catId, 0, plang->dobj.dumpId);
destroyPQExpBuffer(defqry);
destroyPQExpBuffer(delqry);
+ destroyPQExpBuffer(labelq);
}
/*
PQExpBuffer query;
PQExpBuffer q;
PQExpBuffer delqry;
+ PQExpBuffer labelq;
PQExpBuffer asPart;
PGresult *res;
char *funcsig; /* identity signature */
query = createPQExpBuffer();
q = createPQExpBuffer();
delqry = createPQExpBuffer();
+ labelq = createPQExpBuffer();
asPart = createPQExpBuffer();
/* Set proper schema search path so type references list correctly */
appendPQExpBuffer(q, "\n %s;\n", asPart->data);
+ appendPQExpBuffer(labelq, "FUNCTION %s", funcsig);
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &finfo->dobj, labelq->data);
+
ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId,
funcsig_tag,
finfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Function Comments and Security Labels */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "FUNCTION %s", funcsig);
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
finfo->dobj.namespace->dobj.name, finfo->rolname,
finfo->dobj.catId, 0, finfo->dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
finfo->dobj.namespace->dobj.name, finfo->rolname,
finfo->dobj.catId, 0, finfo->dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delqry);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(asPart);
free(funcsig);
free(funcsig_tag);
{
PQExpBuffer defqry;
PQExpBuffer delqry;
- PQExpBuffer castsig;
+ PQExpBuffer labelq;
FuncInfo *funcInfo = NULL;
TypeInfo *sourceInfo;
TypeInfo *targetInfo;
defqry = createPQExpBuffer();
delqry = createPQExpBuffer();
- castsig = createPQExpBuffer();
+ labelq = createPQExpBuffer();
appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
getFormattedTypeName(cast->castsource, zeroAsNone),
appendPQExpBuffer(defqry, " AS IMPLICIT");
appendPQExpBuffer(defqry, ";\n");
- appendPQExpBuffer(castsig, "CAST (%s AS %s)",
+ appendPQExpBuffer(labelq, "CAST (%s AS %s)",
getFormattedTypeName(cast->castsource, zeroAsNone),
getFormattedTypeName(cast->casttarget, zeroAsNone));
+ if (binary_upgrade)
+ binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
+
ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
- castsig->data,
+ labelq->data,
"pg_catalog", NULL, "",
false, "CAST", SECTION_PRE_DATA,
defqry->data, delqry->data, NULL,
NULL, NULL);
/* Dump Cast Comments */
- resetPQExpBuffer(defqry);
- appendPQExpBuffer(defqry, "CAST (%s AS %s)",
- getFormattedTypeName(cast->castsource, zeroAsNone),
- getFormattedTypeName(cast->casttarget, zeroAsNone));
- dumpComment(fout, defqry->data,
+ dumpComment(fout, labelq->data,
NULL, "",
cast->dobj.catId, 0, cast->dobj.dumpId);
destroyPQExpBuffer(defqry);
destroyPQExpBuffer(delqry);
- destroyPQExpBuffer(castsig);
+ destroyPQExpBuffer(labelq);
}
/*
PQExpBuffer query;
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
PQExpBuffer oprid;
PQExpBuffer details;
const char *name;
query = createPQExpBuffer();
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
oprid = createPQExpBuffer();
details = createPQExpBuffer();
appendPQExpBuffer(q, "CREATE OPERATOR %s (\n%s\n);\n",
oprinfo->dobj.name, details->data);
+ appendPQExpBuffer(labelq, "OPERATOR %s", oprid->data);
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &oprinfo->dobj, labelq->data);
+
ArchiveEntry(fout, oprinfo->dobj.catId, oprinfo->dobj.dumpId,
oprinfo->dobj.name,
oprinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Operator Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "OPERATOR %s", oprid->data);
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
oprinfo->dobj.namespace->dobj.name, oprinfo->rolname,
oprinfo->dobj.catId, 0, oprinfo->dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(oprid);
destroyPQExpBuffer(details);
}
PQExpBuffer query;
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
PGresult *res;
int ntups;
int i_opcintype;
query = createPQExpBuffer();
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
/* Make sure we are in proper schema so regoperator works correctly */
selectSourceSchema(opcinfo->dobj.namespace->dobj.name);
appendPQExpBuffer(q, ";\n");
+ appendPQExpBuffer(labelq, "OPERATOR CLASS %s",
+ fmtId(opcinfo->dobj.name));
+ appendPQExpBuffer(labelq, " USING %s",
+ fmtId(amname));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &opcinfo->dobj, labelq->data);
+
ArchiveEntry(fout, opcinfo->dobj.catId, opcinfo->dobj.dumpId,
opcinfo->dobj.name,
opcinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Operator Class Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "OPERATOR CLASS %s",
- fmtId(opcinfo->dobj.name));
- appendPQExpBuffer(q, " USING %s",
- fmtId(amname));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, opcinfo->rolname,
opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
PQExpBuffer query;
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
PGresult *res;
PGresult *res_ops;
PGresult *res_procs;
query = createPQExpBuffer();
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
/* Make sure we are in proper schema so regoperator works correctly */
selectSourceSchema(opfinfo->dobj.namespace->dobj.name);
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
return;
}
appendPQExpBuffer(q, ";\n");
}
+ appendPQExpBuffer(labelq, "OPERATOR FAMILY %s",
+ fmtId(opfinfo->dobj.name));
+ appendPQExpBuffer(labelq, " USING %s",
+ fmtId(amname));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &opfinfo->dobj, labelq->data);
+
ArchiveEntry(fout, opfinfo->dobj.catId, opfinfo->dobj.dumpId,
opfinfo->dobj.name,
opfinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Operator Family Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "OPERATOR FAMILY %s",
- fmtId(opfinfo->dobj.name));
- appendPQExpBuffer(q, " USING %s",
- fmtId(amname));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, opfinfo->rolname,
opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
PQExpBuffer query;
PQExpBuffer q;
PQExpBuffer delq;
- PQExpBuffer details;
+ PQExpBuffer labelq;
PGresult *res;
int ntups;
int i_conname;
query = createPQExpBuffer();
q = createPQExpBuffer();
delq = createPQExpBuffer();
- details = createPQExpBuffer();
+ labelq = createPQExpBuffer();
/* Make sure we are in proper schema */
selectSourceSchema(convinfo->dobj.namespace->dobj.name);
/* regproc is automatically quoted in 7.3 and above */
appendPQExpBuffer(q, " FROM %s;\n", conproc);
+ appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data);
+
ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
convinfo->dobj.name,
convinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Conversion Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "CONVERSION %s", fmtId(convinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
convinfo->dobj.namespace->dobj.name, convinfo->rolname,
convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
- destroyPQExpBuffer(details);
+ destroyPQExpBuffer(labelq);
}
/*
PQExpBuffer query;
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
PQExpBuffer details;
char *aggsig;
char *aggsig_tag;
query = createPQExpBuffer();
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
details = createPQExpBuffer();
/* Make sure we are in proper schema */
appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
aggsig, details->data);
+ appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, labelq->data);
+
ArchiveEntry(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
aggsig_tag,
agginfo->aggfn.dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Aggregate Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "AGGREGATE %s", aggsig);
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname,
agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
- dumpSecLabel(fout, q->data,
+ dumpSecLabel(fout, labelq->data,
agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname,
agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(details);
}
{
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
/* Skip if not to be dumped */
if (!prsinfo->dobj.dump || dataOnly)
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
/* Make sure we are in proper schema */
selectSourceSchema(prsinfo->dobj.namespace->dobj.name);
appendPQExpBuffer(delq, ".%s;\n",
fmtId(prsinfo->dobj.name));
+ appendPQExpBuffer(labelq, "TEXT SEARCH PARSER %s",
+ fmtId(prsinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &prsinfo->dobj, labelq->data);
+
ArchiveEntry(fout, prsinfo->dobj.catId, prsinfo->dobj.dumpId,
prsinfo->dobj.name,
prsinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Parser Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "TEXT SEARCH PARSER %s",
- fmtId(prsinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, "",
prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
{
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
PQExpBuffer query;
PGresult *res;
int ntups;
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
query = createPQExpBuffer();
/* Fetch name and namespace of the dictionary's template */
appendPQExpBuffer(delq, ".%s;\n",
fmtId(dictinfo->dobj.name));
+ appendPQExpBuffer(labelq, "TEXT SEARCH DICTIONARY %s",
+ fmtId(dictinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &dictinfo->dobj, labelq->data);
+
ArchiveEntry(fout, dictinfo->dobj.catId, dictinfo->dobj.dumpId,
dictinfo->dobj.name,
dictinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Dictionary Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "TEXT SEARCH DICTIONARY %s",
- fmtId(dictinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, dictinfo->rolname,
dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(query);
}
{
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
/* Skip if not to be dumped */
if (!tmplinfo->dobj.dump || dataOnly)
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
/* Make sure we are in proper schema */
selectSourceSchema(tmplinfo->dobj.namespace->dobj.name);
appendPQExpBuffer(delq, ".%s;\n",
fmtId(tmplinfo->dobj.name));
+ appendPQExpBuffer(labelq, "TEXT SEARCH TEMPLATE %s",
+ fmtId(tmplinfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &tmplinfo->dobj, labelq->data);
+
ArchiveEntry(fout, tmplinfo->dobj.catId, tmplinfo->dobj.dumpId,
tmplinfo->dobj.name,
tmplinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Template Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "TEXT SEARCH TEMPLATE %s",
- fmtId(tmplinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, "",
tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
{
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
PQExpBuffer query;
PGresult *res;
char *nspname;
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
query = createPQExpBuffer();
/* Fetch name and namespace of the config's parser */
appendPQExpBuffer(delq, ".%s;\n",
fmtId(cfginfo->dobj.name));
+ appendPQExpBuffer(labelq, "TEXT SEARCH CONFIGURATION %s",
+ fmtId(cfginfo->dobj.name));
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &cfginfo->dobj, labelq->data);
+
ArchiveEntry(fout, cfginfo->dobj.catId, cfginfo->dobj.dumpId,
cfginfo->dobj.name,
cfginfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump Configuration Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "TEXT SEARCH CONFIGURATION %s",
- fmtId(cfginfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
NULL, cfginfo->rolname,
cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
destroyPQExpBuffer(query);
}
{
PQExpBuffer q;
PQExpBuffer delq;
- char *namecopy;
+ PQExpBuffer labelq;
+ char *qfdwname;
/* Skip if not to be dumped */
if (!fdwinfo->dobj.dump || dataOnly)
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
+
+ qfdwname = strdup(fmtId(fdwinfo->dobj.name));
appendPQExpBuffer(q, "CREATE FOREIGN DATA WRAPPER %s",
- fmtId(fdwinfo->dobj.name));
+ qfdwname);
if (fdwinfo->fdwvalidator && strcmp(fdwinfo->fdwvalidator, "-") != 0)
appendPQExpBuffer(q, " VALIDATOR %s",
appendPQExpBuffer(q, ";\n");
appendPQExpBuffer(delq, "DROP FOREIGN DATA WRAPPER %s;\n",
- fmtId(fdwinfo->dobj.name));
+ qfdwname);
+
+ appendPQExpBuffer(labelq, "FOREIGN DATA WRAPPER %s",
+ qfdwname);
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &fdwinfo->dobj, labelq->data);
ArchiveEntry(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId,
fdwinfo->dobj.name,
NULL, NULL);
/* Handle the ACL */
- namecopy = strdup(fmtId(fdwinfo->dobj.name));
dumpACL(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId,
"FOREIGN DATA WRAPPER",
- namecopy, NULL, fdwinfo->dobj.name,
+ qfdwname, NULL, fdwinfo->dobj.name,
NULL, fdwinfo->rolname,
fdwinfo->fdwacl);
- free(namecopy);
+
+ free(qfdwname);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
{
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
PQExpBuffer query;
PGresult *res;
int ntups;
- char *namecopy;
+ char *qsrvname;
char *fdwname;
/* Skip if not to be dumped */
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
query = createPQExpBuffer();
+ qsrvname = strdup(fmtId(srvinfo->dobj.name));
+
/* look up the foreign-data wrapper */
selectSourceSchema("pg_catalog");
appendPQExpBuffer(query, "SELECT fdwname "
}
fdwname = PQgetvalue(res, 0, 0);
- appendPQExpBuffer(q, "CREATE SERVER %s", fmtId(srvinfo->dobj.name));
+ appendPQExpBuffer(q, "CREATE SERVER %s", qsrvname);
if (srvinfo->srvtype && strlen(srvinfo->srvtype) > 0)
{
appendPQExpBuffer(q, " TYPE ");
appendPQExpBuffer(q, ";\n");
appendPQExpBuffer(delq, "DROP SERVER %s;\n",
- fmtId(srvinfo->dobj.name));
+ qsrvname);
+
+ appendPQExpBuffer(labelq, "SERVER %s", qsrvname);
+
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &srvinfo->dobj, labelq->data);
ArchiveEntry(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId,
srvinfo->dobj.name,
NULL, NULL);
/* Handle the ACL */
- namecopy = strdup(fmtId(srvinfo->dobj.name));
dumpACL(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId,
"FOREIGN SERVER",
- namecopy, NULL, srvinfo->dobj.name,
+ qsrvname, NULL, srvinfo->dobj.name,
NULL, srvinfo->rolname,
srvinfo->srvacl);
- free(namecopy);
/* Dump user mappings */
dumpUserMappings(fout,
srvinfo->rolname,
srvinfo->dobj.catId, srvinfo->dobj.dumpId);
+ free(qsrvname);
+
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer();
+ PQExpBuffer labelq = createPQExpBuffer();
PGresult *res;
int numParents;
TableInfo **parents;
appendPQExpBuffer(q, "CREATE VIEW %s AS\n %s\n",
fmtId(tbinfo->dobj.name), viewdef);
+ appendPQExpBuffer(labelq, "VIEW %s",
+ fmtId(tbinfo->dobj.name));
+
PQclear(res);
}
else
appendPQExpBuffer(delq, "%s;\n",
fmtId(tbinfo->dobj.name));
+ appendPQExpBuffer(labelq, "%s %s", reltypename,
+ fmtId(tbinfo->dobj.name));
+
if (binary_upgrade)
binary_upgrade_set_pg_class_oids(q, tbinfo->dobj.catId.oid, false);
}
}
+ if (binary_upgrade)
+ binary_upgrade_extension_member(q, &tbinfo->dobj, labelq->data);
+
ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
tbinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
destroyPQExpBuffer(query);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
TableInfo *tbinfo = indxinfo->indextable;
PQExpBuffer q;
PQExpBuffer delq;
+ PQExpBuffer labelq;
if (dataOnly)
return;
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ labelq = createPQExpBuffer();
+
+ appendPQExpBuffer(labelq, "INDEX %s",
+ fmtId(indxinfo->dobj.name));
/*
* If there's an associated constraint, don't dump the index per se, but
}
/* Dump Index Comments */
- resetPQExpBuffer(q);
- appendPQExpBuffer(q, "INDEX %s",
- fmtId(indxinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
tbinfo->dobj.namespace->dobj.name,
tbinfo->rolname,
indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
+ destroyPQExpBuffer(labelq);
}
/*
dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
{
TableInfo *tbinfo = coninfo->contable;
- PQExpBuffer q = createPQExpBuffer();
+ PQExpBuffer labelq = createPQExpBuffer();
- appendPQExpBuffer(q, "CONSTRAINT %s ",
+ appendPQExpBuffer(labelq, "CONSTRAINT %s ",
fmtId(coninfo->dobj.name));
- appendPQExpBuffer(q, "ON %s",
+ appendPQExpBuffer(labelq, "ON %s",
fmtId(tbinfo->dobj.name));
- dumpComment(fout, q->data,
+ dumpComment(fout, labelq->data,
tbinfo->dobj.namespace->dobj.name,
tbinfo->rolname,
coninfo->dobj.catId, 0,
coninfo->separate ? coninfo->dobj.dumpId : tbinfo->dobj.dumpId);
- destroyPQExpBuffer(q);
+ destroyPQExpBuffer(labelq);
}
/*
called;
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer delqry = createPQExpBuffer();
+ PQExpBuffer labelq = createPQExpBuffer();
/* Make sure we are in proper schema */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name);
*/
if (!dataOnly)
{
- resetPQExpBuffer(delqry);
-
/*
* DROP must be fully qualified in case same name appears in
* pg_catalog
appendPQExpBuffer(query, ";\n");
+ appendPQExpBuffer(labelq, "SEQUENCE %s", fmtId(tbinfo->dobj.name));
+
/* binary_upgrade: no need to clear TOAST table oid */
+ if (binary_upgrade)
+ binary_upgrade_extension_member(query, &tbinfo->dobj,
+ labelq->data);
+
ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
tbinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
}
/* Dump Sequence Comments and Security Labels */
- resetPQExpBuffer(query);
- appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo->dobj.name));
- dumpComment(fout, query->data,
+ dumpComment(fout, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
- dumpSecLabel(fout, query->data,
+ dumpSecLabel(fout, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
}
destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry);
+ destroyPQExpBuffer(labelq);
}
static void
TableInfo *tbinfo = tginfo->tgtable;
PQExpBuffer query;
PQExpBuffer delqry;
+ PQExpBuffer labelq;
char *tgargs;
size_t lentgargs;
const char *p;
query = createPQExpBuffer();
delqry = createPQExpBuffer();
+ labelq = createPQExpBuffer();
/*
* DROP must be fully qualified in case same name appears in pg_catalog
fmtId(tginfo->dobj.name));
}
+ appendPQExpBuffer(labelq, "TRIGGER %s ",
+ fmtId(tginfo->dobj.name));
+ appendPQExpBuffer(labelq, "ON %s",
+ fmtId(tbinfo->dobj.name));
+
ArchiveEntry(fout, tginfo->dobj.catId, tginfo->dobj.dumpId,
tginfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
tginfo->dobj.dependencies, tginfo->dobj.nDeps,
NULL, NULL);
- resetPQExpBuffer(query);
- appendPQExpBuffer(query, "TRIGGER %s ",
- fmtId(tginfo->dobj.name));
- appendPQExpBuffer(query, "ON %s",
- fmtId(tbinfo->dobj.name));
-
- dumpComment(fout, query->data,
+ dumpComment(fout, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
tginfo->dobj.catId, 0, tginfo->dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry);
+ destroyPQExpBuffer(labelq);
}
/*
PQExpBuffer query;
PQExpBuffer cmd;
PQExpBuffer delcmd;
+ PQExpBuffer labelq;
PGresult *res;
/* Skip if not to be dumped */
query = createPQExpBuffer();
cmd = createPQExpBuffer();
delcmd = createPQExpBuffer();
+ labelq = createPQExpBuffer();
if (g_fout->remoteVersion >= 70300)
{
appendPQExpBuffer(delcmd, "%s;\n",
fmtId(tbinfo->dobj.name));
+ appendPQExpBuffer(labelq, "RULE %s",
+ fmtId(rinfo->dobj.name));
+ appendPQExpBuffer(labelq, " ON %s",
+ fmtId(tbinfo->dobj.name));
+
ArchiveEntry(fout, rinfo->dobj.catId, rinfo->dobj.dumpId,
rinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
NULL, NULL);
/* Dump rule comments */
- resetPQExpBuffer(query);
- appendPQExpBuffer(query, "RULE %s",
- fmtId(rinfo->dobj.name));
- appendPQExpBuffer(query, " ON %s",
- fmtId(tbinfo->dobj.name));
- dumpComment(fout, query->data,
+ dumpComment(fout, labelq->data,
tbinfo->dobj.namespace->dobj.name,
tbinfo->rolname,
rinfo->dobj.catId, 0, rinfo->dobj.dumpId);
destroyPQExpBuffer(query);
destroyPQExpBuffer(cmd);
destroyPQExpBuffer(delcmd);
+ destroyPQExpBuffer(labelq);
}
/*
/* Record dependency so that getDependencies needn't repeat this */
addObjectDependency(dobj, refdobj->dumpId);
+ dobj->ext_member = true;
+
/*
- * Mark the member object as not to be dumped. We still need the
- * dependency link, to ensure that sorting is done correctly.
+ * Normally, mark the member object as not to be dumped. But in
+ * binary upgrades, we still dump the members individually, since
+ * the idea is to exactly reproduce the database contents rather
+ * than replace the extension contents with something different.
*/
- dobj->dump = false;
+ if (!binary_upgrade)
+ dobj->dump = false;
}
PQclear(res);