【发布时间】:2018-05-08 12:57:51
【问题描述】:
我有一个在 glassfish5 上运行的 JSP 应用程序,它使用 postgresql 作为数据库服务。为了管理连接,我选择了 HikariCP,如下所示
config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
config.addDataSourceProperty("serverName", host);
config.addDataSourceProperty("portNumber", port);
config.addDataSourceProperty("databaseName", database);
config.addDataSourceProperty("user", username);
config.addDataSourceProperty("password", password);
config.addDataSourceProperty("assumeMinServerVersion", postrgesVersion);
config.setMinimumIdle(100);
config.setMaximumPoolSize(100);
config.setAutoCommit(false);
config.setIdleTimeout(3000);
ds = new HikariDataSource(config);
以这种方式使用数据源实现
public static Connection getConnection() throws SQLException {
return ds.getConnection();
}
当我在 pgAdmin 中运行以下查询时
select datname,pid,usename,client_addr,client_port,backend_start,query,state from pg_stat_activity where datname = 'db_name' AND client_addr='10.1.0.56'
我得到以下结果,其中包含许多没有任何查询的连接,如下图所示
几秒钟后,postgres 抱怨连接太多。有没有人遇到过这种情况,请帮忙。
【问题讨论】:
-
你的池子这么大太疯狂了。请阅读About Pool Sizing。
标签: postgresql glassfish database-connection postgresql-9.4 hikaricp