Can I log all queries that run on my Heroku Postgres database?

Issue

You want to send a log statement to your log stream for each query that runs on your database.

Resolution

You can configure the log level for Heroku Postgres via the log-statement option in the Heroku PGsettings. More information is available in Dev Center.

Please note the all setting is generally only intended for debugging purposes, as it can quickly cause significant performance issues for production databases.

If you're trying to identify specific long-running queries, we already log all queries that run longer than 2 seconds. You can also view your most expensive queries through the Heroku Data dashboard, which is usually a better place to start for optimizing performance.

Finally, you can connect to your database by running heroku pg:psql on the command line and run queries directly there. You can put EXPLAIN ANALYZE in front of the query to get detailed performance information, and paste the output into explain.depesz.com to understand a specific query.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support