Warn when creating or enabling a subscription with max_logical_replication_workers = 0
Warn when creating or enabling a subscription with max_logical_replication_workers = 0
Hi, I would like to propose emitting a warning when creating or enabling a subscription while max_logical_replication_workers is set to 0. In this case, the CREATE/ALTER SUBSCRIPTION command completes successfully without any warning, making it difficult to notice that logical replication cannot start. Of course, users can confirm whether logical replication is working by checking system views such as pg_stat_replication or pg_stat_subscription. However, emitting warnings explicitly in these cases would make this situation more visible. We have seen user reports where this behavior caused confusion, with users wondering why replication did not start. I've attached a patch to address this. Regards, Yugo Nagata -- Yugo Nagata
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Wed, Feb 4, 2026 at 4:07 PM Yugo Nagata wrote: > > Hi, > > I would like to propose emitting a warning when creating or enabling a > subscription while max_logical_replication_workers is set to 0. In this > case, the CREATE/ALTER SUBSCRIPTION command completes successfully without > any warning, making it difficult to notice that logical replication cannot > start. > > Of course, users can confirm whether logical replication is working by > checking system views such as pg_stat_replication or pg_stat_subscription. > However, emitting warnings explicitly in these cases would make this > situation more visible. We have seen user reports where this behavior > caused confusion, with users wondering why replication did not start. > Hi Nagata-San. AFAIK the default for `max_logical_replication_workers` is 4. So how does the maximum get to be 0 unless the user had explicitly configured it that way? Also subscriptions require multiple workers in order to work properly [1] so why check only 0? Why not check 1 or 2 or 3.... those low numbers are also likely to cause similar problems aren't they? And what about when the `max_logical_replication_workers` is 100, but those 100 are already being used. IOW, would it be more useful to warn when you do not have enough *available* workers for the Subscription to function properly, rather than checking what the maximum value is set to? ====== [1] https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS Kind Regards, Peter Smith Fujitsu Australia
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Yugo Nagata <nagata@sraoss.co.jp>
Дата:
On Wed, 4 Feb 2026 17:26:25 +1100 Peter Smith wrote: > On Wed, Feb 4, 2026 at 4:07 PM Yugo Nagata wrote: > > > > Hi, > > > > I would like to propose emitting a warning when creating or enabling a > > subscription while max_logical_replication_workers is set to 0. In this > > case, the CREATE/ALTER SUBSCRIPTION command completes successfully without > > any warning, making it difficult to notice that logical replication cannot > > start. > > > > Of course, users can confirm whether logical replication is working by > > checking system views such as pg_stat_replication or pg_stat_subscription. > > However, emitting warnings explicitly in these cases would make this > > situation more visible. We have seen user reports where this behavior > > caused confusion, with users wondering why replication did not start. > > > > Hi Nagata-San. > > AFAIK the default for `max_logical_replication_workers` is 4. So how > does the maximum get to be 0 unless the user had explicitly configured > it that way? That's correct, but the goal here is simply to make it easier for users to be aware of this condition, since the current behavior provides no indication that replication will not start. > Also subscriptions require multiple workers in order to work properly > [1] so why check only 0? Why not check 1 or 2 or 3.... those low > numbers are also likely to cause similar problems aren't they? > > And what about when the `max_logical_replication_workers` is 100, but > those 100 are already being used. IOW, would it be more useful to warn > when you do not have enough *available* workers for the Subscription > to function properly, rather than checking what the maximum value is > set to? When max_logical_replication_workers is zero, the logical replication launcher will never start. Otherwise, it does start and emits the following warning to the server log when workers cannot be obtained: WARNING: out of logical replication worker slots HINT: You might need to increase "max_logical_replication_workers" Given this, I think it is sufficient to warn only when max_logical_replication_workers is zero. That said, this warning is currently emitted only to the server log and does not appear as a response to CREATE/ALTER SUBSCRIPTION. However, I'm not sure whether emitting a similar warning as part of the CREATE/ALTER SUBSCRIPTION response would add much value. Regards, Yugo Nagata > > ====== > [1] https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-MAX-LOGICAL-REPLICATION-WORKERS > > Kind Regards, > Peter Smith > Fujitsu Australia > > -- Yugo Nagata
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Dilip Kumar <dilipbalaut@gmail.com>
Дата:
On Thu, Feb 5, 2026 at 6:42 AM Yugo Nagata wrote: > > On Wed, 4 Feb 2026 17:26:25 +1100 > Peter Smith wrote: > > > On Wed, Feb 4, 2026 at 4:07 PM Yugo Nagata wrote: > > > > > > Hi, > > > > > > I would like to propose emitting a warning when creating or enabling a > > > subscription while max_logical_replication_workers is set to 0. In this > > > case, the CREATE/ALTER SUBSCRIPTION command completes successfully without > > > any warning, making it difficult to notice that logical replication cannot > > > start. > > > > > > Of course, users can confirm whether logical replication is working by > > > checking system views such as pg_stat_replication or pg_stat_subscription. > > > However, emitting warnings explicitly in these cases would make this > > > situation more visible. We have seen user reports where this behavior > > > caused confusion, with users wondering why replication did not start. > > > > > > > Hi Nagata-San. > > > > AFAIK the default for `max_logical_replication_workers` is 4. So how > > does the maximum get to be 0 unless the user had explicitly configured > > it that way? > > That's correct, but the goal here is simply to make it easier for users to > be aware of this condition, since the current behavior provides no > indication that replication will not start. > > > Also subscriptions require multiple workers in order to work properly > > [1] so why check only 0? Why not check 1 or 2 or 3.... those low > > numbers are also likely to cause similar problems aren't they? > > > > And what about when the `max_logical_replication_workers` is 100, but > > those 100 are already being used. IOW, would it be more useful to warn > > when you do not have enough *available* workers for the Subscription > > to function properly, rather than checking what the maximum value is > > set to? > > When max_logical_replication_workers is zero, the logical replication > launcher will never start. Otherwise, it does start and emits the > following warning to the server log when workers cannot be obtained: > > WARNING: out of logical replication worker slots > HINT: You might need to increase "max_logical_replication_workers" > > Given this, I think it is sufficient to warn only when > max_logical_replication_workers is zero. Wouldn't it make sense to emit a WARNING if there are no worker left to be launched for the SUBSCRIPTION? > That said, this warning is currently emitted only to the server log and > does not appear as a response to CREATE/ALTER SUBSCRIPTION. However, I'm > not sure whether emitting a similar warning as part of the > CREATE/ALTER SUBSCRIPTION response would add much value. Yes, I think it would make more sense to emit WARNING during CREATE/ALTER SUBSCRIPTION command as well. -- Regards, Dilip Kumar Google
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata wrote:
>
> On Wed, 4 Feb 2026 17:26:25 +1100
> Peter Smith wrote:
>
> > On Wed, Feb 4, 2026 at 4:07 PM Yugo Nagata wrote:
> > >
> > > Hi,
> > >
> > > I would like to propose emitting a warning when creating or enabling a
> > > subscription while max_logical_replication_workers is set to 0. In this
> > > case, the CREATE/ALTER SUBSCRIPTION command completes successfully without
> > > any warning, making it difficult to notice that logical replication cannot
> > > start.
> > >
> > > Of course, users can confirm whether logical replication is working by
> > > checking system views such as pg_stat_replication or pg_stat_subscription.
> > > However, emitting warnings explicitly in these cases would make this
> > > situation more visible. We have seen user reports where this behavior
> > > caused confusion, with users wondering why replication did not start.
> > >
> >
> > Hi Nagata-San.
> >
> > AFAIK the default for `max_logical_replication_workers` is 4. So how
> > does the maximum get to be 0 unless the user had explicitly configured
> > it that way?
>
> That's correct, but the goal here is simply to make it easier for users to
> be aware of this condition, since the current behavior provides no
> indication that replication will not start.
>
> > Also subscriptions require multiple workers in order to work properly
> > [1] so why check only 0? Why not check 1 or 2 or 3.... those low
> > numbers are also likely to cause similar problems aren't they?
> >
> > And what about when the `max_logical_replication_workers` is 100, but
> > those 100 are already being used. IOW, would it be more useful to warn
> > when you do not have enough *available* workers for the Subscription
> > to function properly, rather than checking what the maximum value is
> > set to?
>
> When max_logical_replication_workers is zero, the logical replication
> launcher will never start. Otherwise, it does start and emits the
> following warning to the server log when workers cannot be obtained:
>
> WARNING: out of logical replication worker slots
> HINT: You might need to increase "max_logical_replication_workers"
>
> Given this, I think it is sufficient to warn only when
> max_logical_replication_workers is zero.
>
Hi Nagata-San,
Oh right, I mistook that you had run out of logical replication
"workers", but in fact, because max_logical_replication_workers = 0
the main "logical replication launcher" process had failed to start,
so logical replication was entirely disabled.
See code: in backend/replication/logical/launcher.c
ApplyLauncherRegister(void)
{
...
if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
return;
~~~
Given this, I felt that instead of testing the GUC, what you really
want to know is just whether that "logical replication launcher" is
running or not.
And that launcher pid is already tested when the Subscription commands
send a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
So, here is a diff patch, of what I tried:
------
diff --git a/src/backend/replication/logical/launcher.c
b/src/backend/replication/logical/launcher.c
index 3ed86480be2..f880380ce4e 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void)
{
if (LogicalRepCtx->launcher_pid != 0)
kill(LogicalRepCtx->launcher_pid, SIGUSR1);
+ else
+ {
+ if (max_logical_replication_workers == 0)
+ ereport(WARNING,
+ errmsg("Logical replication is
currently disabled"),
+ errhint("\"%s\" is 0.",
"max_logical_replication_workers"));
+ }
}
------
AND THE RESULT:
----------
test_sub=# create subscription sub1 connection 'dbname=test_pub'
publication pub1;
NOTICE: created replication slot "sub1" on publisher
WARNING: Logical replication is currently disabled
HINT: "max_logical_replication_workers" is 0
CREATE SUBSCRIPTION
test_sub=#
test_sub=# alter subscription sub1 disable;
ALTER SUBSCRIPTION
test_sub=# alter subscription sub1 enable;
WARNING: Logical replication is currently disabled
HINT: "max_logical_replication_workers" is 0
ALTER SUBSCRIPTION
test_sub=#
----------
IIUC, that seems to be giving the CREATE/ALTER warnings that you wanted.
Thoughts?
======
Kind Regards,
Peter Smith.
Fujitsu Australia
RE: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
"Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>
Дата:
On Thursday, February 5, 2026 3:47 PM Peter Smith wrote:
> On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata wrote:
> >
> > On Wed, 4 Feb 2026 17:26:25 +1100
> > Peter Smith wrote:
> >
> > > On Wed, Feb 4, 2026 at 4:07 PM Yugo Nagata
> wrote:
> > > >
> > > > Hi,
> > > >
> > > > I would like to propose emitting a warning when creating or
> > > > enabling a subscription while max_logical_replication_workers is
> > > > set to 0. In this case, the CREATE/ALTER SUBSCRIPTION command
> > > > completes successfully without any warning, making it difficult to
> > > > notice that logical replication cannot start.
> > > >
> > > > Of course, users can confirm whether logical replication is
> > > > working by checking system views such as pg_stat_replication or
> pg_stat_subscription.
> > > > However, emitting warnings explicitly in these cases would make
> > > > this situation more visible. We have seen user reports where this
> > > > behavior caused confusion, with users wondering why replication did not
> start.
> > > >
> > >
> > > Hi Nagata-San.
> > >
> > > AFAIK the default for `max_logical_replication_workers` is 4. So how
> > > does the maximum get to be 0 unless the user had explicitly
> > > configured it that way?
> >
> > That's correct, but the goal here is simply to make it easier for
> > users to be aware of this condition, since the current behavior
> > provides no indication that replication will not start.
> >
> > > Also subscriptions require multiple workers in order to work
> > > properly [1] so why check only 0? Why not check 1 or 2 or 3....
> > > those low numbers are also likely to cause similar problems aren't they?
> > >
> > > And what about when the `max_logical_replication_workers` is 100,
> > > but those 100 are already being used. IOW, would it be more useful
> > > to warn when you do not have enough *available* workers for the
> > > Subscription to function properly, rather than checking what the
> > > maximum value is set to?
> >
> > When max_logical_replication_workers is zero, the logical replication
> > launcher will never start. Otherwise, it does start and emits the
> > following warning to the server log when workers cannot be obtained:
> >
> > WARNING: out of logical replication worker slots
> > HINT: You might need to increase "max_logical_replication_workers"
> >
> > Given this, I think it is sufficient to warn only when
> > max_logical_replication_workers is zero.
> >
>
> Hi Nagata-San,
>
> Oh right, I mistook that you had run out of logical replication "workers", but in
> fact, because max_logical_replication_workers = 0 the main "logical
> replication launcher" process had failed to start, so logical replication was
> entirely disabled.
>
> See code: in backend/replication/logical/launcher.c
>
> ApplyLauncherRegister(void)
> {
> ...
> if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
> return;
>
> ~~~
>
> Given this, I felt that instead of testing the GUC, what you really want to know
> is just whether that "logical replication launcher" is running or not.
>
> And that launcher pid is already tested when the Subscription commands send
> a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
>
> So, here is a diff patch, of what I tried:
>
> ------
> diff --git a/src/backend/replication/logical/launcher.c
> b/src/backend/replication/logical/launcher.c
> index 3ed86480be2..f880380ce4e 100644
> --- a/src/backend/replication/logical/launcher.c
> +++ b/src/backend/replication/logical/launcher.c
> @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
> if (LogicalRepCtx->launcher_pid != 0)
> kill(LogicalRepCtx->launcher_pid, SIGUSR1);
> + else
> + {
> + if (max_logical_replication_workers == 0)
> + ereport(WARNING,
> + errmsg("Logical replication is
> currently disabled"),
> + errhint("\"%s\" is 0.",
> "max_logical_replication_workers"));
> + }
> }
> ------
>
> Thoughts?
I think this is not the right place to check this issue. The launcher might fail
for some reasons and restart soon (pid will be set to 0), in which case this
warning wouldn't be appropriate.
Besides, I also think it would make more sense to issue a warning if the
subscription has no remaining workers to start instead of raising a
warning for 0 setting (the latter seems rare).
Best Regards,
Hou zj
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Thu, Feb 5, 2026 at 7:12 PM Zhijie Hou (Fujitsu)
wrote:
>
> On Thursday, February 5, 2026 3:47 PM Peter Smith wrote:
> > On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata wrote:
> > >
> > > On Wed, 4 Feb 2026 17:26:25 +1100
> > > Peter Smith wrote:
> > >
...
> >
> > Oh right, I mistook that you had run out of logical replication "workers", but in
> > fact, because max_logical_replication_workers = 0 the main "logical
> > replication launcher" process had failed to start, so logical replication was
> > entirely disabled.
> >
> > See code: in backend/replication/logical/launcher.c
> >
> > ApplyLauncherRegister(void)
> > {
> > ...
> > if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
> > return;
> >
> > ~~~
> >
> > Given this, I felt that instead of testing the GUC, what you really want to know
> > is just whether that "logical replication launcher" is running or not.
> >
> > And that launcher pid is already tested when the Subscription commands send
> > a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
> >
> > So, here is a diff patch, of what I tried:
> >
> > ------
> > diff --git a/src/backend/replication/logical/launcher.c
> > b/src/backend/replication/logical/launcher.c
> > index 3ed86480be2..f880380ce4e 100644
> > --- a/src/backend/replication/logical/launcher.c
> > +++ b/src/backend/replication/logical/launcher.c
> > @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
> > if (LogicalRepCtx->launcher_pid != 0)
> > kill(LogicalRepCtx->launcher_pid, SIGUSR1);
> > + else
> > + {
> > + if (max_logical_replication_workers == 0)
> > + ereport(WARNING,
> > + errmsg("Logical replication is
> > currently disabled"),
> > + errhint("\"%s\" is 0.",
> > "max_logical_replication_workers"));
> > + }
> > }
> > ------
> >
> > Thoughts?
>
> I think this is not the right place to check this issue. The launcher might fail
> for some reasons and restart soon (pid will be set to 0), in which case this
> warning wouldn't be appropriate.
AFAIK, that's not possible. My warning is guarded by checking
max_logical_replication_workers == 0. And in that case, the launcher
cannot "fail" because it was never registered/started in the first
place.
>
> Besides, I also think it would make more sense to issue a warning if the
> subscription has no remaining workers to start instead of raising a
> warning for 0 setting (the latter seems rare).
>
It might be rare, but by my understanding, the original post described
this specific scenario, whereby the user had previously deliberately
configured `max_logical_replication_workers` to 0. Then, some time
later, when they attempted CREATE/ALTER SUBSCRIPTION, nothing
happened, and there was only silence. If they'd forgotten about their
`max_logical_replication_workers` setting, then it could be confusing
why nothing was happening.
OTOH, when max_logical_replication_workers > 0, then the logical
replication launcher would be running, and in that case, there are
already plenty of warning logs about not enough worker resources.
e.g. when max_logical_replication_workers = 1
----------
test_sub=# create subscription sub1 connection 'dbname=test_pub'
publication pub1;
NOTICE: created replication slot "sub1" on publisher
CREATE SUBSCRIPTION
test_sub=# 2026-02-06 08:50:35.306 AEDT [629942] LOG: logical
replication apply worker for subscription "sub1" has started
2026-02-06 08:50:35.348 AEDT [629942] WARNING: out of logical
replication worker slots
2026-02-06 08:50:35.348 AEDT [629942] HINT: You might need to
increase "max_logical_replication_workers".
2026-02-06 08:50:40.356 AEDT [629942] WARNING: out of logical
replication worker slots
2026-02-06 08:50:40.356 AEDT [629942] HINT: You might need to
increase "max_logical_replication_workers".
2026-02-06 08:50:45.365 AEDT [629942] WARNING: out of logical
replication worker slots
2026-02-06 08:50:45.365 AEDT [629942] HINT: You might need to
increase "max_logical_replication_workers".
2026-02-06 08:50:50.426 AEDT [629942] WARNING: out of logical
replication worker slots
2026-02-06 08:50:50.426 AEDT [629942] HINT: You might need to
increase "max_logical_replication_workers".
2026-02-06 08:50:55.531 AEDT [629942] WARNING: out of logical
replication worker slots
2026-02-06 08:50:55.531 AEDT [629942] HINT: You might need to
increase "max_logical_replication_workers".
...
----------
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Yugo Nagata <nagata@sraoss.co.jp>
Дата:
On Fri, 6 Feb 2026 09:58:02 +1100
Peter Smith wrote:
> On Thu, Feb 5, 2026 at 7:12 PM Zhijie Hou (Fujitsu)
> wrote:
> >
> > On Thursday, February 5, 2026 3:47 PM Peter Smith wrote:
> > > On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata wrote:
> > > >
> > > > On Wed, 4 Feb 2026 17:26:25 +1100
> > > > Peter Smith wrote:
> > > >
> ...
> > >
> > > Oh right, I mistook that you had run out of logical replication "workers", but in
> > > fact, because max_logical_replication_workers = 0 the main "logical
> > > replication launcher" process had failed to start, so logical replication was
> > > entirely disabled.
> > >
> > > See code: in backend/replication/logical/launcher.c
> > >
> > > ApplyLauncherRegister(void)
> > > {
> > > ...
> > > if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
> > > return;
> > >
> > > ~~~
> > >
> > > Given this, I felt that instead of testing the GUC, what you really want to know
> > > is just whether that "logical replication launcher" is running or not.
> > >
> > > And that launcher pid is already tested when the Subscription commands send
> > > a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
> > >
> > > So, here is a diff patch, of what I tried:
> > >
> > > ------
> > > diff --git a/src/backend/replication/logical/launcher.c
> > > b/src/backend/replication/logical/launcher.c
> > > index 3ed86480be2..f880380ce4e 100644
> > > --- a/src/backend/replication/logical/launcher.c
> > > +++ b/src/backend/replication/logical/launcher.c
> > > @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
> > > if (LogicalRepCtx->launcher_pid != 0)
> > > kill(LogicalRepCtx->launcher_pid, SIGUSR1);
> > > + else
> > > + {
> > > + if (max_logical_replication_workers == 0)
> > > + ereport(WARNING,
> > > + errmsg("Logical replication is
> > > currently disabled"),
> > > + errhint("\"%s\" is 0.",
> > > "max_logical_replication_workers"));
> > > + }
> > > }
> > > ------
> > >
> > > Thoughts?
> >
> > I think this is not the right place to check this issue. The launcher might fail
> > for some reasons and restart soon (pid will be set to 0), in which case this
> > warning wouldn't be appropriate.
>
> AFAIK, that's not possible. My warning is guarded by checking
> max_logical_replication_workers == 0. And in that case, the launcher
> cannot "fail" because it was never registered/started in the first
> place.
I also initially considered emitting the warning in
ApplyLauncherWakeup() after checking max_logical_replication_workers == 0.
However, I think checking pid == 0 is sufficient.
Even when max_logical_replication_workers is non-zero and the launcher is
normally running, it could still be killed by user action or by the
OS, although such cases should be rare. In that situation, emitting the
same warning would not be appropriate.
I placed the logic in subscriptioncmds.c so that the warning message can
better reflect the actual situation, while keeping consistency with
existing messages such as "subscription was created, but is not
connected".
> >
> > Besides, I also think it would make more sense to issue a warning if the
> > subscription has no remaining workers to start instead of raising a
> > warning for 0 setting (the latter seems rare).
> >
>
> It might be rare, but by my understanding, the original post described
> this specific scenario, whereby the user had previously deliberately
> configured `max_logical_replication_workers` to 0. Then, some time
> later, when they attempted CREATE/ALTER SUBSCRIPTION, nothing
> happened, and there was only silence. If they'd forgotten about their
> `max_logical_replication_workers` setting, then it could be confusing
> why nothing was happening.
>
> OTOH, when max_logical_replication_workers > 0, then the logical
> replication launcher would be running, and in that case, there are
> already plenty of warning logs about not enough worker resources.
Yes. In this case, warnings are emitted to the server log, but they do not
appear as a response to CREATE/ALTER SUBSCRIPTION. There is an option to
also emit such warnings during the CREATE/ALTER SUBSCRIPTION command, so
I will update the patch accordingly.
Nevertheless, this seems to be a different situation from the case where
logical replication is disabled entirely, so I think the warning messages
should be handled separately.
Regards,
Yugo Nagata
--
Yugo Nagata
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Fri, Feb 6, 2026 at 3:37 PM Yugo Nagata wrote:
>
> On Fri, 6 Feb 2026 09:58:02 +1100
> Peter Smith wrote:
>
> > On Thu, Feb 5, 2026 at 7:12 PM Zhijie Hou (Fujitsu)
> > wrote:
> > >
> > > On Thursday, February 5, 2026 3:47 PM Peter Smith wrote:
> > > > On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata wrote:
> > > > >
> > > > > On Wed, 4 Feb 2026 17:26:25 +1100
> > > > > Peter Smith wrote:
> > > > >
> > ...
> > > >
> > > > Oh right, I mistook that you had run out of logical replication "workers", but in
> > > > fact, because max_logical_replication_workers = 0 the main "logical
> > > > replication launcher" process had failed to start, so logical replication was
> > > > entirely disabled.
> > > >
> > > > See code: in backend/replication/logical/launcher.c
> > > >
> > > > ApplyLauncherRegister(void)
> > > > {
> > > > ...
> > > > if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
> > > > return;
> > > >
> > > > ~~~
> > > >
> > > > Given this, I felt that instead of testing the GUC, what you really want to know
> > > > is just whether that "logical replication launcher" is running or not.
> > > >
> > > > And that launcher pid is already tested when the Subscription commands send
> > > > a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
> > > >
> > > > So, here is a diff patch, of what I tried:
> > > >
> > > > ------
> > > > diff --git a/src/backend/replication/logical/launcher.c
> > > > b/src/backend/replication/logical/launcher.c
> > > > index 3ed86480be2..f880380ce4e 100644
> > > > --- a/src/backend/replication/logical/launcher.c
> > > > +++ b/src/backend/replication/logical/launcher.c
> > > > @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
> > > > if (LogicalRepCtx->launcher_pid != 0)
> > > > kill(LogicalRepCtx->launcher_pid, SIGUSR1);
> > > > + else
> > > > + {
> > > > + if (max_logical_replication_workers == 0)
> > > > + ereport(WARNING,
> > > > + errmsg("Logical replication is
> > > > currently disabled"),
> > > > + errhint("\"%s\" is 0.",
> > > > "max_logical_replication_workers"));
> > > > + }
> > > > }
> > > > ------
> > > >
> > > > Thoughts?
> > >
> > > I think this is not the right place to check this issue. The launcher might fail
> > > for some reasons and restart soon (pid will be set to 0), in which case this
> > > warning wouldn't be appropriate.
> >
> > AFAIK, that's not possible. My warning is guarded by checking
> > max_logical_replication_workers == 0. And in that case, the launcher
> > cannot "fail" because it was never registered/started in the first
> > place.
>
> I also initially considered emitting the warning in
> ApplyLauncherWakeup() after checking max_logical_replication_workers == 0.
> However, I think checking pid == 0 is sufficient.
>
> Even when max_logical_replication_workers is non-zero and the launcher is
> normally running, it could still be killed by user action or by the
> OS, although such cases should be rare. In that situation, emitting the
> same warning would not be appropriate.
Sorry, I did not understand the previous paragraph. If "when
max_logical_replication_workers is non-zero" then the warning cannot
be emitted inappropriately because that warning is guarded by "if
(max_logical_replication_workers == 0)" (??).
>
> I placed the logic in subscriptioncmds.c so that the warning message can
> better reflect the actual situation, while keeping consistency with
> existing messages such as "subscription was created, but is not
> connected".
In hindsgght your original patch is very similar to what I posted. I
agree, your messages are better because they are more specific. But
there are multiple calls to ApplyLauncherWakeup() -- not just those 2
that you handled - so I was just unsure if there are some remaining
holes.
>
> > >
> > > Besides, I also think it would make more sense to issue a warning if the
> > > subscription has no remaining workers to start instead of raising a
> > > warning for 0 setting (the latter seems rare).
> > >
> >
> > It might be rare, but by my understanding, the original post described
> > this specific scenario, whereby the user had previously deliberately
> > configured `max_logical_replication_workers` to 0. Then, some time
> > later, when they attempted CREATE/ALTER SUBSCRIPTION, nothing
> > happened, and there was only silence. If they'd forgotten about their
> > `max_logical_replication_workers` setting, then it could be confusing
> > why nothing was happening.
> >
> > OTOH, when max_logical_replication_workers > 0, then the logical
> > replication launcher would be running, and in that case, there are
> > already plenty of warning logs about not enough worker resources.
>
> Yes. In this case, warnings are emitted to the server log, but they do not
> appear as a response to CREATE/ALTER SUBSCRIPTION. There is an option to
> also emit such warnings during the CREATE/ALTER SUBSCRIPTION command, so
> I will update the patch accordingly.
>
> Nevertheless, this seems to be a different situation from the case where
> logical replication is disabled entirely, so I think the warning messages
> should be handled separately.
+1. I also think that running out of worker resources is a different
scenario from the entire logical replication being disabled, so it
should be handled separately
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Yugo Nagata <nagata@sraoss.co.jp>
Дата:
On Fri, 6 Feb 2026 18:28:06 +1100
Peter Smith wrote:
> On Fri, Feb 6, 2026 at 3:37 PM Yugo Nagata wrote:
> >
> > On Fri, 6 Feb 2026 09:58:02 +1100
> > Peter Smith wrote:
> >
> > > On Thu, Feb 5, 2026 at 7:12 PM Zhijie Hou (Fujitsu)
> > > wrote:
> > > >
> > > > On Thursday, February 5, 2026 3:47 PM Peter Smith wrote:
> > > > > On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata wrote:
> > > > > >
> > > > > > On Wed, 4 Feb 2026 17:26:25 +1100
> > > > > > Peter Smith wrote:
> > > > > >
> > > ...
> > > > >
> > > > > Oh right, I mistook that you had run out of logical replication "workers", but in
> > > > > fact, because max_logical_replication_workers = 0 the main "logical
> > > > > replication launcher" process had failed to start, so logical replication was
> > > > > entirely disabled.
> > > > >
> > > > > See code: in backend/replication/logical/launcher.c
> > > > >
> > > > > ApplyLauncherRegister(void)
> > > > > {
> > > > > ...
> > > > > if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
> > > > > return;
> > > > >
> > > > > ~~~
> > > > >
> > > > > Given this, I felt that instead of testing the GUC, what you really want to know
> > > > > is just whether that "logical replication launcher" is running or not.
> > > > >
> > > > > And that launcher pid is already tested when the Subscription commands send
> > > > > a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
> > > > >
> > > > > So, here is a diff patch, of what I tried:
> > > > >
> > > > > ------
> > > > > diff --git a/src/backend/replication/logical/launcher.c
> > > > > b/src/backend/replication/logical/launcher.c
> > > > > index 3ed86480be2..f880380ce4e 100644
> > > > > --- a/src/backend/replication/logical/launcher.c
> > > > > +++ b/src/backend/replication/logical/launcher.c
> > > > > @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
> > > > > if (LogicalRepCtx->launcher_pid != 0)
> > > > > kill(LogicalRepCtx->launcher_pid, SIGUSR1);
> > > > > + else
> > > > > + {
> > > > > + if (max_logical_replication_workers == 0)
> > > > > + ereport(WARNING,
> > > > > + errmsg("Logical replication is
> > > > > currently disabled"),
> > > > > + errhint("\"%s\" is 0.",
> > > > > "max_logical_replication_workers"));
> > > > > + }
> > > > > }
> > > > > ------
> > > > >
> > > > > Thoughts?
> > > >
> > > > I think this is not the right place to check this issue. The launcher might fail
> > > > for some reasons and restart soon (pid will be set to 0), in which case this
> > > > warning wouldn't be appropriate.
> > >
> > > AFAIK, that's not possible. My warning is guarded by checking
> > > max_logical_replication_workers == 0. And in that case, the launcher
> > > cannot "fail" because it was never registered/started in the first
> > > place.
> >
> > I also initially considered emitting the warning in
> > ApplyLauncherWakeup() after checking max_logical_replication_workers == 0.
> > However, I think checking pid == 0 is sufficient.
> >
> > Even when max_logical_replication_workers is non-zero and the launcher is
> > normally running, it could still be killed by user action or by the
> > OS, although such cases should be rare. In that situation, emitting the
> > same warning would not be appropriate.
>
> Sorry, I did not understand the previous paragraph. If "when
> max_logical_replication_workers is non-zero" then the warning cannot
> be emitted inappropriately because that warning is guarded by "if
> (max_logical_replication_workers == 0)" (??).
You're right, I misunderstood that part. Sorry about that.
> > I placed the logic in subscriptioncmds.c so that the warning message can
> > better reflect the actual situation, while keeping consistency with
> > existing messages such as "subscription was created, but is not
> > connected".
>
> In hindsgght your original patch is very similar to what I posted. I
> agree, your messages are better because they are more specific. But
> there are multiple calls to ApplyLauncherWakeup() -- not just those 2
> that you handled - so I was just unsure if there are some remaining
> holes.
I see your point.
There are other places where ApplyLauncherWakeupAtCommit() is called,
for example via AlterSubscription() when retain_dead_tuples is set or
when the owner is changed. However, these cases are not affected when
max_logical_replication_workers = 0 unless the subscription is enabled.
For now, I’ll keep the current approach.
> >
> > > >
> > > > Besides, I also think it would make more sense to issue a warning if the
> > > > subscription has no remaining workers to start instead of raising a
> > > > warning for 0 setting (the latter seems rare).
> > > >
> > >
> > > It might be rare, but by my understanding, the original post described
> > > this specific scenario, whereby the user had previously deliberately
> > > configured `max_logical_replication_workers` to 0. Then, some time
> > > later, when they attempted CREATE/ALTER SUBSCRIPTION, nothing
> > > happened, and there was only silence. If they'd forgotten about their
> > > `max_logical_replication_workers` setting, then it could be confusing
> > > why nothing was happening.
> > >
> > > OTOH, when max_logical_replication_workers > 0, then the logical
> > > replication launcher would be running, and in that case, there are
> > > already plenty of warning logs about not enough worker resources.
> >
> > Yes. In this case, warnings are emitted to the server log, but they do not
> > appear as a response to CREATE/ALTER SUBSCRIPTION. There is an option to
> > also emit such warnings during the CREATE/ALTER SUBSCRIPTION command, so
> > I will update the patch accordingly.
> >
> > Nevertheless, this seems to be a different situation from the case where
> > logical replication is disabled entirely, so I think the warning messages
> > should be handled separately.
>
> +1. I also think that running out of worker resources is a different
> scenario from the entire logical replication being disabled, so it
> should be handled separately
I've investigated whether we can emit a warning during CREATE/ALTER SUBSCRIPTION
when there are no available worker slots to start the subscription.
One issue is that, in the current implementation, this condition is only checked
when the launcher actually forks a worker. There is no infrastructure to perform
this check in advance from a backend process.
Adding such infrastructure would likely require acquiring an LWLock (at least in
shared mode) to inspect the current worker state. Moreover, even if we implement
such a mechanism, the situation may change between the time of the check and the
actual worker startup.
Given these limitations, I'm wondering whether introducing this kind of warning
is worthwhile.
Regards,
Yugo Nagata
--
Yugo Nagata
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
On Mon, 13 Apr 2026 at 09:04, Yugo Nagata <nagata@sraoss.co.jp> wrote:
On Fri, 6 Feb 2026 18:28:06 +1100
Peter Smith <smithpb2250@gmail.com> wrote:
> On Fri, Feb 6, 2026 at 3:37 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> >
> > On Fri, 6 Feb 2026 09:58:02 +1100
> > Peter Smith <smithpb2250@gmail.com> wrote:
> >
> > > On Thu, Feb 5, 2026 at 7:12 PM Zhijie Hou (Fujitsu)
> > > <houzj.fnst@fujitsu.com> wrote:
> > > >
> > > > On Thursday, February 5, 2026 3:47 PM Peter Smith <smithpb2250@gmail.com> wrote:
> > > > > On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> > > > > >
> > > > > > On Wed, 4 Feb 2026 17:26:25 +1100
> > > > > > Peter Smith <smithpb2250@gmail.com> wrote:
> > > > > >
> > > ...
> > > > >
> > > > > Oh right, I mistook that you had run out of logical replication "workers", but in
> > > > > fact, because max_logical_replication_workers = 0 the main "logical
> > > > > replication launcher" process had failed to start, so logical replication was
> > > > > entirely disabled.
> > > > >
> > > > > See code: in backend/replication/logical/launcher.c
> > > > >
> > > > > ApplyLauncherRegister(void)
> > > > > {
> > > > > ...
> > > > > if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
> > > > > return;
> > > > >
> > > > > ~~~
> > > > >
> > > > > Given this, I felt that instead of testing the GUC, what you really want to know
> > > > > is just whether that "logical replication launcher" is running or not.
> > > > >
> > > > > And that launcher pid is already tested when the Subscription commands send
> > > > > a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
> > > > >
> > > > > So, here is a diff patch, of what I tried:
> > > > >
> > > > > ------
> > > > > diff --git a/src/backend/replication/logical/launcher.c
> > > > > b/src/backend/replication/logical/launcher.c
> > > > > index 3ed86480be2..f880380ce4e 100644
> > > > > --- a/src/backend/replication/logical/launcher.c
> > > > > +++ b/src/backend/replication/logical/launcher.c
> > > > > @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
> > > > > if (LogicalRepCtx->launcher_pid != 0)
> > > > > kill(LogicalRepCtx->launcher_pid, SIGUSR1);
> > > > > + else
> > > > > + {
> > > > > + if (max_logical_replication_workers == 0)
> > > > > + ereport(WARNING,
> > > > > + errmsg("Logical replication is
> > > > > currently disabled"),
> > > > > + errhint("\"%s\" is 0.",
> > > > > "max_logical_replication_workers"));
> > > > > + }
> > > > > }
> > > > > ------
> > > > >
> > > > > Thoughts?
> > > >
> > > > I think this is not the right place to check this issue. The launcher might fail
> > > > for some reasons and restart soon (pid will be set to 0), in which case this
> > > > warning wouldn't be appropriate.
> > >
> > > AFAIK, that's not possible. My warning is guarded by checking
> > > max_logical_replication_workers == 0. And in that case, the launcher
> > > cannot "fail" because it was never registered/started in the first
> > > place.
> >
> > I also initially considered emitting the warning in
> > ApplyLauncherWakeup() after checking max_logical_replication_workers == 0.
> > However, I think checking pid == 0 is sufficient.
> >
> > Even when max_logical_replication_workers is non-zero and the launcher is
> > normally running, it could still be killed by user action or by the
> > OS, although such cases should be rare. In that situation, emitting the
> > same warning would not be appropriate.
>
> Sorry, I did not understand the previous paragraph. If "when
> max_logical_replication_workers is non-zero" then the warning cannot
> be emitted inappropriately because that warning is guarded by "if
> (max_logical_replication_workers == 0)" (??).
You're right, I misunderstood that part. Sorry about that.
> > I placed the logic in subscriptioncmds.c so that the warning message can
> > better reflect the actual situation, while keeping consistency with
> > existing messages such as "subscription was created, but is not
> > connected".
>
> In hindsgght your original patch is very similar to what I posted. I
> agree, your messages are better because they are more specific. But
> there are multiple calls to ApplyLauncherWakeup() -- not just those 2
> that you handled - so I was just unsure if there are some remaining
> holes.
I see your point.
There are other places where ApplyLauncherWakeupAtCommit() is called,
for example via AlterSubscription() when retain_dead_tuples is set or
when the owner is changed. However, these cases are not affected when
max_logical_replication_workers = 0 unless the subscription is enabled.
For now, I’ll keep the current approach.
> >
> > > >
> > > > Besides, I also think it would make more sense to issue a warning if the
> > > > subscription has no remaining workers to start instead of raising a
> > > > warning for 0 setting (the latter seems rare).
> > > >
> > >
> > > It might be rare, but by my understanding, the original post described
> > > this specific scenario, whereby the user had previously deliberately
> > > configured `max_logical_replication_workers` to 0. Then, some time
> > > later, when they attempted CREATE/ALTER SUBSCRIPTION, nothing
> > > happened, and there was only silence. If they'd forgotten about their
> > > `max_logical_replication_workers` setting, then it could be confusing
> > > why nothing was happening.
> > >
> > > OTOH, when max_logical_replication_workers > 0, then the logical
> > > replication launcher would be running, and in that case, there are
> > > already plenty of warning logs about not enough worker resources.
> >
> > Yes. In this case, warnings are emitted to the server log, but they do not
> > appear as a response to CREATE/ALTER SUBSCRIPTION. There is an option to
> > also emit such warnings during the CREATE/ALTER SUBSCRIPTION command, so
> > I will update the patch accordingly.
> >
> > Nevertheless, this seems to be a different situation from the case where
> > logical replication is disabled entirely, so I think the warning messages
> > should be handled separately.
>
> +1. I also think that running out of worker resources is a different
> scenario from the entire logical replication being disabled, so it
> should be handled separately
I've investigated whether we can emit a warning during CREATE/ALTER SUBSCRIPTION
when there are no available worker slots to start the subscription.
I find there is another more warning worthy scenario that should be covered too, what if everything is working normally and then someone changes max_logical_replication_workers to 0 in conf file and restarts, now logical replication fails to continue. In this case since no CREATE or ALTER subscription command was issued, the changes discussed upthread would not produce a warning. Shouldn't we cover this case also?
One issue is that, in the current implementation, this condition is only checked
when the launcher actually forks a worker. There is no infrastructure to perform
this check in advance from a backend process.
Adding such infrastructure would likely require acquiring an LWLock (at least in
shared mode) to inspect the current worker state. Moreover, even if we implement
such a mechanism, the situation may change between the time of the check and the
actual worker startup.
What about an alternate way to overcome this, following the same pattern as in apply_error_count for pg_stat_subscription_stats.
So, a rough sketch of the approach is like this.. Create a new field in PgStat_StatSubEntry say worker_failure_count and add a function to increment this field. Now, in logicalrep_worker_launch when it hits worker == NULL, call this function to increment the worker_failure_count. I have added a rough patch to explain the idea better.
Note that this won't be something as emitting a warning or notice but rather needs to be explicitly queried.
Given these limitations, I'm wondering whether introducing this kind of warning
is worthwhile.
Regards,
Rafia Sabih
Rafia Sabih
CYBERTEC PostgreSQL International GmbH
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
Shubhra Jain <shubhra.jain@ksolves.com>
Дата:
Hi Yugo,
I reviewed and tested the patch from your first message (Feb 4,
0001-Warn-when-creating-or-enabling-a-subscription-with-l.patch).
Setup: master at d6393fc40a, built with --enable-cassert --enable-debug
on Linux, with a publisher and a subscriber cluster on one machine.
Without the patch, with max_logical_replication_workers = 0 on the
subscriber, CREATE SUBSCRIPTION prints only the slot NOTICE and
succeeds. pg_stat_subscription lists the subscription with an empty pid,
no "logical replication launcher" process exists on the subscriber, no
rows arrive, and the publisher's slot stays inactive. With the setting
at 4, the same subscription works.
With the patch, same setup:
CREATE SUBSCRIPTION sub_a CONNECTION '...' PUBLICATION pub1;
NOTICE: created replication slot "sub_a" on publisher
WARNING: subscription was created, but logical replication is disabled
HINT: To initiate replication, set "max_logical_replication_workers"
to a non zero value.
ALTER SUBSCRIPTION sub_a ENABLE;
WARNING: subscription was enabled, but logical replication is disabled
HINT: (same hint)
There is no warning for ALTER SUBSCRIPTION ... DISABLE, nor for CREATE
SUBSCRIPTION ... WITH (enabled = false). With
max_logical_replication_workers = 4, none of these commands warn.
make -C src/test/subscription check passes (39 test files, 604 tests).
Observations:
1. On an enabled subscription, ALTER SUBSCRIPTION ... REFRESH
PUBLICATION, SET PUBLICATION, CONNECTION and SET (synchronous_commit)
do not warn with the setting at 0. I assume that is intended, since
those commands do not start replication.
2. With the setting at 0, CREATE SUBSCRIPTION ... WITH (enabled = false,
retain_dead_tuples = true) also prints "subscription was created, but
logical replication is disabled". I see from the comment above the
check that the launcher is needed there to create the conflict
detection slot, so a warning seems justified. But since the
subscription itself is not enabled, "To initiate replication" in the
hint may be confusing. Would different wording be better for that
case? Output:
WARNING: deleted rows to detect conflicts would not be removed
until the subscription is enabled
HINT: Consider setting retain_dead_tuples to false.
NOTICE: created replication slot "sub_r" on publisher
WARNING: subscription was created, but logical replication is disabled
HINT: To initiate replication, set "max_logical_replication_workers"
to a non zero value.
3. Minor: the hint says "non zero"; create_subscription.sgml writes
"non-zero".
4. The patch has no test. If you agree, I would be happy to write a TAP
test in src/test/subscription that starts a subscriber with the
setting at 0 and checks for the warning on CREATE and ENABLE, and for
its absence on DISABLE and with enabled = false. Please tell me if you
would rather add it yourself.
On the slot-exhaustion case discussed upthread: with
max_logical_replication_workers = 1, I created a subscription with the
default options. CREATE SUBSCRIPTION printed only the slot NOTICE in the
client session, while the server log repeated this every 5 seconds:
WARNING: out of logical replication worker slots
HINT: You might need to increase "max_logical_replication_workers".
So that case is not visible to the user who ran the command, and the
patch does not change it, which seems consistent with treating it
separately as discussed upthread. I have not tried a check from the
backend side. If there is interest, I could look into a best-effort check
of free worker slots as a separate patch, but I wanted to ask first
whether that direction would be acceptable.
Regards,
Shubhra
I reviewed and tested the patch from your first message (Feb 4,
0001-Warn-when-creating-or-enabling-a-subscription-with-l.patch).
Setup: master at d6393fc40a, built with --enable-cassert --enable-debug
on Linux, with a publisher and a subscriber cluster on one machine.
Without the patch, with max_logical_replication_workers = 0 on the
subscriber, CREATE SUBSCRIPTION prints only the slot NOTICE and
succeeds. pg_stat_subscription lists the subscription with an empty pid,
no "logical replication launcher" process exists on the subscriber, no
rows arrive, and the publisher's slot stays inactive. With the setting
at 4, the same subscription works.
With the patch, same setup:
CREATE SUBSCRIPTION sub_a CONNECTION '...' PUBLICATION pub1;
NOTICE: created replication slot "sub_a" on publisher
WARNING: subscription was created, but logical replication is disabled
HINT: To initiate replication, set "max_logical_replication_workers"
to a non zero value.
ALTER SUBSCRIPTION sub_a ENABLE;
WARNING: subscription was enabled, but logical replication is disabled
HINT: (same hint)
There is no warning for ALTER SUBSCRIPTION ... DISABLE, nor for CREATE
SUBSCRIPTION ... WITH (enabled = false). With
max_logical_replication_workers = 4, none of these commands warn.
make -C src/test/subscription check passes (39 test files, 604 tests).
Observations:
1. On an enabled subscription, ALTER SUBSCRIPTION ... REFRESH
PUBLICATION, SET PUBLICATION, CONNECTION and SET (synchronous_commit)
do not warn with the setting at 0. I assume that is intended, since
those commands do not start replication.
2. With the setting at 0, CREATE SUBSCRIPTION ... WITH (enabled = false,
retain_dead_tuples = true) also prints "subscription was created, but
logical replication is disabled". I see from the comment above the
check that the launcher is needed there to create the conflict
detection slot, so a warning seems justified. But since the
subscription itself is not enabled, "To initiate replication" in the
hint may be confusing. Would different wording be better for that
case? Output:
WARNING: deleted rows to detect conflicts would not be removed
until the subscription is enabled
HINT: Consider setting retain_dead_tuples to false.
NOTICE: created replication slot "sub_r" on publisher
WARNING: subscription was created, but logical replication is disabled
HINT: To initiate replication, set "max_logical_replication_workers"
to a non zero value.
3. Minor: the hint says "non zero"; create_subscription.sgml writes
"non-zero".
4. The patch has no test. If you agree, I would be happy to write a TAP
test in src/test/subscription that starts a subscriber with the
setting at 0 and checks for the warning on CREATE and ENABLE, and for
its absence on DISABLE and with enabled = false. Please tell me if you
would rather add it yourself.
On the slot-exhaustion case discussed upthread: with
max_logical_replication_workers = 1, I created a subscription with the
default options. CREATE SUBSCRIPTION printed only the slot NOTICE in the
client session, while the server log repeated this every 5 seconds:
WARNING: out of logical replication worker slots
HINT: You might need to increase "max_logical_replication_workers".
So that case is not visible to the user who ran the command, and the
patch does not change it, which seems consistent with treating it
separately as discussed upthread. I have not tried a check from the
backend side. If there is interest, I could look into a best-effort check
of free worker slots as a separate patch, but I wanted to ask first
whether that direction would be acceptable.
Regards,
Shubhra
On Tue, Oct 6, 2026 at 10:31 AM Rafia Sabih <rafia.pghackers@gmail.com> wrote:
--On Mon, 13 Apr 2026 at 09:04, Yugo Nagata <nagata@sraoss.co.jp> wrote:On Fri, 6 Feb 2026 18:28:06 +1100
Peter Smith <smithpb2250@gmail.com> wrote:
> On Fri, Feb 6, 2026 at 3:37 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> >
> > On Fri, 6 Feb 2026 09:58:02 +1100
> > Peter Smith <smithpb2250@gmail.com> wrote:
> >
> > > On Thu, Feb 5, 2026 at 7:12 PM Zhijie Hou (Fujitsu)
> > > <houzj.fnst@fujitsu.com> wrote:
> > > >
> > > > On Thursday, February 5, 2026 3:47 PM Peter Smith <smithpb2250@gmail.com> wrote:
> > > > > On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata <nagata@sraoss.co.jp> wrote:
> > > > > >
> > > > > > On Wed, 4 Feb 2026 17:26:25 +1100
> > > > > > Peter Smith <smithpb2250@gmail.com> wrote:
> > > > > >
> > > ...
> > > > >
> > > > > Oh right, I mistook that you had run out of logical replication "workers", but in
> > > > > fact, because max_logical_replication_workers = 0 the main "logical
> > > > > replication launcher" process had failed to start, so logical replication was
> > > > > entirely disabled.
> > > > >
> > > > > See code: in backend/replication/logical/launcher.c
> > > > >
> > > > > ApplyLauncherRegister(void)
> > > > > {
> > > > > ...
> > > > > if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
> > > > > return;
> > > > >
> > > > > ~~~
> > > > >
> > > > > Given this, I felt that instead of testing the GUC, what you really want to know
> > > > > is just whether that "logical replication launcher" is running or not.
> > > > >
> > > > > And that launcher pid is already tested when the Subscription commands send
> > > > > a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
> > > > >
> > > > > So, here is a diff patch, of what I tried:
> > > > >
> > > > > ------
> > > > > diff --git a/src/backend/replication/logical/launcher.c
> > > > > b/src/backend/replication/logical/launcher.c
> > > > > index 3ed86480be2..f880380ce4e 100644
> > > > > --- a/src/backend/replication/logical/launcher.c
> > > > > +++ b/src/backend/replication/logical/launcher.c
> > > > > @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
> > > > > if (LogicalRepCtx->launcher_pid != 0)
> > > > > kill(LogicalRepCtx->launcher_pid, SIGUSR1);
> > > > > + else
> > > > > + {
> > > > > + if (max_logical_replication_workers == 0)
> > > > > + ereport(WARNING,
> > > > > + errmsg("Logical replication is
> > > > > currently disabled"),
> > > > > + errhint("\"%s\" is 0.",
> > > > > "max_logical_replication_workers"));
> > > > > + }
> > > > > }
> > > > > ------
> > > > >
> > > > > Thoughts?
> > > >
> > > > I think this is not the right place to check this issue. The launcher might fail
> > > > for some reasons and restart soon (pid will be set to 0), in which case this
> > > > warning wouldn't be appropriate.
> > >
> > > AFAIK, that's not possible. My warning is guarded by checking
> > > max_logical_replication_workers == 0. And in that case, the launcher
> > > cannot "fail" because it was never registered/started in the first
> > > place.
> >
> > I also initially considered emitting the warning in
> > ApplyLauncherWakeup() after checking max_logical_replication_workers == 0.
> > However, I think checking pid == 0 is sufficient.
> >
> > Even when max_logical_replication_workers is non-zero and the launcher is
> > normally running, it could still be killed by user action or by the
> > OS, although such cases should be rare. In that situation, emitting the
> > same warning would not be appropriate.
>
> Sorry, I did not understand the previous paragraph. If "when
> max_logical_replication_workers is non-zero" then the warning cannot
> be emitted inappropriately because that warning is guarded by "if
> (max_logical_replication_workers == 0)" (??).
You're right, I misunderstood that part. Sorry about that.
> > I placed the logic in subscriptioncmds.c so that the warning message can
> > better reflect the actual situation, while keeping consistency with
> > existing messages such as "subscription was created, but is not
> > connected".
>
> In hindsgght your original patch is very similar to what I posted. I
> agree, your messages are better because they are more specific. But
> there are multiple calls to ApplyLauncherWakeup() -- not just those 2
> that you handled - so I was just unsure if there are some remaining
> holes.
I see your point.
There are other places where ApplyLauncherWakeupAtCommit() is called,
for example via AlterSubscription() when retain_dead_tuples is set or
when the owner is changed. However, these cases are not affected when
max_logical_replication_workers = 0 unless the subscription is enabled.
For now, I’ll keep the current approach.
> >
> > > >
> > > > Besides, I also think it would make more sense to issue a warning if the
> > > > subscription has no remaining workers to start instead of raising a
> > > > warning for 0 setting (the latter seems rare).
> > > >
> > >
> > > It might be rare, but by my understanding, the original post described
> > > this specific scenario, whereby the user had previously deliberately
> > > configured `max_logical_replication_workers` to 0. Then, some time
> > > later, when they attempted CREATE/ALTER SUBSCRIPTION, nothing
> > > happened, and there was only silence. If they'd forgotten about their
> > > `max_logical_replication_workers` setting, then it could be confusing
> > > why nothing was happening.
> > >
> > > OTOH, when max_logical_replication_workers > 0, then the logical
> > > replication launcher would be running, and in that case, there are
> > > already plenty of warning logs about not enough worker resources.
> >
> > Yes. In this case, warnings are emitted to the server log, but they do not
> > appear as a response to CREATE/ALTER SUBSCRIPTION. There is an option to
> > also emit such warnings during the CREATE/ALTER SUBSCRIPTION command, so
> > I will update the patch accordingly.
> >
> > Nevertheless, this seems to be a different situation from the case where
> > logical replication is disabled entirely, so I think the warning messages
> > should be handled separately.
>
> +1. I also think that running out of worker resources is a different
> scenario from the entire logical replication being disabled, so it
> should be handled separately
I've investigated whether we can emit a warning during CREATE/ALTER SUBSCRIPTION
when there are no available worker slots to start the subscription.I find there is another more warning worthy scenario that should be covered too, what if everything is working normally and then someone changes max_logical_replication_workers to 0 in conf file and restarts, now logical replication fails to continue. In this case since no CREATE or ALTER subscription command was issued, the changes discussed upthread would not produce a warning. Shouldn't we cover this case also?One issue is that, in the current implementation, this condition is only checked
when the launcher actually forks a worker. There is no infrastructure to perform
this check in advance from a backend process.
Adding such infrastructure would likely require acquiring an LWLock (at least in
shared mode) to inspect the current worker state. Moreover, even if we implement
such a mechanism, the situation may change between the time of the check and the
actual worker startup.What about an alternate way to overcome this, following the same pattern as in apply_error_count for pg_stat_subscription_stats.So, a rough sketch of the approach is like this.. Create a new field in PgStat_StatSubEntry say worker_failure_count and add a function to increment this field. Now, in logicalrep_worker_launch when it hits worker == NULL, call this function to increment the worker_failure_count. I have added a rough patch to explain the idea better.Note that this won't be something as emitting a warning or notice but rather needs to be explicitly queried.
Given these limitations, I'm wondering whether introducing this kind of warning
is worthwhile.Regards,
Rafia SabihCYBERTEC PostgreSQL International GmbH
Re: Warn when creating or enabling a subscription with max_logical_replication_workers = 0
От:
João Rito <joaovictor.rito@gmail.com>
Дата:
Hi Yugo,
Thank you for working on this. I think the warning will save people
real debugging time.
Shubhra already covered the basic behaviour on 2026-10-06 (thanks,
Shubhra), and I see the same results on current master. To avoid
repeating her review, below I focus on what I think is new: the patch
no longer applies, ALTER SUBSCRIPTION ... SET (retain_dead_tuples)
gives no warning, the max_worker_processes = 0 case, and a few small
message-style details.
I reviewed 0001-Warn-when-creating-or-enabling-a-subscription-with-l.patch
(the only version of your patch in the thread, posted 2026-02-04; I
did not test the pg_stat_subscription_stats patch from Rafia).
Tested against master c074737f687f604b64f6ee830fccbbe854719823
(2026-11-09), Debian bookworm container, ./configure --enable-cassert
--enable-debug --enable-tap-tests.
Applying
- "git apply" fails on current master (hunks at subscriptioncmds.c:906
and :1694 no longer match), which agrees with the cfbot "Needs rebase"
status. "patch -p1 -F3" applies it with offsets of +196 and +461 lines
and fuzz 2 and 1, so the rebase looks mechanical. Please post a
rebased version.
Build and tests (with the patch applied)
- Build is clean, no compiler warnings.
- make check: all 243 tests passed.
- make -C src/test/subscription check: 39 files, 616 tests, PASS.
- None of these exercise the new code, because the regression and TAP
clusters run with the default max_logical_replication_workers = 4.
Manual testing
Setup: publisher on port 5433 (wal_level = logical, table t,
publication pub1), subscriber on port 5434, default CREATE
SUBSCRIPTION options unless noted.
With max_logical_replication_workers = 0 on the subscriber (no
"logical replication launcher" process present):
- CREATE SUBSCRIPTION (enabled, connected):
NOTICE: created replication slot "s_a" on publisher
WARNING: subscription was created, but logical replication is disabled
HINT: To initiate replication, set
"max_logical_replication_workers" to a non zero value.
- ALTER SUBSCRIPTION ... ENABLE (also for a subscription created with
connect = false):
WARNING: subscription was enabled, but logical replication is disabled
HINT: (same hint)
- ALTER SUBSCRIPTION ... DISABLE, and CREATE SUBSCRIPTION ... WITH
(enabled = false): no new warning, as expected.
- CREATE SUBSCRIPTION ... WITH (connect = false): only the existing
"subscription was created, but is not connected" warning, as expected.
(connect = false together with enabled = true is rejected, so that
combination cannot reach the new code.)
- CREATE SUBSCRIPTION ... WITH (enabled = false, retain_dead_tuples =
true): the new "subscription was created, but logical replication is
disabled" warning is shown, right after the existing "deleted rows to
detect conflicts would not be removed until the subscription is
enabled" warning. See comment 2.
- ALTER SUBSCRIPTION ... SET (retain_dead_tuples = true) on a disabled
subscription, OWNER TO, and REFRESH PUBLICATION: no new warning. See
comment 3.
With max_logical_replication_workers = 4: none of the above commands
emit the new warning.
With max_logical_replication_workers = 4 but max_worker_processes = 0,
the launcher is not running (no launcher process in pg_stat_activity),
and CREATE SUBSCRIPTION and ENABLE succeed silently. With
max_worker_processes = 1 the launcher runs, and there is no warning
either. So the patch only covers the GUC = 0 case, not the "no worker
process available" cases. I think that is acceptable given the
discussion upthread, but it could be mentioned in the commit message
or in a comment.
Comments
1. Design. Peter Smith and Hou-san questioned checking only the GUC,
and preferred a warning based on available workers. You replied
(2026-04-13) that there is no cheap way to do that check from a
backend, and treated it as a separate matter. I agree with keeping
this patch limited to the GUC = 0 case, since that is the case where
nothing will ever start and the launcher does not even exist. Rafia
raised the case of the GUC being changed to 0 and the server restarted
with no CREATE/ALTER command issued afterwards; that is outside what a
warning in these commands can do, so I think it needs a separate
mechanism, as she proposed. It would help to state the scope
explicitly, in the commit message and in a short comment above the
checks, to close that discussion.
2. Hint wording for the retain_dead_tuples case (also raised by
Shubhra Jain). When the subscription is created with enabled = false
and retain_dead_tuples = true, the user is told "To initiate
replication, set ..." although the subscription is not enabled and no
replication would start in any case. The launcher is needed there only
to create the conflict detection slot. Either use a separate message
for that branch (for example, one that says the conflict detection
slot cannot be created because logical replication is disabled), or
restrict the current hint to the opts.enabled case.
3. ALTER SUBSCRIPTION ... SET (retain_dead_tuples = ...) also calls
ApplyLauncherWakeupAtCommit() (the "manage the replication slot for
conflict detection" path), and there is no warning with the GUC at 0,
even though CREATE gives one for the same option. This looks
inconsistent. Either cover it as well or document the reason for
leaving it out. The call in the owner-change path is not affected
unless the subscription is enabled, so leaving it out there looks
right.
4. Message wording.
- Hint: "non zero" should be "non-zero" (create_subscription.sgml and
other messages use "non-zero").
- The errmsg is lower case with no trailing period, and the errhint
is a full sentence ending in a period. This conforms to the message
style guide.
- The GUC name is hard-coded in the hint string. Nearby code passes
GUC names as %s arguments (for example, "Consider setting \"%s\" to
true.") so that translated strings can be shared. Since the same hint
is used twice, errhint("To initiate replication, set \"%s\" to a
non-zero value.", "max_logical_replication_workers") would let both
copies share one translatable string.
- "logical replication is disabled" is slightly ambiguous, since
"disabled" is also what a subscription is when subenabled is false.
Something like "logical replication workers cannot be started because
\"max_logical_replication_workers\" is 0" might be clearer, but I do
not have a strong opinion.
- The new ereport() calls use the extra-parenthesis form, which
matches the neighbouring "is not connected" warning, so that is fine.
Much of the newer code in this file omits the parentheses, so either
is acceptable.
5. Code structure. The same check is duplicated in
CreateSubscription() and AlterSubscription(). A small static helper
that takes the first part of the message (created/enabled) would avoid
duplicating the hint, but with only two callers this is a matter of
taste.
6. Tests. The patch has no test. As far as I can see, the only places
in src/test that set max_logical_replication_workers are
010_truncate.pl and 031_column_list.pl (and
authentication/t/007_pre_auth.pl), and none checks for this. A small
TAP test in src/test/subscription that starts a subscriber with
max_logical_replication_workers = 0 and checks, using psql's stderr,
for the warning on CREATE SUBSCRIPTION and ENABLE, and for its absence
on DISABLE, enabled = false, and with the default setting, would cover
the new code. Shubhra Jain has offered to write one, so please let her
know whether you want that. The core regression tests cannot cover
this because the setting needs a restart.
7. Documentation. No documentation change is included. I do not think
one is required, but a sentence in the max_logical_replication_workers
entry in config.sgml saying that CREATE/ALTER SUBSCRIPTION warn when
it is zero would make the behaviour discoverable. Optional.
Verdict: Waiting on Author.
Reasons: (a) the patch needs a rebase (git apply fails on current
master); (b) the hint is misleading for the enabled = false +
retain_dead_tuples case; (c) the ALTER SUBSCRIPTION SET
(retain_dead_tuples) path is inconsistent with CREATE; (d) there is no
test; (e) minor wording fixes ("non-zero", %s for the GUC name). The
core approach looks correct to me and the main scenarios behave as
intended, so I expect this to be close to Ready for Committer after
the next version.
Thanks again, and I am happy to test the next version.
Regards,
Joao Rito
Em seg., 9 de nov. de 2026 às 22:37, Rafia Sabih
escreveu:
>
>
>
> On Mon, 13 Apr 2026 at 09:04, Yugo Nagata wrote:
>>
>> On Fri, 6 Feb 2026 18:28:06 +1100
>> Peter Smith wrote:
>>
>> > On Fri, Feb 6, 2026 at 3:37 PM Yugo Nagata wrote:
>> > >
>> > > On Fri, 6 Feb 2026 09:58:02 +1100
>> > > Peter Smith wrote:
>> > >
>> > > > On Thu, Feb 5, 2026 at 7:12 PM Zhijie Hou (Fujitsu)
>> > > > wrote:
>> > > > >
>> > > > > On Thursday, February 5, 2026 3:47 PM Peter Smith wrote:
>> > > > > > On Thu, Feb 5, 2026 at 12:12 PM Yugo Nagata wrote:
>> > > > > > >
>> > > > > > > On Wed, 4 Feb 2026 17:26:25 +1100
>> > > > > > > Peter Smith wrote:
>> > > > > > >
>> > > > ...
>> > > > > >
>> > > > > > Oh right, I mistook that you had run out of logical replication "workers", but in
>> > > > > > fact, because max_logical_replication_workers = 0 the main "logical
>> > > > > > replication launcher" process had failed to start, so logical replication was
>> > > > > > entirely disabled.
>> > > > > >
>> > > > > > See code: in backend/replication/logical/launcher.c
>> > > > > >
>> > > > > > ApplyLauncherRegister(void)
>> > > > > > {
>> > > > > > ...
>> > > > > > if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
>> > > > > > return;
>> > > > > >
>> > > > > > ~~~
>> > > > > >
>> > > > > > Given this, I felt that instead of testing the GUC, what you really want to know
>> > > > > > is just whether that "logical replication launcher" is running or not.
>> > > > > >
>> > > > > > And that launcher pid is already tested when the Subscription commands send
>> > > > > > a "kill" to the launcher. e.g. see function ApplyLauncherWakeup.
>> > > > > >
>> > > > > > So, here is a diff patch, of what I tried:
>> > > > > >
>> > > > > > ------
>> > > > > > diff --git a/src/backend/replication/logical/launcher.c
>> > > > > > b/src/backend/replication/logical/launcher.c
>> > > > > > index 3ed86480be2..f880380ce4e 100644
>> > > > > > --- a/src/backend/replication/logical/launcher.c
>> > > > > > +++ b/src/backend/replication/logical/launcher.c
>> > > > > > @@ -1195,6 +1195,13 @@ ApplyLauncherWakeup(void) {
>> > > > > > if (LogicalRepCtx->launcher_pid != 0)
>> > > > > > kill(LogicalRepCtx->launcher_pid, SIGUSR1);
>> > > > > > + else
>> > > > > > + {
>> > > > > > + if (max_logical_replication_workers == 0)
>> > > > > > + ereport(WARNING,
>> > > > > > + errmsg("Logical replication is
>> > > > > > currently disabled"),
>> > > > > > + errhint("\"%s\" is 0.",
>> > > > > > "max_logical_replication_workers"));
>> > > > > > + }
>> > > > > > }
>> > > > > > ------
>> > > > > >
>> > > > > > Thoughts?
>> > > > >
>> > > > > I think this is not the right place to check this issue. The launcher might fail
>> > > > > for some reasons and restart soon (pid will be set to 0), in which case this
>> > > > > warning wouldn't be appropriate.
>> > > >
>> > > > AFAIK, that's not possible. My warning is guarded by checking
>> > > > max_logical_replication_workers == 0. And in that case, the launcher
>> > > > cannot "fail" because it was never registered/started in the first
>> > > > place.
>> > >
>> > > I also initially considered emitting the warning in
>> > > ApplyLauncherWakeup() after checking max_logical_replication_workers == 0.
>> > > However, I think checking pid == 0 is sufficient.
>> > >
>> > > Even when max_logical_replication_workers is non-zero and the launcher is
>> > > normally running, it could still be killed by user action or by the
>> > > OS, although such cases should be rare. In that situation, emitting the
>> > > same warning would not be appropriate.
>> >
>> > Sorry, I did not understand the previous paragraph. If "when
>> > max_logical_replication_workers is non-zero" then the warning cannot
>> > be emitted inappropriately because that warning is guarded by "if
>> > (max_logical_replication_workers == 0)" (??).
>>
>> You're right, I misunderstood that part. Sorry about that.
>>
>> > > I placed the logic in subscriptioncmds.c so that the warning message can
>> > > better reflect the actual situation, while keeping consistency with
>> > > existing messages such as "subscription was created, but is not
>> > > connected".
>> >
>> > In hindsgght your original patch is very similar to what I posted. I
>> > agree, your messages are better because they are more specific. But
>> > there are multiple calls to ApplyLauncherWakeup() -- not just those 2
>> > that you handled - so I was just unsure if there are some remaining
>> > holes.
>>
>> I see your point.
>>
>> There are other places where ApplyLauncherWakeupAtCommit() is called,
>> for example via AlterSubscription() when retain_dead_tuples is set or
>> when the owner is changed. However, these cases are not affected when
>> max_logical_replication_workers = 0 unless the subscription is enabled.
>>
>> For now, I’ll keep the current approach.
>>
>> > >
>> > > > >
>> > > > > Besides, I also think it would make more sense to issue a warning if the
>> > > > > subscription has no remaining workers to start instead of raising a
>> > > > > warning for 0 setting (the latter seems rare).
>> > > > >
>> > > >
>> > > > It might be rare, but by my understanding, the original post described
>> > > > this specific scenario, whereby the user had previously deliberately
>> > > > configured `max_logical_replication_workers` to 0. Then, some time
>> > > > later, when they attempted CREATE/ALTER SUBSCRIPTION, nothing
>> > > > happened, and there was only silence. If they'd forgotten about their
>> > > > `max_logical_replication_workers` setting, then it could be confusing
>> > > > why nothing was happening.
>> > > >
>> > > > OTOH, when max_logical_replication_workers > 0, then the logical
>> > > > replication launcher would be running, and in that case, there are
>> > > > already plenty of warning logs about not enough worker resources.
>> > >
>> > > Yes. In this case, warnings are emitted to the server log, but they do not
>> > > appear as a response to CREATE/ALTER SUBSCRIPTION. There is an option to
>> > > also emit such warnings during the CREATE/ALTER SUBSCRIPTION command, so
>> > > I will update the patch accordingly.
>> > >
>> > > Nevertheless, this seems to be a different situation from the case where
>> > > logical replication is disabled entirely, so I think the warning messages
>> > > should be handled separately.
>> >
>> > +1. I also think that running out of worker resources is a different
>> > scenario from the entire logical replication being disabled, so it
>> > should be handled separately
>>
>> I've investigated whether we can emit a warning during CREATE/ALTER SUBSCRIPTION
>> when there are no available worker slots to start the subscription.
>>
> I find there is another more warning worthy scenario that should be covered too, what if everything is working normally and then someone changes max_logical_replication_workers to 0 in conf file and restarts, now logical replication fails to continue. In this case since no CREATE or ALTER subscription command was issued, the changes discussed upthread would not produce a warning. Shouldn't we cover this case also?
>>
>> One issue is that, in the current implementation, this condition is only checked
>> when the launcher actually forks a worker. There is no infrastructure to perform
>> this check in advance from a backend process.
>>
>> Adding such infrastructure would likely require acquiring an LWLock (at least in
>> shared mode) to inspect the current worker state. Moreover, even if we implement
>> such a mechanism, the situation may change between the time of the check and the
>> actual worker startup.
>
> What about an alternate way to overcome this, following the same pattern as in apply_error_count for pg_stat_subscription_stats.
> So, a rough sketch of the approach is like this.. Create a new field in PgStat_StatSubEntry say worker_failure_count and add a function to increment this field. Now, in logicalrep_worker_launch when it hits worker == NULL, call this function to increment the worker_failure_count. I have added a rough patch to explain the idea better.
>
> Note that this won't be something as emitting a warning or notice but rather needs to be explicitly queried.
>>
>>
>> Given these limitations, I'm wondering whether introducing this kind of warning
>> is worthwhile.
>>
> --
> Regards,
> Rafia Sabih
> CYBERTEC PostgreSQL International GmbH