IMD SolutionComputing LibraryShop main store

Troubleshooting

Why storeTagHistory creates duplicate sqlth_te entries after a rename

Edge computing and IIoT Published 8 min read

Short answer

The historian resolves every storeTagHistory call through an in-memory path-to-id cache that external edits to sqlth_te never refresh. Only a provider restart reloads it, so retire the old row on rename and let the cache miss create one clean new row, or move manual store-and-retrieve workloads to your own time-series tables. Scheduled merges are unsafe because the cache keeps writing to the id you deleted.

On this page
  1. What the historian is doing when it duplicates a row
  2. How to confirm the cache is the cause
  3. The four options, ranked
  4. The scripted restart, and why it stays in the toolbox
  5. Why a scheduled merge makes it worse
  6. Counting sqlth_te rows when one tag is renamed 100 times
  7. Which option fits your case
  8. Questions asked

Your guess is right: the tag historian keeps an in-memory map from tag path to tag id, it resolves every system.tag.storeTagHistory call through that map, and nothing you write to sqlth_te from outside refreshes it. Your path edit lands in the database, the new path misses the cache, and the historian behaves as it would for a tag it has never seen: it inserts a new sqlth_te row. Only restarting the history provider reloads the table, which is why your disable-and-restart test stopped the duplicates. There is no supported per-entry cache refresh, so the workable answers are to retire the old row on every rename and let the cache miss create one clean successor row, or to move a manual store-and-retrieve workload into your own time-series tables. Merging duplicates on a schedule is the one option that makes things worse.

What the historian is doing when it duplicates a row #

The deployment has three moving parts: memory tags with history disabled in their own configuration, values that reach the historian only through system.tag.storeTagHistory, and a web endpoint that renames or moves tags and rewrites the matching tagpath in sqlth_te so history follows the tag. The rename completes cleanly; the duplicate shows up on the next store:

  1. A value stored for folder1/foo makes the historian create a row in sqlth_te.
  2. The endpoint moves the tag to folder2/foo and updates that row's tagpath.
  3. The next value stored for folder2/foo inserts a second row with tagpath = 'folder2/foo' and no retired timestamp.

The historian does not look up sqlth_te on every store. It resolves each path through the in-memory map first: on a hit it writes the samples under the cached id, and on a miss it treats the path as a tag it has never seen — insert a new row, cache the new id, write under it from then on. Your UPDATE changed the database and nothing else: the cache still maps folder1/foo to the original id and holds no entry for folder2/foo, so the next store misses and inserts a second row for the path.

That is the system working as designed, not a defect to report. The database table reference describes sqlth_te as holding the metadata for each historical tag, with one row standing for one unique version of a tag's historical configuration. The historian expects to be the only writer of that versioning, and it never re-reads the table to discover edits made by other code.

The stale half of the cache is the more dangerous half. If a different tag is later created at folder1/foo and stored before any restart, its samples land under the original id — the row whose tagpath now reads folder2/foo. That is silent cross-contamination between two tags, and it is worse than a visible duplicate.

How to confirm the cache is the cause #

  1. Reproduce it: store one more value for the renamed path, then run SELECT id, tagpath, retired FROM sqlth_te WHERE tagpath = 'folder2/foo'; — two rows come back, neither retired.
  2. Restart the provider: disable the history provider and restart it, or edit its configuration on the gateway configuration page and save.
  3. Store the same value again: with the cache reloaded from the edited table, the historian resolves folder2/foo to the existing row and inserts nothing. A duplicate that disappears exactly when the cache reloads is the confirmation.
  4. Find the split data: query the data partitions grouped by tag id. Samples from before the rename sit under the old id and samples after it under the new one, which is why trends and manual queries break at the rename boundary.

The four options, ranked #

Option What it does Supported At several renames per second Effect on manual queries Main risk
Restart the provider Reloads the cache from sqlth_te, by saving the provider config on the gateway page or by the scripted internal call below Config-page save: yes. Scripted call: no No; each restart interrupts storage None while it works Stores issued during a restart fail or queue; the scripted call breaks on upgrade
Retire on rename The rename endpoint stamps the old row retired in the same edit; the next store's cache miss creates one clean successor row In practice; it still edits a historian-owned table Yes, one extra row per rename Stitch rows by path across created and retired windows Row growth; the stale old-path cache entry survives
Scheduled merge Re-points data from the new id to the old id and deletes the new row No No Clean until the next rename The cache keeps writing to the id you deleted
Own tables or a time-series database Stable tag identity you own; a rename is one metadata row update Yes Yes One id per tag for life You build retention, partitioning and trending queries

Retire-on-rename needs one discipline: the endpoint sets the old row's tagpath to the new path and stamps retired in the same edit, then leaves the table alone. The next store misses the cache, the historian creates the successor row, and the pair describes a clean before-and-after for the path.

For the own-tables route, two open-source time-series stores fit this workload. TimescaleDB runs as a PostgreSQL extension and compresses data natively. QuestDB partitions a table by time automatically and presents it as one SQL-facing table, but its compression comes from the filesystem: the documented approach is a ZFS dataset with compression enabled under the database root directory.

The scripted restart, and why it stays in the toolbox #

Saving the provider's configuration on the gateway page restarts it with no code. The scripted equivalent, run from gateway scope, is:

from com.inductiveautomation.ignition.gateway import IgnitionGateway

# prov is a string: the provider name exactly as configured on the
# gateway's tag history page. "MyProvider" is an example value.
prov = "MyProvider"

context = IgnitionGateway.get()
tagHistMan = context.getTagHistoryManager()
tagHistProv = tagHistMan.getTagHistoryProvider(prov)
tagHistProv.shutdown()
tagHistProv.startup()

The proof it worked is in the gateway log — the provider shutdown and startup entries — followed by a store under the renamed path that reuses the existing row instead of inserting one. The call reaches into internal gateway classes that are not part of the supported scripting API and can change in any release, and running it while historian tables carry hand edits can corrupt the historian or destabilize the gateway, so keep it out of production. At several renames per second it also fails on its own terms: the provider would spend nearly all of its time reloading metadata.

Why a scheduled merge makes it worse #

The cache refills with the new id at the first post-rename store. A merge job that re-points that data to the old id and deletes the new row leaves the cache writing to an id that no longer exists, and it keeps writing there until the next restart. Every merge cycle strands more data than the last, and the only exit is the restart you were trying to avoid, with the scripted route's upgrade risk attached. Rule this option out completely.

Counting sqlth_te rows when one tag is renamed 100 times #

Inputs, with where each comes from:

  • One memory tag, history disabled in its configuration, stored only through system.tag.storeTagHistory — the deployment in question.
  • Retire-on-rename in force, so every rename retires one row and the next store creates one successor row.
  • N = 100 renames of that one tag, the round count at which leftover metadata rows stop being negligible in this kind of system.
  • The rename endpoint can fire several renames each second; the growth arithmetic uses 1 rename every second as the floor, with 86,400 seconds in a day and 365 days in a year.

Rule in words: retire-on-rename leaves the retired row in place and adds exactly one successor row per rename, so a path renamed N times ends up described by N + 1 rows, and a manual query that reconstructs the whole history must line up N + 1 created/retired windows.

Arithmetic, written out:

  • Rows for one tag: 100 renames + 1 original row = 100 + 1 = 101 rows.
  • Windows stitched per full-history query: 101.
  • Growth at the floor rate: 1 rename/s × 86,400 s/day = 86,400 new rows each day, and 86,400 rows/day × 365 days = 31,536,000 rows over a full year — metadata rows, before a single data row.

Result: 101 rows and 101 stitch windows for one tag at 100 renames, and roughly 31.5 million sqlth_te rows in a year if renames sustain even one every second.

Decision: up to about 100 renames on a path over its life, retire-on-rename is sound — 101 stitch windows are a query nuisance, not a failure. Above that count, or at anything near one rename every second sustained, move the store-and-retrieve workload to your own tables.

Which option fits your case #

  • You store and retrieve by script, and renames arrive several each second: your own tables. Nothing inside the gateway is touched and a rename costs one row update. The wider question of where those records should live is covered by choosing an edge data path for periodic records.
  • You need the built-in trend components and renames are rare: retire on rename. Trending walks successive rows for one path when the created and retired windows line up, and a few extra rows cost nothing at low rename counts.
  • One maintenance rename in a planned window: edit and save the provider configuration on the gateway page, by hand, once. Never per rename.
  • A rename has already split history you need back: that is a one-off repair — bridging Ignition tag history after a tag path change — not a recurring mechanism.
  • Every case: no scheduled merges.

Questions asked

Can I refresh the path cache without restarting the whole gateway?

Not through any supported call. No scripting function invalidates a single cache entry. Editing and re-saving the history provider's configuration on the gateway page restarts just that provider and reloads sqlth_te, which is the lightest reload available. The scripted equivalent reaches into internal SDK classes and is not part of the supported API, so treat it as a maintenance-window tool, never a per-rename step.

Do the duplicate rows break trends?

Two live rows with the same tagpath and no retired timestamp are the breaking case: a query cannot tell which tag id owns the path, and the data splits across both ids. When the older row carries a retired timestamp and the windows line up, retrieval can walk successive rows for one path, which is the state retire-on-rename leaves behind. Confirm with a manual query grouped by tag id before trusting a trend after a rename.

Why does storeTagHistory also add a sqlth_te row when a tag's datatype changes?

The function's manual page documents that a datatype change after history has been recorded creates a new entry in sqlth_te, because the table holds one row per unique version of a tag's historical configuration. The cache miss after your path edit lands in the same versioning logic: the historian believes it is meeting a new configuration and creates a new row for it.

What exactly should the rename endpoint write to sqlth_te?

One update per rename: set the existing row's tagpath to the new path and stamp its retired timestamp in the same statement, leaving the id untouched. The next store misses the cache and the historian creates the successor row itself. Do not delete the row and do not re-point its id, because the cache keeps mapping the old path to that id until a provider restart.

TimescaleDB or QuestDB for the replacement store?

If storage size leads, the PostgreSQL extension described above is the natural fit. QuestDB partitions a table by time automatically behind one SQL-facing table and needs no partition management, but its compression came from the filesystem at the time: the documented approach is a ZFS dataset with compression enabled under the database root. Pick the extension for compression inside the database, QuestDB for zero partition housekeeping.

Keep reading

  • Troubleshooting

    Why Ignition MQTT shows tagid None and what to key on

    tagid is None because the MQTT payload never carries it: tag IDs are indexes inside the Ignition tag history provider, assigned and retired as tag configuration changes. Key the lake on a site-scoped tag path with the site identity in the MQTT namespace, and trace duplicate sqlth_data_ table sets through their driver IDs in sqlth_drv before stopping the extra writer.

    Edge computing and IIoT

  • Troubleshooting

    Fix duplicate driver IDs after a Docker historian upgrade

    Duplicate rows in the historian driver table after a container upgrade mean the gateway identity changed: the data volume or hostname was not carried forward, so the historian opened a new driver ID and logged under it. Pin the volume and hostname, restart the history provider to flush its cached tag IDs, and rebuild the schema only after that. ID jumps of about 1,000 are database sequence caching, not a fault.

    Edge computing and IIoT

  • How-to

    Move an Ignition historian database with pre-copied partitions

    Yes, the drop-and-restore plan works, but the safer route pre-copies the whole database to the new server and moves only the sqlth_* metadata and the partitions still being written at cutover. Store-and-forward buffers history writes through the switch, so downtime is a delta copy and the history never has a hole.

    Edge computing and IIoT