question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres NOTIFY message queue overflow

See original GitHub issue

We have problem with Postgres LISTEN/NOTIFY. I’ve added some own triggers with pg_notify and now, when hasura is listening for messages in hasura_schema_update channel, Postgres NOTIFY message queue is overflowing.

> SELECT pg_notification_queue_usage();
> 0.79306648254394531

Postgres logs at this moment:

2020-11-26 20:33:26.686 UTC [24866] [user=fastcup,db=fastcup,app=[unknown]] WARNING:  NOTIFY queue is 79% full
2020-11-26 20:33:26.686 UTC [24866] [user=fastcup,db=fastcup,app=[unknown]] DETAIL:  The server process with PID 30986 is among those with the oldest transactions.
2020-11-26 20:33:26.686 UTC [24866] [user=fastcup,db=fastcup,app=[unknown]] HINT:  The NOTIFY queue cannot be emptied until that process ends its current transaction.

I checked PID 30986, and it was connection from hasura with LISTEN hasura_schema_update;. I tried to terminate all connections with this workaround query:

SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE query = 'LISTEN  hasura_schema_update;';

And after that I see that SELECT pg_notification_queue_usage() returns 0, but for 1-2 minutes, after that it is growing again;

From Postgres documentation:

There is a queue that holds notifications that have been sent but not yet processed by all listening sessions. If this queue becomes full, transactions calling NOTIFY will fail at commit. The queue is quite large (8GB in a standard installation) and should be sufficiently sized for almost every use case. However, no cleanup can take place if a session executes LISTEN and then enters a transaction for a very long time. Once the queue is half full you will see warnings in the log file pointing you to the session that is preventing cleanup. In this case you should make sure that this session ends its current transaction so that cleanup can proceed.

The function pg_notification_queue_usage returns the fraction of the queue that is currently occupied by pending notifications. See Section 9.25 for more information.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
osseonewscommented, Dec 4, 2020

We are having this same exact problem with the NOTIFY message queue overflow. How did you fix this? We simply can’t use Hasura anymore. Every time we turn it back on Hasura overwhlems the message queue with connections from LISTEN hasura_schema_update;

1reaction
maxpaincommented, Dec 6, 2020

@rakeshkky @0x777 Could you please check this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: NOTIFY - PostgreSQL
The NOTIFY command sends a notification event together with an optional “payload” string to each client application that has previously executed LISTEN channel ......
Read more >
Postgres Listen/Notify As Message Queue
The NOTIFY command sends a notification event together with an optional "payload" string to each client application that has previously executed ...
Read more >
How to find the current length of a postgres NOTIFY/LISTEN ...
Is there a SQL query or call to determine the existing length of the message queue? (without popping any of the items). I...
Read more >
- postgres doesn't maintain a queue for notify/listen, it's purely ...
The LISTEN/NOTIFY queue has nothing to do with MVCC. Only reason why it exists is that postgresql synchronizes the notification events with transaction ......
Read more >
pg_notification_queue_usage() - a PostgreSQL Encyclopedia
A function reporting how full the asynchronous notification queue is ... postgres=# CREATE TABLE notifications(channel NAME NOT NULL, message TEXT); CREATE ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found