Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdaa076c

Browse files
committed
> Please find attached a submission to add a "exit on error" option to
> pg_restore, as it seems that some people have scripts that rely on the> previous "abort on error" default behavior when restoring data with a> direct connection.>> Fabien Coelho
1 parent46be0c1 commitdaa076c

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

‎doc/src/sgml/ref/pg_restore.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.47 2004/07/13 02:59:49 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.48 2004/08/20 04:20:22 momjian Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<refmeta>
@@ -129,6 +129,18 @@
129129
</listitem>
130130
</varlistentry>
131131

132+
<varlistentry>
133+
<term><option>-e</option></term>
134+
<term><option>--exit-on-error</option></term>
135+
<listitem>
136+
<para>
137+
Exit if an error is encountered while sending SQL commands to
138+
the database. The default is to continue and to display a count of
139+
errors at the end of the restoration.
140+
</para>
141+
</listitem>
142+
</varlistentry>
143+
132144
<varlistentry>
133145
<term><option>-f <replaceable>filename</replaceable></option></term>
134146
<term><option>--file=<replaceable>filename</replaceable></option></term>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 3 additions & 2 deletions
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.31 2004/07/13 03:00:17 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.32 2004/08/20 04:20:22 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -59,7 +59,7 @@ typedef struct _Archive
5959
intmaxRemoteVersion;
6060

6161
/* error handling */
62-
booldie_on_errors;/* whether todie onsql errors... */
62+
boolexit_on_error;/* whether toexit onSQL errors... */
6363
intn_errors;/* number of errors (if no die) */
6464

6565
/* The rest is private */
@@ -103,6 +103,7 @@ typedef struct _restoreOptions
103103
char*username;
104104
intignoreVersion;
105105
intrequirePassword;
106+
intexit_on_error;
106107

107108
bool*idWanted;
108109
boollimitToList;

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 4 additions & 3 deletions
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.92 2004/08/13 21:37:28 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.93 2004/08/20 04:20:22 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -457,6 +457,7 @@ NewRestoreOptions(void)
457457

458458
opts->format=archUnknown;
459459
opts->suppressDumpWarnings= false;
460+
opts->exit_on_error= false;
460461

461462
returnopts;
462463
}
@@ -1227,7 +1228,7 @@ warn_or_die_horribly(ArchiveHandle *AH,
12271228
{
12281229
va_listap;
12291230
va_start(ap,fmt);
1230-
if (AH->public.die_on_errors)
1231+
if (AH->public.exit_on_error)
12311232
{
12321233
_die_horribly(AH,modulename,fmt,ap);
12331234
}
@@ -1693,7 +1694,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
16931694
}
16941695

16951696
/* sql error handling */
1696-
AH->public.die_on_errors= true;
1697+
AH->public.exit_on_error= true;
16971698
AH->public.n_errors=0;
16981699

16991700
returnAH;

‎src/bin/pg_dump/pg_restore.c

Lines changed: 10 additions & 5 deletions
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.59 2004/07/13 03:00:17 momjian Exp $
37+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.60 2004/08/20 04:20:23 momjian Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -90,6 +90,7 @@ main(int argc, char **argv)
9090
{"create",0,NULL,'C'},
9191
{"data-only",0,NULL,'a'},
9292
{"dbname",1,NULL,'d'},
93+
{"exit-on-error",0,NULL,'e'},
9394
{"file",1,NULL,'f'},
9495
{"format",1,NULL,'F'},
9596
{"function",1,NULL,'P'},
@@ -141,7 +142,7 @@ main(int argc, char **argv)
141142
}
142143
}
143144

144-
while ((c=getopt_long(argc,argv,"acCd:f:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
145+
while ((c=getopt_long(argc,argv,"acCd:ef:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
145146
cmdopts,NULL))!=-1)
146147
{
147148
switch (c)
@@ -159,6 +160,9 @@ main(int argc, char **argv)
159160
case'd':
160161
opts->dbname=strdup(optarg);
161162
break;
163+
case'e':
164+
opts->exit_on_error= true;
165+
break;
162166
case'f':/* output file name */
163167
opts->filename=strdup(optarg);
164168
break;
@@ -321,10 +325,10 @@ main(int argc, char **argv)
321325
/* Let the archiver know how noisy to be */
322326
AH->verbose=opts->verbose;
323327

324-
/* restore keeps submitting sql commands as "pg_restore ... | psql ... "
325-
* this behavior choice could be turned into an option.
328+
/*
329+
*Whether to keep submitting sql commands as "pg_restore ... | psql ... "
326330
*/
327-
AH->die_on_errors=false;
331+
AH->exit_on_error=opts->exit_on_error;
328332

329333
if (opts->tocFile)
330334
SortTocFromFile(AH,opts);
@@ -391,6 +395,7 @@ usage(const char *progname)
391395
printf(_(" -p, --port=PORT database server port number\n"));
392396
printf(_(" -U, --username=NAME connect as specified database user\n"));
393397
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
398+
printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
394399

395400
printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
396401
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp