【发布时间】:2012-09-01 16:32:24
【问题描述】:
您如何诊断 PostgreSQL 性能问题?
我有一个基于 Django 的 webapp,在 Ubuntu 12 上使用 PostgreSQL 作为数据库后端,在重负载下,数据库似乎刚刚消失,导致 Django 接口无法访问并导致如下错误:
django.db.utils.DatabaseError: error with no message from the libpq
django.db.utils.DatabaseError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
奇怪的是 /var/log/postgresql 中的日志没有显示任何异常。日志 /var/log/postgresql/postgresql-9.1-main.log 显示的唯一内容是很多行,例如:
2012-09-01 12:24:01 EDT LOG: unexpected EOF on client connection
运行 top 表明 PostgreSQL 似乎没有消耗任何 CPU,尽管 service postgresql status 表明它仍在运行。
执行“service postgresql restart”可以暂时解决问题,但一旦数据库负载过大,问题就会再次出现。
我检查了 dmesg 和 syslog,但我没有看到任何可以解释问题所在的内容。我应该检查哪些其他日志?如何确定我的 PostgreSQL 服务器出了什么问题?
编辑:我的 max_connections 设置为 100。虽然我正在做很多手动交易。在手动模式下使用 PostgreSQL 阅读 Django 的 ORM 行为,看起来我可能必须明确地执行 connection.close(),我没有这样做。
【问题讨论】:
-
可能是数据库的最大连接已用完,或者有太多的连接在没有关闭的情况下什么都不做(超时设置太高)。
-
您是在专用服务器上还是在 VPS 上?
-
@Catcall,基于 KVM 的 VPS。
标签: django postgresql postgresql-9.1