Support PostgreSQL `LISTEN`, `NOTIFY`, `UNLISTEN`, and `pg_notify`
- Dominant language
- Go
- Stars
- 2.1k
- Forks
- 73
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 129
Description
Please add PostgreSQL-compatible asynchronous notification support through `LISTEN`, `NOTIFY`, `UNLISTEN`, and `pg_notify(text, text)`.
Doltgres currently rejects all four operations, which leaves applications without a transaction-coupled way to wake another process after committed work becomes visible.
## Repro
Reproduced with `dolthub/doltgresql:1.3.0`:
```sql
LISTEN test_dispatch;
```
```text
ERROR: at or near "listen": syntax error
```
```sql
NOTIFY test_dispatch, '1';
```
```text
ERROR: at or near "notify": syntax error
```
```sql
SELECT pg_notify('test_dispatch', '1');
```
```text
ERROR: function: 'pg_notify' not found
```
```sql
UNLISTEN test_dispatch;
```
```text
ERROR: at or near "unlisten": syntax error
```
## Use case
The application we are working on stores durable work records in Doltgres. A transaction inserts or updates a pending row, then a separate dispatcher must process it.
The process can terminate after Doltgres commits the row but before the callback, Redis publication, HTTP request, or other wakeup executes.
## Required behavior
The requested behavior is the standard PostgreSQL contract:
- `LISTEN channel` registers the current session for that channel.
- `UNLISTEN channel` and `UNLISTEN *` remove registrations.
- `NOTIFY channel` and `NOTIFY channel, payload` send asynchronous notification messages to listening sessions.
- `pg_notify(channel, payload)` provides the equivalent function form, including use from SQL functions and triggers.
- A notification issued inside a transaction is delivered only after that transaction commits successfully.
- A rolled-back transaction produces no notification.
- The notification includes the channel and payload through the PostgreSQL wire protocol.
- Listener registrations last until `UNLISTEN` or session termination.
- Notifications are scoped to the Doltgres database, not to the currently checked-out Dolt branch.
- A transaction emits its notifications only after the complete Doltgres commit succeeds.
- If the Doltgres commit fails because of a conflict or another error, no notification is delivered.
Contributor guide
Research direction
Start by reproducing LISTEN, NOTIFY, UNLISTEN, and pg_notify('test_dispatch', '1') against Doltgres and compare their behavior with PostgreSQL. Trace the SQL and function entry points, transaction commit and rollback handling, session registrations, and PostgreSQL wire-protocol notifications. Done means all required operations work, notifications wait for successful complete commits, rollbacks and failed commits emit none, and registrations persist for the session.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100