Connections could not be acquired from the underlying database! 解決方案
阿新 • • 發佈:2018-12-21
Connections could not be acquired from the underlying database! //不能連線當前所配置的資料庫 TNS-12541: TNS:no listener //無監聽程式 TNS-12560: TNS:protocol adapter error //協議介面卡錯誤 TNS-00511:no listener //無監聽程式
前言: 在開發環境,專案正常執行,突然登陸頁面可以顯示,登陸操作異常。 查詢後臺日誌,錯誤描述:
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database! at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529) at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423) ... 148 more Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319) at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557) at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525) ... 151 more
專案前一段時間執行正常,今天下午突然出現問題,說明程式配置是正常的,檢查資料庫連線數發現也是正常。這樣問題只能出現在資料庫上。
使用資料庫連線工具連線,發現監聽問題TNS 檢視監聽情況
lsnrctl status
問題如下:
LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 07-11月-2018 18:22:47 Copyright (c) 1991, 2007, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 111: Connection refused Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=GCRM0CV1)(PORT=1521))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 111: Connection refused
這個問題可能是監聽配置檔案有問題,但是這段時間沒有調整過監聽配置檔案,檢查了監聽配置檔案後,是沒有問題的。繼續排查中。。。。。
停止監聽
lsnrctl stop
問題和上面描述一樣。
啟動監聽
lsnrctl start
問題如下:
LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 07-11月-2018 18:23:22 Copyright (c) 1991, 2007, Oracle. All rights reserved. Starting /home/db/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 10.2.0.4.0 - Production NL-00280: error creating log stream /home/db/oracle/product/10.2.0/db_1/network/log/listener.log NL-00278: cannot open log file SNL-00016: snlfohd: error opening file Linux Error: 13: Permission denied Listener failed to start. See the error message(s) above...
檢視日誌:
ls -lh /home/db/oracle/product/10.2.0/db_1/network/log/listener.log
發現日誌大小居然大於4G,找到問題所在,這個是oracle的bug,當listner日誌增長到4GB,通過偵聽器連線很慢。
解決方案:
1. lsnrctl進入互動模式
2. 執行 set current_listener LISTENER
3. set log_status off
4. stop 停止監聽器
5. 手工刪除指定的監聽日誌路徑下的listener.log檔案
6. start 啟動監聽器
7. status 檢視狀態