3

My postgresql 9.3 logs are sprinkled with entries like these (redacted to protect the guilty):

STATEMENT: INSERT INTO table (key, value) VALUES (1,ドル 2ドル)
ERROR: duplicate key value violates unique constraint "table_pkey"
DETAIL: Key (key)=(xyz) already exists.
STATEMENT: INSERT INTO table (key, value) VALUES ('xyz', '{...json...}')

I know the source of the problem (a race condition where two app servers do the same work) and that code gracefully handles the insertion failure, but for the life of me I can't seem to get PostgreSQL to stop logging the statement which generated the error to begin with.

I've set log_statements for this db to 'none' (which persists across connections):

show log_statement;
 log_statement 
---------------
none
(1 row)

But to no avail. These entries still keep hitting the logs. I wouldn't mind except the "values" from the logged statement are JSON blobs which aren't tiny. How can I keep PostgreSQL from logging whenever an insert violates the unique constraint?

asked Mar 20, 2015 at 18:00
4
  • 1
    log_error_verbosity ? Commented Mar 20, 2015 at 19:41
  • @MilenA.Radev correct. "alter database db_name set log_error_verbosity to 'terse';" as an answer and I'll accept it. Commented Mar 20, 2015 at 19:56
  • log_min_messages and log_min_error_statement: postgresql.org/docs/current/static/… Commented Mar 21, 2015 at 11:36
  • log_statement does not do the trick because it logs statements irregardless of errors. You want to modify what's logged in case of an error. Milen and a_horse provided the relevant settings for this. Commented Mar 21, 2015 at 18:04

2 Answers 2

3

The amount of details logged is controlled by log_error_verbosity. Setting it to TERSE will exclude DETAIL, HINT, QUERY, and CONTEXT error information:

ALTER DATABASE db_name SET log_error_verbosity to 'TERSE';
answered Mar 21, 2015 at 6:46
0

Set log_error_verbosity to TERSE and log_min_error_statement to LOG in postgresql.conf and reload with

pc_ctl -D <data_dir> reload
Laurenz Albe
62k4 gold badges57 silver badges93 bronze badges
answered Apr 14, 2020 at 18:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.