【问题标题】:Connection lost after query runs for few minutes in PostgreSQL在 PostgreSQL 中查询运行几分钟后连接丢失
【发布时间】:2013-06-30 15:41:33
【问题描述】:

我正在使用 PostgreSQL 8.4 和 PostGIS 1.5。我想要做的是从一个表插入数据到另一个(但不是严格相同的数据)。对于每一列,运行几个查询,表中总共存储了 50143 行。但是查询非常耗费资源:查询运行几分钟后,连接就会丢失。它在执行查询时发生了大约 21-22k MS,之后我必须再次手动启动 DBMS。我该如何解决这个问题?

报错信息如下:

 [Err] server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

另外,这里是 psql 错误日志:

2013-07-03 05:33:06 AZOST HINT:  In a moment you should be able to reconnect to the database and repeat your command.
2013-07-03 05:33:06 AZOST WARNING:  terminating connection because of crash of another server process
2013-07-03 05:33:06 AZOST DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.

【问题讨论】:

  • 检查 PostgreSQL 日志是否有任何相关内容。
  • 我已经更新了问题。
  • 在日志中回溯到比这更远的地方,这是真正错误的后遗症。另外,使用{}(四个空格缩进)按钮,这样日志就不会换行。
  • 另外,Linux 的内存过量使用是否被禁用? postgresql.org/docs/current/static/…
  • postgis 中是否有连接或查询超时设置?

标签: postgresql postgis


【解决方案1】:

我的猜测是,阅读您的问题,您遇到了内存不足的问题。 Craig 关于关闭过度使用的建议是一个很好的建议。如果这是一个大查询,您可能还需要减少 work_mem。这可能会减慢您的查询速度,但会释放内存。 work_mem 是每个操作,因此查询可以多次使用该设置。

另一种可能性是您在 PostgreSQL 的 C 语言模块中遇到了某种错误。如果是这种情况,请尝试更新到最新版本的 PostGIS 等。

【讨论】:

  • 我在运行 pg_restore 时反复出现此错误,并且在接收端(云机,8GB -> 52GB)碰撞内存后,错误没有返回。我注意到在 52GB 机器上成功运行 pg_restore 时内存消耗的峰值约为 22GB。
猜你喜欢
  • 2020-03-31
  • 1970-01-01
  • 2012-01-01
  • 2013-03-21
  • 1970-01-01
  • 2011-09-12
  • 1970-01-01
  • 2018-09-20
  • 1970-01-01
相关资源
最近更新 更多