c3p0 池无法建立连接。如何调试这个?

发布于 2024-08-19 07:45:34 字数 985 浏览 6 评论 0原文

我在服务器上安装了 Tomcat 和 PostgreSQL。我在尝试使用 c3p0 池从 servlet 连接到 PostgreSQL 数据库时遇到连接问题。

如果我在笔记本电脑上本地运行 Tomcat,我就可以访问数据库。我还可以使用 psql (即命令行 sql 实用程序)从服务器连接到数据库。但是,当我尝试将 servlet 部署到服务器并建立连接时,出现以下错误:

java.sql.SQLException: Connections could not be acquired from the underlying database!
    com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
...
    com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
        com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
        com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
        com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)

我应该检查什么来定位问题?这应该是一个小问题,但可能是由于凌晨 4 点我错过了一些东西:) 提前致谢!

PS:允许所有网络接口连接到数据库。 PostgreSQL JDBC 驱动程序和 c3p0 池以 WAR 形式分发。 Tomcat 配置是非常默认的。不使用 JNDI。

I have a Tomcat and PostgreSQL installed on a server. I'm having a connection problem trying to connect from my servlet to PostgreSQL database using c3p0 pool.

I can reach DB if I'm running Tomcat locally on my laptop. Also I can connect from server to DB using psql (i.e. command line sql utility). But when I'm trying to deploy my servlet to server and establish a connection I'm getting the following error:

java.sql.SQLException: Connections could not be acquired from the underlying database!
    com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
...
    com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
        com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
        com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
        com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)

What should I check to locate a problem? It should be a trivial issue but may be due to 4 a.m. I'm missing something :) Thanks in advance!

PS: Connection from all network interfaces are allowed to database. PostgreSQL JDBC driver and c3p0 pool are distributed in WAR. Tomcat configuration is very default. JNDI is not used.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法少女 2024-08-26 07:45:34

您需要检查一些事情:

  1. tomcat正在使用的java.policy
    (例如
    /etc/tomcat5.5/policy.d/02debian.policy)
  2. 数据库服务器设置(例如
    /etc/postgresql/pg_hba.conf)
  3. 首先尝试在没有池的情况下进行连接
    就我而言,c3p0 向我隐藏了重要信息

You need to check a few things:

  1. java.policy which tomcat is using
    (e.g.
    /etc/tomcat5.5/policy.d/02debian.policy)
  2. db server settings (e.g.
    /etc/postgresql/pg_hba.conf)
  3. try connecting without pool first as
    in my case c3p0 was hiding important information from me
仄言 2024-08-26 07:45:34

添加到 @Alexey 的答案,我在 Tomcat 和 PostgreSQL 9.4 中遇到了这个问题。就我而言,是 postgres 中的 md5 身份验证方法导致了该问题。

如果您使用的是 Windows 服务器RHEL 服务器,请确保更新 pg_hba.conf 文件中的身份验证方法。修改为trust并重启postgresql。

Adding to @Alexey's answer, I had this issue with Tomcat and PostgreSQL 9.4. In my case, the md5 authentication method in postgres was causing the issue.

If you are using Windows server or RHEL server, make sure you update the authentication method in pg_hba.conf file. Modify it to trust and restart postgresql.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文