簡體   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