From daa076c4fdd32aff597eda4c34347d488c5b1e3a Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 20 Aug 2004 04:20:23 +0000 Subject: [PATCH] > 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 --- doc/src/sgml/ref/pg_restore.sgml | 14 +++++++++++++- src/bin/pg_dump/pg_backup.h | 5 +++-- src/bin/pg_dump/pg_backup_archiver.c | 7 ++++--- src/bin/pg_dump/pg_restore.c | 15 ++++++++++----- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml index 533bdd9c0b..6ffad3b538 100644 --- a/doc/src/sgml/ref/pg_restore.sgml +++ b/doc/src/sgml/ref/pg_restore.sgml @@ -1,4 +1,4 @@ - + @@ -129,6 +129,18 @@ + + + + + + Exit if an error is encountered while sending SQL commands to + the database. The default is to continue and to display a count of + errors at the end of the restoration. + + + + diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index 4957ea9a14..7723203df7 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.31 2004/07/13 03:00:17 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.32 2004/08/20 04:20:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -59,7 +59,7 @@ typedef struct _Archive int maxRemoteVersion; /* error handling */ - bool die_on_errors; /* whether to die on sql errors... */ + bool exit_on_error; /* whether to exit on SQL errors... */ int n_errors; /* number of errors (if no die) */ /* The rest is private */ @@ -103,6 +103,7 @@ typedef struct _restoreOptions char *username; int ignoreVersion; int requirePassword; + int exit_on_error; bool *idWanted; bool limitToList; diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index d528d2df57..5c610f962b 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.92 2004/08/13 21:37:28 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.93 2004/08/20 04:20:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -457,6 +457,7 @@ NewRestoreOptions(void) opts->format = archUnknown; opts->suppressDumpWarnings = false; + opts->exit_on_error = false; return opts; } @@ -1227,7 +1228,7 @@ warn_or_die_horribly(ArchiveHandle *AH, { va_list ap; va_start(ap, fmt); - if (AH->public.die_on_errors) + if (AH->public.exit_on_error) { _die_horribly(AH, modulename, fmt, ap); } @@ -1693,7 +1694,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, } /* sql error handling */ - AH->public.die_on_errors = true; + AH->public.exit_on_error = true; AH->public.n_errors = 0; return AH; diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index eef86a25e5..918a93a656 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -34,7 +34,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.59 2004/07/13 03:00:17 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.60 2004/08/20 04:20:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -90,6 +90,7 @@ main(int argc, char **argv) {"create", 0, NULL, 'C'}, {"data-only", 0, NULL, 'a'}, {"dbname", 1, NULL, 'd'}, + {"exit-on-error", 0, NULL, 'e'}, {"file", 1, NULL, 'f'}, {"format", 1, NULL, 'F'}, {"function", 1, NULL, 'P'}, @@ -141,7 +142,7 @@ main(int argc, char **argv) } } - while ((c = getopt_long(argc, argv, "acCd:f:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:", + while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:", cmdopts, NULL)) != -1) { switch (c) @@ -159,6 +160,9 @@ main(int argc, char **argv) case 'd': opts->dbname = strdup(optarg); break; + case 'e': + opts->exit_on_error = true; + break; case 'f': /* output file name */ opts->filename = strdup(optarg); break; @@ -321,10 +325,10 @@ main(int argc, char **argv) /* Let the archiver know how noisy to be */ AH->verbose = opts->verbose; - /* restore keeps submitting sql commands as "pg_restore ... | psql ... " - * this behavior choice could be turned into an option. + /* + * Whether to keep submitting sql commands as "pg_restore ... | psql ... " */ - AH->die_on_errors = false; + AH->exit_on_error = opts->exit_on_error; if (opts->tocFile) SortTocFromFile(AH, opts); @@ -391,6 +395,7 @@ usage(const char *progname) printf(_(" -p, --port=PORT database server port number\n")); printf(_(" -U, --username=NAME connect as specified database user\n")); printf(_(" -W, --password force password prompt (should happen automatically)\n")); + printf(_(" -e, --exit-on-error exit on error, default is to continue\n")); printf(_("\nIf no input file name is supplied, then standard input is used.\n\n")); printf(_("Report bugs to .\n")); -- 2.40.0