From: Nathan Bossart <nathandbossart@gmail.com>
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: pgsql-hackers@postgresql.org
Subject: Re: pg_restore fails on extracted tar archives with large objects
Date: Fri, 20 Nov 2026 11:03:04 -0600
Message-ID: <awB9SALtymS9VpGp@nathan> (raw)
In-Reply-To: <av//A7/fudljFB52@bdtpg>
References: <av9o1Fi3PQ-jqmGO@nathan>
<av//A7/fudljFB52@bdtpg>
On Fri, Nov 20, 2026 at 08:04:19AM +0000, Bertrand Drouvot wrote:
> It looks like _PrepParallelRestore() is affected by the same issue. The stat()
> fails, leaving the BLOBS entry’s dataLength at zero, so the parallel scheduler
> cannot use the intended size estimate. Should this use the same filename
> construction as _LoadLOs()?
Good catch. Here's an updated patch.
--
nathan
Attachments:v2-0001-pg_restore-Fix-incompatibilities-with-extracted-t.patch (text/plain, 3.5K) download
From 2a67852ccf1c07bd7e0c017d5d9250f6a01789f3 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathan@postgresql.org>
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 <samimseih.pg@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
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.cindex 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_<dumpId>.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, bertranddrouvot.pg@gmail.com
Subject: Re: pg_restore fails on extracted tar archives with large objects
In-Reply-To: <awB9SALtymS9VpGp@nathan>
References: <av9o1Fi3PQ-jqmGO@nathan> <av//A7/fudljFB52@bdtpg> <awB9SALtymS9VpGp@nathan>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox