Re: BUG #15293: Stored Procedure Triggered by Logical Replication is Unable to use Notification Events
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Artur Zakirov <artur.zakirov@adjust.com>
Cc: Sergey Fedchenko <seregayoga@bk.ru>,
Daniel Danzberger <daniel@dd-wrt.com>,
Andres Freund <andres@anarazel.de>, 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-09-12T17:29:58Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- v3-0001-signal-backends-on-commit.patch (text/x-diff) patch v3-0001
Artur Zakirov <artur.zakirov@adjust.com> writes: > [ v2-0001-signal-backends-on-commit.patch ] I had an epiphany while looking at this. Now that PostgresMain calls ProcessNotifyInterrupt at the same place it calls ProcessCompletedNotifies (which it does since 790026972), we don't actually need ProcessCompletedNotifies to read self-notifies either. If we merely set notifyInterruptPending, ProcessNotifyInterrupt will handle that just fine. With the other changes already under discussion, this means ProcessCompletedNotifies can go away entirely. That's not only less code, but fewer cycles: in cases where we have both self-notifies and inbound notify signals, the existing code starts two transactions and runs asyncQueueReadAllNotifications twice, but there's no need to do it more than once. Self-notifies become less of a special case on the sending side too, since we can just treat that as signalling ourselves --- though it still seems worthwhile to optimize that by setting notifyInterruptPending directly instead of invoking kill(). Hence, I present the attached, which also tweaks things to avoid an extra pq_flush in the end-of-command code path, and improves the comments to discuss the issue of NOTIFYs sent by procedures. There is still a loose end we ought to think about: what to do when someone issues LISTEN in a background worker. With the code as it stands, or with this patch, the worker will block cleanout of the async SLRU since it will never read any messages. (With the code as it stands, a bgworker author can ameliorate that by calling ProcessCompletedNotifies, but this patch is going to either eliminate ProcessCompletedNotifies or turn it into a no-op. In any case, we still have a problem if an ill-considered trigger issues LISTEN in a replication worker.) I'm inclined to think we should flat-out reject LISTEN in any process that is not attached to a frontend, at least until somebody takes the trouble to add infrastructure that would let it be useful. I've not done that here though; I'm not quite sure what we should test for. regards, tom lane
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