Can I log all queries that run on my Heroku Postgres database?
You want to send a log statement to your log stream for each query that runs on your database.
Heroku Postgres doesn't offer the ability to log all queries, 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 at postgres.heroku.com, 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.