Skip to content

Instantly share code, notes, and snippets.

@cristopher-rodrigues
Last active December 28, 2020 15:06
Show Gist options
  • Save cristopher-rodrigues/e9a8c314602bbadda4f1b792cf8e393b to your computer and use it in GitHub Desktop.
Save cristopher-rodrigues/e9a8c314602bbadda4f1b792cf8e393b to your computer and use it in GitHub Desktop.

Install PgAudit

docker exec -it postgres sh -c 'apt-get update && apt-get install -y --no-install-recommends \
  postgresql-$PG_MAJOR-pgaudit'

Add required changes

$PGDATA/postgresql.conf

shared_preload_libraries = 'pgaudit'
pgaudit.log = 'all, -misc' # ddl...
pgaudit.log_catalog = off
pgaudit.log_level = off
pgaudit.log_parameter = on
pgaudit.log_relation = on
logging_collector = on
log_directory = 'log'
# log_line_prefix = '?'
docker-compose restart postgres && docker exec -it postgres psql -U postgres
CREATE EXTENSION pgaudit;

check config

SELECT EXISTS(SELECT 1 FROM pg_extension where extname = 'pgaudit'); -- t
SHOW logging_collector; -- on

Testing

create table test
(
    test text
);

insert into test (test)
             values ('test');
tail -f $PGDATA/log/postgresql-*.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment