YugabyteDB Anywhere (YBA) provides a powerful management and observability layer for your YugabyteDB clusters, including metrics, health dashboards, alerts, and query performance insights.
One of the most valuable tools under “Performance → Slow Queries” is the Slow Queries Dashboard. This view surfaces statements with high latency, large execution counts, or excessive resource consumption… all powered by PostgreSQL’s pg_stat_statements under the hood.
But sometimes you may want to:
● Export this slow query data to analyze it in Excel or Google Sheets
● Compare performance before and after a workload change
● Reset the slow query list before a new round of testing
In this tip, we’ll walk through a few shell commands that use the YBA REST API to retrieve and manage slow query data programmatically.
Prerequisites
Make sure your environment includes:
● curl and jq installed
● Access to your YBA URL
● A valid API token (generated from your YBA user profile)
● The Universe ID for the target cluster
Step 1. Gather Required IDs and API Token
Before running any commands, you’ll need three identifiers:
🔹 API Token
In YBA, click your user icon (top right corner) → User Profile
Click Generate Key (only one exists at a time per user)
Copy the key and store it securely
🔹 Customer ID
You can usually find this in the same User Profile window. If not, run the following:
This resets YBA’s cached pg_stat_statements data for that universe.
How the Slow Queries Dashboard Works
Under the hood, YBA periodically queries pg_stat_statements on each YSQL node, aggregates the statistics, and stores the top entries in its internal metrics store.
The UI at Performance → Slow Queries then presents this information, including:
● Average latency (ms)
● Total execution count
● Rows returned
● Reads/writes per query
That same data is accessible through the REST API you just used.
✅ Automate Performance Analysis: Schedule periodic exports via cron or CI/CD scripts. ✅ Compare Query Stats: Track improvements or regressions between versions. ✅ Integrate with Other Tools: Feed slow query data into Grafana or BI dashboards. ✅ Clean Slate Testing: Reset pg_stat_statements before each benchmark.
Have Fun!
This is a 50-year-old replica of the first public railway engine, Locomotion No. 1, which originally ran from Darlington to Stockton-on-Tees in England. In September 2025, it followed the same route to celebrate 200 years since that first historic journey. 🚂 🇬🇧