NOTIFY is a PostgreSQL-specific command used for lightweight, asynchronous inter-process communication inside the database. When issued, it queues a message on a specified channel. Any open sessions that previously executed LISTEN on the same channel will receive the notification after the surrounding transaction successfully commits. If the transaction rolls back, no notification is delivered. The optional payload lets you attach up to 8000 bytes of text, allowing consumers to react contextually. Notifications are delivered out of band, so they do not block the issuing transaction, and the consumer reads them with the LISTEN/pg_notification_queue. NOTIFY is ideal for event-driven architectures, cache invalidation, and job signaling. Caveats: payload size is limited, message order is not guaranteed across channels, and heavy use can saturate the notification queue.
channel_name
(identifier) - Name of the channel (must be a valid PostgreSQL identifier)payload_text
(text) - Optional message (single quotes required, max 8000 bytes)LISTEN, UNLISTEN, pg_notify(), triggers, asynchronous events
PostgreSQL 6.4
You need the CONNECT privilege on the database plus write permission on the channel. By default, all roles can NOTIFY any channel but you can restrict this with the pg_notify role attribute or a SECURITY LABEL.
Yes. Execute a separate LISTEN statement for each channel. PostgreSQL will deliver notifications for any channel the session is listening to.
Most PostgreSQL drivers expose an event or callback (e.g., `asyncpg.connection.add_listener`, `psycopg2.extensions.connection.notifies`) that fires when a notification arrives.
The notification is still queued and discarded immediately after commit because there are no listeners. The sender does not receive an error.