How to enable SQL query logging
Written by
Updated at December 17, 2025
Case description
You need to enable SQL query logging.
Solution
To enable query logging, make sure pg_stat_statements is installed. This extension adds an option to track execution plans and collect the statistics of all SQL queries run in the cluster. You must have the mdb_monitor role to use it.
You also need to check the Auto explain sample rate=1 and Auto explain log analyze settings following this guide and enable Log min duration statement. We do not recommend setting the 1 ms value as this will keep the cluster busy with logging only.
You can enable this setting from the management console
yc managed-postgresql cluster update-config <cluster name> --set log_min_duration_statement=100
After that, you can view the log records, e.g., via the YC CLI:
yc managed-postgresql cluster list-logs --service-type postgresql --since '2h' --until '1s' --id=YOUR-CLUSTER-ID