]> granicus.if.org Git - postgresql/commitdiff
Add pg_dump -X no-data-for-failed-tables option to suppress loading data
authorBruce Momjian <bruce@momjian.us>
Tue, 1 Aug 2006 18:21:44 +0000 (18:21 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 1 Aug 2006 18:21:44 +0000 (18:21 +0000)
if table creation failed (the table already exists).

Martin Pitt

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_restore.c

index b82969aaf6336018061b7d08bf69642050fb1c77..2caea151517897dae7163596d81f06091ee89cee 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.59 2006/03/17 16:02:47 petere Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.60 2006/08/01 18:21:44 momjian Exp $ -->
 
 <refentry id="APP-PGRESTORE">
  <refmeta>
       </listitem>
      </varlistentry>
 
-     <varlistentry>
-      <term><option>-X use-set-session-authorization</option></term>
-      <term><option>--use-set-session-authorization</option></term>
-      <listitem>
-       <para>
-        Output SQL-standard <command>SET SESSION AUTHORIZATION</> commands
-        instead of <command>ALTER OWNER</> commands to determine object
-        ownership.  This makes the dump more standards compatible, but
-        depending on the history of the objects in the dump, may not restore
-        properly.
-       </para>
-      </listitem>
-     </varlistentry>
-
      <varlistentry>
       <term><option>-X disable-triggers</></term>
       <term><option>--disable-triggers</></term>
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-X use-set-session-authorization</option></term>
+      <term><option>--use-set-session-authorization</option></term>
+      <listitem>
+       <para>
+        Output SQL-standard <command>SET SESSION AUTHORIZATION</> commands
+        instead of <command>ALTER OWNER</> commands to determine object
+        ownership.  This makes the dump more standards compatible, but
+        depending on the history of the objects in the dump, may not restore
+        properly.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
+      <term><option>-X no-data-for-failed-tables</></term>
+      <listitem>
+       <para>
+       By default, table data objects are restored even if the
+       associated table could not be successfully created (e. g.
+       because it already exists). With this option, such table
+       data is silently ignored. This is useful for dumping and
+       restoring databases with tables which contain auxiliary data
+       for PostgreSQL extensions (e. g. PostGIS).
+       </para>
+      </listitem>
+     </varlistentry>
+
     </variablelist>
    </para>
 
index 6f81b8deecc4b8a7425ba207fbd9da47329b0384..426b5110fbddb6ff04dd9956d04ecaf85a72cddb 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.41 2006/07/14 14:52:26 momjian Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.42 2006/08/01 18:21:44 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -109,6 +109,7 @@ typedef struct _restoreOptions
        char       *pghost;
        char       *username;
        int                     ignoreVersion;
+       int                     noDataForFailedTables;
        int                     requirePassword;
        int                     exit_on_error;
 
index 76ebc0b89b05e89ffb2a41510cfc762189be2dfc..6100633d56ef0eaa1e79ae8db9a635714b12257f 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.134 2006/07/18 17:42:00 momjian Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.135 2006/08/01 18:21:44 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -278,6 +278,23 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
                        _printTocEntry(AH, te, ropt, false, false);
                        defnDumped = true;
 
+                       /* If we could not create a table, ignore the respective TABLE DATA if 
+                        * -X no-data-for-failed-tables is given */
+                       if (ropt->noDataForFailedTables && AH->lastErrorTE == te && strcmp (te->desc, "TABLE") == 0) {
+                               TocEntry *tes, *last;
+                                
+                               ahlog (AH, 1, "table %s could not be created, will not restore its data\n", te->tag);
+
+                               for (last = te, tes = te->next; tes != AH->toc; last = tes, tes = tes->next) {
+                                       if (strcmp (tes->desc, "TABLE DATA") == 0 && strcmp (tes->tag, te->tag) == 0 &&
+                                           strcmp (tes->namespace ? tes->namespace : "", te->namespace ? te->namespace : "") == 0) {
+                                           /* remove this node */
+                                           last->next = tes->next;
+                                            break;
+                                       }
+                               }
+                       }
+
                        /* If we created a DB, connect to it... */
                        if (strcmp(te->desc, "DATABASE") == 0)
                        {
index 410a2104f4f172a2ac5d6579a7cc36b4d61a7f4d..474973ffda9ab0c72878762b32f2d87e67d48c91 100644 (file)
@@ -34,7 +34,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.79 2006/07/14 14:52:26 momjian Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.80 2006/08/01 18:21:44 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -252,6 +252,8 @@ main(int argc, char **argv)
                                        use_setsessauth = 1;
                                else if (strcmp(optarg, "disable-triggers") == 0)
                                        disable_triggers = 1;
+                               else if (strcmp(optarg, "no-data-for-failed-tables") == 0)
+                                       opts->noDataForFailedTables = 1;
                                else
                                {
                                        fprintf(stderr,
@@ -397,6 +399,9 @@ usage(const char *progname)
        printf(_("  -X use-set-session-authorization, --use-set-session-authorization\n"
                         "                           use SESSION AUTHORIZATION commands instead of\n"
                         "                           OWNER TO commands\n"));
+       printf(_("  -X no-data-for-failed-tables\n"
+                        "                           do not restore data of tables which could not be\n"
+                        "                           created\n"));
        printf(_("  -1, --single-transaction restore as a single transaction\n"));
 
        printf(_("\nConnection options:\n"));