diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index 11582dd1c8..50809b4844 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -804,6 +804,15 @@ PostgreSQL documentation
+
+
+
+
+ Do not dump comments.
+
+
+
+
diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml
index 4a639f2d41..5d6fe9b87d 100644
--- a/doc/src/sgml/ref/pg_dumpall.sgml
+++ b/doc/src/sgml/ref/pg_dumpall.sgml
@@ -342,6 +342,15 @@ PostgreSQL documentation
+
+
+
+
+ Do not dump comments.
+
+
+
+
diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
index ee756159f6..345324bd27 100644
--- a/doc/src/sgml/ref/pg_restore.sgml
+++ b/doc/src/sgml/ref/pg_restore.sgml
@@ -575,6 +575,15 @@
+
+
+
+
+ Do not dump comments.
+
+
+
+
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index ce3100f09d..520cd095d3 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -74,6 +74,7 @@ typedef struct _restoreOptions
int dump_inserts;
int column_inserts;
int if_exists;
+ int no_comments; /* Skip comments */
int no_publications; /* Skip publication entries */
int no_security_labels; /* Skip security label entries */
int no_subscriptions; /* Skip subscription entries */
@@ -146,6 +147,7 @@ typedef struct _dumpOptions
int dump_inserts;
int column_inserts;
int if_exists;
+ int no_comments;
int no_security_labels;
int no_publications;
int no_subscriptions;
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 94c511c936..7c5e8c018b 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -169,9 +169,9 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
dopt->outputNoTablespaces = ropt->noTablespace;
dopt->disable_triggers = ropt->disable_triggers;
dopt->use_setsessauth = ropt->use_setsessauth;
-
dopt->disable_dollar_quoting = ropt->disable_dollar_quoting;
dopt->dump_inserts = ropt->dump_inserts;
+ dopt->no_comments = ropt->no_comments;
dopt->no_publications = ropt->no_publications;
dopt->no_security_labels = ropt->no_security_labels;
dopt->no_subscriptions = ropt->no_subscriptions;
@@ -2841,6 +2841,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
if (ropt->aclsSkip && _tocEntryIsACL(te))
return 0;
+ /* If it's a comment, maybe ignore it */
+ if (ropt->no_comments && strcmp(te->desc, "COMMENT") == 0)
+ return 0;
+
/* If it's a publication, maybe ignore it */
if (ropt->no_publications && strcmp(te->desc, "PUBLICATION") == 0)
return 0;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index d047e4a49b..8ca83c06d6 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -359,6 +359,7 @@ main(int argc, char **argv)
{"snapshot", required_argument, NULL, 6},
{"strict-names", no_argument, &strict_names, 1},
{"use-set-session-authorization", no_argument, &dopt.use_setsessauth, 1},
+ {"no-comments", no_argument, &dopt.no_comments, 1},
{"no-publications", no_argument, &dopt.no_publications, 1},
{"no-security-labels", no_argument, &dopt.no_security_labels, 1},
{"no-synchronized-snapshots", no_argument, &dopt.no_synchronized_snapshots, 1},
@@ -877,6 +878,7 @@ main(int argc, char **argv)
ropt->use_setsessauth = dopt.use_setsessauth;
ropt->disable_dollar_quoting = dopt.disable_dollar_quoting;
ropt->dump_inserts = dopt.dump_inserts;
+ ropt->no_comments = dopt.no_comments;
ropt->no_publications = dopt.no_publications;
ropt->no_security_labels = dopt.no_security_labels;
ropt->no_subscriptions = dopt.no_subscriptions;
@@ -967,6 +969,7 @@ help(const char *progname)
printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
+ printf(_(" --no-comments do not dump comments\n"));
printf(_(" --no-publications do not dump publications\n"));
printf(_(" --no-security-labels do not dump security label assignments\n"));
printf(_(" --no-subscriptions do not dump subscriptions\n"));
@@ -2780,7 +2783,7 @@ dumpDatabase(Archive *fout)
*/
char *comment = PQgetvalue(res, 0, PQfnumber(res, "description"));
- if (comment && *comment)
+ if (comment && *comment && !dopt->no_comments)
{
resetPQExpBuffer(dbQry);
@@ -2806,7 +2809,7 @@ dumpDatabase(Archive *fout)
dbCatId, 0, dbDumpId);
}
- /* Dump shared security label. */
+ /* Dump DB security label, if enabled */
if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
{
PGresult *shres;
@@ -9416,6 +9419,10 @@ dumpComment(Archive *fout, const char *target,
CommentItem *comments;
int ncomments;
+ /* do nothing, if --no-comments is supplied */
+ if (dopt->no_comments)
+ return;
+
/* Comments are schema not data ... except blob comments are data */
if (strncmp(target, "LARGE OBJECT ", 13) != 0)
{
@@ -9483,6 +9490,10 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
PQExpBuffer query;
PQExpBuffer target;
+ /* do nothing, if --no-comments is supplied */
+ if (dopt->no_comments)
+ return;
+
/* Comments are SCHEMA not data */
if (dopt->dataOnly)
return;
@@ -11152,6 +11163,10 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
int i_attname;
int i_attnum;
+ /* do nothing, if --no-comments is supplied */
+ if (fout->dopt->no_comments)
+ return;
+
query = createPQExpBuffer();
appendPQExpBuffer(query,
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 2fd5a025af..40ee5d1d8b 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -68,6 +68,7 @@ static int if_exists = 0;
static int inserts = 0;
static int no_tablespaces = 0;
static int use_setsessauth = 0;
+static int no_comments = 0;
static int no_publications = 0;
static int no_security_labels = 0;
static int no_subscriptions = 0;
@@ -127,6 +128,7 @@ main(int argc, char *argv[])
{"load-via-partition-root", no_argument, &load_via_partition_root, 1},
{"role", required_argument, NULL, 3},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
+ {"no-comments", no_argument, &no_comments, 1},
{"no-publications", no_argument, &no_publications, 1},
{"no-role-passwords", no_argument, &no_role_passwords, 1},
{"no-security-labels", no_argument, &no_security_labels, 1},
@@ -392,6 +394,8 @@ main(int argc, char *argv[])
appendPQExpBufferStr(pgdumpopts, " --load-via-partition-root");
if (use_setsessauth)
appendPQExpBufferStr(pgdumpopts, " --use-set-session-authorization");
+ if (no_comments)
+ appendPQExpBufferStr(pgdumpopts, " --no-comments");
if (no_publications)
appendPQExpBufferStr(pgdumpopts, " --no-publications");
if (no_security_labels)
@@ -606,6 +610,7 @@ help(void)
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
+ printf(_(" --no-comments do not dump comments\n"));
printf(_(" --no-publications do not dump publications\n"));
printf(_(" --no-role-passwords do not dump passwords for roles\n"));
printf(_(" --no-security-labels do not dump security label assignments\n"));
@@ -914,7 +919,7 @@ dumpRoles(PGconn *conn)
appendPQExpBufferStr(buf, ";\n");
- if (!PQgetisnull(res, i, i_rolcomment))
+ if (!no_comments && !PQgetisnull(res, i, i_rolcomment))
{
appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename));
appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolcomment), conn);
@@ -1220,7 +1225,7 @@ dumpTablespaces(PGconn *conn)
exit_nicely(1);
}
- if (spccomment && strlen(spccomment))
+ if (!no_comments && spccomment && spccomment[0] != '\0')
{
appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname);
appendStringLiteralConn(buf, spccomment, conn);
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 860a211a3c..edc14f176f 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -71,6 +71,7 @@ main(int argc, char **argv)
static int no_data_for_failed_tables = 0;
static int outputNoTablespaces = 0;
static int use_setsessauth = 0;
+ static int no_comments = 0;
static int no_publications = 0;
static int no_security_labels = 0;
static int no_subscriptions = 0;
@@ -119,6 +120,7 @@ main(int argc, char **argv)
{"section", required_argument, NULL, 3},
{"strict-names", no_argument, &strict_names, 1},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
+ {"no-comments", no_argument, &no_comments, 1},
{"no-publications", no_argument, &no_publications, 1},
{"no-security-labels", no_argument, &no_security_labels, 1},
{"no-subscriptions", no_argument, &no_subscriptions, 1},
@@ -358,6 +360,7 @@ main(int argc, char **argv)
opts->noDataForFailedTables = no_data_for_failed_tables;
opts->noTablespace = outputNoTablespaces;
opts->use_setsessauth = use_setsessauth;
+ opts->no_comments = no_comments;
opts->no_publications = no_publications;
opts->no_security_labels = no_security_labels;
opts->no_subscriptions = no_subscriptions;
@@ -482,6 +485,7 @@ usage(const char *progname)
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
" created\n"));
+ printf(_(" --no-comments do not dump comments\n"));
printf(_(" --no-publications do not restore publications\n"));
printf(_(" --no-security-labels do not restore security labels\n"));
printf(_(" --no-subscriptions do not restore subscriptions\n"));