Skip second WriteToc() call for custom-format dumps without data.
authorNathan Bossart <[email protected]>
Fri, 4 Apr 2025 19:51:08 +0000 (14:51 -0500)
committerNathan Bossart <[email protected]>
Fri, 4 Apr 2025 19:51:08 +0000 (14:51 -0500)
Presently, "pg_dump --format=custom" calls WriteToc() twice.  The
second call updates the data offset information, which allegedly
makes parallel pg_restore significantly faster.  However, if we're
not dumping any data, there are no data offsets to update, so we
can skip this step.

Reviewed-by: Jeff Davis <[email protected]>
Discussion: https://postgr.es/m/Z9c1rbzZegYQTOQE%40nathan

src/bin/pg_dump/pg_backup_custom.c

index e44b887eb29bdbec2b5c8cce51dec98da303dc94..f7c3af56304ce3116a1f5862e4ebb6c14cebd205 100644 (file)
@@ -755,9 +755,11 @@ _CloseArchive(ArchiveHandle *AH)
         * If possible, re-write the TOC in order to update the data offset
         * information.  This is not essential, as pg_restore can cope in most
         * cases without it; but it can make pg_restore significantly faster
-        * in some situations (especially parallel restore).
+        * in some situations (especially parallel restore).  We can skip this
+        * step if we're not dumping any data; there are no offsets to update
+        * in that case.
         */
-       if (ctx->hasSeek &&
+       if (ctx->hasSeek && AH->public.dopt->dumpData &&
            fseeko(AH->FH, tpos, SEEK_SET) == 0)
            WriteToc(AH);
    }