Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Adding an ignore list to pg_restore, prototype patch #1


  • From: Martin Pitt <mpitt(at)debian(dot)org>
  • To: pgsql-hackers(at)postgresql(dot)org
  • Cc: Stephen Frost <sfrost(at)snowman(dot)net>
  • Subject: Re: Adding an ignore list to pg_restore, prototype patch #1
  • Date: Sat, 25 Feb 2006 13:46:48 +0100
  • Message-id: <20060225124648(dot)GA6968(at)piware(dot)de>

Hi again,

Martin Pitt [2006-02-19 14:39 +0100]:
> Since this changes the behaviour of pg_restore, this should probably
> become an option, e. g. -D / --ignore-existing-table-data. I'll do
> this if you agree to the principle of the current patch.

I improved the patch now to only ignore TABLE DATA for existing tables
if '-X ignore-existing-tables' is specified. I also updated the
documentation.

Since this doesn't change the default behaviour now any more, I would
like to put this patch into the Debian packages to provide automatic
upgrades for PostGIS-enabled databases (see [1]). Does anyone object
to this? 

Do you consider to adopt this upstream?

Thanks in advance, and have a nice weekend!

Martin

[1] http://bugs.debian.org/351571

-- 
Martin Pitt        http://www.piware.de
Ubuntu Developer   http://www.ubuntu.com
Debian Developer   http://www.debian.org

In a world without walls and fences, who needs Windows and Gates?
--- postgresql-8.1.3/doc/src/sgml/ref/pg_restore.sgml
+++ postgresql-8.1.3/doc/src/sgml/ref/pg_restore.sgml
@@ -395,6 +395,19 @@
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-X ignore-existing-tables</></term>
+      <listitem>
+       <para>
+       By default, table data objects are restored even if the
+       associated table 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>
 
--- postgresql-8.1.3/src/bin/pg_dump/pg_backup_archiver.c
+++ postgresql-8.1.3/src/bin/pg_dump/pg_backup_archiver.c
@@ -268,6 +268,21 @@
 			_printTocEntry(AH, te, ropt, false, false);
 			defnDumped = true;
 
+			/* If we could not create a table, ignore the respective TABLE DATA if 
+			 * -X ignore-existing-tables is given */
+			if (ropt->ignoreExistingTables && AH->lastErrorTE == te && strcmp (te->desc, "TABLE") == 0) {
+				TocEntry   *tes;
+                                
+				ahlog (AH, 1, "table %s could not be created, will not restore its data\n", te->tag);
+
+				for (tes = te->next; tes != AH->toc; tes = tes->next) {
+					if (strcmp (tes->desc, "TABLE DATA") == 0 && strcmp (tes->tag, te->tag) == 0) {
+                                            strcpy (tes->desc, "IGNOREDATA");
+                                            break;
+					}
+				}
+			}
+
 			/* If we created a DB, connect to it... */
 			if (strcmp(te->desc, "DATABASE") == 0)
 			{
@@ -1876,6 +1891,10 @@
 	if (strcmp(te->desc, "ENCODING") == 0)
 		return 0;
 
+	/* IGNOREDATA is a TABLE DATA which should not be restored */
+	if (strcmp (te->desc, "IGNOREDATA") == 0)
+		return 0;
+
 	/* If it's an ACL, maybe ignore it */
 	if ((!include_acls || ropt->aclsSkip) && strcmp(te->desc, "ACL") == 0)
 		return 0;
--- postgresql-8.1.3/src/bin/pg_dump/pg_backup.h
+++ postgresql-8.1.3/src/bin/pg_dump/pg_backup.h
@@ -106,6 +106,7 @@
 	char	   *pghost;
 	char	   *username;
 	int			ignoreVersion;
+	int			ignoreExistingTables;
 	int			requirePassword;
 	int			exit_on_error;
 
--- postgresql-8.1.3/src/bin/pg_dump/pg_restore.c
+++ postgresql-8.1.3/src/bin/pg_dump/pg_restore.c
@@ -254,6 +254,8 @@
 					use_setsessauth = 1;
 				else if (strcmp(optarg, "disable-triggers") == 0)
 					disable_triggers = 1;
+				else if (strcmp(optarg, "ignore-existing-tables") == 0)
+					opts->ignoreExistingTables = 1;
 				else
 				{
 					fprintf(stderr,
@@ -394,6 +396,8 @@
 	printf(_("  -X use-set-session-authorization, --use-set-session-authorization\n"
 			 "                           use SESSION AUTHORIZATION commands instead of\n"
 			 "                           OWNER TO commands\n"));
+	printf(_("  -X ignore-existing-tables\n"
+			 "                   skip restoration of data for already existing tables\n"));
 
 	printf(_("\nConnection options:\n"));
 	printf(_("  -h, --host=HOSTNAME      database server host or socket directory\n"));

Attachment: signature.asc
Description: Digital signature



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group