Use TEXT_DUMP_HEADER macro instead of hard-coded string in pg_backup_archiver.c

Started by Japin Li3 months ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t139825
psql -h localhost -U postgres

Built from patchset v3 (message #3), July 28, 2026 at 03:04 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t139825_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t139825_3 && git checkout t139825_3

Patchset v3 (message #3) is on t139825_3

Jump to latest
#1Japin Li
japinli@hotmail.com

Hi,

I noticed that in pg_backup_archiver.c, RestoreArchive() writes the dump header
using a hard-coded string:

ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");

However, the macro TEXT_DUMP_HEADER (defined in the same file) already contains
exactly the same content. To keep the code consistent and maintainable, this
patch replaces the hard-coded string with the macro.

A hard-coded version of TEXT_DUMPALL_HEADER exists in pg_dumpall.c, but since
it spans multiple files, it is left untouched.

--
Regards,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.

Attachments:

v1-0001-Use-TEXT_DUMP_HEADER-instead-of-hard-coded-dump-h.patchtext/x-patchDownload+1-2
#2Daniel Gustafsson
daniel@yesql.se
In reply to: Japin Li (#1)
Re: Use TEXT_DUMP_HEADER macro instead of hard-coded string in pg_backup_archiver.c

On 3 Jun 2026, at 09:58, Japin Li <japinli@hotmail.com> wrote:

Hi,

I noticed that in pg_backup_archiver.c, RestoreArchive() writes the dump header
using a hard-coded string:

ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");

However, the macro TEXT_DUMP_HEADER (defined in the same file) already contains
exactly the same content. To keep the code consistent and maintainable, this
patch replaces the hard-coded string with the macro.

Seems reasonable.

A hard-coded version of TEXT_DUMPALL_HEADER exists in pg_dumpall.c, but since
it spans multiple files, it is left untouched.

The alternative would be to move the definitions to pg_backup_archiver.h and
use them consistently.

--
Daniel Gustafsson

#3Japin Li
japinli@hotmail.com
In reply to: Daniel Gustafsson (#2)
Re: Use TEXT_DUMP_HEADER macro instead of hard-coded string in pg_backup_archiver.c

Hi, Daniel

On Wed, 03 Jun 2026 at 10:14, Daniel Gustafsson <daniel@yesql.se> wrote:

On 3 Jun 2026, at 09:58, Japin Li <japinli@hotmail.com> wrote:

Hi,

I noticed that in pg_backup_archiver.c, RestoreArchive() writes the dump header
using a hard-coded string:

ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");

However, the macro TEXT_DUMP_HEADER (defined in the same file) already contains
exactly the same content. To keep the code consistent and maintainable, this
patch replaces the hard-coded string with the macro.

Seems reasonable.

Thanks for your review.

A hard-coded version of TEXT_DUMPALL_HEADER exists in pg_dumpall.c, but since
it spans multiple files, it is left untouched.

The alternative would be to move the definitions to pg_backup_archiver.h and
use them consistently.

Fixed as you suggested.

--
Daniel Gustafsson

--
Regards,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.

Attachments:

t139825_3
v2-0001-Replace-the-hard-coded-dump-headers-with-macros.patchtext/x-patchDownload+4-4