psql似乎因长查询而超时

时间:2013-05-07 11:44:37

标签: postgresql postgresql-9.2 psql

我正在使用大约80GB的数据对postgres进行批量复制。

\copy my_table FROM '/path/csv_file.csv' csv DELIMITER ','

在提交事务之前,我收到以下错误。

  

服务器意外关闭了连接       这可能意味着服务器异常终止       处理请求之前或处理时。

在PostgreSQL日志中:

LOG:server process (PID 21122) was terminated by signal 9: Killed
LOG:terminating any other active server processes
WARNING:terminating connection because of crash of another server process
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.
HINT: In a moment you should be able to reconnect to the database and repeat your command. 

1 个答案:

答案 0 :(得分:12)

您的后端进程收到信号9(SIGKILL)。如果出现这种情况:

  • 有人手动发送kill -9;
  • cron作业设置为在某些情况下发送kill -9(非常不安全,不要这样做);或
  • Linux内存不足(OOM)杀手触发并终止该过程。

在后一种情况下,您将在内核的dmesg输出中看到OOM杀手活动的报告。我希望你能在这种情况下看到这一点。

应该配置PostgreSQL服务器而不会过度使用虚拟内存,这样OOM杀手就不会运行,而PostgreSQL可以自行处理内存不足的情况。请参阅the PostgreSQL documentation on Linux memory overcommit

单独的问题“为什么这么多使用这么多的记忆”仍然存在。回答这个问题需要更多的设置知识:服务器有多少RAM,有多少是空闲的,work_memmaintenance_work_mem设置是什么等等。这不是一个非常有趣的问题。直到您升级到当前的PostgreSQL 8.4补丁版本,以确保问题不是已修复的问题。

相关问题