Updated on 2026-10-21 GMT+08:00

Audit Logs

CREATEROLE can use the audit logs to reproduce a series of events that cause faults in the database and identify unauthorized users, unauthorized operations, and the time when these operations are performed. After the audit function is enabled, a large number of audit logs will be generated, which occupy large storage space. You can customize an audit log maintenance policy based on the size of available storage space.

Log Storage Directory

Audit logs are stored in $GAUSSLOG/pg_audit/ by default. If om is used for cluster deployment, they are stored in $GAUSSLOG/pg_audit/Instance name. The log storage path can be specified by the GUC parameter audit_directory.

Log Query Methods

Only users with the AUDITADMIN permission can view audit records. The query methods are as follows:

  • Query traditional audit records.
    1
    gaussdb=# SELECT * FROM gs_query_audit('2021-03-03 21:30:00', '2021-03-03 22:00:00') where type = 'login_success' and username = 'user1';
    
  • Query traditional audit records of all CNs.
    1
    gaussdb=# SELECT * FROM gs_query_audit_dist('2021-03-03 21:30:00', '2021-03-03 22:00:00') where type = 'login_success' and username = 'user1';
    
  • Query unified audit records.
1
gaussdb=# SELECT * FROM gs_query_unified_audit('2025-04-26 08:00:00','2025-04-26 17:00:00')where type = 'login_success' and username = 'user1';

The difference between the values of the starttime and endtime parameters indicates the query period, which can be any value ranging from 00:00:00 of the starttime parameter to 23:59:59 of the endtime parameter. Therefore, the startime and endtime parameters must be properly set to ensure that the required audit information is displayed.

Log Content Description

For details about the columns in the log, see the definitions of the gs_query_audit function in Table 1.

Table 1 Traditional audit log parameters

Parameter

Description

time

Operation time.

type

Operation type.

result

Operation result.

userid

User ID

username

Name of the user who performs the operation.

database

Database name.

client_conninfo

Client connection information.

object_name

Operation object name.

detail_info

Operation details.

node_name

Node name.

thread_id

Thread ID

local_port

Local port.

remote_port

Remote port.

For details about the columns in the log, see the definitions of the gs_query_unified_audit function in Table 2.

Table 2 Unified audit log parameters

Parameter

Description

time

Operation time.

type

Operation type.

result

Operation result.

userid

User ID.

username

Name of the user who performs the operation.

database

Database name.

client_conninfo

Client connection information.

object_name

Operation object name.

detail_info

Operation details.

node_name

Node name.

thread_id

Thread ID.

local_port

Local port.

remote_port

Remote port.

policy_id

Unified audit policy ID.

unified_audit_type

Unified audit policy type.

unified_audit_policy

Unified audit policy information.