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

Commitec7c4c1

Browse files
committed
Please find attached a small patch so that "pg_restore" ignores some sql
errors. This is the second submission, which integrates Tom comments aboutlocalisation and exit code. I also added some comments about one sqlcommand which is not ignored.Fabien COELHO
1 parentbe6bbce commitec7c4c1

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

‎src/bin/pg_dump/pg_backup.h

Lines changed: 6 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.29 2004/03/24 03:06:08 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.30 2004/04/22 02:39:09 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -57,6 +57,11 @@ typedef struct _Archive
5757
intremoteVersion;
5858
intminRemoteVersion;
5959
intmaxRemoteVersion;
60+
61+
/* error handling */
62+
booldie_on_errors;/* whether to die on sql errors... */
63+
intn_errors;/* number of errors (if no die) */
64+
6065
/* The rest is private */
6166
}Archive;
6267

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 30 additions & 5 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.85 2004/03/24 03:06:08 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.86 2004/04/22 02:39:10 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1197,6 +1197,24 @@ die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
11971197
va_end(ap);
11981198
}
11991199

1200+
/* on some error, we may decide to go on... */
1201+
void
1202+
warn_or_die_horribly(ArchiveHandle*AH,
1203+
constchar*modulename,constchar*fmt, ...)
1204+
{
1205+
va_listap;
1206+
va_start(ap,fmt);
1207+
if (AH->public.die_on_errors)
1208+
{
1209+
_die_horribly(AH,modulename,fmt,ap);
1210+
}
1211+
else
1212+
{
1213+
_write_msg(modulename,fmt,ap);
1214+
AH->public.n_errors++;
1215+
}
1216+
va_end(ap);
1217+
}
12001218

12011219
staticvoid
12021220
_moveAfter(ArchiveHandle*AH,TocEntry*pos,TocEntry*te)
@@ -1651,6 +1669,10 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
16511669
die_horribly(AH,modulename,"unrecognized file format \"%d\"\n",fmt);
16521670
}
16531671

1672+
/* sql error handling */
1673+
AH->public.die_on_errors= true;
1674+
AH->public.n_errors=0;
1675+
16541676
returnAH;
16551677
}
16561678

@@ -2011,6 +2033,7 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
20112033
res=PQexec(AH->connection,cmd->data);
20122034

20132035
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
2036+
/* NOT warn_or_die_horribly... use -O instead to skip this. */
20142037
die_horribly(AH,modulename,"could not set session user to \"%s\": %s",
20152038
user,PQerrorMessage(AH->connection));
20162039

@@ -2042,8 +2065,9 @@ _doSetWithOids(ArchiveHandle *AH, const bool withOids)
20422065
res=PQexec(AH->connection,cmd->data);
20432066

20442067
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
2045-
die_horribly(AH,modulename,"could not set default_with_oids: %s",
2046-
PQerrorMessage(AH->connection));
2068+
warn_or_die_horribly(AH,modulename,
2069+
"could not set default_with_oids: %s",
2070+
PQerrorMessage(AH->connection));
20472071

20482072
PQclear(res);
20492073
}
@@ -2181,8 +2205,9 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
21812205
res=PQexec(AH->connection,qry->data);
21822206

21832207
if (!res||PQresultStatus(res)!=PGRES_COMMAND_OK)
2184-
die_horribly(AH,modulename,"could not set search_path to \"%s\": %s",
2185-
schemaName,PQerrorMessage(AH->connection));
2208+
warn_or_die_horribly(AH,modulename,
2209+
"could not set search_path to \"%s\": %s",
2210+
schemaName,PQerrorMessage(AH->connection));
21862211

21872212
PQclear(res);
21882213
}

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.57 2004/03/24 03:06:08 momjian Exp $
20+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.58 2004/04/22 02:39:10 momjian Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -281,6 +281,7 @@ typedef struct _tocEntry
281281
externconstchar*progname;
282282

283283
externvoiddie_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(printf,3,4)));
284+
externvoidwarn_or_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(printf,3,4)));
284285
externvoidwrite_msg(constchar*modulename,constchar*fmt,...) __attribute__((format(printf,2,3)));
285286

286287
externvoidWriteTOC(ArchiveHandle*AH);

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.52 2004/03/03 21:28:54 tgl Exp $
8+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.53 2004/04/22 02:39:10 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -316,8 +316,8 @@ _executeSqlCommand(ArchiveHandle *AH, PGconn *conn, PQExpBuffer qry, char *desc)
316316
AH->pgCopyIn=1;
317317
}
318318
else
319-
die_horribly(AH,modulename,"%s: %s",
320-
desc,PQerrorMessage(AH->connection));
319+
warn_or_die_horribly(AH,modulename,"%s: %s",
320+
desc,PQerrorMessage(AH->connection));
321321
}
322322

323323
PQclear(res);

‎src/bin/pg_dump/pg_restore.c

Lines changed: 16 additions & 2 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.55 2003/12/06 03:00:16 tgl Exp $
37+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.56 2004/04/22 02:39:10 momjian Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -77,6 +77,7 @@ main(int argc, char **argv)
7777
{
7878
RestoreOptions*opts;
7979
intc;
80+
intexit_code;
8081
Archive*AH;
8182
char*inputFileSpec;
8283
externintoptind;
@@ -323,6 +324,11 @@ main(int argc, char **argv)
323324
/* Let the archiver know how noisy to be */
324325
AH->verbose=opts->verbose;
325326

327+
/* restore keeps submitting sql commands as "pg_restore ... | psql ... "
328+
* this behavior choice could be turned into an option.
329+
*/
330+
AH->die_on_errors= false;
331+
326332
if (opts->tocFile)
327333
SortTocFromFile(AH,opts);
328334

@@ -331,9 +337,17 @@ main(int argc, char **argv)
331337
else
332338
RestoreArchive(AH,opts);
333339

340+
/* done, print a summary of ignored errors */
341+
if (AH->n_errors)
342+
fprintf(stderr,_("WARNING, errors ignored on restore: %d\n"),
343+
AH->n_errors);
344+
345+
/* AH may be freed in CloseArchive? */
346+
exit_code=AH->n_errors?1:0;
347+
334348
CloseArchive(AH);
335349

336-
return0;
350+
returnexit_code;
337351
}
338352

339353
staticvoid

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp