PostgreSQL alerting
The PostgreSQL data source supports Grafana Alerting. You can create alert rules that evaluate time series queries against your PostgreSQL database and send notifications when conditions are met.
Before you begin
- Ensure your PostgreSQL data source is configured.
- Familiarize yourself with Alert rules and Create a Grafana-managed alert rule.
Supported query format
Only time series queries can be used in alert rule conditions.
- Your query must return a column named
time(native SQL date/time or UNIX epoch) and one or more numeric value columns. - Table formatted queries are not supported in alert rule conditions.
For details on writing time series queries, refer to Time series queries in the PostgreSQL query editor.
Create an alert rule
To create an alert rule that uses PostgreSQL:
- Go to Alerting (bell icon) in the left menu and select Alert rules.
- Click New alert rule.
- In the query section, select your PostgreSQL data source.
- Set the query Format to Time series.
- Write a SQL query that returns a
timecolumn and numeric value(s). - Configure the condition, evaluation group, and notification settings.
- Save the rule.
For step-by-step guidance, refer to Create a Grafana-managed alert rule.
Example time series query for alerting
The following query returns a time series suitable for a threshold alert (e.g. alert when value exceeds a limit):
SELECT
$__timeGroupAlias("time_date_time", '5m'),
avg("value_double") AS value
FROM test_data
WHERE $__timeFilter("time_date_time")
GROUP BY time
ORDER BY timeUse condition types such as Is above or Is below in the alert rule to evaluate the series.
Template annotations and labels
You can use template annotations and labels to include query results or metadata in alert notifications and labels.



