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
PackageVersionOSORGSIZEFile URL
pgaudit_1717.1el8.x86_64pgdg28.0 KiBpgaudit_17-17.1-1PGDG.rhel8.x86_64.rpm
pgaudit_1717.0el8.x86_64pgdg27.5 KiBpgaudit_17-17.0-1PGDG.rhel8.x86_64.rpm
pgaudit_1717.1el8.aarch64pgdg27.6 KiBpgaudit_17-17.1-1PGDG.rhel8.aarch64.rpm
pgaudit_1717.0el8.aarch64pgdg27.2 KiBpgaudit_17-17.0-1PGDG.rhel8.aarch64.rpm
pgaudit_1717.1el9.x86_64pgdg28.2 KiBpgaudit_17-17.1-1PGDG.rhel9.x86_64.rpm
pgaudit_1717.0el9.x86_64pgdg27.8 KiBpgaudit_17-17.0-1PGDG.rhel9.x86_64.rpm
pgaudit_1717.1el9.aarch64pgdg28.0 KiBpgaudit_17-17.1-1PGDG.rhel9.aarch64.rpm
pgaudit_1717.0el9.aarch64pgdg27.6 KiBpgaudit_17-17.0-1PGDG.rhel9.aarch64.rpm
pgaudit_1717.1el10.x86_64pgdg28.6 KiBpgaudit_17-17.1-1PGDG.rhel10.x86_64.rpm
pgaudit_1717.1el10.aarch64pgdg28.7 KiBpgaudit_17-17.1-1PGDG.rhel10.aarch64.rpm
postgresql-17-pgaudit17.1d12.x86_64pgdg46.1 KiBpostgresql-17-pgaudit_17.1-2.pgdg12+1_amd64.deb
postgresql-17-pgaudit17.1d12.aarch64pgdg45.7 KiBpostgresql-17-pgaudit_17.1-2.pgdg12+1_arm64.deb
postgresql-17-pgaudit17.1d13.x86_64pgdg46.0 KiBpostgresql-17-pgaudit_17.1-2.pgdg13+1_amd64.deb
postgresql-17-pgaudit17.1d13.aarch64pgdg45.9 KiBpostgresql-17-pgaudit_17.1-2.pgdg13+1_arm64.deb
postgresql-17-pgaudit17.1u22.x86_64pgdg52.6 KiBpostgresql-17-pgaudit_17.1-2.pgdg22.04+1_amd64.deb
postgresql-17-pgaudit17.1u22.aarch64pgdg52.0 KiBpostgresql-17-pgaudit_17.1-2.pgdg22.04+1_arm64.deb
postgresql-17-pgaudit17.1u24.x86_64pgdg46.2 KiBpostgresql-17-pgaudit_17.1-2.pgdg24.04+1_amd64.deb
postgresql-17-pgaudit17.1u24.aarch64pgdg45.9 KiBpostgresql-17-pgaudit_17.1-2.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
pgaudit_1616.1el8.x86_64pgdg27.4 KiBpgaudit_16-16.1-1PGDG.rhel8.x86_64.rpm
pgaudit_1616.0el8.x86_64pgdg26.9 KiBpgaudit_16-16.0-1PGDG.rhel8.x86_64.rpm
pgaudit_1616.1el8.aarch64pgdg27.1 KiBpgaudit_16-16.1-1PGDG.rhel8.aarch64.rpm
pgaudit_1616.0el8.aarch64pgdg26.6 KiBpgaudit_16-16.0-1PGDG.rhel8.aarch64.rpm
pgaudit_1616.1el9.x86_64pgdg27.8 KiBpgaudit_16-16.1-1PGDG.rhel9.x86_64.rpm
pgaudit_1616.0el9.x86_64pgdg27.1 KiBpgaudit_16-16.0-1PGDG.rhel9.x86_64.rpm
pgaudit_1616.1el9.aarch64pgdg27.6 KiBpgaudit_16-16.1-1PGDG.rhel9.aarch64.rpm
pgaudit_1616.0el9.aarch64pgdg26.7 KiBpgaudit_16-16.0-1PGDG.rhel9.aarch64.rpm
pgaudit_1616.1el10.x86_64pgdg28.2 KiBpgaudit_16-16.1-1PGDG.rhel10.x86_64.rpm
pgaudit_1616.1el10.aarch64pgdg28.3 KiBpgaudit_16-16.1-1PGDG.rhel10.aarch64.rpm
postgresql-16-pgaudit16.1d12.x86_64pgdg45.2 KiBpostgresql-16-pgaudit_16.1-2.pgdg12+1_amd64.deb
postgresql-16-pgaudit16.1d12.aarch64pgdg44.9 KiBpostgresql-16-pgaudit_16.1-2.pgdg12+1_arm64.deb
postgresql-16-pgaudit16.1d13.x86_64pgdg45.2 KiBpostgresql-16-pgaudit_16.1-2.pgdg13+1_amd64.deb
postgresql-16-pgaudit16.1d13.aarch64pgdg45.2 KiBpostgresql-16-pgaudit_16.1-2.pgdg13+1_arm64.deb
postgresql-16-pgaudit16.1u22.x86_64pgdg51.2 KiBpostgresql-16-pgaudit_16.1-2.pgdg22.04+1_amd64.deb
postgresql-16-pgaudit16.1u22.aarch64pgdg50.7 KiBpostgresql-16-pgaudit_16.1-2.pgdg22.04+1_arm64.deb
postgresql-16-pgaudit16.1u24.x86_64pgdg45.3 KiBpostgresql-16-pgaudit_16.1-2.pgdg24.04+1_amd64.deb
postgresql-16-pgaudit16.1u24.aarch64pgdg45.0 KiBpostgresql-16-pgaudit_16.1-2.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
pgaudit17_151.7.1el8.x86_64pgdg27.4 KiBpgaudit17_15-1.7.1-1PGDG.rhel8.x86_64.rpm
pgaudit17_151.7.0el8.x86_64pgdg55.7 KiBpgaudit17_15-1.7.0-1.rhel8.x86_64.rpm
pgaudit17_151.7el8.x86_64pgdg55.6 KiBpgaudit17_15-1.7-beta1_1.rhel8.x86_64.rpm
pgaudit17_151.7.1el8.aarch64pgdg27.1 KiBpgaudit17_15-1.7.1-1PGDG.rhel8.aarch64.rpm
pgaudit17_151.7.0el8.aarch64pgdg55.2 KiBpgaudit17_15-1.7.0-1.rhel8.aarch64.rpm
pgaudit17_151.7.1el9.x86_64pgdg27.7 KiBpgaudit17_15-1.7.1-1PGDG.rhel9.x86_64.rpm
pgaudit17_151.7.0el9.x86_64pgdg57.0 KiBpgaudit17_15-1.7.0-1.rhel9.x86_64.rpm
pgaudit17_151.7el9.x86_64pgdg56.9 KiBpgaudit17_15-1.7-beta1_1.rhel9.x86_64.rpm
pgaudit17_151.7.1el9.aarch64pgdg27.5 KiBpgaudit17_15-1.7.1-1PGDG.rhel9.aarch64.rpm
pgaudit17_151.7.0el9.aarch64pgdg56.2 KiBpgaudit17_15-1.7.0-1.rhel9.aarch64.rpm
pgaudit17_151.7.1el10.x86_64pgdg28.1 KiBpgaudit17_15-1.7.1-1PGDG.rhel10.x86_64.rpm
pgaudit17_151.7.1el10.aarch64pgdg28.3 KiBpgaudit17_15-1.7.1-1PGDG.rhel10.aarch64.rpm
postgresql-15-pgaudit1.7.1d12.x86_64pgdg44.0 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg12+1_amd64.deb
postgresql-15-pgaudit1.7.1d12.aarch64pgdg43.5 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg12+1_arm64.deb
postgresql-15-pgaudit1.7.1d13.x86_64pgdg44.1 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg13+1_amd64.deb
postgresql-15-pgaudit1.7.1d13.aarch64pgdg43.7 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg13+1_arm64.deb
postgresql-15-pgaudit1.7.1u22.x86_64pgdg50.2 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg22.04+1_amd64.deb
postgresql-15-pgaudit1.7.1u22.aarch64pgdg49.5 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg22.04+1_arm64.deb
postgresql-15-pgaudit1.7.1u24.x86_64pgdg44.3 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg24.04+1_amd64.deb
postgresql-15-pgaudit1.7.1u24.aarch64pgdg43.6 KiBpostgresql-15-pgaudit_1.7.1-2.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
pgaudit16_141.6.3el8.x86_64pgdg27.8 KiBpgaudit16_14-1.6.3-1PGDG.rhel8.x86_64.rpm
pgaudit16_141.6.2el8.x86_64pgdg56.3 KiBpgaudit16_14-1.6.2-1.rhel8.x86_64.rpm
pgaudit16_141.6.0el8.x86_64pgdg55.0 KiBpgaudit16_14-1.6.0-1.rhel8.x86_64.rpm
pgaudit16_141.6el8.x86_64pgdg55.0 KiBpgaudit16_14-1.6-beta2_1.rhel8.x86_64.rpm
pgaudit16_141.6.3el8.aarch64pgdg27.5 KiBpgaudit16_14-1.6.3-1PGDG.rhel8.aarch64.rpm
pgaudit16_141.6.2el8.aarch64pgdg54.7 KiBpgaudit16_14-1.6.2-1.rhel8.aarch64.rpm
pgaudit16_141.6.3el9.x86_64pgdg28.1 KiBpgaudit16_14-1.6.3-1PGDG.rhel9.x86_64.rpm
pgaudit16_141.6.2el9.x86_64pgdg56.6 KiBpgaudit16_14-1.6.2-1.rhel9.x86_64.rpm
pgaudit16_141.6.3el9.aarch64pgdg27.9 KiBpgaudit16_14-1.6.3-1PGDG.rhel9.aarch64.rpm
pgaudit16_141.6.2el9.aarch64pgdg55.7 KiBpgaudit16_14-1.6.2-1.rhel9.aarch64.rpm
pgaudit16_141.6.3el10.x86_64pgdg28.5 KiBpgaudit16_14-1.6.3-1PGDG.rhel10.x86_64.rpm
pgaudit16_141.6.3el10.aarch64pgdg28.6 KiBpgaudit16_14-1.6.3-1PGDG.rhel10.aarch64.rpm
postgresql-14-pgaudit1.6.3d12.x86_64pgdg44.0 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg12+1_amd64.deb
postgresql-14-pgaudit1.6.3d12.aarch64pgdg43.4 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg12+1_arm64.deb
postgresql-14-pgaudit1.6.3d13.x86_64pgdg44.1 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg13+1_amd64.deb
postgresql-14-pgaudit1.6.3d13.aarch64pgdg43.7 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg13+1_arm64.deb
postgresql-14-pgaudit1.6.3u22.x86_64pgdg49.4 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg22.04+1_amd64.deb
postgresql-14-pgaudit1.6.3u22.aarch64pgdg48.7 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg22.04+1_arm64.deb
postgresql-14-pgaudit1.6.3u24.x86_64pgdg44.2 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg24.04+1_amd64.deb
postgresql-14-pgaudit1.6.3u24.aarch64pgdg43.6 KiBpostgresql-14-pgaudit_1.6.3-2.pgdg24.04+1_arm64.deb

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