8000 Fix pg_restore's processing of old-style BLOB COMMENTS data. · larkly/postgres-docker@294a489 · GitHub
[go: up one dir, main page]

Skip to content

Commit 294a489

Browse files
committed
Fix pg_restore's processing of old-style BLOB COMMENTS data.
Prior to 9.0, pg_dump handled comments on large objects by dumping a bunch of COMMENT commands into a single BLOB COMMENTS archive object. With sufficiently many such comments, some of the commands would likely get split across bufferloads when restoring, causing failures in direct-to-database restores (though no problem would be evident in text output). This is the same type of issue we have with table data dumped as INSERT commands, and it can be fixed in the same way, by using a mini SQL lexer to figure out where the command boundaries are. Fortunately, the COMMENT commands are no more complex to lex than INSERTs, so we can just re-use the existing lexer for INSERTs. Per bug #10611 from Jacek Zalewski. Back-patch to all active branches.
1 parent d5ea7e6 commit 294a489

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,13 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
576576

577577
_selectOutputSchema(AH, "pg_catalog");
578578

579+
/* Send BLOB COMMENTS data to ExecuteSimpleCommands() */
580+
if (strcmp(te->desc, "BLOB COMMENTS") == 0)
581+
AH->outputKind = OUTPUT_OTHERDATA;
582+
579583
(*AH->PrintTocDataPtr) (AH, te, ropt);
584+
585+
AH->outputKind = OUTPUT_SQLCMDS;
580586
}
581587
else
582588
{

src/bin/pg_dump/pg_backup_db.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,14 @@ ExecuteSqlCommand(ArchiveHandle *AH, const char *qry, const char *desc)
383383
* identifiers, so that we can recognize statement-terminating semicolons.
384384
* We assume that INSERT data will not contain SQL comments, E'' literals,
385385
* or dollar-quoted strings, so this is much simpler than a full SQL lexer.
386+
*
387+
* Note: when restoring from a pre-9.0 dump file, this code is also used to
388+
* process BLOB COMMENTS data, which has the same problem of containing
389+
* multiple SQL commands that might be split across bufferloads. Fortunately,
390+
* that data won't contain anything complicated to lex either.
386391
*/
387392
static void
388-
ExecuteInsertCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
393+
ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
389394
{
390395
const char *qry = buf;
391396
const char *eos = buf + bufLen;
@@ -469,9 +474,10 @@ ExecuteSqlCommandBuf(ArchiveH 8000 andle *AH, const char *buf, size_t bufLen)
469474
else if (AH->outputKind == OUTPUT_OTHERDATA)
470475
{
471476
/*
472-
* Table data expressed as INSERT commands.
477+
* Table data expressed as INSERT commands; or, in old dump files,
478+
* BLOB COMMENTS data (which is expressed as COMMENT ON commands).
473479
*/
474-
ExecuteInsertCommands(AH, buf, bufLen);
480+
ExecuteSimpleCommands(AH, buf, bufLen);
475481
}
476482
else
477483
{

src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
14041404
*
14051405
* Caution: when we restore from an archive file direct to database, the
14061406
* INSERT commands emitted by this function have to be parsed by
1407-
* pg_backup_db.c's ExecuteInsertCommands(), which will not handle comments,
1407+
* pg_backup_db.c's ExecuteSimpleCommands(), which will not handle comments,
14081408
* E'' strings, or dollar-quoted strings. So don't emit anything like that.
14091409
*/
14101410
static int

0 commit comments

Comments
 (0)
0