diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index e4c95fe..7746039 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -670,6 +670,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)); @@ -679,6 +680,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 fe364dd..cee625b 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 e34c83a..3e7d53f 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -2802,7 +2802,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 >= 100000) + 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"); @@ -2831,7 +2834,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 >= 100000) + 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, @@ -14683,9 +14689,17 @@ 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 >= 100000 && (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); + appendStringLiteralAH(query, labels[i].label, fout); appendPQExpBufferStr(query, ";\n"); } @@ -14769,6 +14783,7 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename) resetPQExpBuffer(target); appendPQExpBuffer(target, "%s %s", reltypename, fmtId(tbinfo->dobj.name)); + ArchiveEntry(fout, nilCatalogId, createDumpId(), target->data, tbinfo->dobj.namespace->dobj.name,