Audit log files v17
You can generate the audit log file in a CSV, XML, or JSON format. The format is determined by the edb_audit
configuration parameter.
The information in the audit log is based on the logging performed by PostgreSQL, as described in "Using CSV-Format Log Output” under “Error Reporting and Logging” in the PostgreSQL core documentation.
Overview of the CSV audit log format
The following table lists the fields in the order they appear in the CSV audit log format. The table contains the following information:
- Field — Name of the field as shown in the sample table definition in the PostgreSQL documentation.
- XML element/attribute — For the XML format, name of the XML element and its attribute (if used), referencing the value.
- Data type — Data type of the field as given by the PostgreSQL sample table definition.
- Description — Description of the field.
The fields that don't have any values for logging appear as consecutive commas (,,) in the CSV format.
Field | XML element/attribute | Data type | Description |
---|---|---|---|
log_time | event/log_time | timestamp with time zone | Log date/time of the statement. |
user_name | event/user | text | Database user who executed the statement. |
database_name | event/database | text | Database in which the statement was executed. |
process_id | event/process_id | integer | Operating system process ID in which the statement was executed. |
connection_from | event/remote_host | text | Host and port location from where the statement was executed. |
session_id | event/session_id | text | Session ID in which the statement was executed. |
session_line_num | event/session_line_num | bigint | Order of the statement within the session. |
process_status | event/process_status | text | Processing status. |
session_start_time | event/session_start_time | timestamp with time zone | Date/time when the session was started. |
virtual_transaction_id | event/virtual_transaction_id | text | Virtual transaction ID of the statement. |
transaction_id | event/transaction_id | bigint | Regular transaction ID of the statement. |
error_severity | error_severity | text | Statement severity. Values are AUDIT for audited statements and ERROR for any resulting error messages. |
sql_state_code | event/sql_state_code | text | SQL state code returned for the statement. The sql_state_code isn't logged when its value is 00000 for XML log format. |
message | message | text | The SQL statement that was attempted for execution. |
detail | detail | text | Error message detail. |
hint | hint | text | Hint for error. |
internal_query | internal_query | text | Internal query that led to the error, if any. |
internal_query_pos | internal_query_pos | integer | Character count of the error position therein. |
context | context | text | Error context. |
query | query | text | User query that led to the error. For errors only. |
query_pos | query_pos | integer | Character count of the error position therein. For errors only. |
location | location | text | Location of the error in the source code. The location field is populated if log_error_verbosity is set to verbose. |
application_name | event/application_name | text | Name of the application from which the statement was executed, for example, psql.bin . |
backend_type | event/backend_type | text | The backend_type corresponds to what pg_stat_activity.backend_type shows and is added as a column to the csv log. |
leader_pid | event/leader_pid | integer | Process ID of leader for active parallel workers. |
query_id | event/query_id | long | Identifier of this backend's most recent query. |
command_tag | event/command_tag | text | SQL command of the statement. |
audit_tag | event/audit_tag | text | Value specified by the audit_tag parameter in the configuration file. |
type | event/type | text | Determines the audit event_type to identify messages in the log. |
The following examples are generated in the CSV and XML formats.
The non-default audit settings in the postgresql.conf
file are as follows:
The edb_audit parameter
is changed to xml
when generating the XML format.
The following is the audited session:
CSV audit log file
The following is the CSV format of the audit log file. (Each audit log entry was split and displays across multiple lines. A blank line was inserted between the audit log entries for visual clarity.)
XML audit log file
The following is the XML format of the audit log file. (The output was formatted for visual clarity.)
Overview of the JSON audit log format
Including json
as a value for the edb_audit
parameter (see Summary of configuration parameters) allows you to import log files into different programs. This option generates log lines in the JSON format.
The following table shows JSON keys and their associated values. String fields with null values are excluded from output.
Key name | Type | Description |
---|---|---|
timestamp | string | Time stamp with milliseconds |
user | string | User name |
dbname | string | Database name |
pid | number | Process ID |
remote_host | string | Client host |
remote_port | number | Client port |
session_id | string | Session ID |
line_num | number | Per-session line number |
ps | string | Current ps display |
session_start | string | Session start time |
vxid | string | Virtual transaction ID |
txid | string | Regular transaction ID |
error_severity | string | Error severity |
state_code | string | SQLSTATE code |
message | string | Error message |
detail | string | Error message detail |
hint | string | Error message hint |
internal_query | string | Internal query that led to the error |
internal_position | number | Cursor index into internal query |
context | string | Error context |
statement | string | Client-supplied query string |
cursor_position | number | Cursor index into query string |
func_name | string | Error location function name |
file_name | string | File name of error location |
file_line_num | number | File line number of the error location |
application_name | string | Client application name |
backend_type | string | Type of backend |
leader_pid | number | Process ID of leader for active parallel workers |
query_id | number | Query ID |
command_tag | string | SQL command of the statement |
audit_tag | string | Value specified by the audit_tag parameter in the configuration file |
event_type | string | Determines the audit event_type to identify messages in the log |
The following is an example of JSON log output.
Footer