diff --git a/src/postgres_utils.cpp b/src/postgres_utils.cpp index a1aaf0d01..edc19d3e4 100644 --- a/src/postgres_utils.cpp +++ b/src/postgres_utils.cpp @@ -13,7 +13,10 @@ PGconn *PostgresUtils::PGConnect(const string &dsn, const string &attach_path) { // both PQStatus and PQerrorMessage check for nullptr if (PQstatus(conn) == CONNECTION_BAD) { - throw IOException("Unable to connect to Postgres at \"%s\": %s", attach_path, string(PQerrorMessage(conn))); + char *msg_cstr = PQerrorMessage(conn); + std::string msg = msg_cstr != nullptr ? std::string(msg_cstr) : std::string(); + PQfinish(conn); + throw IOException("Unable to connect to Postgres at \"%s\": %s", attach_path, msg); } PQsetNoticeProcessor(conn, PGNoticeProcessor, nullptr); return conn; diff --git a/test/sql/storage/attach_connection_pool_configure.test b/test/sql/storage/attach_connection_pool_configure.test index 0d8795723..486d50ea4 100644 --- a/test/sql/storage/attach_connection_pool_configure.test +++ b/test/sql/storage/attach_connection_pool_configure.test @@ -6,19 +6,28 @@ require postgres_scanner require-env POSTGRES_TEST_DATABASE_AVAILABLE +statement ok +PRAGMA enable_verification + +statement ok +SET pg_pool_max_connections = 8 + statement ok ATTACH 'dbname=postgresscanner' AS s (TYPE POSTGRES); statement ok ATTACH 'dbname=postgresscanner' AS s1 (TYPE POSTGRES); -query I -SELECT catalog_name +statement ok +RESET GLOBAL pg_pool_max_connections + +query II +SELECT catalog_name, max_connections FROM postgres_configure_pool() ORDER BY catalog_name ---- -s -s1 +s 8 +s1 8 query II SELECT catalog_name, acquire_mode diff --git a/test/sql/storage/attach_connection_pool_options.test b/test/sql/storage/attach_connection_pool_options.test index b5180badf..16660bbf4 100644 --- a/test/sql/storage/attach_connection_pool_options.test +++ b/test/sql/storage/attach_connection_pool_options.test @@ -6,6 +6,9 @@ require postgres_scanner require-env POSTGRES_TEST_DATABASE_AVAILABLE +statement ok +PRAGMA enable_verification + statement ok ATTACH 'dbname=postgresscanner' AS s (TYPE POSTGRES); @@ -189,11 +192,6 @@ SELECT current_setting('pg_pool_max_connections') statement ok RESET GLOBAL pg_connection_limit -query I -SELECT current_setting('pg_pool_max_connections') ----- -8 - statement ok DETACH s @@ -217,10 +215,5 @@ SELECT current_setting('pg_pool_max_connections') statement ok RESET GLOBAL pg_connection_cache -query I -SELECT current_setting('pg_pool_max_connections') ----- -8 - statement ok DETACH s