pgauditlogtofile

pgAudit addon to redirect audit log to an independent file

Overview

PackageVersionCategoryLicenseLanguage
pgauditlogtofile1.8.0SECPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
7120pgauditlogtofileNoYesNoYesNoYes-
Relatedpgaudit pg_auth_mon logerrors pg_permissions login_hook set_user pg_drop_events table_log

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.8.01817161514pgauditlogtofile-
RPMPGDG1.8.01817161514pgauditlogtofile_$v-
DEBPGDG1.8.01817161514postgresql-$v-pgauditlogtofile-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
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

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-03-12: add pg extension catalog (95749bf)