Re: [PATCH] Fall back to serializing when parallel apply runs out of DSM segments

From: Zhijie Hou <houzhijie22(at)gmail(dot)com>
To: Baji Shaik <baji(dot)pgdev(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Fall back to serializing when parallel apply runs out of DSM segments
Date: 2026-10-25 03:06:04
Message-ID: CAFvd2n981Sx60E-pnpn6Of2wKxX9mULAEWCa9wbcmfs3NMyGog@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Sat, Oct 24, 2026 at 1:55 AM Baji Shaik <baji(dot)pgdev(at)gmail(dot)com> wrote:
>
> Hi,
>
> When the leader apply worker launches a parallel apply worker,
> pa_setup_dsm() checks dsm_create() for NULL and returns false, and the
> caller then serializes the streamed transaction to a file and applies it
> itself. That's what the docs [1] describe for streaming = parallel: "If no
> parallel apply worker is free to handle streaming transactions then the
> changes are written to temporary files and applied after the transaction
> is committed."
>
> But dsm_create() is called with flags = 0, so it never returns NULL. If
> no DSM segment is available, it raises "too many dynamic shared memory
> segments" instead. The leader exits, restarts, and fails again at the
> same STREAM START, so replication makes no progress until segments are
> freed:
>
> ERROR: too many dynamic shared memory segments
> CONTEXT: processing remote data for replication origin "pg_16394" during message type "STREAM START" in transaction 665
> LOG: background worker "logical replication apply worker" (PID 2514) exited with exit code 1

The fix looks good to me. Without the patch, the code that returns early when
DSM setup fails would be unreachable, so this patch at least improves that.

But I'm not sure we need to change the comments above those early returns, since
it's not this internal function's place to know whether the outer side should
apply the transaction or not.

BTW, I noticed the other caller of pa_setup_dsm() in dsa.c has a similar issue:
it doesn't pass this flag but does have a check for a NULL value, so that path
is also unreachable, but that could be fixed in a separate patch.

Best Regards,
Zhijie Hou

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message xiahoumuxuan 2026-10-25 05:31:41 Re: [PATCH] Keep git-external-diff usage text from executing
Previous Message Tom Lane 2026-10-25 01:21:08 Re: PoC: true in-place major version upgrades