简体   繁体   English

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

[英]Suppress “current transaction is aborted…” messages in PostgreSQL

I have a very big SQL dump I'm working on. 我正在处理一个很大的SQL转储。 The overall structure looks like this: 整体结构如下所示:

BEGIN;
SET CONSTRAINTS ALL DEFERRED;
INSERT …;
-- … ~300K insert operations
INSERT …;
COMMIT;

The problem is if there is an error in any single statement, then error is shown and the message current transaction is aborted, commands ignored until end of transaction block is generated for EACH statement that follows it. 问题是,如果任何一条语句中都有错误,则显示错误,并且消息current transaction is aborted, commands ignored until end of transaction block为其后的EACH语句生成current transaction is aborted, commands ignored until end of transaction block

Why does it behave so weirdly? 为什么它的表现如此怪异? Is there a way to suppress the following messages? 有没有办法抑制以下消息? It's enough to just show the real error message and to skip transaction execution. 仅显示真实的错误消息并跳过事务执行就足够了。 I don't want to see ~300K meaningful error messages. 我不想看到〜300K有意义的错误消息。

Do I need to structure my dump differently? 我是否需要以不同的方式构造转储? Or is there a flag/option I can use? 还是有我可以使用的标志/选项?

Presumably you're using psql to send the queries to the server. 大概您正在使用psql将查询发送到服务器。
You may set the ON_ERROR_STOP built-in variable to on . 您可以将内置变量ON_ERROR_STOP设置为on

From https://www.postgresql.org/docs/current/static/app-psql.html : 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.

It may be set from outside psql with psql -v ON_ERROR_STOP=on -f script.sql , or from inside the script or interactively with the meta-command \\set ON_ERROR_STOP on . 可以在psql外部使用psql -v ON_ERROR_STOP=on -f script.sql进行设置,也可以在脚本内部进行设置,或者使用meta命令\\set ON_ERROR_STOP on交互\\set ON_ERROR_STOP on

pg_dump does not have an option to add this automatically to a dump (as far as I know, it doesn't emit any psql meta-command anyway, only pure SQL commands). pg_dump没有选择将其自动添加到转储中(据我所知,它不会发出任何psql元命令,而只会发出纯SQL命令)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django / postgresql当前事务中止,命令被忽略,直到事务块结束 - django/postgresql current transaction is aborted, commands ignored until end of transaction block PGError:错误:当前事务中止 - PGError: ERROR: current transaction is aborted Django TemplateSyntaxError:当前事务被中止,这个异常是什么意思? postgresql 8.4与django一起工作正常吗? - Django TemplateSyntaxError: current transaction is aborted, what does this exception mean? Does postgresql 8.4 work fine with django? Databene Benerator:org.postgresql.util.PSQLException:错误:当前事务中止,命令被忽略,直到事务块结束 - Databene Benerator: org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block 删除更新表的约束 - 当前事务被中止 - Dropping constraints to update tables - Current transaction is aborted PSQL:当前事务中止,命令被忽略,直到事务块结束 - PSQL: current transaction is aborted, commands ignored until end of transaction block InternalError:当前事务中止,命令被忽略,直到事务块结束 - InternalError: current transaction is aborted, commands ignored until end of transaction block DatabaseError:当前事务被中止,在事务块结束之前忽略命令? - DatabaseError: current transaction is aborted, commands ignored until end of transaction block? PSQLException:当前事务被中止,命令被忽略直到事务块结束 - PSQLException: current transaction is aborted, commands ignored until end of transaction block 当前事务被中止,命令被忽略直到事务结束 - Current transaction is aborted, commands ignored until end of transaction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM