string literal.
In the default configuration it must be shorter than 8000 bytes.
(If binary data or large amounts of information need to be communicated,
it's best to put it in a database table and send the key of the record.)
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
<para>
There is a queue that holds notifications that have been sent but not
yet processed by all listening sessions. If this queue becomes full,
transactions calling <command>NOTIFY</command> will fail at commit.
The queue is quite large (8GB in a standard installation) and should be
sufficiently sized for almost every use case. However, no cleanup can take
place if a session executes <command>LISTEN</command> and then enters a
transaction for a very long time. Once the queue is half full you will see
warnings in the log file pointing you to the session that is preventing
cleanup. In this case you should make sure that this session ends its
current transaction so that cleanup can proceed.
</para>
<para>
The function <function>pg_notification_queue_usage</function> returns the
fraction of the queue that is currently occupied by pending notifications.
See <xref linkend="functions-info"/> for more information.
</para>
<para>
A transaction that has executed <command>NOTIFY</command> cannot be
prepared for two-phase commit.
</para>
<refsect2>
<title>pg_notify</title>
<indexterm>
<primary>pg_notify</primary>
</indexterm>
<para>
To send a notification you can also use the function
<literal><function>pg_notify</function>(<type>text</type>,
<type>text</type>)</literal>. The function takes the channel name as the
first argument and the payload as the second. The function is much easier
to use than the <command>NOTIFY</command> command if you need to work with
non-constant channel names and payloads.
</para>
</refsect2>
</refsect1>
<refsect1>
<title>Examples</title>
<para>
Configure and execute a listen/notify sequence from
<application>psql</application>:
<programlisting>
LISTEN virtual;
NOTIFY virtual;
Asynchronous notification "virtual" received from server process with PID 8448.
NOTIFY virtual, 'This is the payload';
Asynchronous notification "virtual" with payload "This is the payload" received from server process with PID 8448.
LISTEN foo;
SELECT pg_notify('fo' || 'o', 'pay' || 'load');
Asynchronous notification "foo" with payload "payload" received from server process with PID 14728.
</programlisting></para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para>
There is no <command>NOTIFY</command> statement in the SQL
standard.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-listen"/></member>
<member><xref linkend="sql-unlisten"/></member>
<member><xref linkend="guc-max-notify-queue-pages"/></member>
</simplelist>
</refsect1>
</refentry>