diff --git a/src/backend/distributed/executor/adaptive_executor.c b/src/backend/distributed/executor/adaptive_executor.c index 30b2e981e..45328dab4 100644 --- a/src/backend/distributed/executor/adaptive_executor.c +++ b/src/backend/distributed/executor/adaptive_executor.c @@ -1946,9 +1946,6 @@ FindOrCreateWorkerPool(DistributedExecution *execution, char *nodeName, int node workerPool->nodeName = pstrdup(nodeName); workerPool->nodePort = nodePort; - INSTR_TIME_SET_ZERO(workerPool->poolStartTime); - workerPool->distributedExecution = execution; - /* "open" connections aggressively when there are cached connections */ int nodeConnectionCount = MaxCachedConnectionsPerWorker; workerPool->maxNewConnectionsPerCycle = Max(1, nodeConnectionCount); @@ -2422,6 +2419,18 @@ ManageWorkerPool(WorkerPool *workerPool) */ connection->claimedExclusively = true; + if (list_length(workerPool->sessionList) == 0) + { + /* + * The worker pool has just started to establish connections. We need to + * defer this initilization after StartNodeUserDatabaseConnection() + * because for non-optional connections, we have some logic to wait + * until a connection is allowed to be established for a duration of + * citus.connection_retry_timeout. + */ + INSTR_TIME_SET_ZERO(workerPool->poolStartTime); + } + /* create a session for the connection */ WorkerSession *session = FindOrCreateWorkerSession(workerPool, connection);