pgaudit

provides auditing functionality

Overview

PackageVersionCategoryLicenseLanguage
pgaudit18.0SECPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
7100pgauditNoYesYesYesNoYes-
Relatedpgauditlogtofile set_user pg_permissions pg_auth_mon pg_auditor safeupdate pg_drop_events table_log

pg15=pgaudit17, pg14=pgaudit16

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG18.01817161514pgaudit-
RPMPGDG18.01817161514pgaudit_$v-
DEBPGDG18.01817161514postgresql-$v-pgaudit-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
d12.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
d13.x86_64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
d13.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
u22.x86_64
u22.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
u24.x86_64
u24.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3

Install

You can install pgaudit 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 pgaudit;          # Install for current active PG version
pig ext install -y pgaudit -v 18  # PG 18
pig ext install -y pgaudit -v 17  # PG 17
pig ext install -y pgaudit -v 16  # PG 16
pig ext install -y pgaudit -v 15  # PG 15
pig ext install -y pgaudit -v 14  # PG 14
dnf install -y pgaudit_18       # PG 18
dnf install -y pgaudit_17       # PG 17
dnf install -y pgaudit_16       # PG 16
dnf install -y pgaudit_15       # PG 15
dnf install -y pgaudit_14       # PG 14
apt install -y postgresql-18-pgaudit   # PG 18
apt install -y postgresql-17-pgaudit   # PG 17
apt install -y postgresql-16-pgaudit   # PG 16
apt install -y postgresql-15-pgaudit   # PG 15
apt install -y postgresql-14-pgaudit   # PG 14

Preload:

shared_preload_libraries = 'pgaudit';

Create Extension:

CREATE EXTENSION pgaudit;

Usage

pgaudit: Open Source PostgreSQL Audit Logging

pgAudit provides detailed session and/or object audit logging via the standard PostgreSQL logging facility, producing audit trails required for government, financial, or ISO certifications.

CREATE EXTENSION pgaudit;

Configuration Parameters

ParameterDefaultDescription
pgaudit.lognoneStatement classes to log: READ, WRITE, FUNCTION, ROLE, DDL, MISC, MISC_SET, ALL
pgaudit.log_catalogonLog statements when all relations are in pg_catalog
pgaudit.log_clientoffShow audit log messages to client
pgaudit.log_levellogLog level for audit entries
pgaudit.log_parameteroffInclude statement parameters in log
pgaudit.log_parameter_max_size0Max parameter size in bytes (0=unlimited)
pgaudit.log_relationoffSeparate log entry per relation in SELECT/DML
pgaudit.log_rowsoffInclude row count in log
pgaudit.log_statementonInclude statement text in log
pgaudit.log_statement_onceoffLog statement text only with first entry
pgaudit.role(none)Master role for object audit logging

Session Audit Logging

Log all DML and DDL with per-relation detail:

SET pgaudit.log = 'write, ddl';
SET pgaudit.log_relation = on;

Log everything except miscellaneous commands:

SET pgaudit.log = 'all, -misc';

Example output:

AUDIT: SESSION,1,1,DDL,CREATE TABLE,TABLE,public.account,create table account(...)
AUDIT: SESSION,2,1,READ,SELECT,,,select * from account

Object Audit Logging

Grant permissions to an audit role to control which relations are logged:

SET pgaudit.role = 'auditor';

GRANT SELECT, DELETE
   ON public.account
   TO auditor;

Now any SELECT or DELETE on the account table will be audit logged.

Log Format

Entries are CSV with fields: AUDIT_TYPE, STATEMENT_ID, SUBSTATEMENT_ID, CLASS, COMMAND, OBJECT_TYPE, OBJECT_NAME, STATEMENT, PARAMETER.


Last Modified 2026-03-12: add pg extension catalog (95749bf)