Pages

Sunday, December 22, 2019

How you enable basic audits in postgres? What parameters you will use in postgres.conf file

To track each everything happening database level, we need to enable audit log.
To enable this we need to configure below parameter in postgresql.conf file.


log_destination = 'stderr' # audit captured in .txt file. we can write .csv also using 'stderr,crsvlog'
logging_collector = on # entries will be made, who connected and what actions performed. 
log_directory = 'pg_log'    # Log file will be created in pg_log directory inside the data directory
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # format of log files
log_rotation_age = 1d # log file will be rotated every day
log_rotation_size = 10MB  # every log file will be 10MB max
log_min_duration_statement = 0    # this value in milli seconds, 60000 ms for one miniute--for tracking query execution more than mentioned time. -1, disable, 0 - capture all the queries
log_connections = on # What time connected
log_disconnections = on # what time dissconncted
log_line_prefix = '%a %u  %d %h %p %t %i %e' # %a -application, %u -user, %d -database, %h -remote host, %p -process id ,%t -time ,%i %e - sql statement
log_statement = 'all'    # it will capture all sql statements

restrat the postgres services to refrect the changes.

e.g.,

$ /usr/local/pgctl/bin/pg_ctl -D /usr/pgsql restart

No comments:

Post a Comment