June 2024
Intermediate to advanced
456 pages
11h 34m
English
Earlier you saw how to log slow queries to the Rails log. In this section, let’s look at logging them in the postgresql.log.
Open up your postgresql.conf file. Set the following log_min_duration_statement value and save your changes. Reload the config file values by running pg_ctl reload. This assumes you’ve set the PGDATA environment variable (see Set PGDATA for pg_ctl).
Start with a value of one second, with an entry like this:
| | log_min_duration_statement = 1000 |
After reloading, tail the PostgreSQL log file to see the output. From psql, run SELECT pg_sleep(1); to create a query that’s one second long and verify it’s logged. Refer to the pg_scripts repo[177] administration directory ...
Read now
Unlock full access