diff --git a/src/Storages/PostgreSQL/PostgreSQLConnection.h b/src/Storages/PostgreSQL/PostgreSQLConnection.h index 657bd31a502..037fd3e59da 100644 --- a/src/Storages/PostgreSQL/PostgreSQLConnection.h +++ b/src/Storages/PostgreSQL/PostgreSQLConnection.h @@ -49,18 +49,17 @@ class PostgreSQLConnectionHolder { using Pool = ConcurrentBoundedQueue; -using PoolPtr = std::shared_ptr; public: - PostgreSQLConnectionHolder(PostgreSQLConnectionPtr connection_, PoolPtr pool_) + PostgreSQLConnectionHolder(PostgreSQLConnectionPtr connection_, Pool & pool_) : connection(std::move(connection_)) - , pool(std::move(pool_)) + , pool(pool_) { } PostgreSQLConnectionHolder(const PostgreSQLConnectionHolder & other) = delete; - ~PostgreSQLConnectionHolder() { pool->tryPush(connection); } + ~PostgreSQLConnectionHolder() { pool.tryPush(connection); } pqxx::connection & conn() const { return *connection->get(); } @@ -68,7 +67,7 @@ public: private: PostgreSQLConnectionPtr connection; - PoolPtr pool; + Pool & pool; }; using PostgreSQLConnectionHolderPtr = std::shared_ptr; diff --git a/src/Storages/PostgreSQL/PostgreSQLConnectionPool.cpp b/src/Storages/PostgreSQL/PostgreSQLConnectionPool.cpp index 68c0e22f83c..1b156580dfb 100644 --- a/src/Storages/PostgreSQL/PostgreSQLConnectionPool.cpp +++ b/src/Storages/PostgreSQL/PostgreSQLConnectionPool.cpp @@ -48,11 +48,11 @@ PostgreSQLConnectionHolderPtr PostgreSQLConnectionPool::get() PostgreSQLConnectionPtr connection; if (pool->tryPop(connection, POSTGRESQL_POOL_WAIT_MS)) { - return std::make_shared(connection, pool); + return std::make_shared(connection, *pool); } connection = std::make_shared(connection_str, address); - return std::make_shared(connection, pool); + return std::make_shared(connection, *pool); }