Skip to content

Commit c61607b

Browse files
committed
Add pg_dump -X no-data-for-failed-tables option to suppress loading data
if table creation failed (the table already exists). Martin Pitt
1 parent 6d0f5ea commit c61607b

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.59 2006/03/17 16:02:47 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.60 2006/08/01 18:21:44 momjian Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<refmeta>
@@ -360,20 +360,6 @@
360360
</listitem>
361361
</varlistentry>
362362

363-
<varlistentry>
364-
<term><option>-X use-set-session-authorization</option></term>
365-
<term><option>--use-set-session-authorization</option></term>
366-
<listitem>
367-
<para>
368-
Output SQL-standard <command>SET SESSION AUTHORIZATION</> commands
369-
instead of <command>ALTER OWNER</> commands to determine object
370-
ownership. This makes the dump more standards compatible, but
371-
depending on the history of the objects in the dump, may not restore
372-
properly.
373-
</para>
374-
</listitem>
375-
</varlistentry>
376-
377363
<varlistentry>
378364
<term><option>-X disable-triggers</></term>
379365
<term><option>--disable-triggers</></term>
@@ -397,6 +383,34 @@
397383
</listitem>
398384
</varlistentry>
399385

386+
<varlistentry>
387+
<term><option>-X use-set-session-authorization</option></term>
388+
<term><option>--use-set-session-authorization</option></term>
389+
<listitem>
390+
<para>
391+
Output SQL-standard <command>SET SESSION AUTHORIZATION</> commands
392+
instead of <command>ALTER OWNER</> commands to determine object
393+
ownership. This makes the dump more standards compatible, but
394+
depending on the history of the objects in the dump, may not restore
395+
properly.
396+
</para>
397+
</listitem>
398+
</varlistentry>
399+
400+
<varlistentry>
401+
<term><option>-X no-data-for-failed-tables</></term>
402+
<listitem>
403+
<para>
404+
By default, table data objects are restored even if the
405+
associated table could not be successfully created (e. g.
406+
because it already exists). With this option, such table
407+
data is silently ignored. This is useful for dumping and
408+
restoring databases with tables which contain auxiliary data
409+
for PostgreSQL extensions (e. g. PostGIS).
410+
</para>
411+
</listitem>
412+
</varlistentry>
413+
400414
</variablelist>
401415
</para>
402416

src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.41 2006/07/14 14:52:26 momjian Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.42 2006/08/01 18:21:44 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -109,6 +109,7 @@ typedef struct _restoreOptions
109109
char *pghost;
110110
char *username;
111111
int ignoreVersion;
112+
int noDataForFailedTables;
112113
int requirePassword;
113114
int exit_on_error;
114115

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.134 2006/07/18 17:42:00 momjian Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.135 2006/08/01 18:21:44 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -278,6 +278,23 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
278278
_printTocEntry(AH, te, ropt, false, false);
279279
defnDumped = true;
280280

281+
/* If we could not create a table, ignore the respective TABLE DATA if
282+
* -X no-data-for-failed-tables is given */
283+
if (ropt->noDataForFailedTables && AH->lastErrorTE == te && strcmp (te->desc, "TABLE") == 0) {
284+
TocEntry *tes, *last;
285+
286+
ahlog (AH, 1, "table %s could not be created, will not restore its data\n", te->tag);
287+
288+
for (last = te, tes = te->next; tes != AH->toc; last = tes, tes = tes->next) {
289+
if (strcmp (tes->desc, "TABLE DATA") == 0 && strcmp (tes->tag, te->tag) == 0 &&
290+
strcmp (tes->namespace ? tes->namespace : "", te->namespace ? te->namespace : "") == 0) {
291+
/* remove this node */
292+
last->next = tes->next;
293+
break;
294+
}
295+
}
296+
}
297+
281298
/* If we created a DB, connect to it... */
282299
if (strcmp(te->desc, "DATABASE") == 0)
283300
{

src/bin/pg_dump/pg_restore.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.79 2006/07/14 14:52:26 momjian Exp $
37+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.80 2006/08/01 18:21:44 momjian Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -252,6 +252,8 @@ main(int argc, char **argv)
252252
use_setsessauth = 1;
253253
else if (strcmp(optarg, "disable-triggers") == 0)
254254
disable_triggers = 1;
255+
else if (strcmp(optarg, "no-data-for-failed-tables") == 0)
256+
opts->noDataForFailedTables = 1;
255257
else
256258
{
257259
fprintf(stderr,
@@ -397,6 +399,9 @@ usage(const char *progname)
397399
printf(_(" -X use-set-session-authorization, --use-set-session-authorization\n"
398400
" use SESSION AUTHORIZATION commands instead of\n"
399401
" OWNER TO commands\n"));
402+
printf(_(" -X no-data-for-failed-tables\n"
403+
" do not restore data of tables which could not be\n"
404+
" created\n"));
400405
printf(_(" -1, --single-transaction restore as a single transaction\n"));
401406

402407
printf(_("\nConnection options:\n"));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy