我有一个在wildfly 8.1下运行的应用程序,应用程序中使用的数据库连接来自standalone中定义的数据源。xml文件。
问题:我不知道为什么,但池中的连接从不空闲,并且会被释放。最终,池被填满,所有活动连接和应用程序开始抛出javax。资源ResourceException:IJ000453:无法获取java的托管连接:/bo/datasource
同时,当我查看数据库时,大多数连接显示为空闲。(配置和结果输出如下)
我已经做了一个星期了,还没能找出这个问题的根本原因。我还检查了所有创建连接的地方,并确保它们在创建后关闭。
我还应该调查哪些其他可能的地方?或者这是一个bug(或者Wildfly数据源的已知问题)?
野蝇数据源定义:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:/db/pool" pool-name="DBSource" enabled="true">
<connection-url>jdbc:postgresql://<IP>:5432/DB</connection-url>
<driver>postgres</driver>
<new-connection-sql>select 1</new-connection-sql>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>100</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<background-validation>true</background-validation>
<background-validation-millis>60000</background-validation-millis>
</validation>
<timeout>
<idle-timeout-minutes>30</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>true</track-statements>
</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="postgres" module="org.postgres">
<driver-class>org.postgresql.Driver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
Wildfly数据源池信息:
命令:
/subsystem=datasources/data-source=DBSource/statistics=pool:read-resource(recursive=false,proxies=false,include-runtime=true,include-defaults=true)
回应:
{
"outcome" => "success",
"result" => {
"ActiveCount" => "98",
"AvailableCount" => "55",
"AverageBlockingTime" => "1",
"AverageCreationTime" => "125",
"AverageGetTime" => "27",
"BlockingFailureCount" => "0",
"CreatedCount" => "98",
"DestroyedCount" => "0",
"IdleCount" => "3",
"InUseCount" => "95",
"MaxCreationTime" => "1382",
"MaxGetTime" => "1382",
"MaxUsedCount" => "97",
"MaxWaitCount" => "0",
"MaxWaitTime" => "1",
"TimedOut" => "0",
"TotalBlockingTime" => "71",
"TotalCreationTime" => "12340",
"TotalGetTime" => "12696",
"WaitCount" => "0"
},
"response-headers" => {"process-state" => "reload-required"}
}
PostgreSQL查询状态:
命令:
SELECT datname, pid, usename, waiting, state, (now()-query_start) AS since, (now() - state_change) AS since2, (now() - backend_start) as since3, (now() - xact_start) as since4, query FROM pg_stat_activity ORDER BY datname, state, usename, waiting, query, since, pid;
回应:
datname | pid | usename | waiting | state | since | since2 | since3 | since4 |
---------------+------+------------+---------+---------------------+-----------------+------------------+-----------------+-----------------+-----------------------------------------------------------------------------------------------------------------------------------
BOIEDUDBV13R1 | 4871 | blueoptima | f | active | 00:00:00.176188 | 00:00:00.176179 | 01:37:21.045722 | 00:02:17.212346 | Query-1
BOIEDUDBV13R1 | 4568 | blueoptima | f | active | 00:18:33.035399 | 00:18:33.035395 | 04:25:11.916388 | 00:18:33.473355 | Query-2
BOIEDUDBV13R1 | 4564 | blueoptima | f | active | 00:10:10.599237 | 00:10:10.599232 | 04:25:11.943752 | 00:10:10.915048 | Query-3
BOIEDUDBV13R1 | 4498 | blueoptima | f | active | 00:03:25.861284 | 00:03:25.86128 | 05:09:51.735583 | 00:03:25.861823 | Query-4
BOIEDUDBV13R1 | 4535 | blueoptima | f | active | 00:01:16.612227 | 00:01:16.612222 | 04:34:01.668772 | 00:01:16.614149 | Query-5
BOIEDUDBV13R1 | 4534 | blueoptima | f | idle | 00:00:04.72429 | 00:00:04.683504 | 04:35:21.78966 | | COMMIT
BOIEDUDBV13R1 | 4519 | blueoptima | f | idle | 00:00:12.950041 | 00:00:12.913566 | 04:50:53.698877 | | COMMIT
BOIEDUDBV13R1 | 4438 | blueoptima | f | idle | 00:00:25.82585 | 00:00:25.81036 | 05:34:41.528853 | | COMMIT
BOIEDUDBV13R1 | 4425 | blueoptima | f | idle | 00:09:12.999537 | 00:09:12.9731 | 05:41:51.806148 | | COMMIT
BOIEDUDBV13R1 | 4488 | blueoptima | f | idle | 00:56:04.709316 | 00:56:04.686439 | 05:14:45.445165 | | COMMIT
BOIEDUDBV13R1 | 4501 | blueoptima | f | idle | 00:57:00.615919 | 00:57:00.61589 | 05:06:51.861328 | | COMMIT
BOIEDUDBV13R1 | 4466 | blueoptima | f | idle | 04:11:54.8669 | 04:11:54.516947 | 05:25:03.079741 | | COMMIT
BOIEDUDBV13R1 | 4419 | blueoptima | f | idle | 04:51:03.786294 | 04:51:03.749462 | 05:41:51.814577 | | COMMIT
BOIEDUDBV13R1 | 4340 | blueoptima | f | idle | 04:52:19.772533 | 04:52:19.720537 | 06:31:51.758733 | | COMMIT
BOIEDUDBV13R1 | 4502 | blueoptima | f | idle | 04:54:49.892553 | 04:54:49.85151 | 05:06:51.439101 | | COMMIT
BOIEDUDBV13R1 | 4406 | blueoptima | f | idle | 05:09:20.675009 | 05:09:20.655038 | 06:00:50.160594 | | COMMIT
BOIEDUDBV13R1 | 4489 | blueoptima | f | idle | 05:09:54.785706 | 05:09:54.751723 | 05:14:45.358108 | | COMMIT
BOIEDUDBV13R1 | 4449 | blueoptima | f | idle | 05:16:58.881682 | 05:16:58.88074 | 05:26:50.728973 | | COMMIT
BOIEDUDBV13R1 | 4450 | blueoptima | f | idle | 05:17:23.727614 | 05:17:23.726158 | 05:25:55.116657 | | COMMIT
BOIEDUDBV13R1 | 4465 | blueoptima | f | idle | 05:22:32.475769 | 05:22:32.470301 | 05:25:03.230671 | | COMMIT
BOIEDUDBV13R1 | 4421 | blueoptima | f | idle | 05:25:03.596961 | 05:25:03.596942 | 05:41:51.81487 | | COMMIT
BOIEDUDBV13R1 | 4451 | blueoptima | f | idle | 05:25:29.373092 | 05:25:29.364467 | 05:25:52.433709 | | COMMIT
BOIEDUDBV13R1 | 4448 | blueoptima | f | idle | 05:25:58.729039 | 05:25:58.724453 | 05:26:50.898318 | | COMMIT
BOIEDUDBV13R1 | 4423 | blueoptima | f | idle | 05:26:13.2656 | 05:26:13.263502 | 05:41:51.814528 | | COMMIT
BOIEDUDBV13R1 | 4426 | blueoptima | f | idle | 05:26:58.773981 | 05:26:58.765174 | 05:41:51.179333 | | COMMIT
BOIEDUDBV13R1 | 4415 | blueoptima | f | idle | 05:29:07.123798 | 05:29:07.115682 | 05:47:36.740939 | | COMMIT
BOIEDUDBV13R1 | 4394 | blueoptima | f | idle | 05:42:02.02632 | 05:42:01.994772 | 06:05:54.290575 | | COMMIT
BOIEDUDBV13R1 | 4416 | blueoptima | f | idle | 05:45:52.799303 | 05:45:52.793004 | 05:47:36.701474 | | COMMIT
BOIEDUDBV13R1 | 4408 | blueoptima | f | idle | 05:48:02.635413 | 05:48:02.630767 | 05:54:49.133404 | | COMMIT
BOIEDUDBV13R1 | 4410 | blueoptima | f | idle | 05:49:09.631417 | 05:49:09.624039 | 05:49:47.440347 | | COMMIT
BOIEDUDBV13R1 | 4392 | blueoptima | f | idle | 05:49:45.136111 | 05:49:45.124627 | 06:05:54.52666 | | COMMIT
BOIEDUDBV13R1 | 4411 | blueoptima | f | idle | 05:49:45.208436 | 05:49:45.207393 | 05:49:46.326729 | | COMMIT
BOIEDUDBV13R1 | 4399 | blueoptima | f | idle | 05:50:19.476105 | 05:50:19.465746 | 06:04:53.509647 | | COMMIT
BOIEDUDBV13R1 | 4383 | blueoptima | f | idle | 05:54:04.625364 | 05:54:04.56991 | 06:09:43.004602 | | COMMIT
BOIEDUDBV13R1 | 4382 | blueoptima | f | idle | 05:58:29.615594 | 05:58:29.608542 | 06:09:43.496538 | | COMMIT
BOIEDUDBV13R1 | 4404 | blueoptima | f | idle | 06:00:48.381014 | 06:00:48.379175 | 06:00:50.352202 | | COMMIT
BOIEDUDBV13R1 | 4393 | blueoptima | f | idle | 06:01:49.740445 | 06:01:49.733278 | 06:05:54.468595 | | COMMIT
BOIEDUDBV13R1 | 4379 | blueoptima | f | idle | 06:02:12.00668 | 06:02:12.004878 | 06:11:37.044413 | | COMMIT
BOIEDUDBV13R1 | 4396 | blueoptima | f | idle | 06:02:25.216415 | 06:02:25.202565 | 06:05:10.411017 | | COMMIT
BOIEDUDBV13R1 | 4390 | blueoptima | f | idle | 06:03:48.651868 | 06:03:48.647211 | 06:06:05.443 | | COMMIT
BOIEDUDBV13R1 | 4375 | blueoptima | f | idle | 06:04:51.760968 | 06:04:51.732155 | 06:11:37.545217 | | COMMIT
BOIEDUDBV13R1 | 4353 | blueoptima | f | idle | 06:04:53.302492 | 06:04:53.252345 | 06:25:54.61252 | | COMMIT
BOIEDUDBV13R1 | 4372 | blueoptima | f | idle | 06:05:08.158286 | 06:05:08.137553 | 06:11:49.797186 | | COMMIT
BOIEDUDBV13R1 | 4397 | blueoptima | f | idle | 06:05:08.578854 | 06:05:08.544941 | 06:05:10.298185 | | COMMIT
BOIEDUDBV13R1 | 4377 | blueoptima | f | idle | 06:08:34.443118 | 06:08:34.435299 | 06:11:37.432426 | | COMMIT
BOIEDUDBV13R1 | 4378 | blueoptima | f | idle | 06:11:35.00451 | 06:11:34.946687 | 06:11:37.293523 | | COMMIT
BOIEDUDBV13R1 | 4354 | blueoptima | f | idle | 06:12:01.816625 | 06:12:01.812458 | 06:25:50.247498 | | COMMIT
BOIEDUDBV13R1 | 4344 | blueoptima | f | idle | 06:21:56.439509 | 06:21:56.438739 | 06:31:30.8968 | | COMMIT
BOIEDUDBV13R1 | 4350 | blueoptima | f | idle | 06:22:20.125071 | 06:22:20.11839 | 06:29:37.465565 | | COMMIT
BOIEDUDBV13R1 | 4343 | blueoptima | f | idle | 06:25:59.198819 | 06:25:59.197962 | 06:31:30.901491 | | COMMIT
BOIEDUDBV13R1 | 4351 | blueoptima | f | idle | 06:27:23.950853 | 06:27:23.950081 | 06:29:37.456841 | | COMMIT
BOIEDUDBV13R1 | 4348 | blueoptima | f | idle | 06:27:36.13192 | 06:27:36.131014 | 06:29:37.513979 | | COMMIT
BOIEDUDBV13R1 | 4349 | blueoptima | f | idle | 06:27:42.332901 | 06:27:42.331326 | 06:29:37.491039 | | COMMIT
BOIEDUDBV13R1 | 4352 | blueoptima | f | idle | 06:27:54.031819 | 06:27:54.02966 | 06:29:37.265193 | | COMMIT
BOIEDUDBV13R1 | 4341 | blueoptima | f | idle | 06:28:14.444963 | 06:28:14.444105 | 06:31:31.858728 | | COMMIT
BOIEDUDBV13R1 | 4337 | blueoptima | f | idle | 06:29:20.216685 | 06:29:20.215749 | 06:33:13.450564 | | COMMIT
BOIEDUDBV13R1 | 4346 | blueoptima | f | idle | 06:29:28.524638 | 06:29:28.523906 | 06:30:51.904609 | | COMMIT
BOIEDUDBV13R1 | 4342 | blueoptima | f | idle | 06:29:58.433751 | 06:29:58.432939 | 06:31:31.204896 | | COMMIT
BOIEDUDBV13R1 | 4345 | blueoptima | f | idle | 06:30:28.819691 | 06:30:28.818747 | 06:31:26.849458 | | COMMIT
BOIEDUDBV13R1 | 4355 | blueoptima | f | idle | 06:07:48.953452 | 06:07:48.947655 | 06:25:50.216644 | | INSERT
BOIEDUDBV13R1 | 4409 | blueoptima | f | idle | 05:49:25.452863 | 05:49:25.435483 | 05:49:49.502884 | | INSERT-1
BOIEDUDBV13R1 | 4424 | blueoptima | f | idle | 05:35:44.413808 | 05:35:44.381036 | 05:41:51.814529 | | INSERT-2
BOIEDUDBV13R1 | 4398 | blueoptima | f | idle | 05:36:00.621836 | 05:36:00.598047 | 06:04:53.758915 | | INSERT-3
BOIEDUDBV13R1 | 4417 | blueoptima | f | idle | 05:46:18.096148 | 05:46:18.07272 | 05:47:36.576677 | | INSERT-4
BOIEDUDBV13R1 | 4395 | blueoptima | f | idle | 05:50:44.112353 | 05:50:44.074542 | 06:05:10.557776 | | INSERT-5
BOIEDUDBV13R1 | 4388 | blueoptima | f | idle | 06:05:57.843694 | 06:05:57.832724 | 06:06:06.177483 | | INSERT-6
BOIEDUDBV13R1 | 4339 | blueoptima | f | idle | 06:17:57.460712 | 06:17:57.459716 | 06:33:12.657432 | | INSERT-7
BOIEDUDBV13R1 | 4487 | blueoptima | f | idle | 00:00:15.552081 | 00:00:15.552035 | 05:15:49.047066 | | select 1
BOIEDUDBV13R1 | 4565 | blueoptima | f | idle | 00:00:15.553093 | 00:00:15.553037 | 04:25:11.942656 | | select 1
BOIEDUDBV13R1 | 4420 | blueoptima | f | idle | 00:00:15.554958 | 00:00:15.55493 | 05:41:51.814789 | | select 1
BOIEDUDBV13R1 | 4402 | blueoptima | f | idle | 02:16:15.871078 | 02:16:15.871048 | 06:00:52.663433 | | select 1
BOIEDUDBV13R1 | 4384 | blueoptima | f | idle | 05:38:17.430042 | 05:38:17.43002 | 06:09:42.969186 | | select 1
BOIEDUDBV13R1 | 4412 | blueoptima | f | idle | 05:46:47.263716 | 05:46:47.263518 | 05:49:45.575215 | | SELECT DISTINCT column FROM table
BOIEDUDBV13R1 | 4414 | blueoptima | f | idle | 05:49:41.773012 | 05:49:41.772712 | 05:49:45.435716 | | SELECT DISTINCT column FROM table
BOIEDUDBV13R1 | 4405 | blueoptima | f | idle | 05:51:32.2168 | 05:51:32.216636 | 06:00:50.160309 | | SELECT DISTINCT column FROM table
BOIEDUDBV13R1 | 4400 | blueoptima | f | idle | 05:52:44.966233 | 05:52:44.965626 | 06:02:28.601245 | | SELECT DISTINCT column FROM table
BOIEDUDBV13R1 | 4401 | blueoptima | f | idle | 06:01:07.430069 | 06:01:07.429643 | 06:02:28.599077 | | SELECT DISTINCT column FROM table
BOIEDUDBV13R1 | 4389 | blueoptima | f | idle | 06:05:52.187161 | 06:05:52.187081 | 06:06:05.801733 | | SELECT DISTINCT column FROM table
BOIEDUDBV13R1 | 4376 | blueoptima | f | idle | 06:06:04.447668 | 06:06:04.447527 | 06:11:37.448819 | | SELECT DISTINCT column FROM table
BOIEDUDBV13R1 | 4422 | blueoptima | f | idle | 04:48:59.446162 | 04:48:59.446103 | 05:41:51.814892 | | SELECT
BOIEDUDBV13R1 | 4385 | blueoptima | f | idle | 05:28:13.718473 | 05:28:13.643871 | 06:09:42.799857 | | SELECT
BOIEDUDBV13R1 | 4536 | blueoptima | f | idle | 04:29:42.4528 | 04:29:42.429103 | 04:34:01.664679 | | SELECT
BOIEDUDBV13R1 | 4381 | blueoptima | f | idle | 06:05:51.131506 | 06:05:51.131429 | 06:11:35.758195 | | SELECT
BOIEDUDBV13R1 | 4338 | blueoptima | f | idle | 06:28:31.658157 | 06:28:31.658105 | 06:33:12.953437 | | SELECT
BOIEDUDBV13R1 | 4566 | blueoptima | f | idle | 00:00:25.8479 | 00:00:25.835864 | 04:25:11.94033 | | UPDATE-1
BOIEDUDBV13R1 | 4391 | blueoptima | f | idle | 03:52:25.755736 | 03:52:25.73571 | 06:06:05.300207 | | UPDATE-2
BOIEDUDBV13R1 | 4512 | blueoptima | f | idle | 04:56:03.247543 | 04:56:03.232923 | 04:56:44.188961 | | UPDATE-3
BOIEDUDBV13R1 | 4511 | blueoptima | f | idle | 04:56:34.70146 | 04:56:34.691303 | 04:57:00.191291 | | UPDATE-4
BOIEDUDBV13R1 | 4347 | blueoptima | f | idle | 05:32:30.754975 | 05:32:30.732481 | 06:29:46.312612 | | UPDATE-5
BOIEDUDBV13R1 | 4439 | blueoptima | f | idle | 05:32:55.742867 | 05:32:55.741539 | 05:34:41.519884 | | UPDATE-6
BOIEDUDBV13R1 | 4407 | blueoptima | f | idle | 05:37:36.461115 | 05:37:36.451762 | 05:54:49.133383 | | UPDATE-7
BOIEDUDBV13R1 | 4371 | blueoptima | f | idle | 05:53:02.986092 | 05:53:02.830753 | 06:11:55.240785 | | UPDATE-8
BOIEDUDBV13R1 | 4403 | blueoptima | f | idle | 05:59:57.870442 | 05:59:57.865218 | 06:00:52.646267 | | UPDATE-9
BOIEDUDBV13R1 | 4356 | blueoptima | f | idle | 06:09:18.560294 | 06:09:18.559498 | 06:25:50.216061 | | UPDATE-10
BOIEDUDBV13R1 | 4380 | blueoptima | f | idle | 06:09:38.951985 | 06:09:38.924395 | 06:11:36.494018 | | UPDATE-11
BOIEDUDBV13R1 | 4863 | postgres | f | idle | 01:21:12.135105 | 01:21:12.052383 | 02:01:39.736693 | | select a
| | | | | | | | | ;
BOIEDUDBV13R1 | 4988 | postgres | f | idle | 00:11:16.272964 | 00:11:16.145621 | 00:13:26.234094 | | select b
| | | | | | | | |
BOIEDUDBV13R1 | 4437 | blueoptima | f | idle in transaction | 05:29:11.490837 | 05:29:11.490825 | 05:34:41.52984 | 05:29:11.490949 | select 1
BOIEDUDBV13R1 | 4413 | blueoptima | f | idle in transaction | 05:36:47.417173 | 05:36:47.417148 | 05:49:45.5742 | 05:36:47.417257 | select 1
BOIEDUDBV13R1 | 4567 | blueoptima | f | idle in transaction | 00:49:38.844059 | 00:49:38.844027 | 04:25:11.936358 | 00:49:40.950629 | Query
(100 rows)
结果证明Hibernate保持连接,而没有将它们释放到池中。不管我们使用的是线程本地上下文。但是在添加
附言:我仍然不明白为什么我们需要明确定义这个,为什么自动release_mode不会在会话关闭后释放连接。
我正在使用Knex.js来处理与数据库的连接。我正在尝试防止连接池破坏空闲的连接。 我的配置是这样的 然而,我仍然不断得到 在一段时间不活动后。 据我所知,当足够的时间过去时,应该将连接从池中丢弃。因此,如果连接有一段时间没有使用(这就是我的情况),池中将没有连接,我尝试的第一次调用将失败,并出现给定错误。随后的调用顺利进行(直到新的超时) 我的问题是——如何防止这种情况? 编辑 在我的应用空闲一
检测空闲连接和超时是为了及时释放资源。常见的方法发送消息用于测试一个不活跃的连接来,通常称为“心跳”,到远端来确定它是否还活着。(一个更激进的方法是简单地断开那些指定的时间间隔的不活跃的连接)。 处理空闲连接是一项常见的任务,Netty 提供了几个 ChannelHandler 实现此目的。表8.4概述。 Table 8.4 ChannelHandlers for idle connections
环境-Grails 2.0.4、Oracle 11g 我还在调试器中运行了它,并向bootstrap.groovy添加了一些代码来获取上下文。 “ctx”确实具有datasource_secondary中指定的预期值。你知道为什么我仍然得到套接字异常吗?
Tableau可以与广泛使用的所有可访问数据源连接。它可以链接到Excel文件,PDF文件,文本文件等。它还可以使用其ODBC连接器连接到各种数据库。Tableau可以连接到Web连接器和服务器。 Tableaus本机连接器可以连接到以下类型的数据源: 文件系统:如Microsoft Excel,CSV等。 云系统:例如Google bigQuery,Windows Azure等。 关系系统:如M
问题内容: 通过Node MongoDB本机驱动程序使用Nodejs和MongoDB。需要检索一些文档,并进行修改,然后将其保存回来。这是一个例子: 具有异步性质,如果更新文档的过程花费更长的时间,则当光标到达文档末尾时,数据库连接将关闭。并非所有更新都保存到数据库。 如果省略,则所有文档均正确更新,但应用程序挂起,永不退出。 我看到一则帖子建议使用计数器跟踪更新次数,当回落到零时,然后关闭数据库
问题内容: 我有些困惑,我从阅读以下内容 你不需要关闭conn连接吗?如果conn.close()没有发生,那实际上是怎么回事? 我有一个正在维护的私有Web应用程序,该应用程序当前无法关闭任何一种形式,但是重要的应用程序真的是stmt,conn还是两者兼而有之? 该站点间歇性地关闭,但是服务器一直在说这是数据库连接问题,我怀疑它没有关闭,但是我不知道该关闭哪个。 问题答案: 使用完之后,你需要通