[PATCH] Several refactorings for pg_dump

Started by Aleksander Alekseev3 months ago8 messageshackers
Jump to latest
#1Aleksander Alekseev
aleksander@tigerdata.com

Hi,

While examining pg_dump code I found some room for improvement:

1. I found a write-only field ArchiveHandle.lookaheadSize which can
safely be removed.
2. I found magic constants 512 which should be replaced with TAR_BLOCK_SIZE.

Patches are attached.

--
Best regards,
Aleksander Alekseev

Attachments:

t253472_1
v1-0001-pg_dump-remove-unused-ArchiveHandle.lookaheadSize.patchtext/x-patch; charset=US-ASCII; name=v1-0001-pg_dump-remove-unused-ArchiveHandle.lookaheadSize.patchDownload+0-3
v1-0002-pg_dump-use-TAR_BLOCK_SIZE-instead-of-a-hardcoded.patchtext/x-patch; charset=US-ASCII; name=v1-0002-pg_dump-use-TAR_BLOCK_SIZE-instead-of-a-hardcoded.patchDownload+5-5
#2Michael Paquier
michael@paquier.xyz
In reply to: Aleksander Alekseev (#1)
Re: [PATCH] Several refactorings for pg_dump

On Tue, Aug 18, 2026 at 06:10:45PM +0300, Aleksander Alekseev wrote:

1. I found a write-only field ArchiveHandle.lookaheadSize which can
safely be removed.
2. I found magic constants 512 which should be replaced with TAR_BLOCK_SIZE.

Sounds like an acceptable set of cleanups here.
--
Michael

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Aleksander Alekseev (#1)
Re: [PATCH] Several refactorings for pg_dump

On 18 Aug 2026, at 17:10, Aleksander Alekseev <aleksander@tigerdata.com> wrote:

1. I found a write-only field ArchiveHandle.lookaheadSize which can
safely be removed.
2. I found magic constants 512 which should be replaced with TAR_BLOCK_SIZE.

Might be a nitpick, but I'm not sure that using TAR_BLOCK_SIZE is preferred for
a lookahead buffer used to identify the archive format where tar is just one of
the options.

I would be more inclined to initialize .lookaheadSize like today and then use
that instead of the hardcoded 512. Having a buffer in ArchiveHandle without
knowing the size of it does seem like a bad practice even if nothing uses it
today.

--
Daniel Gustafsson

#4Aleksander Alekseev
aleksander@tigerdata.com
In reply to: Daniel Gustafsson (#3)
Re: [PATCH] Several refactorings for pg_dump

Hi Daniel,

I'm not sure that using TAR_BLOCK_SIZE is preferred for
a lookahead buffer used to identify the archive format where tar is just one of
the options.

I would be more inclined to initialize .lookaheadSize like today and then use
that instead of the hardcoded 512. Having a buffer in ArchiveHandle without
knowing the size of it does seem like a bad practice even if nothing uses it
today.

Sounds good. Here is the patch v2.

--
Best regards,
Aleksander Alekseev

Attachments:

t253472_4
v2-0001-pg_dump-use-ArchiveHandle.lookaheadSize-instead-o.patchtext/x-patch; charset=US-ASCII; name=v2-0001-pg_dump-use-ArchiveHandle.lookaheadSize-instead-o.patchDownload+5-5
#5Michael Paquier
michael@paquier.xyz
In reply to: Aleksander Alekseev (#4)
Re: [PATCH] Several refactorings for pg_dump

On Thu, Aug 20, 2026 at 03:53:26PM +0300, Aleksander Alekseev wrote:

Sounds good. Here is the patch v2.

LGTM, at quick glance.
--
Michael

#6Daniel Gustafsson
daniel@yesql.se
In reply to: Aleksander Alekseev (#4)
Re: [PATCH] Several refactorings for pg_dump

On 20 Aug 2026, at 14:53, Aleksander Alekseev <aleksander@tigerdata.com> wrote:

Hi Daniel,

I'm not sure that using TAR_BLOCK_SIZE is preferred for
a lookahead buffer used to identify the archive format where tar is just one of
the options.

I would be more inclined to initialize .lookaheadSize like today and then use
that instead of the hardcoded 512. Having a buffer in ArchiveHandle without
knowing the size of it does seem like a bad practice even if nothing uses it
today.

Sounds good. Here is the patch v2.

Seems reasonable. Are there any consumers of the buffer who hardcode an
assumption of its size which could use .lookaheadSize instead? I'll revist
this on Sunday when I get back in the office unless beaten to it.

--
Daniel Gustafsson

#7Michael Paquier
michael@paquier.xyz
In reply to: Daniel Gustafsson (#6)
Re: [PATCH] Several refactorings for pg_dump

On Fri, Aug 21, 2026 at 08:28:52AM +0200, Daniel Gustafsson wrote:

Seems reasonable. Are there any consumers of the buffer who hardcode an
assumption of its size which could use .lookaheadSize instead? I'll revist
this on Sunday when I get back in the office unless beaten to it.

Please feel free to not wait for me. Thanks!
--
Michael

#8Daniel Gustafsson
daniel@yesql.se
In reply to: Michael Paquier (#7)
Re: [PATCH] Several refactorings for pg_dump

On 22 Aug 2026, at 01:52, Michael Paquier <michael@paquier.xyz> wrote:

On Fri, Aug 21, 2026 at 08:28:52AM +0200, Daniel Gustafsson wrote:

Seems reasonable. Are there any consumers of the buffer who hardcode an
assumption of its size which could use .lookaheadSize instead? I'll revist
this on Sunday when I get back in the office unless beaten to it.

Please feel free to not wait for me. Thanks!

Committed, thanks.

--
Daniel Gustafsson