Patch pg pool (#12081)
This PR implements a global PostgreSQL connection pool sharing mechanism. - Patches pg.Pool to reuse connection pools across the application when connection parameters match, reducing resource overhead. - New environment variables allow enabling/disabling sharing and configuring pool size, idle timeout, and client exit behavior. WorkspaceDatasourceFactory will now use shared pools if enabled, this will avoid recreating 10 connections for each pods for each workspace. --------- Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
@ -755,6 +755,44 @@ export class ConfigVariables {
|
||||
@IsOptional()
|
||||
PG_SSL_ALLOW_SELF_SIGNED = false;
|
||||
|
||||
@ConfigVariablesMetadata({
|
||||
group: ConfigVariablesGroup.ServerConfig,
|
||||
description: 'Enable pg connection pool sharing across tenants',
|
||||
isEnvOnly: true,
|
||||
type: ConfigVariableType.BOOLEAN,
|
||||
})
|
||||
@IsOptional()
|
||||
PG_ENABLE_POOL_SHARING = true;
|
||||
|
||||
@ConfigVariablesMetadata({
|
||||
group: ConfigVariablesGroup.ServerConfig,
|
||||
description: 'Maximum number of clients in pg connection pool',
|
||||
isEnvOnly: true,
|
||||
type: ConfigVariableType.NUMBER,
|
||||
})
|
||||
@CastToPositiveNumber()
|
||||
@IsOptional()
|
||||
PG_POOL_MAX_CONNECTIONS = 10;
|
||||
|
||||
@ConfigVariablesMetadata({
|
||||
group: ConfigVariablesGroup.ServerConfig,
|
||||
description: 'Idle timeout in milliseconds for pg connection pool clients',
|
||||
isEnvOnly: true,
|
||||
type: ConfigVariableType.NUMBER,
|
||||
})
|
||||
@CastToPositiveNumber()
|
||||
@IsOptional()
|
||||
PG_POOL_IDLE_TIMEOUT_MS = 600000;
|
||||
|
||||
@ConfigVariablesMetadata({
|
||||
group: ConfigVariablesGroup.ServerConfig,
|
||||
description: 'Allow idle pg connection pool clients to exit',
|
||||
isEnvOnly: true,
|
||||
type: ConfigVariableType.BOOLEAN,
|
||||
})
|
||||
@IsOptional()
|
||||
PG_POOL_ALLOW_EXIT_ON_IDLE = true;
|
||||
|
||||
@ConfigVariablesMetadata({
|
||||
group: ConfigVariablesGroup.ServerConfig,
|
||||
description: 'Enable configuration variables to be stored in the database',
|
||||
|
||||
@ -40,7 +40,7 @@ export class DatabaseConfigDriver
|
||||
const loadedCount = await this.loadAllConfigVarsFromDb();
|
||||
|
||||
this.logger.log(
|
||||
`[INIT] Config variables loaded: ${loadedCount} values found, ${this.allPossibleConfigKeys.length - loadedCount} missing`,
|
||||
`[INIT] Config variables loaded: ${loadedCount} values found in DB, ${this.allPossibleConfigKeys.length - loadedCount} falling to env vars/defaults`,
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
|
||||
Reference in New Issue
Block a user