IMD SolutionComputing LibraryShop main store

How-to

Reduce stored historian data older than six months to ten seconds

Edge computing and IIoT Published 8 min read

Short answer

Summarize one pilot daily table with set-based PostgreSQL aggregation, verify it through a historian query on a known tag, then rename it in place inside one transaction. Going forward, record new history at ten seconds in a secondary provider and cap the one-second provider's retention at six months. At 28,000 tags, ten-second storage removes about 90% of stored rows.

On this page
  1. How much disk space does ten-second history actually save?
  2. What should ten-second data mean before you convert anything?
  3. Why is one history-query call per tag the expensive path?
  4. How do you convert one pilot table and prove the result?
  5. How do you stop one-second data from piling up again?
  6. What breaks if you rename a table under a live historian?
  7. Which tags and days should stay at one second?
  8. Questions asked

Summarize the old days in PostgreSQL with set-based SQL, then keep the split permanent with two history providers. Convert one pilot daily table first — same structure, one aggregated row per tag per ten-second bucket — verify it through a historian query on a known tag, and swap it in with a transactional rename. At your 28,000-tag, one-second workload, ten-second storage removes 90% of the rows, so a 30–40 GB day scales to roughly a tenth of that. For data still to come, write new history through a ten-second secondary provider and cap the one-second provider's retention at six months.

How much disk space does ten-second history actually save? #

Converting one-second rows to ten-second rows removes 90% of them: 28,000 tags storing once per second write 2,419,200,000 rows per day, and ten-second buckets hold 241,920,000.

The arithmetic: a day holds 86,400 s, so one-second storage means 28,000 × 86,400 = 2,419,200,000 rows per day. Ten-second buckets give 86,400 ÷ 10 = 8,640 intervals per day, so the same day converts to 28,000 × 8,640 = 241,920,000 rows — 2,177,280,000 rows per day fewer, exactly 90%.

Convert bytes with the pilot, not the ideal ratio. Your daily tables run 30–40 GB; if the replacement keeps the same row layout and indexes, size should track the 10:1 row ratio, so a 35 GB day lands near 3.5 GB. Read the real ratio as converted bytes ÷ source bytes on the pilot table and use that number for every projection — indexes and per-row overhead move it. Across the archive, roughly 183 of the 365 stored days sit past the six-month cutoff: 183 × 35 GB ≈ 6.4 TB at one second, near 0.64 TB converted. For turning a per-tag rate into a detailed storage budget, the page on sizing PostgreSQL sensor storage for ten-second samples works the bytes-per-sample math.

What should ten-second data mean before you convert anything? #

Define per tag whether ten seconds means one kept sample per bucket (decimation) or a computed average, minimum or maximum over the bucket (aggregation), because the two give different values for the same trend.

The read path already aggregates when stored data is denser than a query requests — the queryTagHistory manual documents aggregation modes for exactly that case — so charts and exports keep rendering after conversion. What changes is the input: a one-minute average that used sixty one-second samples now uses six ten-second ones, and short spikes flatten differently.

Set the rule per tag kind before writing any SQL:

Tag kind Ten-second rule Consumer loses
Analog trend (temperature, pressure, level) average per bucket single-sample spikes fold into the average
Counter or totalizer max per bucket, or last if resets are handled resets shorter than ten seconds
Discrete state or alarm first and last sample per bucket transitions shorter than ten seconds
Sub-ten-second events that drive decisions keep at one second nothing

An arithmetic mean is what a plain AVG computes, and for densely recorded analog tags it sits close enough to the time-weighted value to use directly. If nothing needs data faster than a minute, converting straight to one-minute rows frees another 6× (one row per minute versus one per ten seconds); the walkthrough on downsampling old Ignition historian data to one-minute averages covers that interval.

Why is one history-query call per tag the expensive path? #

Calling the history API once per tag costs about 5,124,000 round trips for six months of tables: 28,000 tags × 183 days, each with a type lookup, an aggregation query and an insert.

system.tag.queryTagHistory is the right tool for client charts and for verification, and the wrong engine for a bulk rewrite. It works one tag at a time: resolve the tag's identifier from the historian's catalog tables, aggregate that tag's 86,400 rows for the day, hold up to 8,640 result rows in gateway memory, then insert them again. Repeated per tag per daily table, the round trips dominate — 5,124,000 calls before the first converted day is finished, all serialized through one gateway.

The rows already sit together in each daily table. One set-based INSERT ... SELECT groups by tag identifier and ten-second bucket and processes every tag in a single pass inside PostgreSQL, with no application round trips at all. Keep queryTagHistory for the before-and-after checks in the procedure below; commit the bulk conversion to SQL.

How do you convert one pilot table and prove the result? #

Convert one mid-volume day first: record its row count and size, rebuild the identical table structure, fill it with one row per tag per ten-second bucket, compare counts, then roll the pattern across the archive.

Back up the pilot day first: the swap path drops the one-second originals during the rename, and there is no undo.

  1. Measure the pilot. Pick one mid-volume day table and record its row count and total size with indexes. Compare against the ideal 2,419,200,000; the measured number is your real denominator everywhere below.
  2. Build the replacement. Create the converted table with the same column set, types and indexes as the original, so the swap stays invisible to the provider.
  3. Insert the aggregates in one statement. All tags at once, bucketed on ten-second epoch boundaries:
-- Illustrative pattern: substitute the table and column names the
-- historian actually created (tag_id int, ts timestamptz, value numeric).
INSERT INTO day_converted (tag_id, ts, value, quality)
SELECT tag_id,
       to_timestamp(floor(extract(epoch FROM ts) / 10) * 10),
       avg(value),
       min(quality)              -- the quality rule chosen for this tag kind
FROM day_source
GROUP BY 1, 2;

The average suits analog tags; counters take max(value) and states take first and last, per the table above. If the historian's storage layout expects its own typed value and quality fields rather than a free aggregate, map these results into that layout in the same statement — the historian-query check in step 5 is what proves the mapping. 4. Check the row math in SQL. Converted rows should sit near source rows ÷ 10 within the day's measured gap tolerance; spot-check one tag: 86,400 rows in, about 8,640 out. 5. Take a historian baseline. Run system.tag.queryTagHistory for one known tag over one hour of that day: it returns 3,600 rows per tag (one per second). Record a few values and timestamps for comparison. 6. Swap in one transaction. Rename the original out and the replacement in under its old name — BEGIN; ALTER TABLE day_source RENAME TO day_source_1s; ALTER TABLE day_converted RENAME TO day_source; COMMIT — so no client ever sees a half-swapped day. 7. Re-run the same historian query. Same tag, same hour: expect 360 rows (one per ten seconds) with timestamps on ten-second marks and values consistent with the baseline. If SQL counts rows but the historian query returns none, stop and resolve discovery before batching anything.

Batch the remaining tables one day at a time through the same steps, off-shift, logging source rows, converted rows and elapsed time per day. The pilot's rows-per-second rate projects the total runtime before you commit the rest of the archive.

How do you stop one-second data from piling up again? #

A secondary history provider storing at ten seconds plus a six-month retention limit on the one-second provider stops the pile-up: new data lands thin, and nothing older than six months accumulates at one second.

Ignition's Tag Historian supports multiple history providers. Add a secondary provider configured for a ten-second storage rate — the setting that caps how often samples are written — and point the recorded tags' history at it. Set the existing provider's retention to six months, the max-age setting that prunes stored data past the limit; the guide on setting historian pruning and retention for Ignition tag history walks that side, and running two rates in parallel is the same pattern as logging one-second trends and one-minute reports in one historian.

Mind the semantics: a provider storing at a ten-second interval writes snapshots — the value at each ten-second mark — not averages of the intervening samples, so its rows will not match the converted archive's averages row for row. Both are legitimate ten-second history; pick by consumer need. If exports require true ten-second averages going forward, let the one-second provider age each day out past six months and re-run the conversion steps monthly; if snapshots are fine, the provider alone does the job. Set the ten-second provider's retention from the long-term requirement — years, or the site's maximum — not by copying the six-month figure.

What breaks if you rename a table under a live historian? #

SQL counts being right proves nothing about the historian: the provider must still discover the renamed table and its tag identifiers, so run a historian query for one known tag and hour before and after the swap and compare.

Three things must survive the rename: the table name the provider scans for, the tag identifiers that tie rows to tags, and the timestamp meaning. Keep all three identical and the conversion is invisible; change any of them and a correctly bound chart shows wrong or empty history while SQL still counts rows happily. That asymmetry — SQL right, historian wrong — is the failure signature, and step 7 is the test that catches it. If a converted day fails the check, consult the historian's documented maintenance and partition behavior for your version rather than assuming the aggregation was wrong. Commit renames off-shift: readers on that day's tables can hold the commit for a moment, invisible at 03:00 and a support ticket at 10:00.

Which tags and days should stay at one second? #

Exclude from conversion any tag or day where an event faster than ten seconds changes an operator decision — interlock trips, fast counters, sub-second alarm transitions — and convert the analog trends first, one pilot day ahead of the batch.

  • Analog trend tags older than six months: convert to ten-second averages with the set-based path. They are the bulk of the 28,000 tags and nearly all of the space.
  • Counter, state and alarm tags: convert with the per-kind rule from the table, or leave at one second wherever an event faster than ten seconds drives an operator action or a report.
  • Days with heavy communication gaps: convert anyway — empty buckets simply produce no rows — and expect a better-than-90% row cut with a smaller byte saving.
  • Export scripts that demand raw one-second files for old dates: run those exports before converting the day, or exclude the day.
  • Data younger than six months: touch nothing; from the cutover, the retention setting and the ten-second provider handle it.

Executed in that order — pilot, verify at 360 rows per tag-hour, batch the roughly 183 days, then flip the providers — the archive ends at ten-second data older than six months at about a tenth of the bytes, and nothing older than the cutoff ever accumulates at one second again.

Questions asked

Does deleting a day's rows return the disk space to the filesystem?

Not by itself. Dropping the whole table returns its space to the filesystem immediately, which is why the procedure renames and drops rather than deleting rows. If you delete rows in place instead, PostgreSQL keeps the space allocated to that table until a full rewrite such as VACUUM FULL; plain autovacuum only marks the space reusable inside the same table, and the files keep their old size on disk.

How long will the full backfill take?

Project it from the pilot instead of guessing: total runtime equals remaining rows divided by the pilot's rows-per-second rate, plus index builds per table. Worked example: if the pilot converts 241,920,000 rows in 2 hours, that is about 33,600 rows per second, so one full 2,419,200,000-row day projects to 72,000 s, about 20 hours. Schedule large days off-shift and mind database headroom.

Can a historian query return fewer rows than the bucket math predicts?

Yes, and it does not mean the conversion failed. The 90% figure assumes one stored row per tag per second; deadband suppression, communication gaps and quality-only changes make real tables smaller, and a ten-second bucket holding no samples produces no output row. Expect the reduction to hold or improve, and base every projection on the pilot table's measured counts rather than the ideal 2,419,200,000.

Is a time-series extension worth adding under the historian?

Optional. PostgreSQL was not designed as a time-series store, and extensions such as TimescaleDB add automatic time-based partitioning and retention underneath a SQL historian like this one. They can replace the manual daily-table scheme entirely, but they change the storage layer the historian depends on, so trial one on a test gateway against your historian version before pointing production at it.

Keep reading

  • How-to

    Setting historian pruning and retention for Ignition tag history

    Prune tag history on the history provider, not with the transaction group's delete setting: in the Gateway's tag history configuration, enable data pruning and set a retention period in days. At 250 MB per day of growth, 30 days of retention holds about 7.5 GB and a full year about 91 GB. Deadband and Max Time Between Samples decide most of the daily rate, and QC records from transaction groups keep growing on a separate budget.

    Edge computing and IIoT

  • How-to

    Downsampling old Ignition historian data to one-minute averages

    Ignition has no built-in expiry with aggregation, so you downsample stored history yourself. Two workable patterns: a scheduled database job that keeps the first row of each 60,000 ms bucket in the old sqlt_data partitions, or a monthly gateway script that reads averages or min/max with system.tag.queryTagHistory and then deletes the raw rows. Both are irreversible deletes, so run them on a verified backup and tighten per-tag deadbands first.

    Edge computing and IIoT

  • Troubleshooting

    Why an Easy Chart pen shows no historian data

    A live tag with an empty Easy Chart pen is a historian write-path fault, not a tag fault. Clear the SQL Server no count option first; if it is already off, remove the trigger or procedure statement that makes the update return a result set, then let the store-and-forward cache drain.

    Edge computing and IIoT