aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_archiver.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-01-06 13:04:15 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-01-06 13:04:15 -0500
commit522650a6e4516763bcc902c18ac371f50809abb3 (patch)
treec6331a722452d5e6f76b8afd42e2a063d6bde246 /src/bin/pg_dump/pg_backup_archiver.c
parentf9f04845045086feb1144f52cc2911e9f08efe3f (diff)
downloadpostgresql-522650a6e4516763bcc902c18ac371f50809abb3.tar.gz
postgresql-522650a6e4516763bcc902c18ac371f50809abb3.zip
Fix pg_restore's direct-to-database mode for INSERT-style table data.
In commit 6545a901aaf84cb05212bb6a7674059908f527c3, I removed the mini SQL lexer that was in pg_backup_db.c, thinking that it had no real purpose beyond separating COPY data from SQL commands, which purpose had been obsoleted by long-ago fixes in pg_dump's archive file format. Unfortunately this was in error: that code was also used to identify command boundaries in INSERT-style table data, which is run together as a single string in the archive file for better compressibility. As a result, direct-to-database restores from archive files made with --inserts or --column-inserts fail in our latest releases, as reported by Dick Visser. To fix, restore the mini SQL lexer, but simplify it by adjusting the calling logic so that it's only required to cope with INSERT-style table data, not arbitrary SQL commands. This allows us to not have to deal with SQL comments, E'' strings, or dollar-quoted strings, none of which have ever been emitted by dumpTableData_insert. Also, fix the lexer to cope with standard-conforming strings, which was the actual bug that the previous patch was meant to solve. Back-patch to all supported branches. The previous patch went back to 8.2, which unfortunately means that the EOL release of 8.2 contains this bug, but I don't think we're doing another 8.2 release just because of that.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 62206ecda4d..729cc6b5613 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -617,20 +617,20 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
if (te->copyStmt && strlen(te->copyStmt) > 0)
{
ahprintf(AH, "%s", te->copyStmt);
- AH->writingCopyData = true;
+ AH->outputKind = OUTPUT_COPYDATA;
}
+ else
+ AH->outputKind = OUTPUT_OTHERDATA;
(*AH->PrintTocDataPtr) (AH, te, ropt);
/*
* Terminate COPY if needed.
*/
- if (AH->writingCopyData)
- {
- if (RestoringToDB(AH))
- EndDBCopyMode(AH, te);
- AH->writingCopyData = false;
- }
+ if (AH->outputKind == OUTPUT_COPYDATA &&
+ RestoringToDB(AH))
+ EndDBCopyMode(AH, te);
+ AH->outputKind = OUTPUT_SQLCMDS;
/* close out the transaction started above */
if (is_parallel && te->created)
@@ -2006,6 +2006,8 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
AH->mode = mode;
AH->compression = compression;
+ memset(&(AH->sqlparse), 0, sizeof(AH->sqlparse));
+
/* Open stdout with no compression for AH output handle */
AH->gzOut = 0;
AH->OF = stdout;
@@ -4209,7 +4211,8 @@ CloneArchive(ArchiveHandle *AH)
die_horribly(AH, modulename, "out of memory\n");
memcpy(clone, AH, sizeof(ArchiveHandle));
- /* Handle format-independent fields ... none at the moment */
+ /* Handle format-independent fields */
+ memset(&(clone->sqlparse), 0, sizeof(clone->sqlparse));
/* The clone will have its own connection, so disregard connection state */
clone->connection = NULL;
@@ -4242,7 +4245,9 @@ DeCloneArchive(ArchiveHandle *AH)
/* Clear format-specific state */
(AH->DeClonePtr) (AH);
- /* Clear state allocated by CloneArchive ... none at the moment */
+ /* Clear state allocated by CloneArchive */
+ if (AH->sqlparse.curCmd)
+ destroyPQExpBuffer(AH->sqlparse.curCmd);
/* Clear any connection-local state */
if (AH->currUser)