← All notes

PostgreSQL LISTEN and NOTIFY

Answer: The NOTIFY command sends a notification event together with an optional "payload" string to each client application that has previously executed LISTEN channel for the specified channel name in the current database. (S1)

-- session A
LISTEN jobs;

-- session B
NOTIFY jobs, 'job 42 ready';
SELECT pg_notify('jobs', 'job 43 ready');  -- function form

Session A then receives an asynchronous notification with the payload and the sender's PID.

Behavior

Caveats

When NOTIFY is used to signal the occurrence of changes to a particular table, a useful programming technique is to put the NOTIFY in a statement trigger that is triggered by table updates. (S1)

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: NOTIFY, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: LISTEN, PostgreSQL License.

Cite this

Permanent ID: iil:note:2xr2w01h

iinventedlight. 2026. "PostgreSQL LISTEN and NOTIFY." iinventedlight Library, iil:note:2xr2w01h, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-listen-notify/. License: CC-BY-4.0.

@misc{iil_note_2xr2w01h,
  author = {{iinventedlight}},
  title = {{PostgreSQL LISTEN and NOTIFY}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/postgres-listen-notify/},
  note = {Permanent ID iil:note:2xr2w01h. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/postgres-listen-notify.md.