PostgreSQL 连接超时

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

PostgreSQL connection timeout

postgresqlpostgresql-9.1

提问by Prakki

I am using a desktop application with PostgreSQL database server. When I am not using application for 10 to 20 minutescontinuously, the database connection is dropped. And I am using PostgresqlJDBCfor database connection.

我正在使用带有 PostgreSQL 数据库服务器的桌面应用程序。当我连续10 到 20 分钟不使用应用程序时,数据库连接被丢弃。我使用PostgresqlJDBC进行数据库连接。

Please help me on this to database connection time out.

请帮助我解决数据库连接超时问题。

Thanks.

谢谢。

回答by Craig Ringer

Sounds like you are connected via a stateful connection tracking router/firewall that has a short connection tracking timeout. Sounds like you need to enable keepalives.

听起来您是通过有状态的连接跟踪路由器/防火墙连接的,该路由器/防火墙的连接跟踪超时时间很短。听起来您需要启用保活。

Take a look at the tcp_keepalives_intervaland tcp_keepalives_idleparameters.

看看tcp_keepalives_intervaltcp_keepalives_idle参数

You can also request keepalives client-side in the JDBC driver; see the pgJDBC docs.

您还可以在 JDBC 驱动程序中请求 keepalive 客户端;请参阅 pgJDBC 文档。