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

Commit8e4057c

Browse files
committed
Fix pg_restore to properly discard COPY data when trying to continue
after an error in a COPY statement. Formerly it thought the COPY datawas SQL commands, and got quite confused.Stephen Frost
1 parentdb5e39b commit8e4057c

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

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_archiver.c,v 1.119 2006/01/21 02:16:20 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.120 2006/02/05 20:58:47 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -330,10 +330,15 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
330330
* with libpq.
331331
*/
332332
if (te->copyStmt&&strlen(te->copyStmt)>0)
333+
{
333334
ahprintf(AH,"%s",te->copyStmt);
335+
AH->writingCopyData= true;
336+
}
334337

335338
(*AH->PrintTocDataPtr) (AH,te,ropt);
336339

340+
AH->writingCopyData= false;
341+
337342
_enableTriggersIfNecessary(AH,te,ropt);
338343
}
339344
}

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 3 additions & 2 deletions
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.68 2005/10/15 02:49:38 momjian Exp $
20+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.69 2006/02/05 20:58:47 tgl Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -239,7 +239,8 @@ typedef struct _archiveHandle
239239
PGconn*connection;
240240
intconnectToDB;/* Flag to indicate if direct DB connection is
241241
* required */
242-
intpgCopyIn;/* Currently in libpq 'COPY IN' mode. */
242+
boolwritingCopyData;/* True when we are sending COPY data */
243+
boolpgCopyIn;/* Currently in libpq 'COPY IN' mode. */
243244
PQExpBufferpgCopyBuf;/* Left-over data from incomplete lines in
244245
* COPY IN */
245246

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 21 additions & 11 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.66 2005/10/15 02:49:38 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.67 2006/02/05 20:58:47 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -302,7 +302,7 @@ ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc)
302302
{
303303
if (PQresultStatus(res)==PGRES_COPY_IN)
304304
{
305-
AH->pgCopyIn=1;
305+
AH->pgCopyIn=true;
306306
}
307307
else
308308
{
@@ -383,13 +383,12 @@ _sendCopyLine(ArchiveHandle *AH, char *qry, char *eos)
383383
appendPQExpBuffer(AH->pgCopyBuf,"%s\n",qry);
384384
isEnd= (strcmp(AH->pgCopyBuf->data,"\\.\n")==0);
385385

386-
/*---------
387-
*fprintf(stderr, "Sending '%s' via
388-
*COPY(at end = %d)\n\n", AH->pgCopyBuf->data, isEnd);
389-
*---------
386+
/*
387+
*Note that we drop the data on the floor if libpq has failed to
388+
* enterCOPYmode; this allows us to behave reasonably when trying
389+
* to continue after an error in a COPY command.
390390
*/
391-
392-
if (PQputline(AH->connection,AH->pgCopyBuf->data)!=0)
391+
if (AH->pgCopyIn&&PQputline(AH->connection,AH->pgCopyBuf->data)!=0)
393392
die_horribly(AH,modulename,"error returned by PQputline\n");
394393

395394
resetPQExpBuffer(AH->pgCopyBuf);
@@ -400,10 +399,10 @@ _sendCopyLine(ArchiveHandle *AH, char *qry, char *eos)
400399

401400
if (isEnd)
402401
{
403-
if (PQendcopy(AH->connection)!=0)
402+
if (AH->pgCopyIn&&PQendcopy(AH->connection)!=0)
404403
die_horribly(AH,modulename,"error returned by PQendcopy\n");
405404

406-
AH->pgCopyIn=0;
405+
AH->pgCopyIn=false;
407406
}
408407

409408
returnqry+loc+1;
@@ -615,7 +614,18 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, size_t bufLen)
615614
/* Could switch between command and COPY IN mode at each line */
616615
while (qry<eos)
617616
{
618-
if (AH->pgCopyIn)
617+
/*
618+
* If libpq is in CopyIn mode *or* if the archive structure shows we
619+
* are sending COPY data, treat the data as COPY data. The pgCopyIn
620+
* check is only needed for backwards compatibility with ancient
621+
* archive files that might just issue a COPY command without marking
622+
* it properly. Note that in an archive entry that has a copyStmt,
623+
* all data up to the end of the entry will go to _sendCopyLine, and
624+
* therefore will be dropped if libpq has failed to enter COPY mode.
625+
* Also, if a "\." data terminator is found, anything remaining in the
626+
* archive entry will be dropped.
627+
*/
628+
if (AH->pgCopyIn||AH->writingCopyData)
619629
qry=_sendCopyLine(AH,qry,eos);
620630
else
621631
qry=_sendSQLLine(AH,qry,eos);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp