是否有任何C/C++库可用于postgres连接池?我看过pgpool,它更像是一个中间件。我正在寻找一个可以编入我的应用程序的库。postgres连接池库
回答
没有好的应用内连接池库。几乎整个社区都使用外部代理,特别是pgbouncer
由于其额外的运营利益。同样的,SOCI has a connection pool,但它的使用几乎不如pgbouncer
。
我想找到一种解决方案,我不必在服务器中引入任何新的服务/进程。看起来我必须写自己的共享库。顺便说一句关于使用[SQL Relay](http://sqlrelay.sourceforge.net/sqlrelay/)的建议? – Vasu
你看过libpqxx了吗?它本身不是连接池,但它提供了一个C++ API来从应用程序代码中抽象连接处理。这允许应用程序很容易地构建和管理自己的连接池。
这真的很简单,下面是一个示例(使用boost for shared_ptr & pqxx)来说明使用工厂方法的池类。您可以想象runQuery方法将从指定的池中获取连接,并调用pqxx API在基础连接上执行查询。然后它可以将连接返回到池中。
class DbPool {
public:
static db_handle_t create(const string &conn,
uint32_t max = DEFAULT_CON_MAX,
uint32_t min = DEFAULT_CON_MIN);
static pqxx::result runQuery(db_handle_t pool,
const string& query);
private:
DbPool(const string& con, uint32_t max_cons,
uint32_t min_cons);
static boost::ptr_vector<DbPool> pool_; // Keep a static vector of pools,
pqxx::connection *createCon();
void releaseCon(pqxx::connection *c);
uint32_t initializeCons();
pqxx::connection *getCon();
boost::ptr_list<pqxx::connection> m_freeCons;
}
很好的答案,但是你不必管理连接,就像阻止它们干扰对方的查询一样吗?我不熟悉Postgres,因此不知道它是否已经自动管理这个。 – 2014-02-09 21:13:23
- 1. Postgres Npgsql连接池
- 2. Postgres with Glassfish连接池
- 3. sql炼金术和postgres的连接池
- 4. C3P0与Heroku Postgres连接池失速
- 5. Postgres有本地连接池像mysql吗?
- 6. postgres alter table挂起连接池
- 7. 使用Springboot和Postgres废弃连接池
- 8. Glassfish + Postgres无法ping通连接池
- 9. 使用postgres和nodejs连接池
- 10. 我在做连接池吗?使用node-postgres库
- 11. Java:JDBC数据库连接池
- 12. 连接池与NEST ElasticSearch库
- 13. 数据库连接池
- 14. JBoss数据库连接池
- 15. C#postgres数据库连接
- 16. 连接到postgres数据库
- 17. C3P0连接池与MySQL连接池
- 18. Jboss连接池或休眠连接池
- 19. Tomcat连接池概念&c3p0连接池?
- 20. 连接池 - 无连接
- 21. asyncpg - 连接vs连接池
- 22. PreparedStatement的池连接池
- 23. 对象池vs连接池
- 24. 文件池(如连接池)
- 25. OrientDB连接池
- 26. eclipselink连接池
- 27. Perl连接池
- 28. sql连接池
- 29. activemq连接池
- 30. Hbase连接池
要澄清,你正在寻找的东西,将保持连接到一个或多个数据库的列表?最简单的答案是使用一个'PGconn *'数组。也许你应该更具体地了解你需要什么,因为连接池传统上指的是中间件。 – unpythonic
是的,我正在寻找。我正在考虑类似[Apache DBCP](http://commons.apache.org/dbcp/)的Java。一旦我配置了池,我不应该担心检查连接的健康状况,关闭断开的连接等。池应该透明地管理所有这些,并提供一个干净的API。 – Vasu