Re: Support to COMMENT ON DATABASE CURRENT_DATABASE
Started by Jing Wangover 8 years ago2 messages
Hi All,
Enclosed please find the patch only for the pg_dump using the 'comment on
current_database' statement.
This patch should be working with the previous patch which is
comment_on_current_database_no_pgdump_v3.patch
Regards,
Jing Wang
Fujitsu Australia
Attachments:
comment_on_current_database_for_pgdump_v3.patchapplication/octet-stream; name=comment_on_current_database_for_pgdump_v3.patchDownload
diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index a062a6b..68006df 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -671,6 +671,7 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
appendPQExpBuffer(buffer,
"SECURITY LABEL FOR %s ON %s",
fmtId(provider), target);
+
appendPQExpBuffer(buffer,
" %s IS ",
fmtId(objname));
@@ -680,6 +681,40 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
}
/*
+ * emitDatabaseSecLabels
+ *
+ * Format security label data on database.
+ */
+void
+emitDatabaseSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
+ const char *objname, bool current_datbase)
+{
+ int i;
+
+ for (i = 0; i < PQntuples(res); i++)
+ {
+ char *provider = PQgetvalue(res, i, 0);
+ char *label = PQgetvalue(res, i, 1);
+
+ /* must use fmtId result before calling it again */
+ appendPQExpBuffer(buffer,
+ "SECURITY LABEL FOR %s ON DATABASE",
+ fmtId(provider));
+
+ if(current_datbase)
+ appendPQExpBuffer(buffer," CURRENT_DATABASE IS ");
+ else
+ {
+ appendPQExpBuffer(buffer,
+ " %s IS ",
+ fmtId(objname));
+ }
+ appendStringLiteralConn(buffer, label, conn);
+ appendPQExpBufferStr(buffer, ";\n");
+ }
+}
+
+/*
* buildACLQueries
*
* Build the subqueries to extract out the correct set of ACLs to be
diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h
index caa390b..47265ae 100644
--- a/src/bin/pg_dump/dumputils.h
+++ b/src/bin/pg_dump/dumputils.h
@@ -49,8 +49,10 @@ extern bool buildDefaultACLCommands(const char *type, const char *nspname,
extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name,
uint32 objectId, PQExpBuffer sql);
extern void emitShSecLabels(PGconn *conn, PGresult *res,
- PQExpBuffer buffer, const char *target, const char *objname);
-
+ PQExpBuffer buffer, const char *target,
+ const char *objname);
+extern void emitDatabaseSecLabels(PGconn *conn, PGresult *res,
+ PQExpBuffer buffer, const char *objname, bool current_datbase);
extern void buildACLQueries(PQExpBuffer acl_subquery, PQExpBuffer racl_subquery,
PQExpBuffer init_acl_subquery, PQExpBuffer init_racl_subquery,
const char *acl_column, const char *acl_owner,
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index ea64c77..2512173 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -2720,7 +2720,10 @@ dumpDatabase(Archive *fout)
* Generates warning when loaded into a differently-named
* database.
*/
- appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
+ if (fout->remoteVersion >= 100100)
+ appendPQExpBuffer(dbQry, "COMMENT ON DATABASE CURRENT_DATABASE IS ");
+ else
+ appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
appendStringLiteralAH(dbQry, comment, fout);
appendPQExpBufferStr(dbQry, ";\n");
@@ -2749,7 +2752,10 @@ dumpDatabase(Archive *fout)
buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
resetPQExpBuffer(seclabelQry);
- emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
+ if (fout->remoteVersion >= 100100)
+ emitDatabaseSecLabels(conn, shres, seclabelQry, datname, true);
+ else
+ emitDatabaseSecLabels(conn, shres, seclabelQry, datname, false);
if (strlen(seclabelQry->data))
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
dba, false, "SECURITY LABEL", SECTION_NONE,
@@ -14820,9 +14826,19 @@ dumpSecLabel(Archive *fout, const char *target,
if (labels[i].objsubid != subid)
continue;
- appendPQExpBuffer(query,
- "SECURITY LABEL FOR %s ON %s IS ",
- fmtId(labels[i].provider), target);
+ if (fout->remoteVersion >= 100100 && (strncmp(target, "DATABASE", 8) != 0))
+ {
+ appendPQExpBuffer(query,
+ "SECURITY LABEL FOR %s ON DATABASE CURRENT_DATABASE IS ",
+ fmtId(labels[i].provider));
+ }
+ else
+ appendPQExpBuffer(query,
+ "SECURITY LABEL FOR %s ON %s IS ",
+ fmtId(labels[i].provider), target);
+
+ printf("target = %s\n",target);
+
appendStringLiteralAH(query, labels[i].label, fout);
appendPQExpBufferStr(query, ";\n");
}
@@ -14888,6 +14904,8 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename)
{
appendPQExpBuffer(target, "%s %s", reltypename,
fmtId(tbinfo->dobj.name));
+
+ printf("reltypename = %s\n",reltypename);
}
else
{
@@ -14906,6 +14924,9 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename)
resetPQExpBuffer(target);
appendPQExpBuffer(target, "%s %s", reltypename,
fmtId(tbinfo->dobj.name));
+
+ printf("reltypename2 = %s\n",reltypename);
+
ArchiveEntry(fout, nilCatalogId, createDumpId(),
target->data,
tbinfo->dobj.namespace->dobj.name,
i can't apply your patch cleanly i think it needs rebase
Regards
Surafel
On Thu, Aug 31, 2017 at 1:38 PM, Jing Wang <jingwangian@gmail.com> wrote:
Show quoted text
Hi All,
Enclosed please find the patch only for the pg_dump using the 'comment on
current_database' statement.This patch should be working with the previous patch which is
comment_on_current_database_no_pgdump_v3.patchRegards,
Jing Wang
Fujitsu Australia