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
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 Type | Description |
---|
PostgreSQL Log | Contains information on errors, warnings, and other runtime messages |
Notes
- Log files are stored by default in the /var/log/postgresql directory inside the container.
- 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
- 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
- Ensure sufficient disk space is allocated for log storage.