Log Query

Understand the logging process of PostgreSQL instances from the container level, such as PostgreSQL error logs, slow query logs, etc. Properly utilizing logs can help you quickly locate issues, address faults, and handle exceptions.

Note: To save disk space, the platform retains log records for 7 days by default (up to 30 days). The actual retention duration can be set in the operations center under Logs > Policy Management. If you need to retain logs for a longer period, please export them in a timely manner.

Prerequisites

If the interface indicates no data, please deploy the Log Collection Component and ensure it is running properly.

Procedure

CLI
Web Console

View PostgreSQL Logs

# Example: View primary node logs for instance 'my-pg-instance'
kubectl -n my-namespace logs my-pg-instance-0 -c postgres

# Example: View replica node logs
kubectl -n my-namespace logs my-pg-instance-1 -c postgres

View PostgreSQL Logs

# Example: View primary node logs for instance 'my-pg-instance'
kubectl -n my-namespace logs my-pg-instance-0 -c postgres

# Example: View replica node logs
kubectl -n my-namespace logs my-pg-instance-1 -c postgres

Export Logs to File

# Example: Export logs to file
kubectl -n my-namespace logs my-pg-instance-0 -c postgres > postgres.log

Log Type Descriptions

Log TypeDescription
PostgreSQL LogContains information on errors, warnings, and other runtime messages

Notes

  1. Log files are stored by default in the /var/log/postgresql directory inside the container.
  2. Log rotation policies can be adjusted in the PostgreSQL configuration:
    • log_rotation_age: Maximum lifetime of an individual log file
    • log_rotation_size: Maximum size of an individual log file
  3. Log levels can be configured using the log_min_messages parameter:
    • DEBUG5 through DEBUG1: Detailed debugging information
    • INFO: Informational messages
    • NOTICE: Important but non-error conditions
    • WARNING: Warnings
    • ERROR: Errors
  4. Ensure sufficient disk space is allocated for log storage.