Re: BUG #15293: Stored Procedure Triggered by Logical Replication is Unable to use Notification Events
Artur Zakirov <artur.zakirov@adjust.com>
From: Artur Zakirov <artur.zakirov@adjust.com>
To: Sergey Fedchenko <seregayoga@bk.ru>
Cc: Daniel Danzberger <daniel@dd-wrt.com>, Andres Freund <andres@anarazel.de>,
Tom Lane <tgl@sss.pgh.pa.us>, Sergei Kornilov <sk@zsrv.org>, pgsql-hackers@postgresql.org, Peter Eisentraut <peter_e@gmx.net>, Marc Dean <marc.dean.jr@gmail.com>, Petr Jelinek <petr@2ndquadrant.com>, "michael.paul.powers@gmail.com" <michael.paul.powers@gmail.com>,
Alvaro Herrera <alvherre@2ndquadrant.com>, Robert Welin <robert@vaion.com>
Date: 2021-07-22T09:04:07Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- 0001-signal-backends-on-commit.patch (text/x-patch) patch 0001
Hello hackers, On Wed, Jul 14, 2021 at 11:30 AM Sergey Fedchenko <seregayoga@bk.ru> wrote: > > Hi all! I still can reproduce it on 14beta1 version. I adapted a patch I found in this thread https://github.com/seregayoga/postgres/commit/338bc33f2cf77edde7c45bfdfb9f39a92ec57eb8 . It solved this bug for me (tested with simple Go program using https://github.com/lib/pq). It would be nice to have this bug fixed. I’m not so familiar with postgres code base, but would glad to help with testing. In our company in one of our projects we ran into this bug too. I attached the patch which fixes it in a different way. It calls SignalBackends() in AtCommit_Notify(). It is possible to call SignalBackends() outside of ProcessCompletedNotifies() after the commit 51004c7172b5c35afac050f4d5849839a06e8d3b, which removes necessity of checking of SignalBackends()'s result. Moving SignalBackends() to AtCommit_Notify() makes it possible to signal backends by "non-normal" backends including logical replication workers. It seems it is safe to call SignalBackends() in AtCommit_Notify() since SignalBackends() doesn't raise any error except OOM. Regarding Andres concern: > what I am wondering is what happens if there's a background worker (like > the replication worker, but it could be other things too) that queues > notifications, but no normal backends are actually listening. As far as > I can tell, in that case we'd continue to queue stuff into the slru, but > wouldn't actually clean things up until a normal session gets around to > it? Which might be a while, on e.g. a logical replica. A backend which raises notifications calls asyncQueueAdvanceTail() sometimes, which truncates pages up to new tail, which is equal to head if there are no listening backends. But there will be a problem if there is a backend which is listening but it doesn't process incoming notifications and doesn't update its queue position. In that case asyncQueueAdvanceTail() is able to advance tail only up to that backend's queue position. -- Artur Zakirov PostgreSQL Developer at Adjust
Commits
-
Disallow LISTEN in background workers.
- e06cc024bd33 13.5 landed
- d84d62b6225b 14.0 landed
- 1316be28664f 15.0 landed
-
Send NOTIFY signals during CommitTransaction.
- 63f28776cb9f 13.5 landed
- 2e4eae87d02f 15.0 landed
- 0eff10a00844 14.0 landed
-
Make some efficiency improvements in LISTEN/NOTIFY.
- 51004c7172b5 13.0 cited