Skip to main content

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.

Settings, Plant historian, with connection, retention and rollups sections
Settings, Plant historian, with connection, retention and rollups sections

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:

  1. Plant historian: the connection.
  2. How long history is kept: retention.
  3. 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.

FieldMeaningNotes
Store samples in the historianSwitch delivery on or offA chip shows "Site Runtimes will deliver to this historian" or "Historian deliver is off"
Address (host:port)The historian addressFor the plant stack: mi-tsdb:9000
DatabaseDatabase namemi in the plant stack
Username / PasswordLogin 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."

FieldMeaningDefault and notes
Keep for (days)The plant defaultBuilt-in 90; allowed 1 to 10,950
Legal minimum (days, 0: none)Nothing is ever kept shorter. Only an administrator may change it0
Delete between … and …The nightly deletion window, in site timeBoth empty: 01:00 to 05:00
Other times for equipment classesA different period for a class, for example air compressorsAdd class
Other times for single tagsA different period for one tagAdd tag
Deleting needs two administratorsTwo different administrators must approve a shorteningEnterprise 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.

  1. 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.
  2. An administrator writes a reason (Reason (at least 10 characters); 10 to 1000 characters) and clicks Request deletion. Nothing is deleted yet.
  3. 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.
  4. 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.
  5. After the approval there is a waiting time of 24 hours. In that time Cancel request stops it ("Cancelled. Nothing is deleted.").
  6. 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.

caution

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.

StepTrigger (defaults)What happens
Make roomFree space below the larger of 10 % or 5 GBThe oldest daily partitions are dropped, never today's or yesterday's, and never inside the legal minimum
Stop historyStill below the larger of 3 % or 2 GBNew 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):

VariableDefaultMeaning
MI_TSDB_DISK_GUARDonoff switches the guard off
MI_TSDB_DISK_PATHThe database directoryThe disk to watch
MI_TSDB_DISK_MIN_FREE_PERCENT10Make-room level in percent
MI_TSDB_DISK_MIN_FREE_GB5Make-room level in GB
MI_TSDB_DISK_FLOOR_PERCENT3Stop-history level in percent
MI_TSDB_DISK_FLOOR_GB2Stop-history level in GB
MI_TSDB_MAX_GB0 (off)Cap on the database size
MI_TSDB_DISK_CHECK_INTERVAL1mHow 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​

ItemValue
Usermii_reader
PasswordIn the file DATA-ACCESS.txt in the data folder, and in the secret pg-reader.password
Databasemakeitintelligent
Port5433
From other computersOnly 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:

ColumnTypeMeaning
tstimestamptzTime of the sample
pathtextPlant path of the tag
tag_idtextTag id
valuedouble precisionNumeric value (empty for text tags)
value_texttextText value (empty for numeric tags)
qualitytextgood, uncertain, bad or unknown

mii_data.tags (one row per tag):

ColumnMeaning
tag_id, pathAs above
enterprise, site, area, work_centerParts 1 to 4 of the path
work_unitEmpty unless the path has 7 parts
equipment, tagThe last two parts of the path

mii_data.alarms (the alarm journal):

ColumnMeaning
tsTime of the event
path, tag_idThe tag
kindHI, HIHI, LO, LOLO
eventactivate, return, ack, shelve, unshelve, disable, enable, initial
from_state, to_stateStates before and after
priority1 to 4
value, value_textThe value at the event
messageThe 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_reader for BI tools. Never connect them as an administrator.

Troubleshooting​

SymptomCauseFix
"The historian cannot be reached. Nothing is deleted while that is so."The historian is down or the address is wrongTest connection; see Troubleshooting
"The stored retention of the historian cannot be read. Nothing is deleted."The stored policy is damagedSave the retention rules again
"Saved, but not yet in the historian."The rules are saved in the Console but not applied yetThe Console repeats it; nothing is deleted until it works
"The rules were changed meanwhile."Another administrator saved firstThe rules reload; enter your change again
Approval refused, request expiredData grew or rules changed after the checkMake a new request
History stops, live values continueDisk guard hard floorFree disk space or shorten retention
psql is refused from another computerMI_LITE_PG_PUBLIC is not on, or a firewall blocks 5433Set it, restart, open the port
mii_data does not existThe historian is ClickHouseUse the Console or the API