pg_restore fails on extracted tar archives with large objects

Started by Nathan Bossart5 days ago6 messageshackers
Jump to latest
#1Nathan Bossart
nathandbossart@gmail.com

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:

t259507_1
v1-0001-pg_restore-Fix-incompatibility-with-extracted-tar.patchtext/plain; charset=us-asciiDownload+10-3
#2Sami Imseih
samimseih.pg@gmail.com
In reply to: Nathan Bossart (#1)
Re: pg_restore fails on extracted tar archives with large objects

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

#3Bertrand Drouvot
bertranddrouvot.pg@gmail.com
In reply to: Nathan Bossart (#1)
Re: pg_restore fails on extracted tar archives with large objects

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

#4Nathan Bossart
nathandbossart@gmail.com
In reply to: Bertrand Drouvot (#3)
Re: pg_restore fails on extracted tar archives with large objects

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:

t259507_4
v2-0001-pg_restore-Fix-incompatibilities-with-extracted-t.patchtext/plain; charset=us-asciiDownload+25-5
#5Bertrand Drouvot
bertranddrouvot.pg@gmail.com
In reply to: Nathan Bossart (#4)
Re: pg_restore fails on extracted tar archives with large objects

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

#6Nathan Bossart
nathandbossart@gmail.com
In reply to: Bertrand Drouvot (#5)
Re: pg_restore fails on extracted tar archives with large objects

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