postgresql/src/backend/access
Tom Lane 0eff10a008 Send NOTIFY signals during CommitTransaction.
Formerly, we sent signals for outgoing NOTIFY messages within
ProcessCompletedNotifies, which was also responsible for sending
relevant ones of those messages to our connected client.  It therefore
had to run during the main-loop processing that occurs just before
going idle.  This arrangement had two big disadvantages:

* Now that procedures allow intra-command COMMITs, it would be
useful to send NOTIFYs to other sessions immediately at COMMIT
(though, for reasons of wire-protocol stability, we still shouldn't
forward them to our client until end of command).

* Background processes such as replication workers would not send
NOTIFYs at all, since they never execute the client communication
loop.  We've had requests to allow triggers running in replication
workers to send NOTIFYs, so that's a problem.

To fix these things, move transmission of outgoing NOTIFY signals
into AtCommit_Notify, where it will happen during CommitTransaction.
Also move the possible call of asyncQueueAdvanceTail there, to
ensure we don't bloat the async SLRU if a background worker sends
many NOTIFYs with no one listening.

We can also drop the call of asyncQueueReadAllNotifications,
allowing ProcessCompletedNotifies to go away entirely.  That's
because commit 790026972 added a call of ProcessNotifyInterrupt
adjacent to PostgresMain's call of ProcessCompletedNotifies,
and that does its own call of asyncQueueReadAllNotifications,
meaning that we were uselessly doing two such calls (inside two
separate transactions) whenever inbound notify signals coincided
with an outbound notify.  We need only set notifyInterruptPending
to ensure that ProcessNotifyInterrupt runs, and we're done.

The existing documentation suggests that custom background workers
should call ProcessCompletedNotifies if they want to send NOTIFY
messages.  To avoid an ABI break in the back branches, reduce it
to an empty routine rather than removing it entirely.  Removal
will occur in v15.

Although the problems mentioned above have existed for awhile,
I don't feel comfortable back-patching this any further than v13.
There was quite a bit of churn in adjacent code between 12 and 13.
At minimum we'd have to also backpatch 51004c717, and a good deal
of other adjustment would also be needed, so the benefit-to-risk
ratio doesn't look attractive.

Per bug #15293 from Michael Powers (and similar gripes from others).

Artur Zakirov and Tom Lane

Discussion: https://postgr.es/m/153243441449.1404.2274116228506175596@wrigleys.postgresql.org
2021-09-14 17:18:25 -04:00
..
brin Fix an asssortment of typos in brin_minmax_multi.c and mcv.c 2021-06-10 20:13:44 +12:00
common Revert analyze support for partitioned tables 2021-08-16 17:27:52 -04:00
gin Remove redundant memset(0) calls for page init of some index AMs 2021-04-07 14:35:26 +09:00
gist Remove redundant variable pageSize in gistinitpage 2021-06-25 07:55:34 +02:00
hash Further portability tweaks for float4/float8 hash functions. 2021-09-04 16:29:08 -04:00
heap VACUUM VERBOSE: Don't report "pages removed". 2021-08-31 20:37:17 -07:00
index Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
nbtree Remove dead assignment to local variable. 2021-07-12 11:13:59 +03:00
rmgrdesc Improve WAL record descriptions for SP-GiST records. 2021-04-20 17:01:49 -04:00
spgist Count SP-GiST index scans in pg_stat statistics. 2021-08-27 19:53:06 -04:00
table Allow configurable LZ4 TOAST compression. 2021-03-19 15:10:38 -04:00
tablesample Update copyright for 2021 2021-01-02 13:06:25 -05:00
transam Send NOTIFY signals during CommitTransaction. 2021-09-14 17:18:25 -04:00
Makefile Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00