Skip to content
pgaudit

pgaudit

pgaudit : provides auditing functionality

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7100
pgaudit
pgaudit
18.0
SEC
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd-r
No
Yes
Yes
Yes
yes
no
Relationships
See Also
pgauditlogtofile
set_user
pg_permissions
pg_auth_mon
pg_auditor
safeupdate
pg_drop_events
table_log

pg15=pgaudit17, pg14=pgaudit16

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
18.0
18
17
16
15
14
pgaudit-
RPM
PGDG
18.0
18
17
16
15
14
pgaudit_$v-
DEB
PGDG
18.0
18
17
16
15
14
postgresql-$v-pgaudit-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
el8.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
el9.x86_64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
el9.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
el10.x86_64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
el10.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
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
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
u22.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
u24.x86_64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
u24.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
u26.x86_64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3
u26.aarch64
PGDG 18.0
PGDG 17.1
PGDG 16.1
PGDG 1.7.1
PGDG 1.6.3

Source

Install

Make sure PGDG repo available:

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

Install this extension with pig:

pig install pgaudit;		# install via package name, for the active PG version

pig install pgaudit -v 18;   # install for PG 18
pig install pgaudit -v 17;   # install for PG 17
pig install pgaudit -v 16;   # install for PG 16
pig install pgaudit -v 15;   # install for PG 15
pig install pgaudit -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pgaudit';

Create this extension with:

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 updated on