]> granicus.if.org Git - postgresql/commitdiff
Fix pg_restore's processing of old-style BLOB COMMENTS data.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 13 Jun 2014 00:14:52 +0000 (20:14 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 13 Jun 2014 00:14:52 +0000 (20:14 -0400)
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.

src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dump.c

index d34631623ad6301c72e372bceeb814dd71153720..d3f12430dd3789e26d72754bc3bbb80518ea6914 100644 (file)
@@ -566,7 +566,13 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
 
                                        _selectOutputSchema(AH, "pg_catalog");
 
+                                       /* Send BLOB COMMENTS data to ExecuteSimpleCommands() */
+                                       if (strcmp(te->desc, "BLOB COMMENTS") == 0)
+                                               AH->outputKind = OUTPUT_OTHERDATA;
+
                                        (*AH->PrintTocDataPtr) (AH, te, ropt);
+
+                                       AH->outputKind = OUTPUT_SQLCMDS;
                                }
                                else
                                {
index 36e1f6e1c4ab0b53133bd97f712b94b391c5616e..e06bf96d047f87c6258a8498029c761c738b26e4 100644 (file)
@@ -383,9 +383,14 @@ ExecuteSqlCommand(ArchiveHandle *AH, const char *qry, const char *desc)
  * identifiers, so that we can recognize statement-terminating semicolons.
  * We assume that INSERT data will not contain SQL comments, E'' literals,
  * or dollar-quoted strings, so this is much simpler than a full SQL lexer.
+ *
+ * Note: when restoring from a pre-9.0 dump file, this code is also used to
+ * process BLOB COMMENTS data, which has the same problem of containing
+ * multiple SQL commands that might be split across bufferloads.  Fortunately,
+ * that data won't contain anything complicated to lex either.
  */
 static void
-ExecuteInsertCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
+ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
 {
        const char *qry = buf;
        const char *eos = buf + bufLen;
@@ -469,9 +474,10 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen)
        else if (AH->outputKind == OUTPUT_OTHERDATA)
        {
                /*
-                * Table data expressed as INSERT commands.
+                * Table data expressed as INSERT commands; or, in old dump files,
+                * BLOB COMMENTS data (which is expressed as COMMENT ON commands).
                 */
-               ExecuteInsertCommands(AH, buf, bufLen);
+               ExecuteSimpleCommands(AH, buf, bufLen);
        }
        else
        {
index c6441027e4255b2189383d167c234fcddcc8d354..53a513eff979f6fd53067114dbdd4eca7a231166 100644 (file)
@@ -1244,7 +1244,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
  *
  * Caution: when we restore from an archive file direct to database, the
  * INSERT commands emitted by this function have to be parsed by
- * pg_backup_db.c's ExecuteInsertCommands(), which will not handle comments,
+ * pg_backup_db.c's ExecuteSimpleCommands(), which will not handle comments,
  * E'' strings, or dollar-quoted strings.  So don't emit anything like that.
  */
 static int