]> granicus.if.org Git - postgresql/commitdiff
Support --no-comments in pg_dump, pg_dumpall, pg_restore.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 25 Jan 2018 20:27:24 +0000 (15:27 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 25 Jan 2018 20:27:24 +0000 (15:27 -0500)
We have switches already to suppress other subsidiary object properties,
such as ACLs, security labels, ownership, and tablespaces, so just on
the grounds of symmetry we should allow suppressing comments as well.
Also, commit 0d4e6ed30 added a positive reason to have this feature,
i.e. to allow obtaining the old behavior of selective pg_restore should
anyone desire that.

Recent commits have removed the cases where pg_dump emitted comments on
built-in objects that the restoring user might not have privileges to
comment on, so the original primary motivation for this feature is gone,
but it still seems at least somewhat useful in its own right.

Robins Tharakan, reviewed by Fabrízio Mello

Discussion: https://postgr.es/m/CAEP4nAx22Z4ch74oJGzr5RyyjcyUSbpiFLyeYXX8pehfou92ug@mail.gmail.com

doc/src/sgml/ref/pg_dump.sgml
doc/src/sgml/ref/pg_dumpall.sgml
doc/src/sgml/ref/pg_restore.sgml
src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_dump/pg_restore.c

index 11582dd1c8241a596bb6663b81e1291033385211..50809b4844373044380788ad9211918ffc7f9550 100644 (file)
@@ -804,6 +804,15 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-comments</option></term>
+      <listitem>
+       <para>
+        Do not dump comments.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>--no-publications</option></term>
       <listitem>
index 4a639f2d41e1d981c2e410f55cb96dfc593fb4ce..5d6fe9b87d5ff65ce4d6233ebd35c9726c30e495 100644 (file)
@@ -342,6 +342,15 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-comments</option></term>
+      <listitem>
+       <para>
+        Do not dump comments.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>--no-publications</option></term>
       <listitem>
index ee756159f60cab8c7a73b53c6c0f83b997e469f0..345324bd27deb581df0d412dfe2cbcb87a766a38 100644 (file)
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-comments</option></term>
+      <listitem>
+       <para>
+        Do not dump comments.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>--no-data-for-failed-tables</option></term>
       <listitem>
index ce3100f09d65a367994a2d3072eba9f9592ac18a..520cd095d3e0af985ad746516e6b1e2f60a5b11c 100644 (file)
@@ -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;
index 94c511c936be4e0dc46749290581bd004e4dbdf0..7c5e8c018bd36423178cf9c992778f784ad54e08 100644 (file)
@@ -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;
index d047e4a49bc6c1a6cf9693db4fb6604fefea26a3..8ca83c06d6c7e6bb243e41d2d27173bc565f37e1 100644 (file)
@@ -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,
index 2fd5a025af05b96466d1158330b03474a48a75d5..40ee5d1d8b7970b478f4c0c56019228c0db45418 100644 (file)
@@ -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);
index 860a211a3cc6401e370b7dbb43a290f8b3c690fc..edc14f176fa13b6017beb3c8e065b0a742d5c091 100644 (file)
@@ -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"));