Historian
The historian is the database that stores every sample with its time, value and quality. In a plant stack it is mi-tsdb (ClickHouse). In mii Lite it is the embedded PostgreSQL. Every Site Runtime takes the historian settings from the Console, so you change them in one place.

How it works
Open Settings → Plant historian. You need the permission to manage the historian (role integration_engineer or administrator), and your access must not be limited to an area or machine.
The page has three sections:
- Plant historian: the connection.
- How long history is kept: retention.
- Faster long ranges: hourly rollups.
The raw history export (Trends) is embedded on the same page.
Historian settings
"Where process history is stored. Every site runtime takes this setting from the Console." In mii Lite the historian is already set up; you normally do not change it.
| Field | Meaning | Notes |
|---|---|---|
| Store samples in the historian | Switch delivery on or off | A chip shows "Site Runtimes will deliver to this historian" or "Historian deliver is off" |
| Address (host:port) | The historian address | For the plant stack: mi-tsdb:9000 |
| Database | Database name | mi in the plant stack |
| Username / Password | Login of the writer role |
Buttons: Test connection, Save historian.
Retention
The section How long history is kept explains itself: "Readings older than this are deleted every night. Longer is applied at once. Shorter deletes data: it needs a check, an administrator and a waiting time."
| Field | Meaning | Default and notes |
|---|---|---|
| Keep for (days) | The plant default | Built-in 90; allowed 1 to 10,950 |
| Legal minimum (days, 0: none) | Nothing is ever kept shorter. Only an administrator may change it | 0 |
| Delete between … and … | The nightly deletion window, in site time | Both empty: 01:00 to 05:00 |
| Other times for equipment classes | A different period for a class, for example air compressors | Add class |
| Other times for single tags | A different period for one tag | Add tag |
| Deleting needs two administrators | Two different administrators must approve a shortening | Enterprise licence. Switching it off needs two people too |
Rules:
- The longest matching rule wins: a tag rule, a class rule or the plant default, whichever keeps the data longest.
- The legal minimum lifts every result up to its value.
- At most 32 different durations can be used in total.
- Alarms, the audit log and production orders are not covered by retention. The last value of a tag stays.
- After an upgrade nothing is deleted until a rule is saved.
- The built-in baseline is 90 days. In mii Lite it can also be set with
MI_TSDB_RETENTION_DAYS; a saved rule overrides it.
Longer retention
Lengthening applies at once. Click Save. The page says "Nothing is kept shorter. Saving applies at once."
Shorter retention: the approval flow
Shortening deletes data that cannot be brought back. It goes through checks and a waiting time.
- Change the numbers. Click Check the effect. The Console counts the readings that would be deleted ("Counting readings. This can take minutes."). It shows Readings to be deleted, Oldest and Newest of them, and the series that would be kept shorter.
- An administrator writes a reason (Reason (at least 10 characters); 10 to 1000 characters) and clicks Request deletion. Nothing is deleted yet.
- An administrator clicks Approve. In the dialog Approve deleting readings they type the number of readings to confirm, and choose the backup status: A backup or export was made or No backup; the readings may be lost for good.
- With Deleting needs two administrators switched on, a second, different administrator must approve too ("You approved already. Another administrator has to approve."). Without it, one approval is enough.
- After the approval there is a waiting time of 24 hours. In that time Cancel request stops it ("Cancelled. Nothing is deleted.").
- The deletion runs in the nightly window.
The approval is refused and the request expires if the data grew by more than about 10 percent since the check, if the rules changed meanwhile, or if the historian is another one now. Make a new request in that case.
The list Requests and deletions shows every request with its status (waiting for approval, approved, deleting, done, cancelled, expired). The line "Last deletion … N readings" shows the last run.
If deletion was interrupted for a long time, the page says "Deleting was interrupted for long. Nothing is deleted until an administrator approves it again." Click Ask to continue.
Back up the historian database or export the series first. "Deleted readings cannot be brought back."
Rollups
Faster long ranges keeps hourly summaries next to the readings so that long ranges in Trends load faster. The readings do not change, but the summaries need extra disk space.
Click Switch on or Switch off. Switching off deletes the summaries and asks "The summaries are deleted and would have to be built again. Continue?" The page shows how many hours are summarized and how many changes are not yet included.
Disk guard (PostgreSQL historian in mii Lite)
A full disk stops PostgreSQL for everything, including the Console data. The disk guard prevents this. It checks the free space of the disk that holds the database every minute.
| Step | Trigger (defaults) | What happens |
|---|---|---|
| Make room | Free space below the larger of 10 % or 5 GB | The oldest daily partitions are dropped, never today's or yesterday's, and never inside the legal minimum |
| Stop history | Still below the larger of 3 % or 2 GB | New history rows are not stored. Live values keep updating. History resumes when space is back |
The page shows what happened:
- "The disk is almost full (… free): history is NOT being stored; live values continue. Free disk space or keep history shorter."
- "Low disk space: N oldest day(s) of history were deleted to keep the historian running."
- "Low disk space since …, and only today and yesterday are left to keep."
Settings (environment variables in mii.env):
| Variable | Default | Meaning |
|---|---|---|
MI_TSDB_DISK_GUARD | on | off switches the guard off |
MI_TSDB_DISK_PATH | The database directory | The disk to watch |
MI_TSDB_DISK_MIN_FREE_PERCENT | 10 | Make-room level in percent |
MI_TSDB_DISK_MIN_FREE_GB | 5 | Make-room level in GB |
MI_TSDB_DISK_FLOOR_PERCENT | 3 | Stop-history level in percent |
MI_TSDB_DISK_FLOOR_GB | 2 | Stop-history level in GB |
MI_TSDB_MAX_GB | 0 (off) | Cap on the database size |
MI_TSDB_DISK_CHECK_INTERVAL | 1m | How often to check (at least 5 s) |
An invalid value is ignored with a warning, so a typo does not switch the guard off.
Read the data with SQL (mii Lite)
mii Lite exposes the history as read-only views in the schema mii_data. The tables behind them (mi.*) are private and may change between versions. The views keep their columns. This applies only when the historian is PostgreSQL (mii Lite). It does not exist with ClickHouse.
Connect
| Item | Value |
|---|---|
| User | mii_reader |
| Password | In the file DATA-ACCESS.txt in the data folder, and in the secret pg-reader.password |
| Database | makeitintelligent |
| Port | 5433 |
| From other computers | Only when MI_LITE_PG_PUBLIC=on is set (in the Docker image it is on by default). Open the port in your firewall yourself on Windows |
The role has these limits: no superuser, 10 connections, statement timeout 60 seconds, idle-in-transaction timeout 60 seconds. It can only SELECT from the mii_data views.
psql "host=<lite-host> port=5433 dbname=makeitintelligent user=mii_reader"
Views and columns
The path has the form <enterprise>/<site>/<area>/<work center>[/<work unit>]/<equipment>/<tag>, for example DEMOFOODS/IZMIR/UTILITIES/AIR/COMPRESSOR/Pressure.
mii_data.samples (history) and mii_data.latest (the newest sample per tag) have the same columns:
| Column | Type | Meaning |
|---|---|---|
ts | timestamptz | Time of the sample |
path | text | Plant path of the tag |
tag_id | text | Tag id |
value | double precision | Numeric value (empty for text tags) |
value_text | text | Text value (empty for numeric tags) |
quality | text | good, uncertain, bad or unknown |
mii_data.tags (one row per tag):
| Column | Meaning |
|---|---|
tag_id, path | As above |
enterprise, site, area, work_center | Parts 1 to 4 of the path |
work_unit | Empty unless the path has 7 parts |
equipment, tag | The last two parts of the path |
mii_data.alarms (the alarm journal):
| Column | Meaning |
|---|---|
ts | Time of the event |
path, tag_id | The tag |
kind | HI, HIHI, LO, LOLO |
event | activate, return, ack, shelve, unshelve, disable, enable, initial |
from_state, to_state | States before and after |
priority | 1 to 4 |
value, value_text | The value at the event |
message | The alarm message |
Example queries
Hourly average compressor pressure over the last 24 hours, good readings only:
SELECT date_trunc('hour', s.ts) AS hour,
avg(s.value) AS avg_bar,
count(*) AS n
FROM mii_data.samples s
WHERE s.path = 'DEMOFOODS/IZMIR/UTILITIES/AIR/COMPRESSOR/Pressure'
AND s.quality = 'good'
AND s.ts >= now() - interval '24 hours'
GROUP BY 1
ORDER BY 1;
Latest value of every Filler tag:
SELECT t.tag, l.ts, l.value, l.quality
FROM mii_data.latest l
JOIN mii_data.tags t ON t.tag_id = l.tag_id
WHERE t.equipment = 'Filler'
ORDER BY t.tag;
Highest compressor pressure per day for the last week:
SELECT date_trunc('day', ts) AS day,
max(value) AS max_bar
FROM mii_data.samples
WHERE path = 'DEMOFOODS/IZMIR/UTILITIES/AIR/COMPRESSOR/Pressure'
AND quality = 'good'
AND ts >= now() - interval '7 days'
GROUP BY 1
ORDER BY 1;
How many alarms each tag raised in the last 7 days:
SELECT path, kind, count(*) AS times
FROM mii_data.alarms
WHERE event = 'activate'
AND ts >= now() - interval '7 days'
GROUP BY path, kind
ORDER BY times DESC;
Which tags had bad readings in the last hour, by machine:
SELECT t.equipment, t.tag, count(*) AS bad_samples
FROM mii_data.samples s
JOIN mii_data.tags t ON t.tag_id = s.tag_id
WHERE s.quality = 'bad'
AND s.ts >= now() - interval '1 hour'
GROUP BY t.equipment, t.tag
ORDER BY bad_samples DESC;
Tags of the Bottling area that have not been updated for 10 minutes (stale tags):
SELECT t.equipment, t.tag, l.ts AS last_update, l.quality
FROM mii_data.latest l
JOIN mii_data.tags t ON t.tag_id = l.tag_id
WHERE t.area = 'Bottling'
AND l.ts < now() - interval '10 minutes'
ORDER BY l.ts;
Built-in retention for the embedded PostgreSQL is 90 days by default, in daily partitions. Longer queries do not return older data.
ClickHouse note
In a plant stack the historian is ClickHouse (mi-tsdb) with database mi and three roles: mi_writer (insert), mi_reader (select) and mi_admin (DDL). It is reachable only inside the internal container network and is not published to the host. The views mii_data.* are not part of it. Read ClickHouse data through the Console (Trends, raw export) or the public API, not by opening the database to the network.
Limits and good practice
- Plan disk before you plan retention. 900 tags at 1 Hz can grow by about 30 GB per day in the PostgreSQL historian, so 90 days needs about 2.7 TB. Size the disk for the tags and the interval you really use, and see Sizing.
- Keep the disk guard on. It is the last line of defence before the disk is full.
- Set a legal minimum if a rule or contract says how long you must keep data.
- Take a backup or export before every shortening.
- Use the read-only login
mii_readerfor BI tools. Never connect them as an administrator.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| "The historian cannot be reached. Nothing is deleted while that is so." | The historian is down or the address is wrong | Test connection; see Troubleshooting |
| "The stored retention of the historian cannot be read. Nothing is deleted." | The stored policy is damaged | Save the retention rules again |
| "Saved, but not yet in the historian." | The rules are saved in the Console but not applied yet | The Console repeats it; nothing is deleted until it works |
| "The rules were changed meanwhile." | Another administrator saved first | The rules reload; enter your change again |
| Approval refused, request expired | Data grew or rules changed after the check | Make a new request |
| History stops, live values continue | Disk guard hard floor | Free disk space or shorten retention |
psql is refused from another computer | MI_LITE_PG_PUBLIC is not on, or a firewall blocks 5433 | Set it, restart, open the port |
mii_data does not exist | The historian is ClickHouse | Use the Console or the API |