From 2a67852ccf1c07bd7e0c017d5d9250f6a01789f3 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 20 Nov 2026 11:01:07 -0600 Subject: [PATCH v2 1/1] pg_restore: Fix incompatibilities with extracted tar dumps. Extracting a tar-format archive is supposed to produce a valid directory-format archive. Each BLOBS entry in the archive's table of contents (TOC) names a file that lists the large objects to restore, but the tar format puts the wrong file name into these entries. As a result, pg_restore fails to restore large objects from an extracted tar archive, and parallel restore can't estimate their size. To fix, construct the file name instead of using the one in the TOC entry, as commit 166b4f4560 did for directory-format archives made by versions before v12. This commit doesn't change the name recorded by the tar format, as that wouldn't help with existing archives. Reviewed-by: Sami Imseih Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/av9o1Fi3PQ-jqmGO%40nathan Backpatch-through: 15 --- src/bin/pg_dump/pg_backup_directory.c | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c index 34b3b6ba7d7..ddd162ece3d 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]; @@ -409,14 +408,23 @@ _LoadLOs(ArchiveHandle *AH, TocEntry *te) /* * Note: before archive v16, there was always only one BLOBS TOC entry, * now there can be multiple. Furthermore, although the actual filename - * was always "blobs.toc" before v16, the value of tctx->filename did not + * was always "blobs.toc" before v16, the TOC entry's 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 the TOC entry, + * 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 tmp[MAXPGPATH]; + + snprintf(tmp, MAXPGPATH, "blobs_%d.toc", te->dumpId); + setFilePath(AH, tocfname, tmp); + } CFH = ctx->LOsTocFH = InitDiscoverCompressFileHandle(tocfname, PG_BINARY_R); @@ -735,8 +743,21 @@ _PrepParallelRestore(ArchiveHandle *AH) * using compression, the physical file size might not be a very good * guide to the amount of work involved in restoring the file, but we * only need an approximate indicator of that. + * + * Note that we can't rely on tctx->filename for BLOBS entries (see + * _LoadLOs()). */ - setFilePath(AH, fname, tctx->filename); + if (strcmp(te->desc, "BLOBS") != 0) + setFilePath(AH, fname, tctx->filename); + else if (AH->version < K_VERS_1_16) + setFilePath(AH, fname, "blobs.toc"); + else + { + char tmp[MAXPGPATH]; + + snprintf(tmp, MAXPGPATH, "blobs_%d.toc", te->dumpId); + setFilePath(AH, fname, tmp); + } if (stat(fname, &st) == 0) te->dataLength = st.st_size; -- 2.55.0