pg_stat_statements are your friend

sweemeng
2 min readFeb 26, 2023

Let me tell you a story of the day our users face slowness in our application. As we investigate further, we found out that our RDS instance CPU use is at constant 100%.

One of the things we do is to increase our instance size, and that is not helpful. Which lead to one of my go-to tools in PostgreSQL for this kind of issue, pg_stat_statements.

In a rails application, there's many queries to the database. Tracing individual queries can be painful. There is where pg_stat_statements come in. When enabled, this logs all database queries to the…

--

--

sweemeng

Codemonkey coding for tea. Startup developer at day, community organizer at night. I also happens to be on patreon https://www.patreon.com/sweemeng