skip to Main Content

Is there a way to now show DETAIL message of a logged statement in logs? The reason for that is that we would not like to expose bind parameters in logs.

2

Answers


  1. You cannot suppress detail messages in the log, but you can suppress logging the bind parameters by setting log_parameter_max_length to 0.

    Login or Signup to reply.
  2. From:

    https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT

    log_error_verbosity (enum)

    Controls the amount of detail written in the server log for each message that is logged. Valid values are TERSE, DEFAULT, and VERBOSE, each adding more fields to displayed messages. TERSE excludes the logging of DETAIL, HINT, QUERY, and CONTEXT error information. VERBOSE output includes the SQLSTATE error code (see also Appendix A) and the source code file name, function name, and line number that generated the error. Only superusers and users with the appropriate SET privilege can change this setting.

    So:

    test=# d null_test
    
                                 Table "public.null_test"
     Column |       Type        | Collation | Nullable |           Default            
    --------+-------------------+-----------+----------+------------------------------
     id     | integer           |           |          | 
     foo    | character varying |           |          | 
     bar    | character varying |           | not null | 'default'::character varying
    
    test=# show log_error_verbosity ;
     log_error_verbosity 
    ---------------------
     default
    
    --Client side
    test=# insert into null_test values (67, 'test', null);
    ERROR:  null value in column "bar" of relation "null_test" violates not-null constraint
    DETAIL:  Failing row contains (67, test, null).
    
    --In log
    2024-02-16 08:19:53.835 PST [7505] postgres@test ERROR:  null value in column "bar" of relation "null_test" violates not-null constraint
    2024-02-16 08:19:53.835 PST [7505] postgres@test DETAIL:  Failing row contains (67, test, null).
    2024-02-16 08:19:53.835 PST [7505] postgres@test STATEMENT:  insert into null_test values (67, 'test', null);
    
    test=# set log_error_verbosity = TERSE;
    
    --Client side
    test=# insert into null_test values (67, 'test', null);
    ERROR:  null value in column "bar" of relation "null_test" violates not-null constraint
    DETAIL:  Failing row contains (67, test, null).
    
    --Log side
    2024-02-16 08:22:34.523 PST [7505] postgres@test LOG:  statement: insert into null_test values (67, 'test', null);
    2024-02-16 08:22:34.523 PST [7505] postgres@test ERROR:  null value in column "bar" of relation "null_test" violates not-null constraint
    2024-02-16 08:22:34.523 PST [7505] postgres@test STATEMENT:  insert into null_test values (67, 'test', null);
    
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search