-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it safe to use the same connection to perform statements and LISTEN to notifications? #116
Comments
It is safe -- though the handler must be written with care. It can be called during the execution of a query so it is unsafe to do anything with the connection. If you moved up a layer to pgx then you could take advantage of it automatically buffering notifications received while executing a statement. i.e. You could alternate between executing statements and calling |
Cool! What would happen in case the connection is waiting for a notification and a statement is executed, would that interfere? Do you have a suggestion for a good approach to alternate between |
In pgx if a notification is received while a statement is executing it will be buffered and returned when
Nothing wrong with that. In fact, |
Hi,
I am trying to reduce the amount of connection to a Postgres database, as many libraries open a new connection when trying to LISTEN to a channel. I have the idea that
pgconn
supports concurrently executing statements and handling notifications by settings theOnNotification
handler, however, I'm not entirely sure, am I seeing this correctly?Thanks!
The text was updated successfully, but these errors were encountered: