Re: [PATCH 0/2] Parallelizing the archiver

From: Stepan Neretin <slpmcf(at)gmail(dot)com>
To: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH 0/2] Parallelizing the archiver
Date: 2026-11-28 19:23:54
Message-ID: CA+Yyo5TG17+M0DCCpAD1fMnJC9izyrrMBh6zjCyuohEdOiFZOw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Nov 29, 2026 at 12:33 AM Stepan Neretin <slpmcf(at)gmail(dot)com> wrote:

>
>
> On Mon, Nov 23, 2026 at 2:47 PM Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
> wrote:
>
>> Hi Stepan,
>>
>> On November 22, 2026, Stepan Neretin wrote:
>> > with pgarch feeding file names and getting
>> > completed or failed files back one by one?
>>
>> Yes, that is still the direction I'd prefer. I'd like us to consider
>> the archive/restore interface more broadly than parallel execution of
>> archive_command.
>>
>> One missing piece is distinguishing a missing file from a failed
>> attempt to check or retrieve it. We use restore_command results to
>> discover timelines. Today, an ordinary command failure followed by a
>> missing local history file makes existsTimeLineHistory() return false.
>> An unavailable archive can therefore look like an unused timeline ID.
>> PostgreSQL needs to distinguish not-found from retryable and
>> non-retryable errors, rather than infer all of that from success or
>> failure of a shell command. That is a correctness issue, not a
>> throughput optimization.
>>
>> For archiving, I'd like a stream of ready files and independent
>> per-file acknowledgments, without waiting for a whole batch. Completion
>> can be out of order. The contract should distinguish a file being
>> durably archived from merely being queued, and describe retry behavior.
>> Your submit/poll callbacks look like a useful starting point.
>>
>> Tools such as WAL-G and pgBackRest already implement parallelism behind
>> the synchronous API. In WAL-G we predict adjacent .ready names to avoid
>> directory scans, periodically scan for missed or failed uploads, and
>> make our own scheduling decisions. PostgreSQL still sees what looks
>> like a request to push one file. I'd rather give these tools the
>> information they need than make them reconstruct it from archive_status.
>>
>> I'd also like PostgreSQL to control archive/restore concurrency limits
>> and select work, while leaving execution to the tool. For example,
>> WAL-G prefetch guesses subsequent segment names and can issue useless
>> requests on the old timeline near a switch. When PostgreSQL already has
>> the relevant history, it knows where that switch is. Passing the
>> intended files to the tool would avoid duplicating that knowledge.
>>
>> I don't suggest implementing all of this in one patch. Could we first
>> agree on the contract we want the async interface to support, including
>> a long-lived external process and the restore side, and then build it
>> incrementally?
>>
>> Thank you!
>>
>>
>> Best regards, Andrey Borodin.
>>
>>
>
> Hi Andrey,
>
> Thanks for the reply.
>
> I agree: stream ready files, get answers one by one, keep a long-lived
> helper, and grow the restore side later instead of doing everything at
> once.
>
> On Discord, Robert Haas and Christoph Berg said much the same about the
> jobs-pool draft. Robert did not want one short-lived child per file:
> warm connections and parallel transfer should live in one helper, or in
> a C module. Christoph wanted archive_library and a simple stdin
> protocol with per-file ok/fail answers. So please treat
> archive_command_jobs as superseded.
>
> This series is only the archive side. A module can keep the old sync
> callback, or use submit/poll/cancel. Each file comes back as success,
> retry, or fail, and only pgarch marks .done. archive_async_max limits
> how many files are in flight (default 8). For shell users there is one
> long-lived helper:
>
> -> archive\t<file>\t<path>
> <- archived\t<file>\tok|retry|fail
>
> No handshake in v1, no %f/%p, Unix only.
>
> Restore can reuse the same helper later with a second verb, plus a
> missing answer so timeline probes can tell "not in archive" from "try
> again". Something like:
>
> -> restore\t<file>\t<path>
> <- restored\t<file>\tok|missing|retry|fail
>
> Classic restore_command would stay as it is. I would rather settle the
> archive half first, then mail that as a follow-up.
>
> Attached v2:
>
> 0001 Support async archive callbacks in pgarch.
> 0002 Add persistent archive_command protocol.
> 0003 Add TAP coverage for persistent archive_command.
>
> If 0001 alone is easier to review first, I can hold the rest.
>
> Does this direction look closer?
>
> Regards,
> Stepan Neretin
>
> [1]
> https://www.postgresql.org/message-id/CA%2BYyo5TfMpUE3s%3DWKrWcaYbBWbO2VNyRnRt_5hy-VPrMhjXVWg%40mail.gmail.com
> [2]
> https://www.postgresql.org/message-id/ECB4BF94-9B6F-4A85-ADA7-4AFBD77C03CD%40yandex-team.ru
> [3] https://commitfest.postgresql.org/patch/7686/
>

Hi,

CFBot went red on Linux on the hung helper shutdown test. Debian images
use dash as /bin/sh and it forks the helper instead of executing it so
killing only the shell left the Perl process behind.

Fixed in the same series. The helper calls setsid and cancel signals
the process group. The TAP hang command ends with true so bash cannot
hide the same bug by exec.

Regards,
Stepan Neretin

Attachment Content-Type Size
0003-Add-TAP-coverage-for-persistent-archive_command.patch text/x-patch 8.6 KB
0001-Support-async-archive-callbacks-in-pgarch.patch text/x-patch 30.8 KB
0002-Add-persistent-archive_command-protocol.patch text/x-patch 24.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Stepan Neretin 2026-11-28 19:43:23 Restrict postgres_fdw/dblink passfile to user mappings
Previous Message Pierre Forstmann 2026-11-28 18:05:39 Re: gist_trgm_ops '=' operator: planner picks it over btree, ~300x slower