非超级用户超出 PostgreSQL 连接限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9498001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:41:19  来源:igfitidea点击:

PostgreSQL connection limit exceeded for non-superusers

hibernatepostgresql

提问by Rajesh

I am using a spring application and I am getting following exception as:

我正在使用 spring 应用程序,但出现以下异常:

Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection.

When I am manually trying to connect to the database using DBVisualizer I am getting following error

当我手动尝试使用 DBVisualizer 连接到数据库时,出现以下错误

An error occurred while establishing the connection:

Long Message:
FATAL: connection limit exceeded for non-superusers

Details:
???Type: org.postgresql.util.PSQLException
???Error Code: 0
???SQL State: 53300

Here is my spring-context.xml file

这是我的 spring-context.xml 文件

<jee:jndi-lookup id="dataSource1" jndi-name="jdbc/PmdDS"/>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource1" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="current_session_context_class">thread</prop>
                <prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>

            </props>
        </property>
    </bean>

My question is I am getting this error because that I have not added following line in spring-context.xml

我的问题是我收到此错误,因为我没有在 spring-context.xml 中添加以下行

 <prop key="hibernate.connection.release_mode">auto</prop>

Will adding this line will solve my problem. I am fearing that my application is creating connection but not releasing the database connection because I have not added the above line in spring-context.xml.. Note I am not using HibernateTemplate . I am using sessionFactory.getCurrentSession().createQuery("").list()to fire my queries My Context.xml details

添加此行将解决我的问题。我担心我的应用程序正在创建连接但没有释放数据库连接,因为我没有在 spring-context.xml 中添加上面的行。注意我没有使用 HibernateTemplate 。我正在使用sessionFactory.getCurrentSession().createQuery("").list()我的 Context.xml 详细信息来触发我的查询

<Context>
     Specify a JDBC datasource 
    <Resource name="jdbc/PmdDS" 
              auth="Container"
              type="javax.sql.DataSource" 
              username="sdfsfsf" 
              password="sfsdfsdf" maxActive="-1"
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://111.11.11.11:5432/test"/>


</Context>

Please suggest any solution

请提出任何解决方案

采纳答案by Franti?ek Hartman

The problem is in the configuration of the datasource

问题出在数据源的配置上

The default value for max number of connections is higher then max number set in postgres and when hibernate asks for another connection the datasource tries to create one.

最大连接数的默认值高于 postgres 中设置的最大数,并且当休眠请求另一个连接时,数据源会尝试创建一个连接。

Can you show the configuration of your datasource?

你能显示你的数据源的配置吗?

回答by vektor

(recording the steps I took with the same problem)

(记录我遇到同样问题的步骤)

  1. Check your datasource - look for maxActivenumber.
  2. Check your Postgresql settings: SELECT * FROM pg_settings- look for the line with max_connections.
  1. 检查您的数据源 - 查找maxActive数字。
  2. 检查您的 Postgresql 设置:SELECT * FROM pg_settings- 查找带有max_connections.

If the first number is bigger than the second, you have a problem. Either lower the first or increase the second (in postgresql.confof your instance).

如果第一个数字大于第二个数字,则说明有问题。降低第一个或增加第二个(在postgresql.conf您的实例中)。

Also, do not forget to keep some reserve connections for other servers accessing the same DB, as well as some DB management tools:)

另外,不要忘记为访问同一数据库的其他服务器以及一些数据库管理工具保留一些保留连接:)