@@ -2696,6 +2696,68 @@ dumpDatabase(Archive *fout)
26962696 NULL, /* Dumper */
26972697 NULL); /* Dumper Arg */
26982698
2699+ /* Compute correct tag for comments etc */
2700+ appendPQExpBuffer(labelq, "DATABASE %s", fmtId(datname));
2701+
2702+ /* Dump DB comment if any */
2703+ if (fout->remoteVersion >= 80200)
2704+ {
2705+ /*
2706+ * 8.2 and up keep comments on shared objects in a shared table, so we
2707+ * cannot use the dumpComment() code used for other database objects.
2708+ * Be careful that the ArchiveEntry parameters match that function.
2709+ */
2710+ char *comment = PQgetvalue(res, 0, PQfnumber(res, "description"));
2711+
2712+ if (comment && *comment)
2713+ {
2714+ resetPQExpBuffer(dbQry);
2715+
2716+ /*
2717+ * Generates warning when loaded into a differently-named
2718+ * database.
2719+ */
2720+ appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
2721+ appendStringLiteralAH(dbQry, comment, fout);
2722+ appendPQExpBufferStr(dbQry, ";\n");
2723+
2724+ ArchiveEntry(fout, nilCatalogId, createDumpId(),
2725+ labelq->data, NULL, NULL, dba,
2726+ false, "COMMENT", SECTION_NONE,
2727+ dbQry->data, "", NULL,
2728+ &(dbDumpId), 1,
2729+ NULL, NULL);
2730+ }
2731+ }
2732+ else
2733+ {
2734+ dumpComment(fout, labelq->data, NULL, dba,
2735+ dbCatId, 0, dbDumpId);
2736+ }
2737+
2738+ /* Dump shared security label. */
2739+ if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
2740+ {
2741+ PGresult *shres;
2742+ PQExpBuffer seclabelQry;
2743+
2744+ seclabelQry = createPQExpBuffer();
2745+
2746+ buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
2747+ shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
2748+ resetPQExpBuffer(seclabelQry);
2749+ emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
2750+ if (seclabelQry->len > 0)
2751+ ArchiveEntry(fout, nilCatalogId, createDumpId(),
2752+ labelq->data, NULL, NULL, dba,
2753+ false, "SECURITY LABEL", SECTION_NONE,
2754+ seclabelQry->data, "", NULL,
2755+ &(dbDumpId), 1,
2756+ NULL, NULL);
2757+ destroyPQExpBuffer(seclabelQry);
2758+ PQclear(shres);
2759+ }
2760+
26992761 /*
27002762 * pg_largeobject and pg_largeobject_metadata come from the old system
27012763 * intact, so set their relfrozenxids and relminmxids.
@@ -2788,68 +2850,6 @@ dumpDatabase(Archive *fout)
27882850 destroyPQExpBuffer(loOutQry);
27892851 }
27902852
2791- /* Compute correct tag for comments etc */
2792- appendPQExpBuffer(labelq, "DATABASE %s", fmtId(datname));
2793-
2794- /* Dump DB comment if any */
2795- if (fout->remoteVersion >= 80200)
2796- {
2797- /*
2798- * 8.2 and up keep comments on shared objects in a shared table, so we
2799- * cannot use the dumpComment() code used for other database objects.
2800- * Be careful that the ArchiveEntry parameters match that function.
2801- */
2802- char *comment = PQgetvalue(res, 0, PQfnumber(res, "description"));
2803-
2804- if (comment && *comment)
2805- {
2806- resetPQExpBuffer(dbQry);
2807-
2808- /*
2809- * Generates warning when loaded into a differently-named
2810- * database.
2811- */
2812- appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
2813- appendStringLiteralAH(dbQry, comment, fout);
2814- appendPQExpBufferStr(dbQry, ";\n");
2815-
2816- ArchiveEntry(fout, nilCatalogId, createDumpId(),
2817- labelq->data, NULL, NULL, dba,
2818- false, "COMMENT", SECTION_NONE,
2819- dbQry->data, "", NULL,
2820- &(dbDumpId), 1,
2821- NULL, NULL);
2822- }
2823- }
2824- else
2825- {
2826- dumpComment(fout, labelq->data, NULL, dba,
2827- dbCatId, 0, dbDumpId);
2828- }
2829-
2830- /* Dump shared security label. */
2831- if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
2832- {
2833- PGresult *shres;
2834- PQExpBuffer seclabelQry;
2835-
2836- seclabelQry = createPQExpBuffer();
2837-
2838- buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
2839- shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
2840- resetPQExpBuffer(seclabelQry);
2841- emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
2842- if (seclabelQry->len > 0)
2843- ArchiveEntry(fout, nilCatalogId, createDumpId(),
2844- labelq->data, NULL, NULL, dba,
2845- false, "SECURITY LABEL", SECTION_NONE,
2846- seclabelQry->data, "", NULL,
2847- &(dbDumpId), 1,
2848- NULL, NULL);
2849- destroyPQExpBuffer(seclabelQry);
2850- PQclear(shres);
2851- }
2852-
28532853 PQclear(res);
28542854
28552855 destroyPQExpBuffer(dbQry);
@@ -14395,6 +14395,12 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
1439514395 NULL, 0,
1439614396 NULL, NULL);
1439714397
14398+ /* Dump Foreign Data Wrapper Comments */
14399+ if (fdwinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
14400+ dumpComment(fout, labelq->data,
14401+ NULL, fdwinfo->rolname,
14402+ fdwinfo->dobj.catId, 0, fdwinfo->dobj.dumpId);
14403+
1439814404 /* Handle the ACL */
1439914405 if (fdwinfo->dobj.dump & DUMP_COMPONENT_ACL)
1440014406 dumpACL(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId,
@@ -14404,12 +14410,6 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
1440414410 fdwinfo->fdwacl, fdwinfo->rfdwacl,
1440514411 fdwinfo->initfdwacl, fdwinfo->initrfdwacl);
1440614412
14407- /* Dump Foreign Data Wrapper Comments */
14408- if (fdwinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
14409- dumpComment(fout, labelq->data,
14410- NULL, fdwinfo->rolname,
14411- fdwinfo->dobj.catId, 0, fdwinfo->dobj.dumpId);
14412-
1441314413 free(qfdwname);
1441414414
1441514415 destroyPQExpBuffer(q);
@@ -14492,6 +14492,12 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
1449214492 NULL, 0,
1449314493 NULL, NULL);
1449414494
14495+ /* Dump Foreign Server Comments */
14496+ if (srvinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
14497+ dumpComment(fout, labelq->data,
14498+ NULL, srvinfo->rolname,
14499+ srvinfo->dobj.catId, 0, srvinfo->dobj.dumpId);
14500+
1449514501 /* Handle the ACL */
1449614502 if (srvinfo->dobj.dump & DUMP_COMPONENT_ACL)
1449714503 dumpACL(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId,
@@ -14508,12 +14514,6 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
1450814514 srvinfo->rolname,
1450914515 srvinfo->dobj.catId, srvinfo->dobj.dumpId);
1451014516
14511- /* Dump Foreign Server Comments */
14512- if (srvinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
14513- dumpComment(fout, labelq->data,
14514- NULL, srvinfo->rolname,
14515- srvinfo->dobj.catId, 0, srvinfo->dobj.dumpId);
14516-
1451714517 free(qsrvname);
1451814518
1451914519 destroyPQExpBuffer(q);
@@ -16245,7 +16245,7 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo)
1624516245
1624616246 if (attachinfo->partitionIdx->dobj.dump & DUMP_COMPONENT_DEFINITION)
1624716247 {
16248- PQExpBuffer q = createPQExpBuffer();
16248+ PQExpBuffer q = createPQExpBuffer();
1624916249
1625016250 appendPQExpBuffer(q, "\nALTER INDEX %s ",
1625116251 fmtQualifiedId(fout->remoteVersion,
0 commit comments