pg_dump: Add --no-subscriptions option
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 9 May 2017 14:58:06 +0000 (10:58 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 9 May 2017 14:58:06 +0000 (10:58 -0400)
Author: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.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 6cf7e570efa90e4e98c4d6ea0532b02368306584..d326f08b07893750e98bb12c79c4266574d643c2 100644 (file)
@@ -798,6 +798,15 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-subscriptions</option></term>
+      <listitem>
+       <para>
+        Do not dump subscriptions.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>--no-synchronized-snapshots</></term>
       <listitem>
index 070b902487201358462f2826990f3fafed656eab..60e67a2c7b3b63cef3bf3cb1a9eb073943492cff 100644 (file)
@@ -354,6 +354,15 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-subscriptions</option></term>
+      <listitem>
+       <para>
+        Do not dump subscriptions.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>--no-sync</option></term>
       <listitem>
index 44f051506618bc426fbfd453b56925f15593a421..943378530bdfe724536846c6780c6f694a721852 100644 (file)
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-subscriptions</option></term>
+      <listitem>
+       <para>
+        Do not output commands to restore subscriptions, even if the archive
+        contains them.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>--no-tablespaces</option></term>
       <listitem>
index 08b883efb0012839aaef0a7d7f5c7689d1b9534a..d00262cb9e8b514ed054722d13c842cc937be6f3 100644 (file)
@@ -75,6 +75,7 @@ typedef struct _restoreOptions
        int                     column_inserts;
        int                     if_exists;
        int                     no_security_labels;             /* Skip security label entries */
+       int                     no_subscriptions;               /* Skip subscription entries */
        int                     strict_names;
 
        const char *filename;
@@ -145,6 +146,7 @@ typedef struct _dumpOptions
        int                     column_inserts;
        int                     if_exists;
        int                     no_security_labels;
+       int                     no_subscriptions;
        int                     no_synchronized_snapshots;
        int                     no_unlogged_table_data;
        int                     serializable_deferrable;
index b622506a00d504d0ce0856d06305b2e868646aef..751f7463643cef9d5f9a0b27bd368b55418d0568 100644 (file)
@@ -167,6 +167,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
        dopt->disable_dollar_quoting = ropt->disable_dollar_quoting;
        dopt->dump_inserts = ropt->dump_inserts;
        dopt->no_security_labels = ropt->no_security_labels;
+       dopt->no_subscriptions = ropt->no_subscriptions;
        dopt->lockWaitTimeout = ropt->lockWaitTimeout;
        dopt->include_everything = ropt->include_everything;
        dopt->enable_row_security = ropt->enable_row_security;
@@ -2795,6 +2796,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
        if (ropt->no_security_labels && strcmp(te->desc, "SECURITY LABEL") == 0)
                return 0;
 
+       /* If it's a subcription, maybe ignore it */
+       if (ropt->no_subscriptions && strcmp(te->desc, "SUBSCRIPTION") == 0)
+               return 0;
+
        /* Ignore it if section is not to be dumped/restored */
        switch (curSection)
        {
index af84c25093eb499b353a20fe8f4c0e4e49dfa85d..d724b1193540cb8c310d808e4eb02e83014c873d 100644 (file)
@@ -355,6 +355,7 @@ main(int argc, char **argv)
                {"no-security-labels", no_argument, &dopt.no_security_labels, 1},
                {"no-synchronized-snapshots", no_argument, &dopt.no_synchronized_snapshots, 1},
                {"no-unlogged-table-data", no_argument, &dopt.no_unlogged_table_data, 1},
+               {"no-subscriptions", no_argument, &dopt.no_subscriptions, 1},
                {"no-sync", no_argument, NULL, 7},
 
                {NULL, 0, NULL, 0}
@@ -862,6 +863,7 @@ main(int argc, char **argv)
        ropt->disable_dollar_quoting = dopt.disable_dollar_quoting;
        ropt->dump_inserts = dopt.dump_inserts;
        ropt->no_security_labels = dopt.no_security_labels;
+       ropt->no_subscriptions = dopt.no_subscriptions;
        ropt->lockWaitTimeout = dopt.lockWaitTimeout;
        ropt->include_everything = dopt.include_everything;
        ropt->enable_row_security = dopt.enable_row_security;
@@ -950,6 +952,7 @@ help(const char *progname)
        printf(_("  --if-exists                  use IF EXISTS when dropping objects\n"));
        printf(_("  --inserts                    dump data as INSERT commands, rather than COPY\n"));
        printf(_("  --no-security-labels         do not dump security label assignments\n"));
+       printf(_("  --no-subscriptions           do not dump subscriptions\n"));
        printf(_("  --no-synchronized-snapshots  do not use synchronized snapshots in parallel jobs\n"));
        printf(_("  --no-tablespaces             do not dump tablespace assignments\n"));
        printf(_("  --no-unlogged-table-data     do not dump unlogged table data\n"));
@@ -3674,6 +3677,7 @@ is_superuser(Archive *fout)
 void
 getSubscriptions(Archive *fout)
 {
+       DumpOptions *dopt = fout->dopt;
        PQExpBuffer query;
        PGresult   *res;
        SubscriptionInfo *subinfo;
@@ -3688,7 +3692,7 @@ getSubscriptions(Archive *fout)
        int                     i,
                                ntups;
 
-       if (fout->remoteVersion < 100000)
+       if (dopt->no_subscriptions || fout->remoteVersion < 100000)
                return;
 
        if (!is_superuser(fout))
index 0bf5b7c666ae9f709b1e31daad6f1a457bb420f8..d91c4e1cd3f8c8d8f913705ad5c6052b5d10c752 100644 (file)
@@ -75,6 +75,7 @@ static int    inserts = 0;
 static int     no_tablespaces = 0;
 static int     use_setsessauth = 0;
 static int     no_security_labels = 0;
+static int     no_subscriptions = 0;
 static int     no_unlogged_table_data = 0;
 static int     no_role_passwords = 0;
 static int     server_version;
@@ -129,6 +130,7 @@ main(int argc, char *argv[])
                {"role", required_argument, NULL, 3},
                {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
                {"no-security-labels", no_argument, &no_security_labels, 1},
+               {"no-subscriptions", no_argument, &no_subscriptions, 1},
                {"no-sync", no_argument, NULL, 4},
                {"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1},
                {"no-role-passwords", no_argument, &no_role_passwords, 1},
@@ -385,6 +387,8 @@ main(int argc, char *argv[])
                appendPQExpBufferStr(pgdumpopts, " --use-set-session-authorization");
        if (no_security_labels)
                appendPQExpBufferStr(pgdumpopts, " --no-security-labels");
+       if (no_subscriptions)
+               appendPQExpBufferStr(pgdumpopts, " --no-subscriptions");
        if (no_unlogged_table_data)
                appendPQExpBufferStr(pgdumpopts, " --no-unlogged-table-data");
 
@@ -591,6 +595,7 @@ help(void)
        printf(_("  --if-exists                  use IF EXISTS when dropping objects\n"));
        printf(_("  --inserts                    dump data as INSERT commands, rather than COPY\n"));
        printf(_("  --no-security-labels         do not dump security label assignments\n"));
+       printf(_("  --no-subscriptions           do not dump subscriptions\n"));
        printf(_("  --no-sync                    do not wait for changes to be written safely to disk\n"));
        printf(_("  --no-tablespaces             do not dump tablespace assignments\n"));
        printf(_("  --no-unlogged-table-data     do not dump unlogged table data\n"));
index ddd79429b4bd2e9a9f74e0de0322737bbd58e42d..46830ea2a4f6a9cc42affe3eca402c823c1209ec 100644 (file)
@@ -72,6 +72,7 @@ main(int argc, char **argv)
        static int      outputNoTablespaces = 0;
        static int      use_setsessauth = 0;
        static int      no_security_labels = 0;
+       static int      no_subscriptions = 0;
        static int      strict_names = 0;
 
        struct option cmdopts[] = {
@@ -118,6 +119,7 @@ main(int argc, char **argv)
                {"strict-names", no_argument, &strict_names, 1},
                {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
                {"no-security-labels", no_argument, &no_security_labels, 1},
+               {"no-subscriptions", no_argument, &no_subscriptions, 1},
 
                {NULL, 0, NULL, 0}
        };
@@ -355,6 +357,7 @@ main(int argc, char **argv)
        opts->noTablespace = outputNoTablespaces;
        opts->use_setsessauth = use_setsessauth;
        opts->no_security_labels = no_security_labels;
+       opts->no_subscriptions = no_subscriptions;
 
        if (if_exists && !opts->dropSchema)
        {
@@ -477,6 +480,7 @@ usage(const char *progname)
        printf(_("  --no-data-for-failed-tables  do not restore data of tables that could not be\n"
                         "                               created\n"));
        printf(_("  --no-security-labels         do not restore security labels\n"));
+       printf(_("  --no-subscriptions           do not restore subscriptions\n"));
        printf(_("  --no-tablespaces             do not restore tablespace assignments\n"));
        printf(_("  --section=SECTION            restore named section (pre-data, data, or post-data)\n"));
        printf(_("  --strict-names               require table and/or schema include patterns to\n"