Skip to content

Instantly share code, notes, and snippets.

@meglio
Created April 8, 2021 15:32
Show Gist options
  • Save meglio/44fbb60f6f69c0367da2e4f04811146a to your computer and use it in GitHub Desktop.
Save meglio/44fbb60f6f69c0367da2e4f04811146a to your computer and use it in GitHub Desktop.
pgbadger in Docker controlled by Makefile
# - docker/pgbadger/Dockerfile
# - Makefile
FROM perl:5.32.1
LABEL "com.mycompany.container"="pgbadger"
ARG PGBADGER_VERSION=11.5
WORKDIR /pgbadger
COPY pgbadger-${PGBADGER_VERSION}.tar.gz /pgbadger/
# Below is the installation of bgbadger as documented here:
# https://pgbadger.darold.net/documentation.html
# For the CSV input and JSON output formats to work
RUN apt-get update && apt-get install -y \
libtext-csv-perl \
libjson-xs-perl \
&& rm -rf /var/lib/apt/lists/*
# pgbadger installation
RUN cd /pgbadger \
&& tar xzf pgbadger-${PGBADGER_VERSION}.tar.gz \
&& cd ./pgbadger-${PGBADGER_VERSION}/ \
&& perl Makefile.PL \
&& make && make install \
&& cd ~ && rm -rf /pgbadger
WORKDIR /pgbadger_reports
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(patsubst %/,%,$(dir $(mkfile_path)))
pgbadger-build:
docker build --label com.YOURCOMPANY.container=pgbadger --tag="yourcompany/pgbadger:v0.1" ./docker/pgbadger
pgbadger-remove:
docker images --filter "label=com.yourcompany.container=pgbadger" -q | awk '{print $3}' | xargs docker rmi
pgbadger-run:
docker run --rm -a stderr -a stdout --name yourcompany_pgbadger --label com.yourcompany.container=pgbadger -v ${mkfile_dir}/docker/log/pgbadger:/pgbadger_reports -v ${mkfile_dir}/docker/log/db:/pglogs yourcompany/pgbadger:v0.1 pgbadger --format csv --outdir /pgbadger_reports --extension html /pglogs/postgresql.csv
# Valid values are combinations of stderr, csvlog, syslog, and eventlog, depending on platform.
# csvlog requires logging_collector to be on.
log_destination = csvlog
# Enable capturing of stderr and csvlog into log files. Required to be on for csvlogs.
logging_collector = on
log_directory = '/var/dblog'
# Automatic rotation of logfiles will happen after that time.
# Set to zero to disable time-based creation of new log files
log_rotation_age = 0
# Automatic rotation of logfiles will happen after that much log output.
log_rotation_size = 100MB
log_truncate_on_rotation = on
log_filename = 'postgresql.log'
application_name = 'yourcompany'
#log_min_error_statement = 'WARNING'
# Both sbhould be disabled. Read here: https://pgbadger.darold.net/documentation.html#LOG-STATEMENTS
# log_duration = on
# log_statement = 'all'
log_min_duration_statement=0
# time [session id]
log_line_prefix = '%m [%c] '
# Read more: https://pgbadger.darold.net/documentation.html#POSTGRESQL-CONFIGURATION
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0
log_autovacuum_min_duration = 0
log_error_verbosity = default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment