Data explorer
This page shows you how to query what Sensora stores, with SQL or with a question in plain words, and how to get the result out as a chart, a CSV file or a direct database connection.
The Data explorer is under Developer › Data in the sidebar (/data). Everything on it is read-only. A query cannot change or delete data.
Run a query
- Open Developer › Data.
- In the Tables list, select a table name to see its columns. Hover over the table and select Query to load
SELECT * FROM <table> LIMIT 100into the editor. - Change the SQL in the editor.
- Select Run, or press Ctrl+Enter (Cmd+Enter on a Mac).
A first query to try:
SELECT device_uid, avg(value) AS avg_temperature
FROM metrics
WHERE metric = 'temperature'
AND recorded_at > now() - interval '1 hour'
GROUP BY 1
ORDER BY 2 DESCYou can run a query over the API too:
curl -X POST http://localhost:8090/api/data/query \
-H "Content-Type: application/json" \
-d '{"sql": "SELECT status, count(*) AS devices FROM devices GROUP BY 1"}'The answer looks like this:
{
"cols": [["status", "text"], ["devices", "int8"]],
"rows": [["online", 148], ["provisioned", 13], ["offline", 115]],
"ms": "1"
}If your instance has API keys, add the header Authorization: Bearer <key>. See API reference.
Tables
The Tables list shows nine tables with their columns and row counts.
| Table | One row is |
|---|---|
metrics | One stored reading of one metric: device_uid, metric, value, unit, recorded_at, sim |
metrics_5m | A 5-minute average of one metric of one device: bucket, avg_value, min_value, max_value, n |
events | One log line: device_uid, type, detail, at, rule_id. See Logs |
devices | One device with its name, template, status (online, offline or provisioned) and last_seen |
templates | One device template |
integrations | One webhook or MQTT integration |
inbox_items | One payload an integration received, with its status and raw_payload |
rule_executions | One run of a rule, with condition_met, action_result and error_message |
rules | One rule with its graph |
The database is PostgreSQL 16, so PostgreSQL functions work. Sensora adds time_bucket('1 hour', recorded_at) to group timestamps into periods.
The read-only role sees more than nine tables
A query can read almost every table in the database, not only the nine in the list. That includes settings, api_keys (a hash and a masked form of each key, never the key itself), claim codes in plain text, and the URL tokens of webhook integrations. Treat access to the Data explorer, and to the direct connection below, as access to the whole instance.
Limits
| Limit | Value |
|---|---|
| Statements per query | One. SELECT, WITH ... SELECT, VALUES or TABLE only |
| Rows returned | 1,000 at most |
| Run time | 5 seconds. A longer query is stopped |
| Length of the SQL | 20,000 characters |
A result is cut at 1,000 rows. The page then shows "Showing the first 1,000", but the API answer has no such mark. When the API returns exactly 1,000 rows, assume the result was cut. Add a WHERE on time or aggregate with GROUP BY.
Ask in plain words
Type a question in Ask a question about your data, for example average temperature per device, last hour, and select Ask. Ask Sensora writes the SQL, puts it in the editor and runs it. The SQL stays on screen, so you can read it, change it and run it again.
This needs an AI model. Without one, the page shows Connect a model, as in the picture above. See Ask Sensora.
Save a query
- Select Save query above the editor.
- Type a name and select Save.
Saved queries show in the left rail. There are no user accounts, so everyone who uses the instance sees the same list. Select a saved query to load it. Its menu has Open, Rename… and Delete…. Names must be unique, ignoring upper and lower case.
Chart and download
- Chart draws the first number column of the result, over time when the result has a timestamp column, otherwise as bars per category.
- Download CSV saves the rows on screen as
sensora-query.csv. This is at most 1,000 rows.
To export more than 1,000 rows, use a direct connection.
Connect Grafana or a notebook directly
Tools such as Grafana, Jupyter and psql can read the PostgreSQL database directly. Sensora creates a database role named readonly for this. The bundled Docker Compose stack does not create a login for it and does not open the database port. You do both yourself. Run the commands from the repository folder.
Create a login user that is a member of the
readonlyrole. The role itself cannot log in.bashdocker compose -f deploy/docker-compose.yml exec db \ psql -U postgres -d sensora \ -c "CREATE ROLE grafana LOGIN PASSWORD 'choose-a-password' IN ROLE readonly;"Replace
postgresandsensoraif you changedDB_USERorDB_NAME.Publish the database port. Save this as
deploy/db-port.yml:yamlservices: db: ports: - "127.0.0.1:5432:5432"Then start the stack with both files. Use both
-foptions every time you start the stack, or the port closes again.bashdocker compose -f deploy/docker-compose.yml -f deploy/db-port.yml up -d127.0.0.1lets only programs on the server itself connect. To reach the database from another machine, replace it with the server's address on your network.Connect your tool with the user from step 1:
textpostgresql://grafana:[email protected]:5432/sensora
DANGER
The published port also accepts the database owner, whose password is password unless you set DB_PASSWORD before the first start. Never publish the port on an address that the internet can reach.
A direct connection has no row cap and no time limit. It is still read-only: the readonly role cannot write.
Over a direct connection, write explorer.devices to get the devices table of the explorer with its status column. The plain name devices is the underlying table, which has no status column.
Show the connection string on the Data page
Optional: set READONLY_DSN in deploy/.env and start the stack again. The Direct connection card on the Data page then shows the string with a copy button.
READONLY_DSN=postgresql://grafana:[email protected]:5432/sensoraREADONLY_DSN only puts text on the screen. It does not create the user or open the port. Everyone who can open the Data page can read the password in it.
When READONLY_DSN is not set, the Read-only database row in Settings › Server & storage shows the placeholder postgresql://readonly@localhost:5432/sensora. It does not work as it is.

