pgauditlogtofile
pgAudit addon to redirect audit log to an independent file
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pgauditlogtofile | 1.8.0 | SEC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7120 | pgauditlogtofile | No | Yes | No | Yes | No | Yes | - |
| Related | pgaudit pg_auth_mon logerrors pg_permissions login_hook set_user pg_drop_events table_log |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.8.0 | 1817161514 | pgauditlogtofile | - |
| RPM | PGDG | 1.8.0 | 1817161514 | pgauditlogtofile_$v | - |
| DEB | PGDG | 1.8.0 | 1817161514 | postgresql-$v-pgauditlogtofile | - |
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
| Parameter | Default | Description |
|---|---|---|
pgaudit.log_format | csv | Output format: csv or json |
pgaudit.log_directory | log | Directory for audit files (empty disables) |
pgaudit.log_filename | audit-%Y%m%d_%H%M.log | Filename pattern (supports time patterns) |
pgaudit.log_file_mode | 0600 | File permissions for audit logs |
pgaudit.log_rotation_age | 1440 | Rotation interval in minutes (1 day) |
pgaudit.log_connections | off | Log connection events (requires log_connections = on) |
pgaudit.log_disconnections | off | Log disconnection events (requires log_disconnections = on) |
pgaudit.log_autoclose_minutes | 0 | Auto-close file handler after N minutes of inactivity |
pgaudit.log_execution_time | off | Measure statement execution time |
pgaudit.log_execution_memory | off | Measure 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.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.