mirror of
https://github.com/postgres/postgres.git
synced 2025-05-06 19:59:18 +03:00
Reorder code in pg_dump to dump comments etc in a uniform order.
Most of the code in pg_dump dumps an object's comment, security label, and ACL auxiliary TOC entries, in that order, immediately after the object's main TOC entry, and at least dumpComment's API spec says this isn't optional. dumpDatabase was significantly violating that when in binary-upgrade mode, by inserting totally unrelated stuff between. Also, dumpForeignDataWrapper and dumpForeignServer were being randomly inconsistent. Reorder code so everybody does it the same. This may be future-proofing us against some code growing a requirement for such auxiliary entries to be adjacent to their main entry. But for now it's just neatnik-ism, so I see no need for back-patch. Discussion: https://postgr.es/m/21714.1516553459@sss.pgh.pa.us
This commit is contained in:
parent
f498704346
commit
d6c84667d1
@ -2696,6 +2696,68 @@ dumpDatabase(Archive *fout)
|
||||
NULL, /* Dumper */
|
||||
NULL); /* Dumper Arg */
|
||||
|
||||
/* Compute correct tag for comments etc */
|
||||
appendPQExpBuffer(labelq, "DATABASE %s", fmtId(datname));
|
||||
|
||||
/* Dump DB comment if any */
|
||||
if (fout->remoteVersion >= 80200)
|
||||
{
|
||||
/*
|
||||
* 8.2 and up keep comments on shared objects in a shared table, so we
|
||||
* cannot use the dumpComment() code used for other database objects.
|
||||
* Be careful that the ArchiveEntry parameters match that function.
|
||||
*/
|
||||
char *comment = PQgetvalue(res, 0, PQfnumber(res, "description"));
|
||||
|
||||
if (comment && *comment)
|
||||
{
|
||||
resetPQExpBuffer(dbQry);
|
||||
|
||||
/*
|
||||
* Generates warning when loaded into a differently-named
|
||||
* database.
|
||||
*/
|
||||
appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
|
||||
appendStringLiteralAH(dbQry, comment, fout);
|
||||
appendPQExpBufferStr(dbQry, ";\n");
|
||||
|
||||
ArchiveEntry(fout, nilCatalogId, createDumpId(),
|
||||
labelq->data, NULL, NULL, dba,
|
||||
false, "COMMENT", SECTION_NONE,
|
||||
dbQry->data, "", NULL,
|
||||
&(dbDumpId), 1,
|
||||
NULL, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dumpComment(fout, labelq->data, NULL, dba,
|
||||
dbCatId, 0, dbDumpId);
|
||||
}
|
||||
|
||||
/* Dump shared security label. */
|
||||
if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
|
||||
{
|
||||
PGresult *shres;
|
||||
PQExpBuffer seclabelQry;
|
||||
|
||||
seclabelQry = createPQExpBuffer();
|
||||
|
||||
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
|
||||
shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
|
||||
resetPQExpBuffer(seclabelQry);
|
||||
emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
|
||||
if (seclabelQry->len > 0)
|
||||
ArchiveEntry(fout, nilCatalogId, createDumpId(),
|
||||
labelq->data, NULL, NULL, dba,
|
||||
false, "SECURITY LABEL", SECTION_NONE,
|
||||
seclabelQry->data, "", NULL,
|
||||
&(dbDumpId), 1,
|
||||
NULL, NULL);
|
||||
destroyPQExpBuffer(seclabelQry);
|
||||
PQclear(shres);
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_largeobject and pg_largeobject_metadata come from the old system
|
||||
* intact, so set their relfrozenxids and relminmxids.
|
||||
@ -2788,68 +2850,6 @@ dumpDatabase(Archive *fout)
|
||||
destroyPQExpBuffer(loOutQry);
|
||||
}
|
||||
|
||||
/* Compute correct tag for comments etc */
|
||||
appendPQExpBuffer(labelq, "DATABASE %s", fmtId(datname));
|
||||
|
||||
/* Dump DB comment if any */
|
||||
if (fout->remoteVersion >= 80200)
|
||||
{
|
||||
/*
|
||||
* 8.2 and up keep comments on shared objects in a shared table, so we
|
||||
* cannot use the dumpComment() code used for other database objects.
|
||||
* Be careful that the ArchiveEntry parameters match that function.
|
||||
*/
|
||||
char *comment = PQgetvalue(res, 0, PQfnumber(res, "description"));
|
||||
|
||||
if (comment && *comment)
|
||||
{
|
||||
resetPQExpBuffer(dbQry);
|
||||
|
||||
/*
|
||||
* Generates warning when loaded into a differently-named
|
||||
* database.
|
||||
*/
|
||||
appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
|
||||
appendStringLiteralAH(dbQry, comment, fout);
|
||||
appendPQExpBufferStr(dbQry, ";\n");
|
||||
|
||||
ArchiveEntry(fout, nilCatalogId, createDumpId(),
|
||||
labelq->data, NULL, NULL, dba,
|
||||
false, "COMMENT", SECTION_NONE,
|
||||
dbQry->data, "", NULL,
|
||||
&(dbDumpId), 1,
|
||||
NULL, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dumpComment(fout, labelq->data, NULL, dba,
|
||||
dbCatId, 0, dbDumpId);
|
||||
}
|
||||
|
||||
/* Dump shared security label. */
|
||||
if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
|
||||
{
|
||||
PGresult *shres;
|
||||
PQExpBuffer seclabelQry;
|
||||
|
||||
seclabelQry = createPQExpBuffer();
|
||||
|
||||
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
|
||||
shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
|
||||
resetPQExpBuffer(seclabelQry);
|
||||
emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
|
||||
if (seclabelQry->len > 0)
|
||||
ArchiveEntry(fout, nilCatalogId, createDumpId(),
|
||||
labelq->data, NULL, NULL, dba,
|
||||
false, "SECURITY LABEL", SECTION_NONE,
|
||||
seclabelQry->data, "", NULL,
|
||||
&(dbDumpId), 1,
|
||||
NULL, NULL);
|
||||
destroyPQExpBuffer(seclabelQry);
|
||||
PQclear(shres);
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
|
||||
destroyPQExpBuffer(dbQry);
|
||||
@ -14395,6 +14395,12 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
|
||||
NULL, 0,
|
||||
NULL, NULL);
|
||||
|
||||
/* Dump Foreign Data Wrapper Comments */
|
||||
if (fdwinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
|
||||
dumpComment(fout, labelq->data,
|
||||
NULL, fdwinfo->rolname,
|
||||
fdwinfo->dobj.catId, 0, fdwinfo->dobj.dumpId);
|
||||
|
||||
/* Handle the ACL */
|
||||
if (fdwinfo->dobj.dump & DUMP_COMPONENT_ACL)
|
||||
dumpACL(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId,
|
||||
@ -14404,12 +14410,6 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
|
||||
fdwinfo->fdwacl, fdwinfo->rfdwacl,
|
||||
fdwinfo->initfdwacl, fdwinfo->initrfdwacl);
|
||||
|
||||
/* Dump Foreign Data Wrapper Comments */
|
||||
if (fdwinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
|
||||
dumpComment(fout, labelq->data,
|
||||
NULL, fdwinfo->rolname,
|
||||
fdwinfo->dobj.catId, 0, fdwinfo->dobj.dumpId);
|
||||
|
||||
free(qfdwname);
|
||||
|
||||
destroyPQExpBuffer(q);
|
||||
@ -14492,6 +14492,12 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
|
||||
NULL, 0,
|
||||
NULL, NULL);
|
||||
|
||||
/* Dump Foreign Server Comments */
|
||||
if (srvinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
|
||||
dumpComment(fout, labelq->data,
|
||||
NULL, srvinfo->rolname,
|
||||
srvinfo->dobj.catId, 0, srvinfo->dobj.dumpId);
|
||||
|
||||
/* Handle the ACL */
|
||||
if (srvinfo->dobj.dump & DUMP_COMPONENT_ACL)
|
||||
dumpACL(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId,
|
||||
@ -14508,12 +14514,6 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
|
||||
srvinfo->rolname,
|
||||
srvinfo->dobj.catId, srvinfo->dobj.dumpId);
|
||||
|
||||
/* Dump Foreign Server Comments */
|
||||
if (srvinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
|
||||
dumpComment(fout, labelq->data,
|
||||
NULL, srvinfo->rolname,
|
||||
srvinfo->dobj.catId, 0, srvinfo->dobj.dumpId);
|
||||
|
||||
free(qsrvname);
|
||||
|
||||
destroyPQExpBuffer(q);
|
||||
@ -16245,7 +16245,7 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo)
|
||||
|
||||
if (attachinfo->partitionIdx->dobj.dump & DUMP_COMPONENT_DEFINITION)
|
||||
{
|
||||
PQExpBuffer q = createPQExpBuffer();
|
||||
PQExpBuffer q = createPQExpBuffer();
|
||||
|
||||
appendPQExpBuffer(q, "\nALTER INDEX %s ",
|
||||
fmtQualifiedId(fout->remoteVersion,
|
||||
|
Loading…
x
Reference in New Issue
Block a user