Top
Enterprise Postgres 17 Security Operation Guide

6.5 Session Audit Logging

In Session Audit Logging, specify the rules for filtering logs to be output in the rule section in the pgaudit configuration file.

Rules are specified using the formats below. Multiple values can be specified, using a comma as the delimiter.

If [rule] is described on its own in the rule section with no parameters specified, all audit logs of Session Audit Logging will be output.

Example
[output]
logger = 'auditlog'
[rule]

If [rule] is not described as a section, audit logs of Session Audit Logging will not be output.

Example
[output]
logger = 'auditlog'

The valid parameters in the rule section are shown in the table below.

Parameter name

Description

Example

timestamp

Timestamp range

Refer to "timestamp" for details on how to specify timestamps.

timestamp = '09:00:00 - 10:00:00, 18:00:00 - 18:30:00'

database

Database name

To specify a blank value, specify use a pair of double quotation marks ("") instead of the value. When specifying a name containing uppercase characters, key words, multibyte characters and commas, enclose the name in double quotation marks.

database = 'prodcut_db'

audit_role

Role name

To specify a blank value, specify use a pair of double quotation marks ("") instead of the value. When specifying a name containing uppercase characters, key words, multibyte characters and commas, enclose the name in double quotation marks.

audit_role = 'appuser1'

class

Operation class

Select from the values below. Multiple values can be specified. Refer to "class" for details on the meaning of each class.

  • BACKUP

  • CONNECT

  • DDL

  • ERROR

  • FUNCTION

  • MISC

  • READ

  • ROLE

  • WRITE

  • SYSTEM

class = 'READ, WRITE'

object_type

Object type

This parameter is enabled when the class parameter is "READ" and "WRITE".

Select from the values below. Multiple values can be specified.

  • TABLE

  • INDEX

  • SEQUENCE

  • TOAST_VALUE

  • VIEW

  • MATERIALIZED_VIEW

  • COMPOSITE_TYPE

  • FOREIGN_TABLE

  • FUNCTION

object_type = 'TABLE, INDEX'

object_name

Object name

This parameter is enabled when the class parameter is "READ" and "WRITE".

For objects that can be modified by a schema, such as a table, modify such objects by schema name.

When specifying a name containing uppercase characters, key words, multibyte characters and commas, enclose the name in double quotation marks. When specifying the object name "schemaName.tableName", enclose the entire object name modified by schema name in double quotation marks.

To specify a blank value, use a pair of double quotation marks ("") instead of the value.

object_name = 'myschema.tbl1'

object_name = 'myschema.tbl1, "mySchema.TABLE"'

application_name

Application name

To specify a blank value, use a pair of double quotation marks ("") instead of the value.

application_name = 'myapp'

remote_host

Connection source(client side) host name or IP address

If "on" is specified for the log_hostname parameter in the postgresql.conf file, specify a host name. Otherwise, specify the IP address. If using a local host, specify "[local]".

To specify a blank value, use a pair of double quotation marks ("") instead of the value.

remote_host = 'ap_server'


timestamp

Specify a timestamp range from "startTime" to "endTime" for the log output target. The timestamp format is 'hh:mm:dd-hh:mm:dd' (hh is expressed in 24-hour notation, and hh, mm, and dd are expressed in two-digit notation).

The start time must be earlier than the end time. If specifying multiple ranges, specify each start and end timestamp using a comma as the delimiter.

End timestamps consider milliseconds. For example, if '11:00:00 - 11:59:59' is specified for the timestamp, "11:00:00:000" to "11:59:59:999" will be the target range.

The timestamps used by evaluation in the rule section of pgaudit are different to the timestamps issued in the log entries. That is because log entries are output after evaluation by pgaudit, with the timestamp being generated at that time.

class

The meaning of each class specified in the class parameter is below:

  • READ: SELECT, COPY FROM

  • WRITE: INSERT, UPDATE, DELETE, TRUNCATE, COPY TO

  • FUNCTION: Function call, DO

  • ROLE: GRANT, REVOKE, CREATE ROLE, ALTER ROLE, DROP ROLE

  • DDL: All DDLs (such as CREATE and ALTER) other than the DDLs of the ROLE class

  • CONNECT: Events relating to connecting (request, authenticate, and disconnect)

  • SYSTEM: Instance start, promotion to primary server

  • BACKUP: pg_basebackup

  • ERROR: Event completed by an error (PostgreSQL error codes other than 00). This class can be used if ERROR or lower level is specified for the log_min_messages parameter in postgresql.conf.

  • MISC: Other commands (such as DISCARD, FETCH, CHECKPOINT, and VACUUM)

Evaluation of the rule section

Output format

In Session Audit Logging, audit logs are output in the format below:

AUDIT: SESSION,READ,2022-03-12 19:00:58 PDT,
   (1)         (2)     (3)
[local],19944,psql,appuser,postgres,2/8, 2, 1,SELECT,,TABLE,myschema.account, ,
  (4)    (5)   (6)   (7)      (8)   (9)(10)(11)(12)(13)(14)    (15)        (16)
SELECT * FROM myschema.account;,<not logged>
       (17)                      (18)

No

Content

(1)

Log header

Fixed as "AUDIT: SESSION".

(2)

Class

(3)

SQL start time

(4)

Remote host name

If using a local host, [local] is output.

(5)

Backend process ID

(6)

Application name

If an application name is not specified, [unknown] is output.

(7)

User name

(8)

Database name

(9)

Virtual transaction ID

(10)

Statement ID

(11)

Substatement ID

(12)

Command tag

(13)

SQLSTATE

(14)

Object type

(15)

Object name

(16)

Error message

(17)

SQL

If the SQL contains a password, such as for CREATE ROLE, and so on, it will be replaced with "<REDACTED>".

Additionally, if "on" is specified for the log_statement_once parameter of the option section in the pgaudit configuration file, "<previously logged>" is output for the second and subsequent statements.

(18)

Depending on the log_parameter parameter value of the option section in the pgaudit configuration file, the output content will be as below.

  • log_parameter=on is specified

    If parameters are specified in the SQL, the parameters are concatenated and output, using a space as the delimiter.
    If parameters are not specified in the SQL, "<none>" is output.

  • log_parameter=off (default) is specified

    "<not logged>" is output.

Additionally, if "on" is specified for the log_statement_once parameter of the option section in the pgaudit configuration file, "<previously logged>" is output for the second and subsequent statements.

Information

If accessing resources that use the features below, the command tag (12) may be output as "???".

  • INSTEAD OF trigger

  • RULE

  • VIEW

  • Security policy per row

  • Table inheritance

Example

Below is an example of retrieving audit logs in Session Audit Logging.

1. Settings

In the pgaudit configuration file, specify the rule section below.

[rule]
class = 'READ, WRITE'
object_name = 'myschema.account'

2. Retrieving logs

Execute the SQL below from the client.

CREATE TABLE myschema.account
(
    id int,
    name text,
    password text,
    description text
);
INSERT INTO myschema.account (id, name, password, description) VALUES (1, 'user1', 'HASH1', 'blah, blah');
SELECT * FROM myschema.account;

The audit log below can be retrieved.

'DDL' is not defined in the class parameter, so CREATE TABLE is not output as an audit log.

AUDIT: SESSION,WRITE,2022-03-12 19:00:49 PDT,[local],19944,psql,appuser,postgres,2/7,1,1,INSERT,,TABLE,myschema.account,,"INSERT INTO myschema.account (id, name, password, description) VALUES (1, 'user1', 'HASH1', 'blah, blah');",<not logged>
AUDIT: SESSION,READ,2022-03-12 19:00:58 PDT,[local],19944,psql,appuser,postgres,2/8,2,1,SELECT,,TABLE,myschema.account,,SELECT * FROM myschema.account;,<not logged>