PostgreSQL Evolutions:“PSQLException:致命:抱歉,客户端已经太多了”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14049185/
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-09-10 23:55:55  来源:igfitidea点击:

PostgreSQL Evolutions: "PSQLException: FATAL: sorry, too many clients already"

postgresqlscalaplayframework-2.0

提问by Ryan

I'm trying to set up a dev PostgreSQL server. It's running and I'm able to create roles, tables, etc. from the command line. However when I try to apply evolutions using Play, I get the following error:

我正在尝试设置一个开发 PostgreSQL 服务器。它正在运行,我可以从命令行创建角色、表等。但是,当我尝试使用 Play 应用进化时,出现以下错误:

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already

I'm able to connect and if I put in a syntax error on purpose, it returns the syntax error so I know that Play is able to connect to the database. However, after the evolution is successfully applied I get the error shown above.

我能够连接,如果我故意输入语法错误,它会返回语法错误,所以我知道 Play 能够连接到数据库。但是,在成功应用进化之后,我得到了上面显示的错误。

I'm not terribly well versed in PostgreSQl administration so I'm not sure if the problem is with Play or my PostgreSQL installation. I just installed it using Heroku's Postgres.app on a Mac running Mountain Lion.

我不太精通 PostgreSQl 管理,所以我不确定问题是出在 Play 还是我的 PostgreSQL 安装上。我刚刚在运行 Mountain Lion 的 Mac 上使用 Heroku 的 Postgres.app 安装了它。

Here is what gets written to the console:

以下是写入控制台的内容:

! @6cnb0blpp - Internal server error, for request [GET /] ->

play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution! [An SQL script need to be run on your database.]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$$anonfun$apply.apply$mcV$sp(Evolutions.scala:427) ~[play_2.9.1.jar:2.0.4]
    at play.api.db.evolutions.EvolutionsPlugin.withLock(Evolutions.scala:448) ~[play_2.9.1.jar:2.0.4]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart.apply(Evolutions.scala:414) ~[play_2.9.1.jar:2.0.4]
    at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart.apply(Evolutions.scala:412) ~[play_2.9.1.jar:2.0.4]
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.3]
    at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.3]
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 9. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 8. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 7. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 6. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 5. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 4. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 3. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 2. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 1. Exception: null
[error] application - 

Thanks!

谢谢!

采纳答案by i.am.michiel

You can reduce the number of connections used by your application. Had the same errors on a mac install. As shown in the official documentation:

您可以减少应用程序使用的连接数。在mac安装上有同样的错误。如官方文档所示:

db.default.partitionCount=2

# The number of connections to create per partition. Setting this to 
# 5 with 3 partitions means you will have 15 unique connections to the 
# database. Note that BoneCP will not create all these connections in   
# one go but rather start off with minConnectionsPerPartition and 
# gradually increase connections as required.
db.default.maxConnectionsPerPartition=5

# The number of initial connections, per partition.
db.default.minConnectionsPerPartition=5

回答by Erwin Brandstetter

The number of allowed connections is set in postgresql.confwith the GUC ("Grand Unified Configuration") max_connections. Default is 100.

postgresql.conf使用 GUC(“Grand Unified Configuration”)设置允许的连接数max_connections。默认值为 100。

But before you tinker whit the setting, you must ask yourself: where did all those other 100 connections come from, before your cluster hit the limit? That's usually pointing to a bug in your installation or program!

但是在修改设置之前,您必须问自己:在集群达到限制之前,所有其他 100 个连接是从哪里来的?这通常表示您的安装或程序中存在错误!

You may also be interested in connection poolingand this article about The Number of Connectionsin the Postgres Wiki.

您可能还对连接池和Postgres Wiki 中关于连接数的这篇文章感兴趣。

回答by Mike White

Postgres.app defaults to max_connections = 10. See ~/Library/Application Support/Postgres/var/postgresql.conf.

Postgres.app 默认为 max_connections = 10。参见~/Library/Application Support/Postgres/var/postgresql.conf

I fixed this by increasing max_connections to 50. On Mountain Lion I also had to reduce shared_buffers to 500kB for Postgres to start.

我通过将 max_connections 增加到 50 来解决这个问题。在 Mountain Lion 上,我还必须将 shared_buffers 减少到 500kB 才能启动 Postgres。