【问题标题】:Why do some Django ORM queries end abruptly with the message "Killed"?为什么一些 Django ORM 查询突然以消息“Killed”结束?
【发布时间】:2010-08-19 22:19:25
【问题描述】:

有时,当通过 python shell 或 python 脚本从数据库中获取数据时,python 进程会死掉,并且会在终端上打印一个单词:Killed

这就是它所说的全部内容。它只发生在某些脚本上,但总是发生在那些脚本上。运行需要一段时间的单个查询以及向数据库逐一添加一堆行的南迁移都会发生这种情况。

我最初的预感是单个事务花费的时间太长,所以我为 Postgres 开启了自动提交功能。没有解决问题。

我检查了 Postgres 日志,这是里面唯一的东西:

2010-08-19 22:06:34 UTC LOG: could not receive data from client: Connection reset by peer

2010-08-19 22:06:34 UTC LOG: unexpected EOF on client connection

我试过用谷歌搜索,但正如你所料,一个单词的错误消息很难用谷歌搜索。

我在单个 Ubuntu 10.4 机架空间云 VPS 上使用 Django 1.2 和 Postgres 8.4,所有内容的库存配置。

【问题讨论】:

  • 我能想到的只有一件事会自动杀死 Linux 上的进程——OOM 杀手。系统日志中有什么内容?
  • Aug 19 21:38:53 db kernel: [782904.033075] python invoked oom-killer: gfp_mask=0x200da, order=0, oom_adj=0 你说得对!谢谢:)

标签: python django postgresql


【解决方案1】:

我能想到的只有一件事会自动杀死 Linux 上的进程——OOM 杀手。系统日志中有什么内容?

【讨论】:

  • 为了完整起见,在 Debian 和 Ubuntu 服务器中,/var/log/syslog 文件。
【解决方案2】:

如果正在使用 psycopg,则问题可能是数据库连接未关闭。

根据 psycopg docs 示例:

# Connect to an existing database
>>> conn = psycopg2.connect("dbname=test user=postgres")
# Open a cursor to perform database operations
>>> cur = conn.cursor()
# Close communication with the database
>>> cur.close()
>>> conn.close()

请注意,如果您确实删除了连接(使用dbcon.close() 或通过删除连接对象,您可能需要发出提交或回滚,具体取决于您的连接所使用的事务类型。

更多详情请见the close connection docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2014-11-14
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多