concurrent queries in a connection
See original GitHub issueHi
What happens when I submit two sequential queries:
client.query("SELECT ...", function() {} )
client.query("SELECT ...", function() {} )
I understand there is a queue and second query will execute only after first is complete. But what does it mean “complete” - will pg send the second query to the server only after all results from the first query came back? Is it the driver behavior or does postgres mandate that only one query should be sent to the server by the client at a given moment?
Thanks, Yaron
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
concurrent queries with a single connection in pyodbc
There is a protocol to allow a single connection to have multiple concurrent queries running at the same time. It's called Multiple Active ......
Read more >Concurrent queries on single connection #738 - GitHub
can't run multiple queries concurrently on a single PostgreSQL connection. It's inherent to the protocol. The protocol does not allow parallel ...
Read more >Concurrent queries are slow or fail in Watson Query - IBM
There are many different reasons why concurrent queries might be slow or fail. For example, when the connection pool becomes full.
Read more >Improve database performance with connection pooling
Caching frequently-accessed queries in memory or via a database can optimize write/read performance and reduce network latency, especially for ...
Read more >Refreshing queries in parallel
For each connection, the number of data providers that can be refreshed in parallel is set to 4 by default. The database administrator...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks @brianc ! So to finally sum it up see those 3 snippets:
1:
2:
3:
snippet 1 is faster than the others (assuming there is an available connection) since the second query will not wait for the first to finish. snippets 2, 3 are the same since the second query will not start until first finishes, which is implicit in 2 and explicit in 3.
right again?
node-postgres maintains an internal queue of queries and sends them serially to the PostgreSQL server backend one at a time because the protocol & server mandate a maximum of 1 in-flight query per connected client. If you don’t care about order execution you can use something like pg-query and async just be aware transactions don’t work at all across multiple clients.