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/reference/labels.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana-cloud/monitor-applications/database-observability/reference/labels/. 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.
Labels reference
Labels identify and organize your database telemetry data. This reference documents all labels used by Database Observability, their requirements, and best practices.
Required labels
These labels must be configured correctly for Database Observability to function.
job
The job label identifies Database Observability telemetry.
| Requirement | Value |
|---|---|
| Required | Yes |
| Must be | integrations/db-o11y |
| Where | Both metrics and logs |
Configuration:
loki.relabel "mydb" {
forward_to = [loki.write.default.receiver]
rule {
target_label = "job"
replacement = "integrations/db-o11y"
}
}
discovery.relabel "mydb" {
targets = database_observability.postgres.mydb.targets
rule {
target_label = "job"
replacement = "integrations/db-o11y"
}
}Warning
If
jobis not exactlyintegrations/db-o11y, the Database Observability dashboards cannot find your data.
instance
The instance label uniquely identifies each database server.
| Requirement | Value |
|---|---|
| Required | Yes |
| Format | hostname:port |
| Must match | Same value in both metrics and logs |
Configuration:
loki.relabel "mydb" {
forward_to = [loki.write.default.receiver]
rule {
target_label = "instance"
replacement = "db.example.com:5432"
}
}
discovery.relabel "mydb" {
targets = database_observability.postgres.mydb.targets
rule {
target_label = "instance"
replacement = "db.example.com:5432"
}
}Best practices:
| Do | Don’t |
|---|---|
Use FQDN: orders-db.prod.example.com:3306 | Use IP addresses (they can change) |
Include port: mydb:5432 | Omit port: mydb |
| Be consistent across all databases | Use different formats for different databases |
For AWS RDS/Aurora:
Use the instance endpoint, not the cluster endpoint:
// Correct - instance endpoint
instance = "mydb-instance.abcd1234.us-east-1.rds.amazonaws.com:5432"
// Incorrect - cluster endpoint (changes during failover)
instance = "mydb-cluster.cluster-abcd1234.us-east-1.rds.amazonaws.com:5432"For Google Cloud SQL:
Use a consistent instance label value across metrics and logs. The instance IP address or hostname is typical:
// Correct - instance IP or hostname with port
instance = "10.0.0.5:5432"
// Also set connection_name in the cloud_provider block for infrastructure metrics
cloud_provider {
gcp {
connection_name = "my-project:us-central1:my-db"
}
}Refer to Set up Google Cloud SQL PostgreSQL or Set up Google Cloud SQL MySQL for Alloy configuration. For Cloud Provider Observability navigation, refer to Google Cloud Platform observability.
System-managed labels
These labels are set automatically by Alloy. Do not modify them.
| Label | Description |
|---|---|
server_id | Unique server identifier, used internally to associate telemetry |
op | Operation type for log entries (query_sample, query_association, wait_event, explain_plan_output, create_statement, health_status) |
Warning
Do not override
server_idoropin relabel rules. Modifying these labels prevents Database Observability from querying and correlating your data.
Database-specific labels
These labels come from the database itself and are automatically added by exporters.
PostgreSQL labels
| Label | Source | Description |
|---|---|---|
datname | pg_stat_statements | Database name |
usename | pg_stat_statements | User who executed query |
queryid | pg_stat_statements | Unique query identifier |
MySQL labels
| Label | Source | Description |
|---|---|---|
schema | performance_schema | Database schema name |
digest | performance_schema | Statement digest (query identifier) |
user | performance_schema | Database user |
Recommended custom labels
Add these labels in both loki.relabel and discovery.relabel to organize and filter databases. Values must match across both components.
| Label | Purpose | Example values |
|---|---|---|
app | Application that uses the database | order-service, user-api |
team | Team responsible for the database | checkout, platform |
environment | Deployment stage | production, staging, dev |
region | Geographic region or data center | us-east-1, eu-west-1 |
cluster | Database cluster (for replicated setups) | orders-primary, orders-replica |
provider | Infrastructure provider | aws, gcp, azure, self-managed |
Example:
rule {
target_label = "app"
replacement = "order-service"
}For complete configuration examples showing custom labels in context, refer to Monitor multiple databases.
Environment variables
For dynamic labels, use environment variables:
rule {
target_label = "environment"
replacement = sys.env("DEPLOYMENT_ENV")
}
rule {
target_label = "region"
replacement = sys.env("AWS_REGION") // or sys.env("GCP_REGION") for Google Cloud
}Label name and value restrictions
| Restriction | Details |
|---|---|
| Name characters | Letters, numbers, underscores. Must match [a-zA-Z_][a-zA-Z0-9_]* |
| Value characters | Any UTF-8 string |
| Case | Case-sensitive; use lowercase for consistency |
| Empty | Empty values are ignored |
Related documentation
- Telemetry reference: Available metrics and logs
- Monitor multiple databases: Labeling strategies and configuration at scale
- Tune Alloy collection: Configure collection and manage cardinality
- Troubleshoot Alloy components: Validate relabeling rules and diagnose label issues
- View query performance: Use labels in dashboards
Was this page helpful?
Related resources from Grafana Labs


