]> granicus.if.org Git - postgresql/commitdiff
Support a --no-tablespaces option in pg_dump/pg_dumpall/pg_restore, so that
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 20 Mar 2008 17:36:58 +0000 (17:36 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 20 Mar 2008 17:36:58 +0000 (17:36 +0000)
dumps can be loaded into databases without the same tablespaces that the
source had.  The option acts by suppressing all "SET default_tablespace"
commands, and also CREATE TABLESPACE commands in pg_dumpall's case.

Gavin Roy, with documentation and minor fixes by me.

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 fd0d56d8c0ef24a7776fef49077c8fda130442d2..9767cfbcd75cdee5e550135b134cdb0d7f716f9b 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.98 2007/12/11 19:57:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.99 2008/03/20 17:36:57 tgl Exp $
 PostgreSQL documentation
 -->
 
@@ -427,6 +427,23 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-tablespaces</option></term>
+      <listitem>
+       <para>
+        Do not output commands to select tablespaces.
+        With this option, all objects will be created in whichever
+        tablespace is the default during restore.
+       </para>
+
+       <para>
+        This option is only meaningful for the plain-text format.  For
+        the archive formats, you can specify the option when you
+        call <command>pg_restore</command>.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-s</option></term>
       <term><option>--schema-only</option></term>
index a697cdbb9115990d7b4b6be9e62b307e3478fb83..e624210bac4db1c8fd8fea4f8b16a920911dd9d8 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.69 2007/12/11 19:57:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.70 2008/03/20 17:36:57 tgl Exp $
 PostgreSQL documentation
 -->
 
@@ -40,7 +40,8 @@ PostgreSQL documentation
    that are common to all databases.
    (<application>pg_dump</application> does not save these objects.)
    This currently includes information about database users and
-   groups, and access permissions that apply to databases as a whole.
+   groups, tablespaces, and properties such as access permissions
+   that apply to databases as a whole.
   </para>
 
   <para>
@@ -204,6 +205,18 @@ PostgreSQL documentation
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-tablespaces</option></term>
+      <listitem>
+       <para>
+        Do not output commands to create tablespaces nor select tablespaces
+        for objects.
+        With this option, all objects will be created in whichever
+        tablespace is the default during restore.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-r</option></term>
       <term><option>--roles-only</option></term>
index 17a99e5395e918cea485891cc645371ef258a804..f908d93dcab621dcbeadf829e9bc92d7221c38fb 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.72 2007/12/11 19:57:32 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.73 2008/03/20 17:36:57 tgl Exp $ -->
 
 <refentry id="APP-PGRESTORE">
  <refmeta>
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--no-tablespaces</option></term>
+      <listitem>
+       <para>
+        Do not output commands to select tablespaces.
+        With this option, all objects will be created in whichever
+        tablespace is the default during restore.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-P <replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>
       <term><option>--function=<replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>
index a870516d7a98e7b60a68d9885422ef7ec0c60826..c4eb6e22e4a010811c4539b5c2e8c52e4be67cfb 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.45 2007/01/25 03:30:43 momjian Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.46 2008/03/20 17:36:57 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -83,6 +83,7 @@ typedef struct _restoreOptions
 {
        int                     create;                 /* Issue commands to create the database */
        int                     noOwner;                /* Don't try to match original object owner */
+       int                     noTablespace;   /* Don't issue tablespace-related commands */
        int                     disable_triggers;               /* disable triggers during data-only
                                                                                 * restore */
        int                     use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
index af44e85251308956d1e6bde749f324691dbaf5e6..7c36aef5484c13fba267ca85d195a2b7540b9083 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.152 2008/01/14 19:27:41 tgl Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.153 2008/03/20 17:36:57 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2378,6 +2378,10 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
        const char *want,
                           *have;
 
+       /* do nothing in --no-tablespaces mode */
+       if (AH->ropt->noTablespace)
+               return;
+
        have = AH->currTablespace;
        want = tablespace;
 
@@ -2578,7 +2582,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
                                 pfx, te->tag, te->desc,
                                 te->namespace ? te->namespace : "-",
                                 ropt->noOwner ? "-" : te->owner);
-               if (te->tablespace)
+               if (te->tablespace && !ropt->noTablespace)
                        ahprintf(AH, "; Tablespace: %s", te->tablespace);
                ahprintf(AH, "\n");
 
index c284bbb2da9637cd61ff252a237769b13760ad28..f9313c5f334a9680ed367027d6010c264d507106 100644 (file)
@@ -12,7 +12,7 @@
  *     by PostgreSQL
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.482 2008/01/30 18:35:55 tgl Exp $
+ *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.483 2008/03/20 17:36:57 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -223,9 +223,10 @@ main(int argc, char **argv)
        int                     outputCreate = 0;
        bool            outputBlobs = false;
        int                     outputNoOwner = 0;
-       static int      use_setsessauth = 0;
-       static int      disable_triggers = 0;
        char       *outputSuperuser = NULL;
+       static int      disable_triggers = 0;
+       static int  outputNoTablespaces = 0;
+       static int      use_setsessauth = 0;
 
        RestoreOptions *ropt;
 
@@ -266,6 +267,7 @@ main(int argc, char **argv)
                 */
                {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
                {"disable-triggers", no_argument, &disable_triggers, 1},
+               {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
                {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
 
                {NULL, 0, NULL, 0}
@@ -417,6 +419,8 @@ main(int argc, char **argv)
                                        disable_dollar_quoting = 1;
                                else if (strcmp(optarg, "disable-triggers") == 0)
                                        disable_triggers = 1;
+                               else if (strcmp(optarg, "no-tablespaces") == 0)
+                                       outputNoTablespaces = 1;
                                else if (strcmp(optarg, "use-set-session-authorization") == 0)
                                        use_setsessauth = 1;
                                else
@@ -708,6 +712,7 @@ main(int argc, char **argv)
                ropt->superuser = outputSuperuser;
                ropt->create = outputCreate;
                ropt->noOwner = outputNoOwner;
+               ropt->noTablespace = outputNoTablespaces;
                ropt->disable_triggers = disable_triggers;
                ropt->use_setsessauth = use_setsessauth;
                ropt->dataOnly = dataOnly;
@@ -768,6 +773,7 @@ help(const char *progname)
        printf(_("  -x, --no-privileges         do not dump privileges (grant/revoke)\n"));
        printf(_("  --disable-dollar-quoting    disable dollar quoting, use SQL standard quoting\n"));
        printf(_("  --disable-triggers          disable triggers during data-only restore\n"));
+       printf(_("  --no-tablespaces            do not dump tablespace assignments\n"));
        printf(_("  --use-set-session-authorization\n"
                         "                              use SESSION AUTHORIZATION commands instead of\n"
        "                              ALTER OWNER commands to set ownership\n"));
index 64b72333931be4eda9e311eaf905befeb943e06f..fb93cfa7b109fd78af2c5637cbd19b76c3bd7d03 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.100 2008/01/01 19:45:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.101 2008/03/20 17:36:57 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -64,6 +64,7 @@ static bool ignoreVersion = false;
 
 static int     disable_dollar_quoting = 0;
 static int     disable_triggers = 0;
+static int     no_tablespaces = 0;
 static int     use_setsessauth = 0;
 static int     server_version;
 
@@ -118,6 +119,7 @@ main(int argc, char *argv[])
                 */
                {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
                {"disable-triggers", no_argument, &disable_triggers, 1},
+               {"no-tablespaces", no_argument, &no_tablespaces, 1},
                {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
 
                {NULL, 0, NULL, 0}
@@ -285,11 +287,13 @@ main(int argc, char *argv[])
                        case 'X':
                                /* -X is a deprecated alternative to long options */
                                if (strcmp(optarg, "disable-dollar-quoting") == 0)
-                                       appendPQExpBuffer(pgdumpopts, " --disable-dollar-quoting");
+                                       disable_dollar_quoting = 1;
                                else if (strcmp(optarg, "disable-triggers") == 0)
-                                       appendPQExpBuffer(pgdumpopts, " --disable-triggers");
+                                       disable_triggers = 1;
+                               else if (strcmp(optarg, "no-tablespaces") == 0) 
+                                       no_tablespaces = 1;
                                else if (strcmp(optarg, "use-set-session-authorization") == 0)
-                                        /* no-op, still allowed for compatibility */ ;
+                                       use_setsessauth = 1;
                                else
                                {
                                        fprintf(stderr,
@@ -314,6 +318,8 @@ main(int argc, char *argv[])
                appendPQExpBuffer(pgdumpopts, " --disable-dollar-quoting");
        if (disable_triggers)
                appendPQExpBuffer(pgdumpopts, " --disable-triggers");
+       if (no_tablespaces)
+               appendPQExpBuffer(pgdumpopts, " --no-tablespaces");
        if (use_setsessauth)
                appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization");
 
@@ -444,7 +450,7 @@ main(int argc, char *argv[])
                                dumpGroups(conn);
                }
 
-               if (!roles_only)
+               if (!roles_only && !no_tablespaces)
                {
                        /* Dump tablespaces */
                        if (server_version >= 80000)
@@ -502,6 +508,7 @@ help(void)
        printf(_("  --disable-dollar-quoting\n"
                         "                           disable dollar quoting, use SQL standard quoting\n"));
        printf(_("  --disable-triggers       disable triggers during data-only restore\n"));
+       printf(_("  --no-tablespaces         do not dump tablespace assignments\n"));
        printf(_("  --use-set-session-authorization\n"
                         "                           use SESSION AUTHORIZATION commands instead of\n"
                         "                           OWNER TO commands\n"));
index 94f407c45b5e7cf62e9d7563dee8c709444401f9..dec2b57aac97fcfe5d26efc89531ea580bb2e2ee 100644 (file)
@@ -34,7 +34,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.85 2007/12/11 19:01:06 tgl Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.86 2008/03/20 17:36:58 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -74,9 +74,10 @@ main(int argc, char **argv)
        char       *inputFileSpec;
        extern int      optind;
        extern char *optarg;
-       static int      use_setsessauth = 0;
        static int      disable_triggers = 0;
        static int      no_data_for_failed_tables = 0;
+       static int  outputNoTablespaces = 0;
+       static int      use_setsessauth = 0;
 
        struct option cmdopts[] = {
                {"clean", 0, NULL, 'c'},
@@ -110,9 +111,10 @@ main(int argc, char **argv)
                /*
                 * the following options don't have an equivalent short option letter
                 */
-               {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
                {"disable-triggers", no_argument, &disable_triggers, 1},
                {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
+               {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
+               {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
 
                {NULL, 0, NULL, 0}
        };
@@ -241,10 +243,14 @@ main(int argc, char **argv)
 
                        case 'X':
                                /* -X is a deprecated alternative to long options */
-                               if (strcmp(optarg, "use-set-session-authorization") == 0)
-                                       use_setsessauth = 1;
-                               else if (strcmp(optarg, "disable-triggers") == 0)
+                               if (strcmp(optarg, "disable-triggers") == 0)
                                        disable_triggers = 1;
+                               else if (strcmp(optarg, "no-data-for-failed-tables") == 0)
+                                       no_data_for_failed_tables = 1;
+                               else if (strcmp(optarg, "no-tablespaces") == 0)
+                                       outputNoTablespaces = 1;
+                               else if (strcmp(optarg, "use-set-session-authorization") == 0)
+                                       use_setsessauth = 1;
                                else
                                {
                                        fprintf(stderr,
@@ -290,8 +296,9 @@ main(int argc, char **argv)
        }
 
        opts->disable_triggers = disable_triggers;
-       opts->use_setsessauth = use_setsessauth;
        opts->noDataForFailedTables = no_data_for_failed_tables;
+       opts->noTablespace = outputNoTablespaces;
+       opts->use_setsessauth = use_setsessauth;
 
        if (opts->formatName)
        {
@@ -395,12 +402,13 @@ usage(const char *progname)
        printf(_("  -T, --trigger=NAME       restore named trigger\n"));
        printf(_("  -x, --no-privileges      skip restoration of access privileges (grant/revoke)\n"));
        printf(_("  --disable-triggers       disable triggers during data-only restore\n"));
-       printf(_("  --use-set-session-authorization\n"
-                        "                           use SESSION AUTHORIZATION commands instead of\n"
-                        "                           OWNER TO commands\n"));
        printf(_("  --no-data-for-failed-tables\n"
                         "                           do not restore data of tables that could not be\n"
                         "                           created\n"));
+       printf(_("  --no-tablespaces         do not dump tablespace assignments\n"));
+       printf(_("  --use-set-session-authorization\n"
+                        "                           use SESSION AUTHORIZATION commands instead of\n"
+                        "                           OWNER TO commands\n"));
        printf(_("  -1, --single-transaction\n"
                         "                           restore as a single transaction\n"));