Grafana version : Grafana v13.0.1 (a100054f)
Noticed this error of late.
<30>1 2026-05-04T10:59:40.20063-04:00 raspberry05 grafana 247674 - - logger=ngalert.state.historian backend=annotations rule_uid=cf50q8nv3ooaoe org_id=1 t=2026-05-04T10:59:40.200174121-04:00 level=error msg=“Failed to save history batch” samples=6 err=“error saving alert annotation batch: SQL logic error: too many SQL variables (1)”
Is there something I can do to eliminate this from happening?
Just going back three hours I see it has happen 10 times.
hellow @scootertramp what is your evaluation interval , increased it.
Reduce labels in alerts
or
Move Grafana DB to: Postgresql if needed
Evaluation was 30 seconds with a pending period of 30 seconds.
I changed it to 10 seconds with a pending period of 20 seconds.
What would moving to Postgres solve? The current Grafana db is rather small at 260M.
The update frequency isn’t all that high since this is a Home Lab monitoring set-up.
Here are six messages that meet the alert settings. These are pretty consistent as they happen every hour. Also attached is my alert definition
Rsyslog.json (1.2 KB)
.
warn <4>1 2026-05-05T08:58:51.961732-04:00 xt8-down kernel - - [meta sequenceId=“3240”] replay_ctr:
warn <4>1 2026-05-05T08:58:51.961732-04:00 xt8-down kernel - - [meta sequenceId=“3241”] 0000: 00 00 00 00 00 00 00 4b
warn <4>1 2026-05-05T08:58:51.955346-04:00 xt8-down kernel - - [meta sequenceId=“3238”] kek:
warn <4>1 2026-05-05T08:58:51.955346-04:00 xt8-down kernel - - [meta sequenceId=“3239”] 0000: 3e b4 44 6b 2f 04 0a 09 c9 8a f5 b7 50 aa 34 e8
warn <4>1 2026-05-05T08:58:51.954313-04:00 xt8-down kernel - - [meta sequenceId=“3236”] kck:
warn <4>1 2026-05-05T08:58:51.954313-04:00 xt8-down kernel - - [meta sequenceId=“3237”] 0000: a0 a5 1b 2d 55 5c 00 15 ee dd 8e 6a de 94 ef c7
Changing interval had no effect. I tried ungrouping alert emails since the samples size seemed to match the number of warning alerts. Did not resolve error.
Just more background information. It appears this started on May 2nd.
Grafana was last upgraded on Apr 18th.
dpkg.log.1:2026-04-18 06:48:19 status unpacked grafana:arm64 13.0.1
dpkg.log.1:2026-04-18 06:48:19 status half-configured grafana:arm64 13.0.1
dpkg.log.1:2026-04-18 06:48:20 status installed grafana:arm64 13.0.1
Since i am using the default Grafana Contact point with the Grafana default Notification Policy and Grafana Built-in Templates. Can anybody provide any insights in to why I am getting this error for every alert that fires.
error saving alert annotation batch: SQL logic error: too many SQL variables
This looks like a Grafana bug.
No change in behavior after upgrading Grafana to 13.0.2.
<30>1 2026-06-04T06:50:10.261409-04:00 raspberry05 grafana 8217 - - logger=ngalert.state.historian backend=annotations rule_uid=cf50q8nv3ooaoe org_id=1 t=2026-06-04T06:50:10.261053441-04:00 level=error msg=“Failed to save history batch” samples=1 err=“error saving alert annotation batch: SQL logic error: too many SQL variables (1)”
No change in behavior after upgrading Grafana to 13.1.0
<30>1 2026-06-23T10:31:10.241667-04:00 raspberry05 grafana 42357 - - logger=ngalert.state.historian backend=annotations rule_uid=cf50q8nv3ooaoe org_id=1 t=2026-06-23T10:31:10.241336634-04:00 level=error msg=“Failed to save history batch” samples=1 err=“error saving alert annotation batch: SQL logic error: too many SQL variables (1)”
This is a Grafana bug → the default annotations historian generates a batch SQL insert that exceeds SQLite’s variable limit. Upgrading Grafana will not fix it.
Edit /etc/grafana/grafana.ini:
If you have Loki:
ini
[unified_alerting.state_history]
enabled = true
backend = loki
loki_remote_url = http://localhost:3100
If you have Prometheus:
ini
[unified_alerting.state_history]
enabled = true
backend = prometheus
prometheus_target_datasource_uid = <UID found at Connections → Data Sources → your Prometheus → copy UID from URL>
If you have neither, migrate Grafana’s database to PostgreSQL or MySQL → both handle this correctly without SQLite’s variable limit.
Restart:
bash
sudo systemctl restart grafana-server
Confirm it:
bash
sudo journalctl -fu grafana-server | grep historian
No Failed to save history batch = fixed.
Please also file a bug at Sign in to GitHub · GitHub
Thank You.
I added to settings for loki and no more errors. I also run prometheus but have not added the settings for it as yet.
Unfortunately moving the alert annotations out of Grafana sqllite to Loki just moved what error
I am seeing.
https://community.grafana.com/t/loki-errors-when-viewing-some-alert-rules-history/163864