@@ -39,11 +39,14 @@ NOTIFY <replaceable class="parameter">channel</replaceable> [ , <replaceable cla
3939
4040 <para>
4141 <command>NOTIFY</command> provides a simple
42- interprocess communication mechanism for a collection of processes
42+ interprocess communication mechanism,
43+ in essentially the form of a first-in-first-out (FIFO) queue,
44+ for a collection of processes
4345 accessing the same <productname>PostgreSQL</productname> database.
44- A payload string can be sent along with the notification, and
45- higher-level mechanisms for passing structured data can be built by using
46- tables in the database to pass additional data from notifier to listener(s).
46+ While a payload string can be sent along with the notification,
47+ higher-level mechanisms for passing structured data
48+ from notifier to listener(s) must be built using
49+ tables in the database.
4750 </para>
4851
4952 <para>
@@ -61,12 +64,12 @@ NOTIFY <replaceable class="parameter">channel</replaceable> [ , <replaceable cla
6164 take a look at it to see what's new</quote>. But no such association is enforced by
6265 the <command>NOTIFY</command> and <command>LISTEN</command> commands. For
6366 example, a database designer could use several different channel names
64- to signal different sorts of changes to a single table. Alternatively,
67+ to indicate different sorts of changes to a single table. Alternatively,
6568 the payload string could be used to differentiate various cases.
6669 </para>
6770
6871 <para>
69- When <command>NOTIFY</command> is used to signal the occurrence of changes
72+ When <command>NOTIFY</command> is used to communicate the occurrence of changes
7073 to a particular table, a useful programming technique is to put the
7174 <command>NOTIFY</command> in a statement trigger that is triggered by table updates.
7275 In this way, notification happens automatically when the table is changed,
@@ -76,40 +79,38 @@ NOTIFY <replaceable class="parameter">channel</replaceable> [ , <replaceable cla
7679 <para>
7780 <command>NOTIFY</command> interacts with SQL transactions in some important
7881 ways. Firstly, if a <command>NOTIFY</command> is executed inside a
79- transaction, the notify events are not delivered until and unless the
82+ transaction, the notification events are not enqueued until and unless the
8083 transaction is committed. This is appropriate, since if the transaction
8184 is aborted, all the commands within it have had no
8285 effect, including <command>NOTIFY</command>. But it can be disconcerting if one
83- is expecting the notification events to be delivered immediately. Secondly, if
84- a listening session receives a notification signal while it is within a transaction,
85- the notification event will not be delivered to its connected client until just
86- after the transaction is completed (either committed or aborted). Again, the
86+ is expecting the notification events to be delivered to client connections immediately.
87+ Secondly, a listening session never processes the notification queue events
88+ while it is within a transaction. Again, the
8789 reasoning is that if a notification were delivered within a transaction that was
8890 later aborted, one would want the notification to be undone somehow —
8991 but
90- the server cannot <quote>take back</quote> a notification once it has sent it to the client.
92+ the server cannot <quote>take back</quote> a notification once it has delivered
93+ it to the client.
9194 So notification events are only delivered between transactions. The upshot of this
92- is that applications using <command>NOTIFY</command> for real-time signaling
93- should try to keep their transactions short.
95+ is that applications using <command>NOTIFY</command> should try to keep their
96+ transactions short.
97+ </para>
98+
99+ <para>
100+ If, within the same transaction, a channel name is notified multiple times,
101+ with identical payload strings, only the first the notification is enqueued.
94102 </para>
95103
96104 <para>
97- If the same channel name is signaled multiple times with identical
98- payload strings within the same transaction, only one instance of the
99- notification event is delivered to listeners.
100- On the other hand, notifications with distinct payload strings will
101- always be delivered as distinct notifications. Similarly, notifications from
102- different transactions will never get folded into one notification.
103- Except for dropping later instances of duplicate notifications,
104105 <command>NOTIFY</command> guarantees that notifications from the same
105- transaction get delivered in the order they were sent . It is also
106- guaranteed that messages from different transactions are delivered in
106+ transaction get delivered in the order they were issued . It also
107+ guarantees that messages from different transactions are delivered in
107108 the order in which the transactions committed.
108109 </para>
109110
110111 <para>
111112 It is common for a client that executes <command>NOTIFY</command>
112- to be listening on the same notification channel itself . In that case
113+ to be listening on the same notification channel. In that case
113114 it will get back a notification event, just like all the other
114115 listening sessions. Depending on the application logic, this could
115116 result in useless work, for example, reading a database table to
@@ -131,7 +132,7 @@ NOTIFY <replaceable class="parameter">channel</replaceable> [ , <replaceable cla
131132 <term><replaceable class="parameter">channel</replaceable></term>
132133 <listitem>
133134 <para>
134- Name of the notification channel to be signaled (any identifier).
135+ Name of the notification channel (any identifier).
135136 </para>
136137 </listitem>
137138 </varlistentry>
@@ -154,16 +155,19 @@ NOTIFY <replaceable class="parameter">channel</replaceable> [ , <replaceable cla
154155 <title>Notes</title>
155156
156157 <para>
157- There is a queue that holds notifications that have been sent but not
158- yet processed by all listening sessions. If this queue becomes full,
159- transactions calling <command>NOTIFY</command> will fail at commit.
158+ The notification FIFO queue contains a single entry per notification event
159+ and all listening sessions publish which events they have processed. Events
160+ which have been processed by all sessions are removed. If a listening session
161+ holds a transaction open for a very long time the queue could become full,
162+ at which point transactions calling <command>NOTIFY</command> will fail at commit.
163+ </para>
164+ <para>
160165 The queue is quite large (8GB in a standard installation) and should be
161- sufficiently sized for almost every use case. However, no cleanup can take
162- place if a session executes <command>LISTEN</command> and then enters a
163- transaction for a very long time. Once the queue is half full you will see
166+ sufficiently sized for almost every use case. Once the queue is half
167+ full you will see
164168 warnings in the log file pointing you to the session that is preventing
165169 cleanup. In this case you should make sure that this session ends its
166- current transaction so that cleanup can proceed .
170+ current transaction so that events can be removed .
167171 </para>
168172 <para>
169173 The function <function>pg_notification_queue_usage</function> returns the
0 commit comments