Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/postgres_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,54 +246,61 @@ static void LoadInternal(ExtensionLoader &loader) {
"pg_pool_acquire_mode",
"How to acquire connections from the pool: 'force' (always connect, ignore pool limit), "
"'wait' (block until available), 'try' (fail immediately if unavailable) (default: force)",
LogicalType::VARCHAR, Value("force"), PostgresConnectionPool::ValidatePoolAcquireMode);
LogicalType::VARCHAR, Value("force"), PostgresConnectionPool::ValidatePoolAcquireMode, SetScope::GLOBAL);
config.AddExtensionOption("pg_pool_max_connections",
"Maximum number of connections that are allowed to be cached in a connection pool for "
"each attached Postgres database. "
"This number can be temporary exceeded when parallel scans are used. " +
CreatePoolNote("max_connections=42"),
LogicalType::UBIGINT, Value::UBIGINT(PostgresConnectionPool::DefaultPoolSize()));
LogicalType::UBIGINT, Value::UBIGINT(PostgresConnectionPool::DefaultPoolSize()), nullptr,
SetScope::GLOBAL);
config.AddExtensionOption("pg_pool_wait_timeout_millis",
"Maximum number of milliseconds to wait when acquiring a connection from a pool where "
"all available connections are already taken. " +
CreatePoolNote("wait_timeout_millis=60000"),
LogicalType::UBIGINT,
Value::UBIGINT(dbconnector::pool::ConnectionPoolConfig().wait_timeout_millis));
Value::UBIGINT(dbconnector::pool::ConnectionPoolConfig().wait_timeout_millis), nullptr,
SetScope::GLOBAL);
config.AddExtensionOption(
"pg_pool_enable_thread_local_cache",
"Whether to enable the connection caching in thread-local cache. Such connections are getting pinned to the "
"threads and are not made available to other threads, while still taking the place in the pool. " +
CreatePoolNote("enable_thread_local_cache=FALSE"),
LogicalType::BOOLEAN, Value::BOOLEAN(dbconnector::pool::ConnectionPoolConfig().tl_cache_enabled));
LogicalType::BOOLEAN, Value::BOOLEAN(dbconnector::pool::ConnectionPoolConfig().tl_cache_enabled), nullptr,
SetScope::GLOBAL);
config.AddExtensionOption("pg_pool_max_lifetime_millis",
"Maximum number of milliseconds the connection can be kept open. This number is checked "
"when the connection is taken from the pool and returned to the pool. "
"When the connection pool reaper thread is enabled ('pg_pool_enable_reaper_thread' "
"option), then this number is checked in background periodically. " +
CreatePoolNote("max_lifetime_millis=600000"),
LogicalType::UBIGINT,
Value::UBIGINT(dbconnector::pool::ConnectionPoolConfig().max_lifetime_millis));
Value::UBIGINT(dbconnector::pool::ConnectionPoolConfig().max_lifetime_millis), nullptr,
SetScope::GLOBAL);
config.AddExtensionOption("pg_pool_idle_timeout_millis",
"Maximum number of milliseconds the connection can be kept idle in the pool. This number "
"is checked when the connection is taken from the pool. "
"When the connection pool reaper thread is enabled ('pg_pool_enable_reaper_thread' "
"option), then this number is checked in background periodically. " +
CreatePoolNote("idle_timeout_millis=300000"),
LogicalType::UBIGINT,
Value::UBIGINT(dbconnector::pool::ConnectionPoolConfig().idle_timeout_millis));
Value::UBIGINT(dbconnector::pool::ConnectionPoolConfig().idle_timeout_millis), nullptr,
SetScope::GLOBAL);
config.AddExtensionOption(
"pg_pool_enable_reaper_thread",
"Whether to enable the connection pool reaper thread, that periodically scans the pool to check the "
"'max_lifetime_millis' and 'idle_timeout_millis' and closes the connection which exceed the specified values. "
"Either 'max_lifetime_millis' or 'idle_timeout_millis' must be set to a non-zero value for this option to be "
"effective. " +
CreatePoolNote("enable_reaper_thread=TRUE"),
LogicalType::BOOLEAN, Value::BOOLEAN(dbconnector::pool::ConnectionPoolConfig().start_reaper_thread));
LogicalType::BOOLEAN, Value::BOOLEAN(dbconnector::pool::ConnectionPoolConfig().start_reaper_thread), nullptr,
SetScope::GLOBAL);
config.AddExtensionOption("pg_pool_health_check_query",
"The query that is used to check that the connection is healthy. Setting this option to "
"an empty string disables the health check. " +
CreatePoolNote("health_check_query=SELECT 42"),
LogicalType::VARCHAR, PostgresConnectionPool::DefaultHealthCheckQuery());
LogicalType::VARCHAR, PostgresConnectionPool::DefaultHealthCheckQuery(), nullptr,
SetScope::GLOBAL);

OptimizerExtension postgres_optimizer;
postgres_optimizer.optimize_function = PostgresOptimizer::Optimize;
Expand Down
3 changes: 2 additions & 1 deletion src/storage/postgres_connection_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ void PostgresConnectionPool::SetAcquireMode(PostgresPoolAcquireMode mode) {

idx_t PostgresConnectionPool::DefaultPoolSize() {
idx_t detected = static_cast<idx_t>(std::thread::hardware_concurrency());
idx_t detected_adjusted = detected * 3 / 2;
idx_t default_num = static_cast<idx_t>(8);
return detected > default_num ? detected : default_num;
return detected_adjusted > default_num ? detected_adjusted : default_num;
}

std::string PostgresConnectionPool::DefaultHealthCheckQuery() {
Expand Down
2 changes: 1 addition & 1 deletion test/sql/storage/attach_connection_pool.test
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ FROM postgres_configure_pool(catalog_name='s')
s 1 FALSE

statement ok
RESET pg_pool_enable_thread_local_cache
RESET GLOBAL pg_pool_enable_thread_local_cache

statement ok
SELECT catalog_name, health_check_query
Expand Down
22 changes: 11 additions & 11 deletions test/sql/storage/attach_connection_pool_options.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SET pg_pool_acquire_mode = 'wait'
pg_pool_max_connections > 0

statement ok
RESET pg_pool_max_connections
RESET GLOBAL pg_pool_max_connections

statement ok
SET pg_pool_acquire_mode = 'try'
Expand All @@ -48,7 +48,7 @@ FROM postgres_configure_pool(catalog_name='s')
s try

statement ok
RESET pg_pool_acquire_mode
RESET GLOBAL pg_pool_acquire_mode

statement ok
DETACH s
Expand All @@ -66,7 +66,7 @@ FROM postgres_configure_pool(catalog_name='s')
s 42

statement ok
RESET pg_pool_max_connections
RESET GLOBAL pg_pool_max_connections

statement ok
DETACH s
Expand All @@ -84,7 +84,7 @@ FROM postgres_configure_pool(catalog_name='s')
s 42000

statement ok
RESET pg_pool_wait_timeout_millis
RESET GLOBAL pg_pool_wait_timeout_millis

statement ok
DETACH s
Expand All @@ -102,7 +102,7 @@ FROM postgres_configure_pool(catalog_name='s')
s FALSE

statement ok
RESET pg_pool_enable_thread_local_cache
RESET GLOBAL pg_pool_enable_thread_local_cache

statement ok
DETACH s
Expand All @@ -120,7 +120,7 @@ FROM postgres_configure_pool(catalog_name='s')
s 42000

statement ok
RESET pg_pool_max_lifetime_millis
RESET GLOBAL pg_pool_max_lifetime_millis

statement ok
DETACH s
Expand All @@ -138,7 +138,7 @@ FROM postgres_configure_pool(catalog_name='s')
s 42000

statement ok
RESET pg_pool_idle_timeout_millis
RESET GLOBAL pg_pool_idle_timeout_millis

statement ok
DETACH s
Expand All @@ -159,10 +159,10 @@ FROM postgres_configure_pool(catalog_name='s')
s TRUE

statement ok
RESET pg_pool_enable_reaper_thread
RESET GLOBAL pg_pool_enable_reaper_thread

statement ok
RESET pg_pool_idle_timeout_millis
RESET GLOBAL pg_pool_idle_timeout_millis

statement ok
DETACH s
Expand All @@ -187,7 +187,7 @@ SELECT current_setting('pg_pool_max_connections')
42

statement ok
RESET pg_connection_limit
RESET GLOBAL pg_connection_limit

query I
SELECT current_setting('pg_pool_max_connections')
Expand Down Expand Up @@ -215,7 +215,7 @@ SELECT current_setting('pg_pool_max_connections')
0

statement ok
RESET pg_connection_cache
RESET GLOBAL pg_connection_cache

query I
SELECT current_setting('pg_pool_max_connections')
Expand Down
Loading