PolarDB for PostgreSQL Lightweight Edition provides audit logs that allow database administrators to track and analyze database activity.
Log printing
PolarDB for PostgreSQL Lightweight Edition creates three types of log files by default:
Audit log (
_audit.log): Records all executed SQL statements by default (log_statement='all').Slow query log (
_slow.log): Records SQL statements whose running time exceeds the value oflog_min_duration_statement(in milliseconds).Error log (
_error.log): Records SQL statements that failed to execute and system error messages.
Log Processing Mechanism
In PolarDB for PostgreSQL Lightweight Edition, execution processes send relevant logs to the syslogger process for printing. Because a single syslogger process has performance limitations, PolarDB supports configuring multiple syslogger processes for log printing. When multiple syslogger processes are used, the first process (logger 0) prints error logs and slow query logs. The other processes (logger 1, logger 2, and so on) print audit logs. Each syslogger process that handles audit logs prints to a separate log file. Therefore, if multiple audit log processes exist, multiple audit log files are printed in parallel. The log filename suffix consists of the syslogger index and the filename suffix. For example, when multiple processes run in parallel, the audit log printed by the logger 1 process has the suffix _1_audit.log.
Log audit parameter settings
In addition to the basic log printing parameters, PolarDB for PostgreSQL Lightweight Edition supports the following audit log parameters.
Parameter | Description |
polar_enable_multi_syslogger | Specifies whether to enable multiple |
polar_num_of_sysloggers | The number of Note This parameter can be set only in the configuration file. |
polar_enable_syslog_pipe_buffer | Specifies whether to enable the buffer for |
polar_enable_syslog_file_buffer | Specifies whether to enable the buffer for the |
polar_audit_log_flush_timeout | Sets the timeout period for flushing audit logs. The default value is 10 seconds. If the buffer on the |
polar_auditlog_max_query_length | Sets the truncation length for printed logs. The default value is 4096 bytes, and the maximum value is 65536 bytes. Logs that exceed this length are truncated. This parameter can be set dynamically. |
polar_enable_error_to_audit_log | Specifies whether to record SQL statements that cause errors in the audit log. This feature is enabled by default. When enabled, SQL statements that fail to execute and their error messages are recorded in the audit log. |
polar_max_log_files | Sets the maximum number of error log files to retain. The default value is 20. |
polar_max_auditlog_files | Sets the maximum number of audit log files to retain. The default value is 20. |
polar_max_slowlog_files | Sets the maximum number of slow query log files to retain. The default value is 20. |
log_connections | Records the connecting user and database. |
log_disconnections | Records the connection duration. |
Audit log content
An audit log contains the following information:
Timestamp: Defined by the
log_line_prefixparameter. The default value is%m [%p].Log content: Includes the running time, SQL statement, and SQL parameters.
Example
2020-07-30 08:36:08.042 UTC [19626] LOG: execute P0_7: UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2;params: $1 = '-203', $2 = '86'