1 min read

Real-time Notifications (SSE)

Subscribe to PostgreSQL NOTIFY channels over Server-Sent Events:

curl -N "http://localhost:8080/db/my_database/sse?channels=orders,users" \
  -H "Authorization: Bearer $TOKEN"

Each message is JSON with the channel name and payload:

{"channel":"orders","data":{"id":123,"status":"created"}}

If the payload is plain text, it is wrapped as a string in data.

Sending notifications from PostgreSQL

From psql or any database session:

-- Simple text payload
NOTIFY orders, 'new order';

-- JSON payload
NOTIFY orders, '{"id":123,"status":"created"}';

From a trigger or stored procedure:

PERFORM pg_notify('orders', json_build_object('id', NEW.id, 'status', NEW.status)::text);
Note: NOTIFY is only delivered to other sessions after the sending transaction commits. If you run it inside an open transaction in psql, subscribers won’t receive it until you execute COMMIT.