Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/grafana-cloud/monitor-applications/database-observability/monitor/find-application-queries.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana-cloud/monitor-applications/database-observability/monitor/find-application-queries/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Find your application’s queries
When you need to understand how your application uses the database, Database Observability helps you identify specific queries and filter by application components.
Overview
This guide covers two approaches to finding your application’s queries:
- Filtering: Use the Queries Overview dashboard filters to narrow down by instance, schema, or custom labels
- Labels: Organize queries by application, team, or environment using Alloy labels
Filter queries in the dashboard
The Queries Overview dashboard provides several filtering options to find specific queries.
Use the search box
The search box at the top of the dashboard filters queries by SQL text:
- Navigate to Database Observability in Grafana Cloud.
- In the search box, enter part of your query text.
- The table filters to show only matching queries.
Search examples:
SELECT * FROM users- Find queries that select from the users tableINSERT INTO orders- Find insert operations on ordersJOIN products- Find queries that join with the products table
Filter by instance
To view queries for a specific database server:
- Click the Filters dropdown and select the instance label.
- Select one database instance.
- The dashboard updates to show only queries from the selected instance.
Filter by schema or database
To narrow down to a specific schema:
- Click the Filters dropdown and select the schema label (MySQL) or datname label (PostgreSQL).
- Select the schema or database name.
- View queries that execute against that schema.
Group queries
Use the Group by control to organize queries:
| Group by | Use case |
|---|---|
| None | See all individual queries |
| Instance | Compare query patterns across database servers |
| Schema | Analyze query distribution across schemas |
| Database | See queries grouped by logical database |
Use labels to identify applications
Configure Alloy to add custom labels that identify which application or service generates each query.
Add application labels in Alloy
In your Alloy configuration, add labels in the loki.relabel component:
loki.relabel "db_o11y" {
forward_to = [loki.write.default.receiver]
rule {
target_label = "app"
replacement = "order-service"
}
rule {
target_label = "team"
replacement = "checkout"
}
rule {
target_label = "environment"
replacement = "production"
}
}Ensure the same labels are added to your discovery.relabel component for metrics:
discovery.relabel "db_o11y" {
targets = prometheus.exporter.postgres.default.targets
rule {
target_label = "app"
replacement = "order-service"
}
rule {
target_label = "team"
replacement = "checkout"
}
rule {
target_label = "environment"
replacement = "production"
}
}Filter by custom labels
After adding labels, use them in the dashboard:
- Click Add filter in the Queries Overview dashboard.
- Select your custom label (for example,
app). - Choose the value to filter by (for example,
order-service).
Label strategy for multi-application environments
When multiple applications share a database, use a consistent labeling strategy:
| Label | Purpose | Example values |
|---|---|---|
app | Application name | order-service, user-api, inventory |
team | Owning team | checkout, platform, fulfillment |
environment | Deployment environment | production, staging, development |
region | Geographic region | us-east-1, eu-west-1 |
Was this page helpful?
Related resources from Grafana Labs


