1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-21 12:05:57 +03:00

Replace the pg_listener-based LISTEN/NOTIFY mechanism with an in-memory queue.

In addition, add support for a "payload" string to be passed along with
each notify event.

This implementation should be significantly more efficient than the old one,
and is also more compatible with Hot Standby usage.  There is not yet any
facility for HS slaves to receive notifications generated on the master,
although such a thing is possible in future.

Joachim Wieland, reviewed by Jeff Davis; also hacked on by me.
This commit is contained in:
Tom Lane 2010-02-16 22:34:57 +00:00
parent fc5173ad51
commit d1e027221d
37 changed files with 1831 additions and 744 deletions

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.221 2010/02/07 20:48:09 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.222 2010/02/16 22:34:41 tgl Exp $ -->
<!-- <!--
Documentation of the system catalogs, directed toward PostgreSQL developers Documentation of the system catalogs, directed toward PostgreSQL developers
--> -->
@ -168,11 +168,6 @@
<entry>metadata for large objects</entry> <entry>metadata for large objects</entry>
</row> </row>
<row>
<entry><link linkend="catalog-pg-listener"><structname>pg_listener</structname></link></entry>
<entry>asynchronous notification support</entry>
</row>
<row> <row>
<entry><link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link></entry> <entry><link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link></entry>
<entry>schemas</entry> <entry>schemas</entry>
@ -3253,68 +3248,6 @@
</table> </table>
</sect1> </sect1>
<sect1 id="catalog-pg-listener">
<title><structname>pg_listener</structname></title>
<indexterm zone="catalog-pg-listener">
<primary>pg_listener</primary>
</indexterm>
<para>
The catalog <structname>pg_listener</structname> supports the
<xref linkend="sql-listen" endterm="sql-listen-title"> and
<xref linkend="sql-notify" endterm="sql-notify-title">
commands. A listener creates an entry in
<structname>pg_listener</structname> for each notification name
it is listening for. A notifier scans <structname>pg_listener</structname>
and updates each matching entry to show that a notification has occurred.
The notifier also sends a signal (using the PID recorded in the table)
to awaken the listener from sleep.
</para>
<table>
<title><structname>pg_listener</> Columns</title>
<tgroup cols="3">
<thead>
<row>
<entry>Name</entry>
<entry>Type</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><structfield>relname</structfield></entry>
<entry><type>name</type></entry>
<entry>
Notify condition name. (The name need not match any actual
relation in the database; the name <structfield>relname</> is historical.)
</entry>
</row>
<row>
<entry><structfield>listenerpid</structfield></entry>
<entry><type>int4</type></entry>
<entry>PID of the server process that created this entry</entry>
</row>
<row>
<entry><structfield>notification</structfield></entry>
<entry><type>int4</type></entry>
<entry>
Zero if no event is pending for this listener. If an event is
pending, the PID of the server process that sent the notification
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1>
<sect1 id="catalog-pg-namespace"> <sect1 id="catalog-pg-namespace">
<title><structname>pg_namespace</structname></title> <title><structname>pg_namespace</structname></title>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.503 2010/02/16 21:18:01 momjian Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.504 2010/02/16 22:34:42 tgl Exp $ -->
<chapter id="functions"> <chapter id="functions">
<title>Functions and Operators</title> <title>Functions and Operators</title>
@ -11529,6 +11529,12 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
</entry> </entry>
</row> </row>
<row>
<entry><literal><function>pg_listening_channels</function>()</literal></entry>
<entry><type>setof text</type></entry>
<entry>channel names that the session is currently listening on</entry>
</row>
<row> <row>
<entry><literal><function>inet_client_addr</function>()</literal></entry> <entry><literal><function>inet_client_addr</function>()</literal></entry>
<entry><type>inet</type></entry> <entry><type>inet</type></entry>
@ -11674,6 +11680,16 @@ SET search_path TO <replaceable>schema</> <optional>, <replaceable>schema</>, ..
</para> </para>
</note> </note>
<indexterm>
<primary>pg_listening_channels</primary>
</indexterm>
<para>
<function>pg_listening_channels</function> returns a set of names of
channels that the current session is listening to. See <xref
linkend="sql-listen" endterm="sql-listen-title"> for more information.
</para>
<indexterm> <indexterm>
<primary>inet_client_addr</primary> <primary>inet_client_addr</primary>
</indexterm> </indexterm>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.298 2010/02/16 20:58:13 momjian Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.299 2010/02/16 22:34:42 tgl Exp $ -->
<chapter id="libpq"> <chapter id="libpq">
<title><application>libpq</application> - C Library</title> <title><application>libpq</application> - C Library</title>
@ -4111,50 +4111,48 @@ typedef struct {
<productname>PostgreSQL</productname> offers asynchronous notification <productname>PostgreSQL</productname> offers asynchronous notification
via the <command>LISTEN</command> and <command>NOTIFY</command> via the <command>LISTEN</command> and <command>NOTIFY</command>
commands. A client session registers its interest in a particular commands. A client session registers its interest in a particular
notification condition with the <command>LISTEN</command> command (and notification channel with the <command>LISTEN</command> command (and
can stop listening with the <command>UNLISTEN</command> command). All can stop listening with the <command>UNLISTEN</command> command). All
sessions listening on a particular condition will be notified sessions listening on a particular channel will be notified
asynchronously when a <command>NOTIFY</command> command with that asynchronously when a <command>NOTIFY</command> command with that
condition name is executed by any session. No additional information channel name is executed by any session. A <quote>payload</> string can
is passed from the notifier to the listener. Thus, typically, any be passed to communicate additional data to the listeners.
actual data that needs to be communicated is transferred through a
database table. Commonly, the condition name is the same as the
associated table, but it is not necessary for there to be any associated
table.
</para> </para>
<para> <para>
<application>libpq</application> applications submit <application>libpq</application> applications submit
<command>LISTEN</command> and <command>UNLISTEN</command> commands as <command>LISTEN</command>, <command>UNLISTEN</command>,
and <command>NOTIFY</command> commands as
ordinary SQL commands. The arrival of <command>NOTIFY</command> ordinary SQL commands. The arrival of <command>NOTIFY</command>
messages can subsequently be detected by calling messages can subsequently be detected by calling
<function>PQnotifies</function>.<indexterm><primary>PQnotifies</></> <function>PQnotifies</function>.<indexterm><primary>PQnotifies</></>
</para> </para>
<para> <para>
The function <function>PQnotifies</function> The function <function>PQnotifies</function> returns the next notification
returns the next notification from a list of unhandled from a list of unhandled notification messages received from the server.
notification messages received from the server. It returns a null pointer if It returns a null pointer if there are no pending notifications. Once a
there are no pending notifications. Once a notification is notification is returned from <function>PQnotifies</>, it is considered
returned from <function>PQnotifies</>, it is considered handled and will be handled and will be removed from the list of notifications.
removed from the list of notifications.
<synopsis> <synopsis>
PGnotify *PQnotifies(PGconn *conn); PGnotify *PQnotifies(PGconn *conn);
typedef struct pgNotify { typedef struct pgNotify {
char *relname; /* notification condition name */ char *relname; /* notification channel name */
int be_pid; /* process ID of notifying server process */ int be_pid; /* process ID of notifying server process */
char *extra; /* notification parameter */ char *extra; /* notification payload string */
} PGnotify; } PGnotify;
</synopsis> </synopsis>
After processing a <structname>PGnotify</structname> object returned After processing a <structname>PGnotify</structname> object returned
by <function>PQnotifies</function>, be sure to free it with by <function>PQnotifies</function>, be sure to free it with
<function>PQfreemem</function>. It is sufficient to free the <function>PQfreemem</function>. It is sufficient to free the
<structname>PGnotify</structname> pointer; the <structname>PGnotify</structname> pointer; the
<structfield>relname</structfield> and <structfield>extra</structfield> <structfield>relname</structfield> and <structfield>extra</structfield>
fields do not represent separate allocations. (At present, the fields do not represent separate allocations. (The names of these fields
<structfield>extra</structfield> field is unused and will always point are historical; in particular, channel names need not have anything to
to an empty string.) do with relation names.)
</para> </para>
<para> <para>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/protocol.sgml,v 1.80 2010/02/16 20:58:14 momjian Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/protocol.sgml,v 1.81 2010/02/16 22:34:43 tgl Exp $ -->
<chapter id="protocol"> <chapter id="protocol">
<title>Frontend/Backend Protocol</title> <title>Frontend/Backend Protocol</title>
@ -1117,7 +1117,7 @@
backend will send a NotificationResponse message (not to be backend will send a NotificationResponse message (not to be
confused with NoticeResponse!) whenever a confused with NoticeResponse!) whenever a
<command>NOTIFY</command> command is executed for the same <command>NOTIFY</command> command is executed for the same
notification name. channel name.
</para> </para>
<note> <note>
@ -3187,7 +3187,7 @@ NotificationResponse (B)
</term> </term>
<listitem> <listitem>
<para> <para>
The name of the condition that the notify has been raised on. The name of the channel that the notify has been raised on.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@ -3197,9 +3197,7 @@ NotificationResponse (B)
</term> </term>
<listitem> <listitem>
<para> <para>
Additional information passed from the notifying process. The <quote>payload</> string passed from the notifying process.
(Currently, this feature is unimplemented so the field
is always an empty string.)
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@ -4353,7 +4351,7 @@ the backend.
<para> <para>
The NotificationResponse ('<literal>A</>') message has an additional string The NotificationResponse ('<literal>A</>') message has an additional string
field, which is presently empty but might someday carry additional data passed field, which can carry a <quote>payload</> string passed
from the <command>NOTIFY</command> event sender. from the <command>NOTIFY</command> event sender.
</para> </para>
@ -4364,5 +4362,4 @@ string parameter; this has been removed.
</sect1> </sect1>
</chapter> </chapter>

View File

@ -1,5 +1,5 @@
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/listen.sgml,v 1.23 2008/11/14 10:22:47 petere Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/listen.sgml,v 1.24 2010/02/16 22:34:43 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
LISTEN <replaceable class="PARAMETER">name</replaceable> LISTEN <replaceable class="PARAMETER">channel</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -30,24 +30,23 @@ LISTEN <replaceable class="PARAMETER">name</replaceable>
<para> <para>
<command>LISTEN</command> registers the current session as a <command>LISTEN</command> registers the current session as a
listener on the notification condition <replaceable listener on the notification channel named <replaceable
class="PARAMETER">name</replaceable>. class="PARAMETER">channel</replaceable>.
If the current session is already registered as a listener for If the current session is already registered as a listener for
this notification condition, nothing is done. this notification channel, nothing is done.
</para> </para>
<para> <para>
Whenever the command <command>NOTIFY <replaceable Whenever the command <command>NOTIFY <replaceable
class="PARAMETER">name</replaceable></command> is invoked, either class="PARAMETER">channel</replaceable></command> is invoked, either
by this session or another one connected to the same database, all by this session or another one connected to the same database, all
the sessions currently listening on that notification condition are the sessions currently listening on that notification channel are
notified, and each will in turn notify its connected client notified, and each will in turn notify its connected client
application. See the discussion of <command>NOTIFY</command> for application.
more information.
</para> </para>
<para> <para>
A session can be unregistered for a given notify condition with the A session can be unregistered for a given notification channel with the
<command>UNLISTEN</command> command. A session's listen <command>UNLISTEN</command> command. A session's listen
registrations are automatically cleared when the session ends. registrations are automatically cleared when the session ends.
</para> </para>
@ -78,16 +77,31 @@ LISTEN <replaceable class="PARAMETER">name</replaceable>
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><replaceable class="PARAMETER">name</replaceable></term> <term><replaceable class="PARAMETER">channel</replaceable></term>
<listitem> <listitem>
<para> <para>
Name of a notify condition (any identifier). Name of a notification channel (any identifier).
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
<refsect1>
<title>Notes</title>
<para>
<command>LISTEN</command> takes effect at transaction commit.
If <command>LISTEN</command> or <command>UNLISTEN</command> is executed
within a transaction that later rolls back, the set of notification
channels being listened to is unchanged.
</para>
<para>
A transaction that has executed <command>LISTEN</command> cannot be
prepared for two-phase commit.
</para>
</refsect1>
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>

View File

@ -1,5 +1,5 @@
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/notify.sgml,v 1.31 2008/11/14 10:22:47 petere Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/notify.sgml,v 1.32 2010/02/16 22:34:43 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
NOTIFY <replaceable class="PARAMETER">name</replaceable> NOTIFY <replaceable class="PARAMETER">channel</replaceable> [ , <replaceable class="PARAMETER">payload</replaceable> ]
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -29,35 +29,39 @@ NOTIFY <replaceable class="PARAMETER">name</replaceable>
<title>Description</title> <title>Description</title>
<para> <para>
The <command>NOTIFY</command> command sends a notification event to each The <command>NOTIFY</command> command sends a notification event together
client application that has previously executed with an optional <quote>payload</> string to each client application that
<command>LISTEN <replaceable class="parameter">name</replaceable></command> has previously executed
for the specified notification name in the current database. <command>LISTEN <replaceable class="parameter">channel</></command>
for the specified channel name in the current database.
</para> </para>
<para> <para>
<command>NOTIFY</command> provides a simple form of signal or <command>NOTIFY</command> provides a simple
interprocess communication mechanism for a collection of processes interprocess communication mechanism for a collection of processes
accessing the same <productname>PostgreSQL</productname> database. accessing the same <productname>PostgreSQL</productname> database.
Higher-level mechanisms can be built by using tables in the database to A payload string can be sent along with the notification, and
pass additional data (beyond a mere notification name) from notifier to higher-level mechanisms for passing structured data can be built by using
listener(s). tables in the database to pass additional data from notifier to listener(s).
</para> </para>
<para> <para>
The information passed to the client for a notification event includes the notification The information passed to the client for a notification event includes the
name and the notifying session's server process <acronym>PID</>. It is up to the notification channel
database designer to define the notification names that will be used in a given name, the notifying session's server process <acronym>PID</>, and the
database and what each one means. payload string, which is an empty string if it has not been specified.
</para> </para>
<para> <para>
Commonly, the notification name is the same as the name of some table in It is up to the database designer to define the channel names that will
be used in a given database and what each one means.
Commonly, the channel name is the same as the name of some table in
the database, and the notify event essentially means, <quote>I changed this table, the database, and the notify event essentially means, <quote>I changed this table,
take a look at it to see what's new</quote>. But no such association is enforced by take a look at it to see what's new</quote>. But no such association is enforced by
the <command>NOTIFY</command> and <command>LISTEN</command> commands. For the <command>NOTIFY</command> and <command>LISTEN</command> commands. For
example, a database designer could use several different notification names example, a database designer could use several different channel names
to signal different sorts of changes to a single table. to signal different sorts of changes to a single table. Alternatively,
the payload string could be used to differentiate various cases.
</para> </para>
<para> <para>
@ -89,19 +93,22 @@ NOTIFY <replaceable class="PARAMETER">name</replaceable>
</para> </para>
<para> <para>
<command>NOTIFY</command> behaves like Unix signals in one important If the same channel name is signaled multiple times from the same
respect: if the same notification name is signaled multiple times in quick transaction with identical payload strings, the
succession, recipients might get only one notification event for several executions database server can decide to deliver a single notification only.
of <command>NOTIFY</command>. So it is a bad idea to depend on the number On the other hand, notifications with distinct payload strings will
of notifications received. Instead, use <command>NOTIFY</command> to wake up always be delivered as distinct notifications. Similarly, notifications from
applications that need to pay attention to something, and use a database different transactions will never get folded into one notification.
object (such as a sequence) to keep track of what happened or how many times Except for dropping later instances of duplicate notifications,
it happened. <command>NOTIFY</command> guarantees that notifications from the same
transaction get delivered in the order they were sent. It is also
guaranteed that messages from different transactions are delivered in
the order in which the transactions committed.
</para> </para>
<para> <para>
It is common for a client that executes <command>NOTIFY</command> It is common for a client that executes <command>NOTIFY</command>
to be listening on the same notification name itself. In that case to be listening on the same notification channel itself. In that case
it will get back a notification event, just like all the other it will get back a notification event, just like all the other
listening sessions. Depending on the application logic, this could listening sessions. Depending on the application logic, this could
result in useless work, for example, reading a database table to result in useless work, for example, reading a database table to
@ -111,12 +118,7 @@ NOTIFY <replaceable class="PARAMETER">name</replaceable>
notification event message) is the same as one's own session's notification event message) is the same as one's own session's
<acronym>PID</> (available from <application>libpq</>). When they <acronym>PID</> (available from <application>libpq</>). When they
are the same, the notification event is one's own work bouncing are the same, the notification event is one's own work bouncing
back, and can be ignored. (Despite what was said in the preceding back, and can be ignored.
paragraph, this is a safe technique.
<productname>PostgreSQL</productname> keeps self-notifications
separate from notifications arriving from other sessions, so you
cannot miss an outside notification by ignoring your own
notifications.)
</para> </para>
</refsect1> </refsect1>
@ -125,16 +127,61 @@ NOTIFY <replaceable class="PARAMETER">name</replaceable>
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><replaceable class="PARAMETER">name</replaceable></term> <term><replaceable class="PARAMETER">channel</replaceable></term>
<listitem> <listitem>
<para> <para>
Name of the notification to be signaled (any identifier). Name of the notification channel to be signaled (any identifier).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">payload</replaceable></term>
<listitem>
<para>
The <quote>payload</> string to be communicated along with the
notification. This string must be shorter than 8000 bytes, and
is treated as text.
(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> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
<refsect1>
<title>Notes</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>
<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>
A transaction that has executed <command>NOTIFY</command> cannot be
prepared for two-phase commit.
</para>
</refsect1>
<refsect1> <refsect1>
<title>Examples</title> <title>Examples</title>
@ -146,6 +193,12 @@ NOTIFY <replaceable class="PARAMETER">name</replaceable>
LISTEN virtual; LISTEN virtual;
NOTIFY virtual; NOTIFY virtual;
Asynchronous notification "virtual" received from server process with PID 8448. 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> </programlisting>
</para> </para>
</refsect1> </refsect1>

View File

@ -1,5 +1,5 @@
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/unlisten.sgml,v 1.30 2008/11/14 10:22:47 petere Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/unlisten.sgml,v 1.31 2010/02/16 22:34:43 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
UNLISTEN { <replaceable class="PARAMETER">name</replaceable> | * } UNLISTEN { <replaceable class="PARAMETER">channel</replaceable> | * }
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -33,8 +33,8 @@ UNLISTEN { <replaceable class="PARAMETER">name</replaceable> | * }
registration for <command>NOTIFY</command> events. registration for <command>NOTIFY</command> events.
<command>UNLISTEN</command> cancels any existing registration of <command>UNLISTEN</command> cancels any existing registration of
the current <productname>PostgreSQL</productname> session as a the current <productname>PostgreSQL</productname> session as a
listener on the notification <replaceable listener on the notification channel named <replaceable
class="PARAMETER">name</replaceable>. The special wildcard class="PARAMETER">channel</replaceable>. The special wildcard
<literal>*</literal> cancels all listener registrations for the <literal>*</literal> cancels all listener registrations for the
current session. current session.
</para> </para>
@ -52,10 +52,10 @@ UNLISTEN { <replaceable class="PARAMETER">name</replaceable> | * }
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><replaceable class="PARAMETER">name</replaceable></term> <term><replaceable class="PARAMETER">channel</replaceable></term>
<listitem> <listitem>
<para> <para>
Name of a notification (any identifier). Name of a notification channel (any identifier).
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@ -83,6 +83,11 @@ UNLISTEN { <replaceable class="PARAMETER">name</replaceable> | * }
At the end of each session, <command>UNLISTEN *</command> is At the end of each session, <command>UNLISTEN *</command> is
automatically executed. automatically executed.
</para> </para>
<para>
A transaction that has executed <command>UNLISTEN</command> cannot be
prepared for two-phase commit.
</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
@ -100,7 +105,7 @@ Asynchronous notification "virtual" received from server process with PID 8448.
<para> <para>
Once <command>UNLISTEN</> has been executed, further <command>NOTIFY</> Once <command>UNLISTEN</> has been executed, further <command>NOTIFY</>
commands will be ignored: messages will be ignored:
<programlisting> <programlisting>
UNLISTEN virtual; UNLISTEN virtual;

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/storage.sgml,v 1.31 2010/02/07 20:48:09 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/storage.sgml,v 1.32 2010/02/16 22:34:43 tgl Exp $ -->
<chapter id="storage"> <chapter id="storage">
@ -77,6 +77,11 @@ Item
(used for shared row locks)</entry> (used for shared row locks)</entry>
</row> </row>
<row>
<entry><filename>pg_notify</></entry>
<entry>Subdirectory containing LISTEN/NOTIFY status data</entry>
</row>
<row> <row>
<entry><filename>pg_stat_tmp</></entry> <entry><filename>pg_stat_tmp</></entry>
<entry>Subdirectory containing temporary files for the statistics <entry>Subdirectory containing temporary files for the statistics

View File

@ -41,7 +41,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.48 2010/01/02 16:57:35 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.49 2010/02/16 22:34:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -59,25 +59,6 @@
#include "miscadmin.h" #include "miscadmin.h"
/*
* Define segment size. A page is the same BLCKSZ as is used everywhere
* else in Postgres. The segment size can be chosen somewhat arbitrarily;
* we make it 32 pages by default, or 256Kb, i.e. 1M transactions for CLOG
* or 64K transactions for SUBTRANS.
*
* Note: because TransactionIds are 32 bits and wrap around at 0xFFFFFFFF,
* page numbering also wraps around at 0xFFFFFFFF/xxxx_XACTS_PER_PAGE (where
* xxxx is CLOG or SUBTRANS, respectively), and segment numbering at
* 0xFFFFFFFF/xxxx_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT. We need
* take no explicit notice of that fact in this module, except when comparing
* segment and page numbers in SimpleLruTruncate (see PagePrecedes()).
*
* Note: this file currently assumes that segment file names will be four
* hex digits. This sets a lower bound on the segment size (64K transactions
* for 32-bit TransactionIds).
*/
#define SLRU_PAGES_PER_SEGMENT 32
#define SlruFileName(ctl, path, seg) \ #define SlruFileName(ctl, path, seg) \
snprintf(path, MAXPGPATH, "%s/%04X", (ctl)->Dir, seg) snprintf(path, MAXPGPATH, "%s/%04X", (ctl)->Dir, seg)
@ -183,6 +164,8 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
shared = (SlruShared) ShmemInitStruct(name, shared = (SlruShared) ShmemInitStruct(name,
SimpleLruShmemSize(nslots, nlsns), SimpleLruShmemSize(nslots, nlsns),
&found); &found);
if (!shared)
elog(ERROR, "out of shared memory");
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/twophase_rmgr.c,v 1.12 2010/01/02 16:57:35 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/twophase_rmgr.c,v 1.13 2010/02/16 22:34:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -16,7 +16,6 @@
#include "access/multixact.h" #include "access/multixact.h"
#include "access/twophase_rmgr.h" #include "access/twophase_rmgr.h"
#include "commands/async.h"
#include "pgstat.h" #include "pgstat.h"
#include "storage/lock.h" #include "storage/lock.h"
@ -25,7 +24,6 @@ const TwoPhaseCallback twophase_recover_callbacks[TWOPHASE_RM_MAX_ID + 1] =
{ {
NULL, /* END ID */ NULL, /* END ID */
lock_twophase_recover, /* Lock */ lock_twophase_recover, /* Lock */
NULL, /* notify/listen */
NULL, /* pgstat */ NULL, /* pgstat */
multixact_twophase_recover /* MultiXact */ multixact_twophase_recover /* MultiXact */
}; };
@ -34,7 +32,6 @@ const TwoPhaseCallback twophase_postcommit_callbacks[TWOPHASE_RM_MAX_ID + 1] =
{ {
NULL, /* END ID */ NULL, /* END ID */
lock_twophase_postcommit, /* Lock */ lock_twophase_postcommit, /* Lock */
notify_twophase_postcommit, /* notify/listen */
pgstat_twophase_postcommit, /* pgstat */ pgstat_twophase_postcommit, /* pgstat */
multixact_twophase_postcommit /* MultiXact */ multixact_twophase_postcommit /* MultiXact */
}; };
@ -43,7 +40,6 @@ const TwoPhaseCallback twophase_postabort_callbacks[TWOPHASE_RM_MAX_ID + 1] =
{ {
NULL, /* END ID */ NULL, /* END ID */
lock_twophase_postabort, /* Lock */ lock_twophase_postabort, /* Lock */
NULL, /* notify/listen */
pgstat_twophase_postabort, /* pgstat */ pgstat_twophase_postabort, /* pgstat */
multixact_twophase_postabort /* MultiXact */ multixact_twophase_postabort /* MultiXact */
}; };
@ -52,7 +48,6 @@ const TwoPhaseCallback twophase_standby_recover_callbacks[TWOPHASE_RM_MAX_ID + 1
{ {
NULL, /* END ID */ NULL, /* END ID */
lock_twophase_standby_recover, /* Lock */ lock_twophase_standby_recover, /* Lock */
NULL, /* notify/listen */
NULL, /* pgstat */ NULL, /* pgstat */
NULL /* MultiXact */ NULL /* MultiXact */
}; };

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.285 2010/02/13 16:15:46 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.286 2010/02/16 22:34:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1736,8 +1736,12 @@ CommitTransaction(void)
/* close large objects before lower-level cleanup */ /* close large objects before lower-level cleanup */
AtEOXact_LargeObject(true); AtEOXact_LargeObject(true);
/* NOTIFY commit must come before lower-level cleanup */ /*
AtCommit_Notify(); * Insert notifications sent by NOTIFY commands into the queue. This
* should be late in the pre-commit sequence to minimize time spent
* holding the notify-insertion lock.
*/
PreCommit_Notify();
/* Prevent cancel/die interrupt while cleaning up */ /* Prevent cancel/die interrupt while cleaning up */
HOLD_INTERRUPTS(); HOLD_INTERRUPTS();
@ -1825,6 +1829,7 @@ CommitTransaction(void)
/* Check we've released all catcache entries */ /* Check we've released all catcache entries */
AtEOXact_CatCache(true); AtEOXact_CatCache(true);
AtCommit_Notify();
AtEOXact_GUC(true, 1); AtEOXact_GUC(true, 1);
AtEOXact_SPI(true); AtEOXact_SPI(true);
AtEOXact_on_commit_actions(true); AtEOXact_on_commit_actions(true);

View File

@ -2,7 +2,7 @@
# #
# Makefile for backend/catalog # Makefile for backend/catalog
# #
# $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.76 2010/01/06 19:56:29 tgl Exp $ # $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.77 2010/02/16 22:34:43 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -30,7 +30,7 @@ POSTGRES_BKI_SRCS = $(addprefix $(top_srcdir)/src/include/catalog/,\
pg_attrdef.h pg_constraint.h pg_inherits.h pg_index.h pg_operator.h \ pg_attrdef.h pg_constraint.h pg_inherits.h pg_index.h pg_operator.h \
pg_opfamily.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \ pg_opfamily.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
pg_language.h pg_largeobject_metadata.h pg_largeobject.h pg_aggregate.h \ pg_language.h pg_largeobject_metadata.h pg_largeobject.h pg_aggregate.h \
pg_statistic.h pg_rewrite.h pg_trigger.h pg_listener.h pg_description.h \ pg_statistic.h pg_rewrite.h pg_trigger.h pg_description.h \
pg_cast.h pg_enum.h pg_namespace.h pg_conversion.h pg_depend.h \ pg_cast.h pg_enum.h pg_namespace.h pg_conversion.h pg_depend.h \
pg_database.h pg_db_role_setting.h pg_tablespace.h pg_pltemplate.h \ pg_database.h pg_db_role_setting.h pg_tablespace.h pg_pltemplate.h \
pg_authid.h pg_auth_members.h pg_shdepend.h pg_shdescription.h \ pg_authid.h pg_auth_members.h pg_shdepend.h pg_shdescription.h \

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.461 2010/02/12 17:33:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.462 2010/02/16 22:34:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -2777,6 +2777,7 @@ _copyNotifyStmt(NotifyStmt *from)
NotifyStmt *newnode = makeNode(NotifyStmt); NotifyStmt *newnode = makeNode(NotifyStmt);
COPY_STRING_FIELD(conditionname); COPY_STRING_FIELD(conditionname);
COPY_STRING_FIELD(payload);
return newnode; return newnode;
} }

View File

@ -22,7 +22,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.382 2010/02/12 17:33:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.383 2010/02/16 22:34:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1325,6 +1325,7 @@ static bool
_equalNotifyStmt(NotifyStmt *a, NotifyStmt *b) _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
{ {
COMPARE_STRING_FIELD(conditionname); COMPARE_STRING_FIELD(conditionname);
COMPARE_STRING_FIELD(payload);
return true; return true;
} }

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.382 2010/02/12 17:33:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.383 2010/02/16 22:34:43 tgl Exp $
* *
* NOTES * NOTES
* Every node type that can appear in stored rules' parsetrees *must* * Every node type that can appear in stored rules' parsetrees *must*
@ -1820,6 +1820,7 @@ _outNotifyStmt(StringInfo str, NotifyStmt *node)
WRITE_NODE_TYPE("NOTIFY"); WRITE_NODE_TYPE("NOTIFY");
WRITE_STRING_FIELD(conditionname); WRITE_STRING_FIELD(conditionname);
WRITE_STRING_FIELD(payload);
} }
static void static void

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.231 2010/02/12 17:33:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.232 2010/02/16 22:34:43 tgl Exp $
* *
* NOTES * NOTES
* Path and Plan nodes do not have any readfuncs support, because we * Path and Plan nodes do not have any readfuncs support, because we
@ -231,6 +231,7 @@ _readNotifyStmt(void)
READ_LOCALS(NotifyStmt); READ_LOCALS(NotifyStmt);
READ_STRING_FIELD(conditionname); READ_STRING_FIELD(conditionname);
READ_STRING_FIELD(payload);
READ_DONE(); READ_DONE();
} }

View File

@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.708 2010/02/12 17:33:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.709 2010/02/16 22:34:49 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
@ -400,7 +400,7 @@ static TypeName *TableFuncTypeName(List *columns);
%type <ival> Iconst SignedIconst %type <ival> Iconst SignedIconst
%type <list> Iconst_list %type <list> Iconst_list
%type <str> Sconst comment_text %type <str> Sconst comment_text notify_payload
%type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst %type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
%type <list> var_list %type <list> var_list
%type <str> ColId ColLabel var_name type_function_name param_name %type <str> ColId ColLabel var_name type_function_name param_name
@ -6123,14 +6123,20 @@ DropRuleStmt:
* *
*****************************************************************************/ *****************************************************************************/
NotifyStmt: NOTIFY ColId NotifyStmt: NOTIFY ColId notify_payload
{ {
NotifyStmt *n = makeNode(NotifyStmt); NotifyStmt *n = makeNode(NotifyStmt);
n->conditionname = $2; n->conditionname = $2;
n->payload = $3;
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
notify_payload:
',' Sconst { $$ = $2; }
| /*EMPTY*/ { $$ = NULL; }
;
ListenStmt: LISTEN ColId ListenStmt: LISTEN ColId
{ {
ListenStmt *n = makeNode(ListenStmt); ListenStmt *n = makeNode(ListenStmt);

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.103 2010/01/15 09:19:03 heikki Exp $ * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.104 2010/02/16 22:34:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -20,6 +20,7 @@
#include "access/nbtree.h" #include "access/nbtree.h"
#include "access/subtrans.h" #include "access/subtrans.h"
#include "access/twophase.h" #include "access/twophase.h"
#include "commands/async.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "pgstat.h" #include "pgstat.h"
#include "postmaster/autovacuum.h" #include "postmaster/autovacuum.h"
@ -122,6 +123,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
size = add_size(size, WalRcvShmemSize()); size = add_size(size, WalRcvShmemSize());
size = add_size(size, BTreeShmemSize()); size = add_size(size, BTreeShmemSize());
size = add_size(size, SyncScanShmemSize()); size = add_size(size, SyncScanShmemSize());
size = add_size(size, AsyncShmemSize());
#ifdef EXEC_BACKEND #ifdef EXEC_BACKEND
size = add_size(size, ShmemBackendArraySize()); size = add_size(size, ShmemBackendArraySize());
#endif #endif
@ -225,6 +227,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port)
*/ */
BTreeShmemInit(); BTreeShmemInit();
SyncScanShmemInit(); SyncScanShmemInit();
AsyncShmemInit();
#ifdef EXEC_BACKEND #ifdef EXEC_BACKEND

View File

@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.55 2010/01/02 16:57:52 momjian Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.56 2010/02/16 22:34:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -24,6 +24,7 @@
#include "access/clog.h" #include "access/clog.h"
#include "access/multixact.h" #include "access/multixact.h"
#include "access/subtrans.h" #include "access/subtrans.h"
#include "commands/async.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "pg_trace.h" #include "pg_trace.h"
#include "storage/ipc.h" #include "storage/ipc.h"
@ -174,6 +175,9 @@ NumLWLocks(void)
/* multixact.c needs two SLRU areas */ /* multixact.c needs two SLRU areas */
numLocks += NUM_MXACTOFFSET_BUFFERS + NUM_MXACTMEMBER_BUFFERS; numLocks += NUM_MXACTOFFSET_BUFFERS + NUM_MXACTMEMBER_BUFFERS;
/* async.c needs one per Async buffer */
numLocks += NUM_ASYNC_BUFFERS;
/* /*
* Add any requested by loadable modules; for backwards-compatibility * Add any requested by loadable modules; for backwards-compatibility
* reasons, allocate at least NUM_USER_DEFINED_LWLOCKS of them even if * reasons, allocate at least NUM_USER_DEFINED_LWLOCKS of them even if

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.589 2010/02/16 20:15:14 momjian Exp $ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.590 2010/02/16 22:34:50 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
@ -3779,7 +3779,8 @@ PostgresMain(int argc, char *argv[], const char *username)
* collector, and to update the PS stats display. We avoid doing * collector, and to update the PS stats display. We avoid doing
* those every time through the message loop because it'd slow down * those every time through the message loop because it'd slow down
* processing of batched messages, and because we don't want to report * processing of batched messages, and because we don't want to report
* uncommitted updates (that confuses autovacuum). * uncommitted updates (that confuses autovacuum). The notification
* processor wants a call too, if we are not in a transaction block.
*/ */
if (send_ready_for_query) if (send_ready_for_query)
{ {
@ -3795,6 +3796,7 @@ PostgresMain(int argc, char *argv[], const char *username)
} }
else else
{ {
ProcessCompletedNotifies();
pgstat_report_stat(false); pgstat_report_stat(false);
set_ps_display("idle", false); set_ps_display("idle", false);

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.332 2010/02/14 18:42:15 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.333 2010/02/16 22:34:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -926,17 +926,17 @@ standard_ProcessUtility(Node *parsetree,
case T_NotifyStmt: case T_NotifyStmt:
{ {
NotifyStmt *stmt = (NotifyStmt *) parsetree; NotifyStmt *stmt = (NotifyStmt *) parsetree;
PreventCommandDuringRecovery();
Async_Notify(stmt->conditionname); PreventCommandDuringRecovery();
Async_Notify(stmt->conditionname, stmt->payload);
} }
break; break;
case T_ListenStmt: case T_ListenStmt:
{ {
ListenStmt *stmt = (ListenStmt *) parsetree; ListenStmt *stmt = (ListenStmt *) parsetree;
PreventCommandDuringRecovery();
PreventCommandDuringRecovery();
CheckRestrictedOperation("LISTEN"); CheckRestrictedOperation("LISTEN");
Async_Listen(stmt->conditionname); Async_Listen(stmt->conditionname);
} }
@ -945,8 +945,8 @@ standard_ProcessUtility(Node *parsetree,
case T_UnlistenStmt: case T_UnlistenStmt:
{ {
UnlistenStmt *stmt = (UnlistenStmt *) parsetree; UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
PreventCommandDuringRecovery();
PreventCommandDuringRecovery();
CheckRestrictedOperation("UNLISTEN"); CheckRestrictedOperation("UNLISTEN");
if (stmt->conditionname) if (stmt->conditionname)
Async_Unlisten(stmt->conditionname); Async_Unlisten(stmt->conditionname);
@ -1105,8 +1105,8 @@ standard_ProcessUtility(Node *parsetree,
case T_ReindexStmt: case T_ReindexStmt:
{ {
ReindexStmt *stmt = (ReindexStmt *) parsetree; ReindexStmt *stmt = (ReindexStmt *) parsetree;
PreventCommandDuringRecovery();
PreventCommandDuringRecovery();
switch (stmt->kind) switch (stmt->kind)
{ {
case OBJECT_INDEX: case OBJECT_INDEX:

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.322 2010/02/14 18:42:16 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.323 2010/02/16 22:34:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -3465,6 +3465,11 @@ get_utility_query_def(Query *query, deparse_context *context)
0, PRETTYINDENT_STD, 1); 0, PRETTYINDENT_STD, 1);
appendStringInfo(buf, "NOTIFY %s", appendStringInfo(buf, "NOTIFY %s",
quote_identifier(stmt->conditionname)); quote_identifier(stmt->conditionname));
if (stmt->payload)
{
appendStringInfoString(buf, ", ");
simple_quote_literal(buf, stmt->payload);
}
} }
else else
{ {

View File

@ -42,7 +42,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD. * Portions taken from FreeBSD.
* *
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.184 2010/01/26 16:18:12 tgl Exp $ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.185 2010/02/16 22:34:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -2458,6 +2458,7 @@ main(int argc, char *argv[])
"pg_xlog", "pg_xlog",
"pg_xlog/archive_status", "pg_xlog/archive_status",
"pg_clog", "pg_clog",
"pg_notify",
"pg_subtrans", "pg_subtrans",
"pg_twophase", "pg_twophase",
"pg_multixact/members", "pg_multixact/members",

View File

@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2010, PostgreSQL Global Development Group * Copyright (c) 2000-2010, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.143 2010/01/02 16:57:59 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.144 2010/02/16 22:34:50 tgl Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
@ -555,6 +555,11 @@ PrintNotifications(void)
while ((notify = PQnotifies(pset.db))) while ((notify = PQnotifies(pset.db)))
{ {
/* for backward compatibility, only show payload if nonempty */
if (notify->extra[0])
fprintf(pset.queryFout, _("Asynchronous notification \"%s\" with payload \"%s\" received from server process with PID %d.\n"),
notify->relname, notify->extra, notify->be_pid);
else
fprintf(pset.queryFout, _("Asynchronous notification \"%s\" received from server process with PID %d.\n"), fprintf(pset.queryFout, _("Asynchronous notification \"%s\" received from server process with PID %d.\n"),
notify->relname, notify->be_pid); notify->relname, notify->be_pid);
fflush(pset.queryFout); fflush(pset.queryFout);

View File

@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2010, PostgreSQL Global Development Group * Copyright (c) 2000-2010, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.193 2010/02/15 02:55:01 itagaki Exp $ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.194 2010/02/16 22:34:50 tgl Exp $
*/ */
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
@ -1864,7 +1864,7 @@ psql_completion(char *text, int start, int end)
/* NOTIFY */ /* NOTIFY */
else if (pg_strcasecmp(prev_wd, "NOTIFY") == 0) else if (pg_strcasecmp(prev_wd, "NOTIFY") == 0)
COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(relname) FROM pg_catalog.pg_listener WHERE substring(pg_catalog.quote_ident(relname),1,%d)='%s'"); COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s'");
/* OPTIONS */ /* OPTIONS */
else if (pg_strcasecmp(prev_wd, "OPTIONS") == 0) else if (pg_strcasecmp(prev_wd, "OPTIONS") == 0)
@ -2105,7 +2105,7 @@ psql_completion(char *text, int start, int end)
/* UNLISTEN */ /* UNLISTEN */
else if (pg_strcasecmp(prev_wd, "UNLISTEN") == 0) else if (pg_strcasecmp(prev_wd, "UNLISTEN") == 0)
COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(relname) FROM pg_catalog.pg_listener WHERE substring(pg_catalog.quote_ident(relname),1,%d)='%s' UNION SELECT '*'"); COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s' UNION SELECT '*'");
/* UPDATE */ /* UPDATE */
/* If prev. word is UPDATE suggest a list of tables */ /* If prev. word is UPDATE suggest a list of tables */

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/slru.h,v 1.25 2010/01/02 16:58:00 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.26 2010/02/16 22:34:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -17,6 +17,25 @@
#include "storage/lwlock.h" #include "storage/lwlock.h"
/*
* Define SLRU segment size. A page is the same BLCKSZ as is used everywhere
* else in Postgres. The segment size can be chosen somewhat arbitrarily;
* we make it 32 pages by default, or 256Kb, i.e. 1M transactions for CLOG
* or 64K transactions for SUBTRANS.
*
* Note: because TransactionIds are 32 bits and wrap around at 0xFFFFFFFF,
* page numbering also wraps around at 0xFFFFFFFF/xxxx_XACTS_PER_PAGE (where
* xxxx is CLOG or SUBTRANS, respectively), and segment numbering at
* 0xFFFFFFFF/xxxx_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT. We need
* take no explicit notice of that fact in slru.c, except when comparing
* segment and page numbers in SimpleLruTruncate (see PagePrecedes()).
*
* Note: slru.c currently assumes that segment file names will be four hex
* digits. This sets a lower bound on the segment size (64K transactions
* for 32-bit TransactionIds).
*/
#define SLRU_PAGES_PER_SEGMENT 32
/* /*
* Page status codes. Note that these do not include the "dirty" bit. * Page status codes. Note that these do not include the "dirty" bit.
* page_dirty can be TRUE only in the VALID or WRITE_IN_PROGRESS states; * page_dirty can be TRUE only in the VALID or WRITE_IN_PROGRESS states;
@ -55,8 +74,8 @@ typedef struct SlruSharedData
/* /*
* Optional array of WAL flush LSNs associated with entries in the SLRU * Optional array of WAL flush LSNs associated with entries in the SLRU
* pages. If not zero/NULL, we must flush WAL before writing pages (true * pages. If not zero/NULL, we must flush WAL before writing pages (true
* for pg_clog, false for multixact and pg_subtrans). group_lsn[] has * for pg_clog, false for multixact, pg_subtrans, pg_notify). group_lsn[]
* lsn_groups_per_page entries per buffer slot, each containing the * has lsn_groups_per_page entries per buffer slot, each containing the
* highest LSN known for a contiguous group of SLRU entries on that slot's * highest LSN known for a contiguous group of SLRU entries on that slot's
* page. * page.
*/ */
@ -94,7 +113,7 @@ typedef struct SlruCtlData
/* /*
* This flag tells whether to fsync writes (true for pg_clog and multixact * This flag tells whether to fsync writes (true for pg_clog and multixact
* stuff, false for pg_subtrans). * stuff, false for pg_subtrans and pg_notify).
*/ */
bool do_fsync; bool do_fsync;

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/twophase_rmgr.h,v 1.11 2010/01/02 16:58:00 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/twophase_rmgr.h,v 1.12 2010/02/16 22:34:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -23,9 +23,8 @@ typedef uint8 TwoPhaseRmgrId;
*/ */
#define TWOPHASE_RM_END_ID 0 #define TWOPHASE_RM_END_ID 0
#define TWOPHASE_RM_LOCK_ID 1 #define TWOPHASE_RM_LOCK_ID 1
#define TWOPHASE_RM_NOTIFY_ID 2 #define TWOPHASE_RM_PGSTAT_ID 2
#define TWOPHASE_RM_PGSTAT_ID 3 #define TWOPHASE_RM_MULTIXACT_ID 3
#define TWOPHASE_RM_MULTIXACT_ID 4
#define TWOPHASE_RM_MAX_ID TWOPHASE_RM_MULTIXACT_ID #define TWOPHASE_RM_MAX_ID TWOPHASE_RM_MULTIXACT_ID
extern const TwoPhaseCallback twophase_recover_callbacks[]; extern const TwoPhaseCallback twophase_recover_callbacks[];

View File

@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.584 2010/02/12 17:33:20 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.585 2010/02/16 22:34:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 201002121 #define CATALOG_VERSION_NO 201002161
#endif #endif

View File

@ -1,59 +0,0 @@
/*-------------------------------------------------------------------------
*
* pg_listener.h
* Asynchronous notification
*
*
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_listener.h,v 1.28 2010/01/05 01:06:56 tgl Exp $
*
* NOTES
* the genbki.pl script reads this file and generates .bki
* information from the DATA() statements.
*
*-------------------------------------------------------------------------
*/
#ifndef PG_LISTENER_H
#define PG_LISTENER_H
#include "catalog/genbki.h"
/* ----------------------------------------------------------------
* pg_listener definition.
*
* cpp turns this into typedef struct FormData_pg_listener
* ----------------------------------------------------------------
*/
#define ListenerRelationId 2614
CATALOG(pg_listener,2614) BKI_WITHOUT_OIDS
{
NameData relname;
int4 listenerpid;
int4 notification;
} FormData_pg_listener;
/* ----------------
* Form_pg_listener corresponds to a pointer to a tuple with
* the format of pg_listener relation.
* ----------------
*/
typedef FormData_pg_listener *Form_pg_listener;
/* ----------------
* compiler constants for pg_listener
* ----------------
*/
#define Natts_pg_listener 3
#define Anum_pg_listener_relname 1
#define Anum_pg_listener_listenerpid 2
#define Anum_pg_listener_notification 3
/* ----------------
* initial contents of pg_listener are NOTHING.
* ----------------
*/
#endif /* PG_LISTENER_H */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.568 2010/02/07 20:48:11 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.569 2010/02/16 22:34:56 tgl Exp $
* *
* NOTES * NOTES
* The script catalog/genbki.pl reads this file and generates .bki * The script catalog/genbki.pl reads this file and generates .bki
@ -4133,6 +4133,10 @@ DATA(insert OID = 2856 ( pg_timezone_names PGNSP PGUID 12 1 1000 0 f f f t t s
DESCR("get the available time zone names"); DESCR("get the available time zone names");
DATA(insert OID = 2730 ( pg_get_triggerdef PGNSP PGUID 12 1 0 0 f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_triggerdef_ext _null_ _null_ _null_ )); DATA(insert OID = 2730 ( pg_get_triggerdef PGNSP PGUID 12 1 0 0 f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_triggerdef_ext _null_ _null_ _null_ ));
DESCR("trigger description with pretty-print option"); DESCR("trigger description with pretty-print option");
DATA(insert OID = 3035 ( pg_listening_channels PGNSP PGUID 12 1 10 0 f f f t t s 0 0 25 "" _null_ _null_ _null_ _null_ pg_listening_channels _null_ _null_ _null_ ));
DESCR("get the channels that the current backend listens to");
DATA(insert OID = 3036 ( pg_notify PGNSP PGUID 12 1 0 0 f f f f f v 2 0 2278 "25 25" _null_ _null_ _null_ _null_ pg_notify _null_ _null_ _null_ ));
DESCR("send a notification event");
/* non-persistent series generator */ /* non-persistent series generator */
DATA(insert OID = 1066 ( generate_series PGNSP PGUID 12 1 1000 0 f f f t t i 3 0 23 "23 23 23" _null_ _null_ _null_ _null_ generate_series_step_int4 _null_ _null_ _null_ )); DATA(insert OID = 1066 ( generate_series PGNSP PGUID 12 1 1000 0 f f f t t i 3 0 23 "23 23 23" _null_ _null_ _null_ _null_ generate_series_step_int4 _null_ _null_ _null_ ));

View File

@ -6,28 +6,44 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/async.h,v 1.39 2010/01/02 16:58:03 momjian Exp $ * $PostgreSQL: pgsql/src/include/commands/async.h,v 1.40 2010/02/16 22:34:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef ASYNC_H #ifndef ASYNC_H
#define ASYNC_H #define ASYNC_H
#include "fmgr.h"
/*
* The number of SLRU page buffers we use for the notification queue.
*/
#define NUM_ASYNC_BUFFERS 8
extern bool Trace_notify; extern bool Trace_notify;
extern Size AsyncShmemSize(void);
extern void AsyncShmemInit(void);
/* notify-related SQL statements */ /* notify-related SQL statements */
extern void Async_Notify(const char *relname); extern void Async_Notify(const char *channel, const char *payload);
extern void Async_Listen(const char *relname); extern void Async_Listen(const char *channel);
extern void Async_Unlisten(const char *relname); extern void Async_Unlisten(const char *channel);
extern void Async_UnlistenAll(void); extern void Async_UnlistenAll(void);
/* notify-related SQL functions */
extern Datum pg_listening_channels(PG_FUNCTION_ARGS);
extern Datum pg_notify(PG_FUNCTION_ARGS);
/* perform (or cancel) outbound notify processing at transaction commit */ /* perform (or cancel) outbound notify processing at transaction commit */
extern void PreCommit_Notify(void);
extern void AtCommit_Notify(void); extern void AtCommit_Notify(void);
extern void AtAbort_Notify(void); extern void AtAbort_Notify(void);
extern void AtSubStart_Notify(void); extern void AtSubStart_Notify(void);
extern void AtSubCommit_Notify(void); extern void AtSubCommit_Notify(void);
extern void AtSubAbort_Notify(void); extern void AtSubAbort_Notify(void);
extern void AtPrepare_Notify(void); extern void AtPrepare_Notify(void);
extern void ProcessCompletedNotifies(void);
/* signal handler for inbound notifies (PROCSIG_NOTIFY_INTERRUPT) */ /* signal handler for inbound notifies (PROCSIG_NOTIFY_INTERRUPT) */
extern void HandleNotifyInterrupt(void); extern void HandleNotifyInterrupt(void);
@ -40,7 +56,4 @@ extern void HandleNotifyInterrupt(void);
extern void EnableNotifyInterrupt(void); extern void EnableNotifyInterrupt(void);
extern bool DisableNotifyInterrupt(void); extern bool DisableNotifyInterrupt(void);
extern void notify_twophase_postcommit(TransactionId xid, uint16 info,
void *recdata, uint32 len);
#endif /* ASYNC_H */ #endif /* ASYNC_H */

View File

@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.429 2010/02/12 17:33:20 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.430 2010/02/16 22:34:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -2097,6 +2097,7 @@ typedef struct NotifyStmt
{ {
NodeTag type; NodeTag type;
char *conditionname; /* condition name to notify */ char *conditionname; /* condition name to notify */
char *payload; /* the payload string, or NULL if none */
} NotifyStmt; } NotifyStmt;
/* ---------------------- /* ----------------------

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.44 2010/02/07 20:48:13 tgl Exp $ * $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.45 2010/02/16 22:34:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -68,6 +68,8 @@ typedef enum LWLockId
AutovacuumScheduleLock, AutovacuumScheduleLock,
SyncScanLock, SyncScanLock,
RelationMappingLock, RelationMappingLock,
AsyncCtlLock,
AsyncQueueLock,
/* Individual lock IDs end here */ /* Individual lock IDs end here */
FirstBufMappingLock, FirstBufMappingLock,
FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS, FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS,

View File

@ -532,9 +532,9 @@ CREATE TEMP TABLE tmp_foo (data text) ON COMMIT DELETE ROWS;
CREATE ROLE temp_reset_user; CREATE ROLE temp_reset_user;
SET SESSION AUTHORIZATION temp_reset_user; SET SESSION AUTHORIZATION temp_reset_user;
-- look changes -- look changes
SELECT relname FROM pg_listener; SELECT pg_listening_channels();
relname pg_listening_channels
----------- -----------------------
foo_event foo_event
(1 row) (1 row)
@ -571,9 +571,9 @@ SELECT current_user = 'temp_reset_user';
-- discard everything -- discard everything
DISCARD ALL; DISCARD ALL;
-- look again -- look again
SELECT relname FROM pg_listener; SELECT pg_listening_channels();
relname pg_listening_channels
--------- -----------------------
(0 rows) (0 rows)
SELECT name FROM pg_prepared_statements; SELECT name FROM pg_prepared_statements;

View File

@ -107,7 +107,6 @@ SELECT relname, relhasindex
pg_language | t pg_language | t
pg_largeobject | t pg_largeobject | t
pg_largeobject_metadata | t pg_largeobject_metadata | t
pg_listener | f
pg_namespace | t pg_namespace | t
pg_opclass | t pg_opclass | t
pg_operator | t pg_operator | t
@ -154,7 +153,7 @@ SELECT relname, relhasindex
timetz_tbl | f timetz_tbl | f
tinterval_tbl | f tinterval_tbl | f
varchar_tbl | f varchar_tbl | f
(143 rows) (142 rows)
-- --
-- another sanity check: every system catalog that has OIDs should have -- another sanity check: every system catalog that has OIDs should have

View File

@ -165,7 +165,7 @@ CREATE TEMP TABLE tmp_foo (data text) ON COMMIT DELETE ROWS;
CREATE ROLE temp_reset_user; CREATE ROLE temp_reset_user;
SET SESSION AUTHORIZATION temp_reset_user; SET SESSION AUTHORIZATION temp_reset_user;
-- look changes -- look changes
SELECT relname FROM pg_listener; SELECT pg_listening_channels();
SELECT name FROM pg_prepared_statements; SELECT name FROM pg_prepared_statements;
SELECT name FROM pg_cursors; SELECT name FROM pg_cursors;
SHOW vacuum_cost_delay; SHOW vacuum_cost_delay;
@ -174,7 +174,7 @@ SELECT current_user = 'temp_reset_user';
-- discard everything -- discard everything
DISCARD ALL; DISCARD ALL;
-- look again -- look again
SELECT relname FROM pg_listener; SELECT pg_listening_channels();
SELECT name FROM pg_prepared_statements; SELECT name FROM pg_prepared_statements;
SELECT name FROM pg_cursors; SELECT name FROM pg_cursors;
SHOW vacuum_cost_delay; SHOW vacuum_cost_delay;