Saturday, 23 October 2021

Log Management - PostgreSQL

 standard error --> stderr

log_destination='stderr'


This can be on or off, and when on, collects stderr output into a configured log directory.

logging_collector=on


log_directory='capegemini_log'


log_filename='capegemini-%Y-%m-%d_%H%M%S.log'


log_rotation_age='1d'


log_rotation_size='10MB'



log_destination = 'stderr'   # Valid values are combinations of
                             # stderr, csvlog, syslog, and eventlog,
                             # depending on platform.  csvlog
                             # requires logging_collector to be on.


# This is used when logging to stderr:
logging_collector = on       # Enable capturing of stderr and csvlog
                             # into log files. Required to be on for
                             # csvlogs.
                             # (change requires restart)


# These are only used if logging_collector is on:
log_directory = 'pg_log'     # directory where log files are written,
                             # can be absolute or relative to PGDATA


log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
                                        # can include strftime() escapes

log_file_mode = 0600            # creation mode for log files,
                                # begin with 0 to use octal notation

log_truncate_on_rotation = off  # If on, an existing log file with the
                    # same name as the new log file will be
                    # truncated rather than appended to.
                    # But such truncation only occurs on
                    # time-driven rotation, not on restarts
                    # or size-driven rotation.  Default is
                    # off, meaning append to existing files
                    # in all cases.

log_rotation_age = 1d  # Automatic rotation of logfiles will
                    # happen after that time.  0 disables.

log_rotation_size = 10MB  # Automatic rotation of logfiles will
                    # happen after that much log output.
                    # 0 disables.


Notes: 

Will there be a performance impact by enabling PostgreSQL logging?

R&D did some testing with the following settings:

in the postgresql.conf file:
log_destination = 'csvlog'
logging_collector = on
log_connections = on
log_disconnections = on
log_hostname = on
log_statement = 'all'
log_line_prefix = '%a%%%u%%%s'

 
R&D's statement from their testing:

Average response time:
Slightly higher with logging enabled but the biggest difference was only 4ms. Average time without logging 163ms, with logging 166ms.

Processor time:
PostgreSQL used very little CPU time. Average time without logging was 0.29%, with logging 0.33%.

Memory usage:
Here, slightly less memory was used with logging enabled. Average without logging 1.16GB, with logging 1.13GB.

Log files on disk:
With logging enabled, a number of files were created on the local disk. About 10MB of data were created every minute.

The conclusion from the tests: that it is safe to enable the logs in PostgreSQL. The only thing that needs attention is to make sure the log files do not fill up the storage.



No comments:

Post a Comment

Master and Slave - Sync check - PostgreSQL

  1) Run the below Query on Primary:- SELECT     pid,     usename,     application_name,     client_addr,     state,     sync_state,     sen...