pgauditlogtofile

pgAudit addon to redirect audit log to an independent file

Overview

PackageVersionCategoryLicenseLanguage
pgauditlogtofile1.8.3SECPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
7120pgauditlogtofileNoYesYesYesNoYes-
Relatedpgaudit pg_auth_mon logerrors pg_permissions login_hook set_user pg_drop_events table_log

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.8.31817161514pgauditlogtofile-
RPMPGDG1.8.31817161514pgauditlogtofile_$v-
DEBPGDG1.8.31817161514postgresql-$v-pgauditlogtofile-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 1.8.4
el8.x86_64.pg14 : pgauditlogtofile_14
pgauditlogtofile_14-1.8.4-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.4 · 34.0KiB pgauditlogtofile_14-1.8.3-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.3 · 33.3KiB pgauditlogtofile_14-1.8.2-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.2 · 33.2KiB pgauditlogtofile_14-1.8.1-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.1 · 30.7KiB pgauditlogtofile_14-1.8.0-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.0 · 30.8KiB pgauditlogtofile_14-1.7.7-2PGDG.rhel8.10.x86_64.rpm PGDG · 1.7.7 · 28.1KiB pgauditlogtofile_14-1.7.6-1PGDG.rhel8.x86_64.rpm PGDG · 1.7.6 · 27.5KiB pgauditlogtofile_14-1.7.5-1PGDG.rhel8.x86_64.rpm PGDG · 1.7.5 · 27.4KiB pgauditlogtofile_14-1.7.4-1PGDG.rhel8.x86_64.rpm PGDG · 1.7.4 · 27.2KiB pgauditlogtofile_14-1.6.4-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.4 · 24.3KiB pgauditlogtofile_14-1.6.3-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.3 · 24.2KiB pgauditlogtofile_14-1.6.2-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.2 · 24.0KiB pgauditlogtofile_14-1.6.0-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.0 · 23.2KiB pgauditlogtofile_14-1.5.12-2PGDG.rhel8.x86_64.rpm PGDG · 1.5.12 · 19.7KiB pgauditlogtofile_14-1.5.12-1PGDG.rhel8.x86_64.rpm PGDG · 1.5.12 · 19.6KiB pgauditlogtofile_14-1.5.10-1.rhel8.x86_64.rpm PGDG · 1.5.10 · 19.2KiB pgauditlogtofile_14-1.5.6-1.rhel8.x86_64.rpm PGDG · 1.5.6 · 17.9KiB pgauditlogtofile_14-1.5.5-1.rhel8.x86_64.rpm PGDG · 1.5.5 · 32.9KiB pgauditlogtofile_14-1.5.1-1.rhel8.x86_64.rpm PGDG · 1.5.1 · 32.3KiB pgauditlogtofile_14-1.4-1.rhel8.x86_64.rpm PGDG · 1.4 · 31.5KiB pgauditlogtofile_14-1.3-1.rhel8.x86_64.rpm PGDG · 1.3 · 32.8KiB
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

Install

You can install pgauditlogtofile directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pgauditlogtofile;          # Install for current active PG version
pig ext install -y pgauditlogtofile -v 18  # PG 18
pig ext install -y pgauditlogtofile -v 17  # PG 17
pig ext install -y pgauditlogtofile -v 16  # PG 16
pig ext install -y pgauditlogtofile -v 15  # PG 15
pig ext install -y pgauditlogtofile -v 14  # PG 14
dnf install -y pgauditlogtofile_18       # PG 18
dnf install -y pgauditlogtofile_17       # PG 17
dnf install -y pgauditlogtofile_16       # PG 16
dnf install -y pgauditlogtofile_15       # PG 15
dnf install -y pgauditlogtofile_14       # PG 14
apt install -y postgresql-18-pgauditlogtofile   # PG 18
apt install -y postgresql-17-pgauditlogtofile   # PG 17
apt install -y postgresql-16-pgauditlogtofile   # PG 16
apt install -y postgresql-15-pgauditlogtofile   # PG 15
apt install -y postgresql-14-pgauditlogtofile   # PG 14

Preload:

shared_preload_libraries = 'pgauditlogtofile';

Create Extension:

CREATE EXTENSION pgauditlogtofile;

Usage

pgauditlogtofile: Redirect pgAudit logs to an independent file

pgauditlogtofile is an addon to pgAudit that redirects audit log lines to a separate file instead of the PostgreSQL server log, with automatic rotation support.

CREATE EXTENSION pgauditlogtofile;

Configuration Parameters

ParameterDefaultDescription
pgaudit.log_formatcsvOutput format: csv or json
pgaudit.log_directorylogDirectory for audit files (empty disables)
pgaudit.log_filenameaudit-%Y%m%d_%H%M.logFilename pattern (supports time patterns)
pgaudit.log_file_mode0600File permissions for audit logs
pgaudit.log_rotation_age1440Rotation interval in minutes (1 day)
pgaudit.log_connectionsoffLog connection events (requires log_connections = on)
pgaudit.log_disconnectionsoffLog disconnection events (requires log_disconnections = on)
pgaudit.log_autoclose_minutes0Auto-close file handler after N minutes of inactivity
pgaudit.log_execution_timeoffMeasure statement execution time
pgaudit.log_execution_memoryoffMeasure memory footprint of statements

Setup

Add to postgresql.conf:

shared_preload_libraries = 'pgaudit, pgauditlogtofile'
pgaudit.log_directory = 'log'
pgaudit.log_filename = 'audit-%Y%m%d_%H%M.log'
pgaudit.log_rotation_age = 1440

Audit entries are written to the separate file while server logs remain clean.


Last Modified 2026-04-14: update extension catalog (29617e5)