-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Queries stuck in ClientRead
#2189
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
Comments
Hm, which state do you expect it to be in? Which query’s execution is being prevented? I thought idle ClientRead (showing the last completed query) was the normal state – it’s waiting for the connected client to send the next message, e.g. the next query. This seems to match up with the entry for an idle psql. |
Hmmm I'm pretty sure the callback is executed after the query is entirely complete and the backend is ready for another query. Here is where the You can try |
Thanks to you both for your help. My reproduction case here is incorrect, so I'll be closing this issue. We've opted into the performance improvements, although our issue with |
Isn't the issue, that the callback of a query could block the query queue? var pg = require("pg"); // or require("pg").native
var client = new pg.Client({
connectionString: "postgres://postgres@localhost/postgres"
});
client.connect();
client.query("SELECT 1", function(_error, _rows) {
while (true) {}
});
client.query("SELECT 2", function(_error, _rows) {}); It might be worth investigating if the callback can be deferred until the next query is in flight. The user could also do this selectively: client.query("SELECT 1", function(_error, _rows) {
setTimeout(function () { while (true) {} }, 0);
}); Could the ClientReady also indicate higher latency? |
@boromisp Thanks for the suggestions! |
We're experiencing database server performance issues caused by sessions spending the vast majority of time in the
ClientRead
state. A few other similar issues have been opened: #1774, #1993, #1952.To reproduce:
Run the above, it will hang in the
while
loop. In another terminal run:$ psql --username postgres --command "SELECT * FROM pg_stat_activity WHERE wait_event = 'ClientRead' AND query = 'SELECT 1'"
We can see the query stuck in
ClientRead
.The problem here is that node-postgres is executing the response callback before the session is out of the
ClientRead
state. This is isn't optimal: any CPU time spent in the callback prevents the PostgreSQL server from executing the query.Would it be possible for node-postgres to execute the callback only after the server is able to execute the query?
Thanks in advance! We get a tremendous amount of value from node-postgres.
The text was updated successfully, but these errors were encountered: