Example of Logging Setup

qhb.conf settings:

  1. Enable logging: logging_collector = on;
  2. Enable logging to log files: log_directory = '/u01/db/log` the log directory must be defined locally. It can be an absolute path, but you can also specify a relative path ./log/;
  3. Set the logging level: log_min_messages = info or another suitable one;
  4. Parameter for the fact of logging into the system: log_connections = true;
  5. Enable logging of failed queries: log_min_error_statement=info;
  6. Enable connection hostname logging: log_hostname = true — it is advisable to log it in addition to the IP address for security or further debugging reasons;
  7. Enable logging of replication actions: log_replication_commands = true. Required for setting up high availability clusters;
  8. Enable logging of operations on the DBMS (for security reasons): log_statement = 'none' # none, ddl, mod, all;
  9. Generate a log line template to record the above parameters:
log_line_prefix = '%m [%p] '            # special values:
                                        #   %a = application name
                                        #   %u = user name
                                        #   %d = database name
                                        #   %r = remote host and port
                                        #   %h = remote host
                                        #   %p = process ID
                                        #   %t = timestamp without milliseconds
                                        #   %m = timestamp with milliseconds
                                        #   %n = timestamp with milliseconds (as a Unix epoch)
                                        #   %i = command tag
                                        #   %e = SQL state
                                        #   %c = session ID
                                        #   %l = session line number
                                        #   %s = session start timestamp
                                        #   %v = virtual transaction ID
                                        #   %x = transaction ID (0 if none)
                                        #   %q = stop here in non-session
                                        #        processes
                                        #   %% = '%'
                                        # e.g. '<%u%%%d> '

Assembled example of a line with logging format:

%m [%p]: [%l] [txid=%x] user=%u, db=%d, app%a, client=%r

Links to Additional Resources