From a1f54aa34f39756173de63e8528ac248c340c6bb Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Thu, 19 Nov 2026 15:14:58 -0600 Subject: [PATCH v1 1/1] pg_restore: Fix incompatibility with extracted tar dumps. pg_restore fails to restore large objects from a directory-format archive that was created by extracting a tar-format archive. That's because the tar format puts the wrong file name into the BLOBS TOC entries. This was harmless before v17, because we ignored the file name field. Commit 166b4f4560 fixed the same problem for directory-format archives made by versions before v12. To fix, construct the file name instead of using the one in the TOC entry, as we already do for those older archives. This commit doesn't change the name recorded by the tar format, as that wouldn't help with existing archives. Oversight in commit a45c78e328. Backpatch-through: 17 --- src/bin/pg_dump/pg_backup_directory.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c index 34b3b6ba7d7..e14369181f4 100644 --- a/src/bin/pg_dump/pg_backup_directory.c +++ b/src/bin/pg_dump/pg_backup_directory.c @@ -399,7 +399,6 @@ _LoadLOs(ArchiveHandle *AH, TocEntry *te) { Oid oid; lclContext *ctx = (lclContext *) AH->formatData; - lclTocEntry *tctx = (lclTocEntry *) te->formatData; CompressFileHandle *CFH; char tocfname[MAXPGPATH]; char line[MAXPGPATH]; @@ -412,11 +411,20 @@ _LoadLOs(ArchiveHandle *AH, TocEntry *te) * was always "blobs.toc" before v16, the value of tctx->filename did not * match that before commit 548e50976 fixed it. For simplicity we assume * it must be "blobs.toc" in all archives before v16. + * + * Likewise, the tar format puts the wrong filename into tctx->filename, + * which matters when reading an extracted tar archive. For simplicity we + * assume it must be "blobs_.toc" in all newer archives. */ if (AH->version < K_VERS_1_16) setFilePath(AH, tocfname, "blobs.toc"); else - setFilePath(AH, tocfname, tctx->filename); + { + char fname[MAXPGPATH]; + + snprintf(fname, MAXPGPATH, "blobs_%d.toc", te->dumpId); + setFilePath(AH, tocfname, fname); + } CFH = ctx->LOsTocFH = InitDiscoverCompressFileHandle(tocfname, PG_BINARY_R); -- 2.55.0