Is there a way to prevent Postgresql from logging ERRORs caused by attempted insertions where a UNIQUE KEY constraint is violated?

I could change the server_log_min directive, but this would disable all ERROR messages and not just those for UNIQUE KEY constraint.


No. No such way exists. Short of piping logs via | grep -v ... | filter.

  • i guess i'll have to do some sort of log file post-processing...
    – bugmenot77
    Oct 1 '09 at 20:39
  • Actually. Anyone know if there's a way to specify piping via sed script through the conf file?
    – bugmenot77
    Jan 13 '10 at 23:50

There's no way to do this just by adjusting the logging mechanism on the server. You could do it by hacking the source code if you absolutely had to; the relevant code is in src/backend/access/nbtree/nbtinsert.c and looks like this, around line 300:

        errmsg("duplicate key value violates unique constraint \"%s\"",

You could change the log level there from ERROR to LOG or NOTICE.

  • thanks. i thought of hacking source code but it would end up being another maintenance nightmare! :)
    – bugmenot77
    Oct 1 '09 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy