1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Fix PostgreSQL query performance for large datasets.

The asynchronous logic used to implement the query timeout was misusing PQisBusy(), which caused the wait handler to throttle the consumption of command results. It could introduce a large delay on a query up to `db-timeout` because of the back-off sequence.

Following the recommendation of libpq, fix by polling the client socket for data availability and then continue consuming results and checking for command busyness.
This commit is contained in:
Thibault VINCENT
2024-10-10 08:48:43 +02:00
committed by GitHub
parent 33fa396561
commit c8ccaaa755
6 changed files with 59 additions and 1 deletions

View File

@ -6,6 +6,7 @@ Postgres Client
#include <libpq-fe.h>
#include "common/debug.h"
#include "common/io/fd.h"
#include "common/log.h"
#include "common/wait.h"
#include "postgres/client.h"
@ -198,7 +199,7 @@ pgClientQuery(PgClient *const this, const String *const query, const PgClientQue
PQconsumeInput(this->connection);
busy = PQisBusy(this->connection);
}
while (busy && waitMore(wait));
while (busy && fdReadyRead(PQsocket(this->connection), waitRemains(wait)));
// If the query is still busy after the timeout attempt to cancel
if (busy)