Help Center/ Relational Database Service/ Best Practices/ RDS for PostgreSQL/ Viewing Slow Query Logs of RDS for PostgreSQL DB Instances
Updated on 2024-11-21 GMT+08:00

Viewing Slow Query Logs of RDS for PostgreSQL DB Instances

Scenarios

Slow query logs record statements that exceed the log_min_duration_statement value (1 second by default). You can view log details and statistics to identify statements that are slowly executed and optimize the statements. RDS for PostgreSQL supports the following statement types:
  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • CREATE
  • DROP
  • ALTER
  • DO
  • CALL
  • COPY

Parameter Description

Table 1 Parameters related to RDS for PostgreSQL slow queries

Parameter

Description

log_min_duration_statement

Specifies the minimum execution time. The statements whose execution time is greater than or equal to the value of this parameter are recorded.

If this parameter is set to a smaller value, the number of log records increases, which increases disk I/O utilization and deteriorates the SQL performance.

log_statement

Specifies the statement type. The value can be none, ddl, mod, or all.

The default value is none. Changing it to all will have the following impacts:

  • The database disk I/O utilization increases, and the SQL performance deteriorates.
  • The log format changes, and you cannot view slow query logs on the console.

log_statement_stats

Specifies whether to generate performance statistics to server logs.

The default value is off. Changing it to on will have the following impacts:

  • The database disk I/O utilization increases, and the SQL performance deteriorates.
  • The log format changes, and you cannot view slow query logs on the console.

Procedure

  1. Log in to the management console.
  2. Click in the upper left corner and select a region.
  3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
  4. On the Instances page, click the DB instance name.
  5. In the navigation pane on the left, choose Logs. On the Slow Query Logs page, click Log Details.

    You can view the slow query log records of a specified statement type in a specified time period.