Hibernate+PostgreSQL "Too Many Connections" 错误

Hibernate+PostgreSQL "Too Many Connections" error

我有一个应用程序,它在多个并发会话(超过 1000 个)中使用数据库。 在 Postgres 中,可用的最大连接数默认设置为 100,我没有更改它。

Hibernate 的最大连接池大小为 20,但应用程序似乎忽略了这一点并抛出 "Too many connections" 错误。

所以问题是当只有 100 个可用会话时如何处理超过 1000 个会话? 可以这样排队吗?

Hibernate has max connection pool size is 20, but the app seems to be ignored this and throws "Too many connections" error.

仔细检查您对 Hibernate 会话工厂的使用:

  • 如果您是网络应用程序,请阅读此 [1]
  • 如果您是独立应用,请阅读此 [2]

问题通常是 Hibernate Session 的错误使用。

[1] https://developer.jboss.org/wiki/UsingHibernatewithTomcat [2] http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch01.html#tutorial-firstapp-workingpersistence

So the problem is how to handle over 1000 sessions when the only available is 100? Is there queue or smth like this is possible?

100 是您可以打开的并发连接,超过这些您可以执行 100 多个操作:Hibernate 只是为您管理队列。