If I have a Django + PG query that takes 1 second and I want to deeply inspect the breakdown of that entire second, where might I begin reading to learn what tools to use and how?
If I have a Django + PG query that takes 1 second and I want to deeply inspect the breakdown of that entire second, where might I begin reading to learn what tools to use and how?
Take the result of this and paste it into https://explain.depesz.com/
which will make it human readable.
Understanding this is sometimes very easy, but if you want to understand what they _really_ mean, you can read depesz.com
It covers all major databases and is a good start to dive into database interna and how to interpret output from query analyzers.
Other than that, I highly recommend joining the mailing list and IRC (#postgresql on libera.chat).
Lots of valuable tricks being shared there by people with decades of experience.
It can also be used with Django Rest Framework via the browsable api.
May be parent is looking for deeper insight than this but it is useful to do quick visual query inspection.
django debug toolbar (or similar) should be the first thing you go to because these tools understand the django ORM well.
the other thing that comes to mind is enabling query timing in your django shell. i believe you might need an extension for this.
then you can look at the postgres itself. but i would keep it at the django layer at first because it might reveal something about the ORM.
Note that this isn't valid SQL, just an approximation, because Django doesn't generate a single SQL string, but uses the underlying library's parameterization. So you'll have to fiddle with quotes and such to get SQL you can run the EXPLAIN on that's mentioned in the other replies.