From 1f0f8ee4511342957dfeefb1914afa86de0ce1cb Mon Sep 17 00:00:00 2001 From: Disassembler Date: Wed, 20 Sep 2017 11:35:13 +0200 Subject: [PATCH] Add possibility to enable PostgreSQL query logging --- 01-basic.sh | 8 ++++++++ basic/etc/postgresql/9.6/main/postgresql.conf | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/01-basic.sh b/01-basic.sh index 4b4923a..d0ffeb6 100755 --- a/01-basic.sh +++ b/01-basic.sh @@ -122,5 +122,13 @@ apt-get -y --no-install-recommends -y install postgresql-9.6 postgresql-9.6-post cp ${SOURCE_DIR}/basic/etc/postgresql/9.6/main/postgresql.conf /etc/postgresql/9.6/main/postgresql.conf cp ${SOURCE_DIR}/basic/etc/postgresql/9.6/main/pg_hba.conf /etc/postgresql/9.6/main/pg_hba.conf +# Enable query logging. Only if the DEBUG environment variable exists +if [ -n "${DEBUG}" ]; then + sed -i 's/#log_destination/log_destination/' /etc/postgresql/9.6/main/postgresql.conf + sed -i 's/#logging_collector/logging_collector/' /etc/postgresql/9.6/main/postgresql.conf + sed -i 's/#log_directory/log_directory/' /etc/postgresql/9.6/main/postgresql.conf + sed -i 's/#log_statement/log_statement/' /etc/postgresql/9.6/main/postgresql.conf +fi + # Restart systemctl restart postgresql diff --git a/basic/etc/postgresql/9.6/main/postgresql.conf b/basic/etc/postgresql/9.6/main/postgresql.conf index 1425edb..23ddd77 100644 --- a/basic/etc/postgresql/9.6/main/postgresql.conf +++ b/basic/etc/postgresql/9.6/main/postgresql.conf @@ -334,13 +334,13 @@ effective_cache_size = 1GB # requires logging_collector to be on. # This is used when logging to stderr: -#logging_collector = off # Enable capturing of stderr and csvlog +#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, +#log_directory = '/var/log/postgresql' # 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 @@ -450,7 +450,7 @@ log_line_prefix = '%m [%p] %q%u@%d ' # special values: # %% = '%' # e.g. '<%u%%%d> ' #log_lock_waits = off # log lock waits >= deadlock_timeout -#log_statement = 'none' # none, ddl, mod, all +#log_statement = 'all' # none, ddl, mod, all #log_replication_commands = off #log_temp_files = -1 # log temporary files equal or larger # than the specified size in kilobytes;