DEV Community

Ariel Bodan
Ariel Bodan

Posted on

PostgreSQL LISTEN/NOTIFY Queue Full: A 512 KiB Reproduction

What causes PostgreSQL to report:

ERROR: too many notifications in the NOTIFY queue
Enter fullscreen mode Exit fullscreen mode

I reproduced it with PostgreSQL 17, Docker, and two psql sessions.

Instead of trying to fill PostgreSQL's default multi-gigabyte queue, I started the server with:

max_notify_queue_pages=64
Enter fullscreen mode Exit fullscreen mode

With 8 KiB pages, that gave the experiment a queue capacity of only 512 KiB.

The listener did this:

LISTEN demo;
BEGIN;
Enter fullscreen mode Exit fullscreen mode

and remained idle in transaction.

From another connection, I generated 100 large pg_notify() calls.

The result was easy to observe:

Successful sends: 64
Failed sends:     36
Queue usage:      100%
Enter fullscreen mode Exit fullscreen mode

PostgreSQL reported:

ERROR: too many notifications in the NOTIFY queue
Enter fullscreen mode Exit fullscreen mode

Then I returned to the listener and executed:

COMMIT;
Enter fullscreen mode Exit fullscreen mode

Pending notifications were delivered and:

SELECT pg_notification_queue_usage();
Enter fullscreen mode Exit fullscreen mode

returned to 0.

The useful takeaway is that increasing max_notify_queue_pages only gives the system more space. It does not remove a transaction that is preventing notification cleanup.

The full experiment includes the Docker Compose setup, SQL commands, queue measurements, inspection of pg_notify/, and recovery verification:

https://bodanthebackend.com/articles/en/postgresql-listen-notify-queue-full/

Top comments (0)