![](/img/trans.png)
[英]django/postgresql current transaction is aborted, commands ignored until end of transaction block
[英]Suppress “current transaction is aborted…” messages in PostgreSQL
我正在处理一个很大的SQL转储。 整体结构如下所示:
BEGIN;
SET CONSTRAINTS ALL DEFERRED;
INSERT …;
-- … ~300K insert operations
INSERT …;
COMMIT;
问题是,如果任何一条语句中都有错误,则显示错误,并且消息current transaction is aborted, commands ignored until end of transaction block
为其后的EACH语句生成current transaction is aborted, commands ignored until end of transaction block
。
为什么它的表现如此怪异? 有没有办法抑制以下消息? 仅显示真实的错误消息并跳过事务执行就足够了。 我不想看到〜300K有意义的错误消息。
我是否需要以不同的方式构造转储? 还是有我可以使用的标志/选项?
大概您正在使用psql
将查询发送到服务器。
您可以将内置变量ON_ERROR_STOP
设置为on
。
从https://www.postgresql.org/docs/current/static/app-psql.html :
ON_ERROR_STOP
By default, command processing continues after an error. When this
variable is set to on, processing will instead stop
immediately. In interactive mode, psql will return to the command
prompt; otherwise, psql will exit, returning error code 3 to
distinguish this case from fatal error conditions, which are
reported using error code 1.
可以在psql外部使用psql -v ON_ERROR_STOP=on -f script.sql
进行设置,也可以在脚本内部进行设置,或者使用meta命令\\set ON_ERROR_STOP on
交互\\set ON_ERROR_STOP on
。
pg_dump
没有选择将其自动添加到转储中(据我所知,它不会发出任何psql
元命令,而只会发出纯SQL命令)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.