Super-charge ActiveRecord#explain with pg-eyeballs 👀
When I have a slow Postgres ActiveRecord query, one of the first tools I reach for
Those of you that know your way around ActiveRecord might be confused. ActiveRecord comes with
- ActiveRecord just
onthe query. Without
,the query isn't actually executed, which means you can't compare the query planner's estimates with what actually happened.
outputis noisy. It is difficult to grok if you aren't running the command frequently.
pg-eyeballsmakes it easy to export the output to tools that provide a more user-friendly view of the query plan.
Visualizing queries in rails console
pg-eyeballs plays well with the
Here's an example:
gocmdpev is a command-line Go app. You'll need to install this separately.
Outputing EXPLAIN results to Pev
gocmdpev is my default eyeballs flavor, there are a couple of cases where I need a different visualization tool:
- There are many nodes in the query plan.
output, which is displayed in the terminal, doesn't have the interactivity that a web UI can provide.
- The ops team isn't excited about installing another binary on app servers.
In the above cases, I reach for Pev, the inspiration
Subscribe for more ActiveRecord optimization tips👇.