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