Dear patchers,
please find a small patch submission so that "pg_restore" ignores some sql
errors.
The implementation seems quite reasonnable to me, but pg-gods may have a
different opinion. Two fields are added to the ArchiveHandler to trigger
the behavior. A count summary of ignored sql errors is printed at the end
of the restoration.
I did not fixed the "set session auth" attempt as option "-O" can already
be used to avoid it.
It validates for me, but it seems that pg_dump/pg_restore is just *NOT*
tested at all in the validation:-(. So at least I tested it.
My tests suggest that a feature of pg_restore is that it is only expected
to work with its own server. Indeed, it generates some new syntax, such as
$$ quoting, which is not compatible with older servers. This fact does not
seem to appear in the documentation.
Have a nice day,
--
Fabien Coelho - [EMAIL PROTECTED]
*** ./src/bin/pg_dump/pg_backup.h.orig Wed Mar 24 17:19:43 2004
--- ./src/bin/pg_dump/pg_backup.h Fri Apr 9 18:39:50 2004
***************
*** 57,62 ****
--- 57,67 ----
int remoteVersion;
int minRemoteVersion;
int maxRemoteVersion;
+
+ /* error handling */
+ bool die_on_errors; /* whether to die on sql errors... */
+ int n_errors; /* number of errors (if no
die) */
+
/* The rest is private */
} Archive;
*** ./src/bin/pg_dump/pg_backup_archiver.c.orig Wed Mar 24 17:19:43 2004
--- ./src/bin/pg_dump/pg_backup_archiver.c Fri Apr 9 19:10:26 2004
***************
*** 1197,1202 ****
--- 1197,1218 ----
va_end(ap);
}
+ /* on some error, we may decide to go on... */
+ void
+ warn_or_die_horribly(ArchiveHandle *AH,
+ const char *modulename, const char *fmt, ...)
+ {
+ va_list ap;
+ va_start(ap, fmt);
+ if (AH->public.die_on_errors)
+ _die_horribly(AH, modulename, fmt, ap);
+ else
+ {
+ _write_msg(modulename, fmt, ap);
+ AH->public.n_errors++;
+ }
+ va_end(ap);
+ }
static void
_moveAfter(ArchiveHandle *AH, TocEntry *pos, TocEntry *te)
***************
*** 1651,1656 ****
--- 1667,1676 ----
die_horribly(AH, modulename, "unrecognized file format
\"%d\"\n", fmt);
}
+ /* sql error handling */
+ AH->public.die_on_errors = true;
+ AH->public.n_errors = 0;
+
return AH;
}
***************
*** 2042,2049 ****
res = PQexec(AH->connection, cmd->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! die_horribly(AH, modulename, "could not set default_with_oids:
%s",
! PQerrorMessage(AH->connection));
PQclear(res);
}
--- 2062,2070 ----
res = PQexec(AH->connection, cmd->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! warn_or_die_horribly(AH, modulename,
! "could not set
default_with_oids: %s",
!
PQerrorMessage(AH->connection));
PQclear(res);
}
***************
*** 2181,2188 ****
res = PQexec(AH->connection, qry->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! die_horribly(AH, modulename, "could not set search_path to
\"%s\": %s",
! schemaName,
PQerrorMessage(AH->connection));
PQclear(res);
}
--- 2202,2210 ----
res = PQexec(AH->connection, qry->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! warn_or_die_horribly(AH, modulename,
! "could not set
search_path to \"%s\": %s",
! schemaName,
PQerrorMessage(AH->connection));
PQclear(res);
}
*** ./src/bin/pg_dump/pg_backup_archiver.h.orig Wed Mar 24 17:19:43 2004
--- ./src/bin/pg_dump/pg_backup_archiver.h Fri Apr 9 18:55:50 2004
***************
*** 281,286 ****
--- 281,287 ----
extern const char *progname;
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char
*fmt,...) __attribute__((format(printf, 3, 4)));
+ extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const
char *fmt,...) __attribute__((format(printf, 3, 4)));
extern void write_msg(const char *modulename, const char *fmt,...)
__attribute__((format(printf, 2, 3)));
extern void WriteTOC(ArchiveHandle *AH);
*** ./src/bin/pg_dump/pg_backup_db.c.orig Wed Mar 3 22:28:54 2004
--- ./src/bin/pg_dump/pg_backup_db.c Fri Apr 9 19:10:42 2004
***************
*** 316,323 ****
AH->pgCopyIn = 1;
}
else
! die_horribly(AH, modulename, "%s: %s",
! desc, PQerrorMessage(AH->connection));
}
PQclear(res);
--- 316,323 ----
AH->pgCopyIn = 1;
}
else
! warn_or_die_horribly(AH, modulename, "%s: %s",
! desc,
PQerrorMessage(AH->connection));
}
PQclear(res);
*** ./src/bin/pg_dump/pg_restore.c.orig Sat Dec 6 04:00:16 2003
--- ./src/bin/pg_dump/pg_restore.c Fri Apr 9 19:17:22 2004
***************
*** 322,327 ****
--- 322,328 ----
/* Let the archiver know how noisy to be */
AH->verbose = opts->verbose;
+ AH->die_on_errors = false;
if (opts->tocFile)
SortTocFromFile(AH, opts);
***************
*** 331,336 ****
--- 332,343 ----
else
RestoreArchive(AH, opts);
+ if (AH->n_errors)
+ /* translator: %s stands for "error" or "errors" */
+ fprintf(stderr, _("warning: %d %s ignored on restore\n"),
+ /* translator: in sentence warning: 123 errors
ignored... */
+ AH->n_errors, AH->n_errors>1? _("errors"): _("error"));
+
CloseArchive(AH);
return 0;
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly