Postgres sql文件插入挂起

时间:2016-07-29 10:40:53

标签: postgresql

我正在尝试从大小约为1.6GB的sql文件中插入数据。我用了命令:

\i filename.sql
然而,它已经运行了十多分钟。最初,当我运行它时,我得到如下输出:

psql:xxx.sql:1102: ERROR:  role "xxx" does not exist
psql:xxx.sql:1124: ERROR:  relation "xxx" already exists
psql:xxx.sql:1127: ERROR:  role "xxx" does not exist
psql:xxx.sql:1138: ERROR:  relation "xxx" already exists
psql:xxx.sql:1141: ERROR:  role "xxx" does not exist
psql:xxx.sql:1177: ERROR:  relation "xxx" already exists
psql:xxx.sql:1180: ERROR:  role "xxx" does not exist
psql:xxx.sql:1191: ERROR:  relation "xxx" already exists
psql:xxx.sql:1194: ERROR:  role "xxx" does not exist
psql:xxx.sql:1223: ERROR:  relation "xxx" already exists
psql:xxx.sql:1226: ERROR:  role "xxx" does not exist
psql:xxx.sql:1237: ERROR:  relation "xxx" already exists
psql:xxx.sql:1240: ERROR:  role "xxx" does not exist

这一直持续到最终输出为:

psql:xxx.sql:1183266: ERROR:  duplicate key value violates unique constraint "xxx"
DETAIL:  Key (id)=(2) already exists.
CONTEXT:  COPY mo_logs, line 1: "2  +6421558671     +15759151518    LolWithPlus     unable to deliver, dropping : undefined method `bytesize' for..."

然后控制台显示此后没有任何新内容。在我的第一次尝试时,我认为它已经悬挂,但得到了以下输出:

Cancel request sent

这让我相信剧本仍然在运行,但我无从谈论。任何人都可以建议我如何诊断正在发生的事情,或者告诉我插件是否失效,如挂起所示。

1 个答案:

答案 0 :(得分:1)

似乎SQL脚本包含多个COPY语句 当您中断处理时,其中一个(COPY TO mo_logs)失败,另一个(COPY TO midn_protections)正在运行。

通常psql在发生错误后继续工作,并且只执行下一个语句。为避免这种情况,请使用选项--set ON_ERROR_STOP=on启动它。