---
title: "PostgreSQL alerting | Grafana documentation"
description: "Set up alerts using PostgreSQL data in Grafana"
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# PostgreSQL alerting

> You can use Grafana Cloud to avoid installing, maintaining, and scaling your own instance of Grafana. [Create a free account](/auth/sign-up/create-user?pg=docs-grafana-latest-datasources-postgres-alerting) to get started, which includes free forever access to 10k metrics, 50GB logs, 50GB traces, 500VUh k6 testing &amp; more.

The PostgreSQL data source supports [Grafana Alerting](/docs/grafana/latest/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](/docs/grafana/latest/datasources/postgres/configure/).
- Familiarize yourself with [Alert rules](/docs/grafana/latest/alerting/fundamentals/alert-rules/) and [Create a Grafana-managed alert rule](/docs/grafana/latest/alerting/alerting-rules/create-grafana-managed-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](/docs/grafana/latest/datasources/postgres/query-editor/#time-series-queries) in the PostgreSQL query editor.

## Create an alert rule

To create an alert rule that uses PostgreSQL:

1. Go to **Alerting** (bell icon) in the left menu and select **Alert rules**.
2. Click **New alert rule**.
3. In the query section, select your **PostgreSQL** data source.
4. Set the query **Format** to **Time series**.
5. Write a SQL query that returns a `time` column and numeric value(s).
6. Configure the condition, evaluation group, and notification settings.
7. Save the rule.

For step-by-step guidance, refer to [Create a Grafana-managed alert rule](/docs/grafana/latest/alerting/alerting-rules/create-grafana-managed-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):

SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sql
SELECT
  $__timeGroupAlias("time_date_time", '5m'),
  avg("value_double") AS value
FROM test_data
WHERE $__timeFilter("time_date_time")
GROUP BY time
ORDER BY time
```

Use 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](/docs/grafana/latest/alerting/alerting-rules/templates/) to include query results or metadata in alert notifications and labels.
