Logo

dev-resources.site

for different kinds of informations.

Bringing PostgreSQL Query Issues to Light with Insightful Visuals

Published at
12/19/2024
Categories
postgres
postgressql
sql
query
Author
saby_explain
Categories
4 categories in total
postgres
open
postgressql
open
sql
open
query
open
Author
12 person written this
saby_explain
open
Bringing PostgreSQL Query Issues to Light with Insightful Visuals

As we keep sharing more features of our PostgreSQL query analysis service Saby Explain, today we'll give you a quick overview of how to spot issues in large and complex query plans by just taking a quick look at their visualization.
Image description
You’ll see that our visualization tools may really come in handy for this. To analyze your plan click DEMO on the Saby page.

Simplified visualization

Reading a query plan as plain text can be quite challenging, even if it's an easy one:
Image description
That’s exactly why our developers normally deal with a simplified version of the plan. It shows all the key data on execution time and buffers used for each node separately, making it easier to pinpoint extreme values:
Image description

Pie chart

Just figuring out the most critical issues can sometimes be a real hassle, especially with so many nodes to look through and a simplified visualization that spans more than two screens.
Image description
In this case, you can hardly do without a pie chart.
Image description
Glance over the chart to quickly assess the approximate share of resource usage for each node. When hovering over a specific sector, an icon appears to help you locate the corresponding node in the plan’s text.

Tile view

The pie chart doesn’t give us the whole story. If you need to see the relationship between nodes or identify critical issues, you’d better use a tile visualization.
Image description

Processing flow diagram

But neither of the visualization options above shows the full hierarchy of nested CTE, InitPlan, and SubPlan nodes. If you want to get the whole picture, take a look at the diagram:
Image description

More metrics? Say no more!

If you run the query execution plan using the EXPLAIN (ANALYZE) command, you'll only see the time spent. But we need more than just that to come to an accurate conclusion.
Here’s the thing: when you run a query on a cold cache, the time you actually see includes the time it takes to fetch data from storage, not just the time spent executing the query itself (even though it might not be obvious).
Building on that, here are a couple of tips to keep in mind:

  • Use the EXPLAIN (ANALYZE, BUFFERS) command only to see how many data pages are being read. This metric doesn’t depend much on the server workload, so you can use it as a reliable benchmark for query optimization.
  • To measure the time spent on disk operations, use track_io_timing. And since your execution plan shows not just the time spent but also things like buffers and I/O timings, you can easily get to the analysis of all these metrics from any type of diagram. This can sometimes reveal the unpleasant truth that more than half of all the reads go to just one problematic node: Image description

More articles if you're interested in the topic:

Get Saby Explain

postgressql Article's
30 articles in total
Favicon
GraphDB for CMDB
Favicon
Not able to connect to PostgreSQL server on Fedora
Favicon
Master Test Data Generation With dbForge Studio for PostgreSQL
Favicon
Exploring the Power of Full-Stack Development with Next.js and Prisma
Favicon
Bringing PostgreSQL Query Issues to Light with Insightful Visuals
Favicon
POSTGRESQL - ÍNDICE GIN NA PRÁTICA
Favicon
Reading PostgreSQL Query Plans Brought to a New Level
Favicon
Understanding PostgreSQL Isolation Levels
Favicon
How to Activate and Enable the PostgreSQL Service on Your Kali Linux System
Favicon
Mastering charts and database visualization with ChartDB
Favicon
The Best Ways to Connect to a PostgreSQL Database
Favicon
Hey, welcome to my blog
Favicon
How to Create a Database and Always Connect to It in PostgreSQL Without Needing Superuser Access
Favicon
03. ரிலேஷனல் டேட்டாபேஸ் மாடல் என்றால் என்ன? What is Relational Database Model ? (RDBMS)
Favicon
04. தரவு ஒருங்கிணைவு (Data Integrity)
Favicon
02. DBMS என்றால் என்ன? What is a DBMS?
Favicon
How To Use Materialized Views
Favicon
PostgreSQL Secrets You Wish You Knew Earlier
Favicon
Reading Parallel Plans Correctly
Favicon
New PostgreSQL ORM for Golang: Enterprise
Favicon
Migrate 🪳Coackroach DB into Postgres🐘
Favicon
💡 Database Development: It’s Not Just About Querying!
Favicon
Building Real-Time Data Pipelines with Debezium and Kafka: A Practical Guide
Favicon
01. தரவுத்தளம் எவ்வாறு உருவானது, அதன் தேவை என்ன? How did the database come about, What is its need?
Favicon
Data inconsistency in AWS Amazon Aurora Postgres solved with Local Write Forwarding?
Favicon
PostgreSQL vs. MySQL
Favicon
How To Handle Custom S/DQL Queries On Different Database Engine with DoctrineExpression
Favicon
Deploying PostgreSQL on Kubernetes: 2024 Guide
Favicon
Step-by-Step Guide to Installing PostgreSQL on Arch Linux
Favicon
Remedy for Poor-Performing SQL Queries

Featured ones: