SQL access for Grafana and other tools
Read your organization's readings, incidents, releases and collector alerts with SQL, from Grafana, Metabase, psql or any tool that speaks PostgreSQL. Each SQL reader is a read-only Postgres login that sees only your organization.
Create a reader#
Only owners can create and revoke readers.
- Open Settings > SQL access.
- Name the reader, for example "Grafana on the test bench", and click Create reader.
- Copy the host, database, user and password. The password is shown once and Avrel does not keep it. If you lose it, revoke the reader and create a new one.
An organization can have up to 10 readers. Revoke a reader in the same place when it is no longer used: it stops seeing data straight away, and it can no longer sign in.
Every reader that is created or revoked is recorded in the audit log, with who did it. AI assistants cannot create, list or revoke readers.
Connect Grafana#
- In Grafana, open Connections > Add new connection > PostgreSQL.
- Fill in Host URL (the host and port 5432), Database name, Username and Password from Settings.
- Set TLS/SSL Mode to
require. - Click Save & test.
A panel showing one signal over time:
SELECT time, value
FROM readings
WHERE $__timeFilter(time) AND system = 'RIG-01' AND signal = 'supply_rail_v'
ORDER BY time
Every signal of a System, one series each:
SELECT time, signal AS metric, value
FROM readings
WHERE $__timeFilter(time) AND system = 'RIG-01'
ORDER BY time
From psql:
psql "host=<host> port=5432 dbname=<database> user=<user> sslmode=require"
What a reader can see#
A reader sees the views below, in the avrel_sql schema, which is also its default search path. Live readings are kept for 30 days, and imported history is kept. Times are timestamptz in UTC.
Readings#
View readings.
| Column | What it is |
|---|---|
time | When the reading was taken (timestamptz). |
system | The System that reported it. |
signal | Sensor name, or supply_rail_v for the supply rail. |
value | The reading (double precision). |
unit | Unit of the reading, when the collector sent one. |
imported | True for readings imported from history, false for live ones. |
Systems#
View systems.
| Column | What it is |
|---|---|
system | The System. |
last_reading_at | When its collector last reported (timestamptz). |
Incidents#
View incidents.
| Column | What it is |
|---|---|
id | Incident id. |
title | Incident title. |
system | The System it happened on. |
started_at | Start of the recorded window (timestamptz). |
ended_at | End of the recorded window (timestamptz). |
recorded_at | When it was recorded (timestamptz). |
Releases#
View releases.
| Column | What it is |
|---|---|
id | Release id. |
name | Release name. |
sha | Commit or build the release is. |
state | candidate, approved, deployed, superseded, rolled_back or withdrawn. |
gate_verdict | The release gate's verdict when it was recorded. |
created_at | When it was recorded (timestamptz). |
state_at | When it reached its current state (timestamptz). |
Collector alerts#
View collector_alerts.
| Column | What it is |
|---|---|
id | Alert id. |
collector_id | The collector it is about. |
system | The System that collector reports for, when known. |
kind | What happened, for example stopped or source_unreachable. |
opened_at | When it opened (timestamptz). |
closed_at | When it closed, or null while it is open (timestamptz). |
Limits#
- Read-only: a reader cannot change anything.
- Each query stops after 15s. Keep dashboards to the time range you need.
- At most 3 connections at once per reader. Grafana needs one or two.
- A session left idle inside a transaction is closed after 60s.
How your data is kept apart#
The database itself enforces the separation, not Avrel's application code:
- A reader has no privilege on any table. It can only read the
avrel_sqlviews. - Each view keeps only the rows of the organization the signed-in reader belongs to. The views are
security_barrierviews, so a crafted query cannot make Postgres look at another organization's rows first. - The view definitions name no organization, and reader names are random (
avq_and 16 hex digits), so the catalog reveals nothing about other customers. - Members, email addresses, keys, alert channels, the audit log and sign-in data are not in any view.
- Data access rules hold here too: each view leaves out the Systems, channels and incidents a rule hides from the reader, worked out from the reader's own attributes as soon as an owner saves a tag or rule.
- Avrel sends Postgres a SCRAM-SHA-256 verifier, not the password, wherever the database accepts one, so the password does not appear in database logs. Connections must use TLS.
- When a reader is revoked, it is unmapped first, so any open session sees no rows. Then its login is removed.
Self-hosted installs#
SQL access needs Postgres 16 or newer, and the server's database role needs CREATEROLE so it can create reader logins. It is not available on a SQLite install. By default readers connect to the same host and database as the server. Set AVREL_SQL_HOST and AVREL_SQL_PORT to give them another address, for example a direct host instead of a connection pooler. See Self-hosting.