创建与 PostgreSQL 的连接时出现“致命:数据库系统正在关闭”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24442623/
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
"FATAL: the database system is shutting down" while creating connection to PostgreSQL
提问by Dan
I am getting FATAL: the database system is shutting down
errors while creating PostgreSQL JDBC connections to a PostgreSQL 9.2 server. The specific exception path I'm getting from JDBC is here:
FATAL: the database system is shutting down
在创建与 PostgreSQL 9.2 服务器的 PostgreSQL JDBC 连接时出现错误。我从 JDBC 得到的具体异常路径在这里:
Caused by: org.postgresql.util.PSQLException: FATAL: the database system is shutting down
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:398)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:173)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:136)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:31)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
From various log files (from PostgreSQL, from our management layer, from the app using PostgreSQL), I do not see any database shutdown actually happening (other connections are created to PostgreSQL as usual, no shutdown was initiated from our management layer, etc.), however in the PostgreSQL server logs I do see the error message with the same timestamp:
从各种日志文件(来自 PostgreSQL、来自我们的管理层、来自使用 PostgreSQL 的应用程序),我没有看到任何实际发生的数据库关闭(其他连接像往常一样创建到 PostgreSQL,我们的管理层没有启动关闭等。 ),但是在 PostgreSQL 服务器日志中,我确实看到了具有相同时间戳的错误消息:
2014-06-16 12:30:00.736 GMT LOG: connection received: host=127.0.0.1 port=38530
2014-06-16 12:30:00.737 GMT FATAL: the database system is shutting down
Researching online, I learned that this error message is used whenever PostgreSQL shuts down connections.
在线研究,我了解到每当 PostgreSQL 关闭连接时都会使用此错误消息。
Why would PostgreSQL refuse to give me a new connection? Could this be caused by some sort of resource contention? How can I get more information about the error from PostgreSQL itself?
为什么 PostgreSQL 会拒绝给我一个新的连接?这可能是由某种资源争用引起的吗?如何从 PostgreSQL 本身获取有关错误的更多信息?
回答by Dan
This issue turned out to be caused by a very bad misuse of PostgreSQL where our server had booted two PostgreSQL instances on the same data directory (it had deleted postmaster.pid
and used a new port number, so the normal safeguards against this behavior were bypassed) which explains why the logs did not hold any useful information -- they were being overwritten by the PostgreSQL instance which wasn't refusing connections. The actual issue was caused by a complex interaction between the competing PostgreSQL instances, and I hope nobody else runs into this issue as well!
事实证明,这个问题是由于对 PostgreSQL 的严重滥用造成的,我们的服务器在同一数据目录中启动了两个 PostgreSQL 实例(它已删除postmaster.pid
并使用了新的端口号,因此绕过了针对此行为的正常保护措施),这解释了为什么日志没有包含任何有用的信息——它们被不拒绝连接的 PostgreSQL 实例覆盖。实际问题是由竞争 PostgreSQL 实例之间的复杂交互引起的,我希望其他人也不会遇到这个问题!
回答by Thyago César Souto
We encountered this problem when the server was restarted. In this case the reboot did not initiate the connection with PostgreSql. Just check the status: "/etc/init.d/postgresql status" if the return is: "no server running" just start: "/etc/init.d/postgresql start"
我们在重新启动服务器时遇到了这个问题。在这种情况下,重启并没有启动与 PostgreSql 的连接。只需检查状态:“/etc/init.d/postgresql status”,如果返回:“没有服务器运行”,只需启动:“/etc/init.d/postgresql start”