pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_restore fails on extracted tar archives with large objects
6+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2026-11-23 5331da1dc9 24dfdcfdc2 398074af76 0b582da744 ffc0fbbd1d 732c475ff8  pg_restore: Fix incompatibilities with extracted tar dumps.
* pg_restore fails on extracted tar archives with large objects
@ 2026-11-19 21:23  Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-11-19 21:23 UTC (permalink / raw)
  To: pgsql-hackers

The following commands produce an error:

    createdb src
    createdb dst
    psql src -c "select lo_from_bytea(1, '\xff')"
    pg_dump -Ft -f d.tar src
    mkdir ex
    tar xf d.tar -C ex
    pg_restore -Fd -d dst ex

    pg_restore: error: could not open large object TOC file "ex/2966.dat" for input: No such file or directory

This is because the tar format puts NNN.dat instead of blobs_NNN.toc into
the BLOBS TOC entry.  That was harmless until commit a45c78e328 (v17)
taught the directory format's restore code to use the file name in the TOC
entry.  Commit 166b4f4560 fixed a similar problem for directory-format
dumps made by versions before v12.

The attached patch fixes it by constructing the file name instead of using
the one in the TOC entry.  Given the lack of reports, I'm guessing few
users are using extracted tar archives like this, or even using the tar
format at all.  IMHO we should seriously consider putting the tar format on
a path to deprecation, but I'll save that discussion for later.

-- 
nathan

Attachments:

v1-0001-pg_restore-Fix-incompatibility-with-extracted-tar.patch (text/plain, 2.3K) download From a1f54aa34f39756173de63e8528ac248c340c6bb Mon Sep 17 00:00:00 2001 From: Nathan Bossart <nathan@postgresql.org> 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_<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 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
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: pg_restore fails on extracted tar archives with large objects
@ 2026-11-19 23:11  Sami Imseih <samimseih.pg@gmail.com>
  parent: Nathan Bossart <nathandbossart@gmail.com>
  1 sibling, 0 replies; 6+ messages in thread

From: Sami Imseih @ 2026-11-19 23:11 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: pgsql-hackers

Hi,

> The attached patch fixes it by constructing the file name instead of using
> the one in the TOC entry.

I was able to reproduce this, and the patch fixes it for me. For
completeness I also tried multiple BLOBS batches and -j2, though I
didn't expect any problems, and directory-format dumps with large
objects still restore fine too. LGTM.

Maybe we could add a small test to 011_restore.pl, which already
pg_dumps and unpacks a tar archive, though if tar is headed for
deprecation it may not be worth the trouble atm.

--
Sami






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: pg_restore fails on extracted tar archives with large objects
@ 2026-11-20 08:04  Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  parent: Nathan Bossart <nathandbossart@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Bertrand Drouvot @ 2026-11-20 08:04 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: pgsql-hackers

Hi,

On Thu, Nov 19, 2026 at 03:23:32PM -0600, Nathan Bossart wrote:
> The following commands produce an error:
> 
>     createdb src
>     createdb dst
>     psql src -c "select lo_from_bytea(1, '\xff')"
>     pg_dump -Ft -f d.tar src
>     mkdir ex
>     tar xf d.tar -C ex
>     pg_restore -Fd -d dst ex
> 
>     pg_restore: error: could not open large object TOC file "ex/2966.dat" for input: No such file or directory
> 
> This is because the tar format puts NNN.dat instead of blobs_NNN.toc into
> the BLOBS TOC entry.  That was harmless until commit a45c78e328 (v17)
> taught the directory format's restore code to use the file name in the TOC
> entry.  Commit 166b4f4560 fixed a similar problem for directory-format
> dumps made by versions before v12.
> 
> The attached patch fixes it by constructing the file name instead of using
> the one in the TOC entry. 

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()?

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: pg_restore fails on extracted tar archives with large objects
@ 2026-11-20 17:03  Nathan Bossart <nathandbossart@gmail.com>
  parent: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Nathan Bossart @ 2026-11-20 17:03 UTC (permalink / raw)
  To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: pgsql-hackers

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.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_<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
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: pg_restore fails on extracted tar archives with large objects
@ 2026-11-20 19:41  Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  parent: Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Bertrand Drouvot @ 2026-11-20 19:41 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: pgsql-hackers

Hi,

On Fri, Nov 20, 2026 at 11:03:04AM -0600, Nathan Bossart wrote:
> 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.

Thanks for the new patch version! LGTM.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: pg_restore fails on extracted tar archives with large objects
@ 2026-11-23 18:33  Nathan Bossart <nathandbossart@gmail.com>
  parent: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-11-23 18:33 UTC (permalink / raw)
  To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: pgsql-hackers

On Fri, Nov 20, 2026 at 07:41:01PM +0000, Bertrand Drouvot wrote:
> Thanks for the new patch version! LGTM.

Committed, thanks for reviewing.

-- 
nathan






^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-11-23 18:33 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 21:23 pg_restore fails on extracted tar archives with large objects Nathan Bossart <nathandbossart@gmail.com>
2026-11-19 23:11 ` Sami Imseih <samimseih.pg@gmail.com>
2026-11-20 08:04 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-11-20 17:03   ` Nathan Bossart <nathandbossart@gmail.com>
2026-11-20 19:41     ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-11-23 18:33       ` Nathan Bossart <nathandbossart@gmail.com>

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