繁体   English   中英

禁止在PostgreSQL中显示“当前事务中止…”消息

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM