Enabling audit logging v17
You can configure EDB Postgres Advanced Server to log all connections, disconnections, DDL statements, DCL statements, DML statements, and any statements resulting in an error.
- Enable auditing by setting the
edb_audit
parameter toxml
orcsv
. - Set the file rotation day when the new file is created by setting the parameter
edb_audit_rotation_day
to the desired value. - To audit all connections, set the parameter
edb_audit_connect
toall
. - To audit all disconnections, set the parameter
edb_audit_disconnect
toall
. - To audit DDL, DCL, DML and other statements, set the parameter
edb_audit_statement
according to the instructions in Selecting SQL statements to audit. - To specify the desired location of audit files, set the
edb_audit_directory
parameter.
Setting the edb_audit_statement
parameter in the configuration file affects the entire database cluster.
You can further refine the type of statements that are audited. The type is controlled by the edb_audit_statement
parameter according to the database in use as well as the database role running the session:
- You can set the
edb_audit_statement
parameter as an attribute of a specified database with theALTER DATABASE dbname SET edb_audit_statement
command. This setting overrides theedb_audit_statement
parameter in the configuration file for statements executed when connected to databasedbname
. - You can set the
edb_audit_statement
parameter as an attribute of a specified role with theALTER ROLE rolename SET edb_audit_statement
command. This setting overrides theedb_audit_statement
parameter in the configuration file as well as any setting assigned to the database by theALTER DATABASE
command when the specified role is running the current session. - You can set the
edb_audit_statement
parameter as an attribute of a specified role when using a specified database with theALTER ROLE rolename IN DATABASE dbname SET edb_audit_statement
command. This setting overrides theedb_audit_statement
parameter in the configuration file. It also overrides any setting assigned to the database by theALTER DATABASE
command and as any setting assigned to the role with theALTER ROLE
command without theIN DATABASE
clause.
Examples
The following are examples of this technique.
The database cluster is established with edb_audit_statement
set to all
as shown in its postgresql.conf
file:
A database and role are established with the following settings for the edb_audit_statement
parameter:
- Database
auditdb
withddl
,insert
,update
, anddelete
- Role
admin
withselect
,truncate
, andset
- Role
admin
in databaseauditdb
withcreate table
,insert
, andupdate
The following shows creating and altering the database and role: