System.tag.queryTagHistory() doesn't work with Imported Data

Hi,

I have a test gateway that I am using to see how my one of my report scripts run with production gateway data. This test gateway is copy of a production gateway, so all its tags were imported with the project as well as the tag history.

When I run System.tag.queryTagHistory() to test the data grab:

start = system.date.parse('April 1, 2025 00:00','MMMM dd, yyyy hh:mm')
end = system.date.parse('April 30, 2025 00:00','MMMM dd, yyyy hh:mm')
path = '[EHS]EHS/B2 Permit/Incoming Water/CH00243/Total'
history =system.tag.queryTagHistory([path],startDate=start, endDate= end, ignoreBadQuality=True,noInterpolation=True)
print(history.getRowCount())

I get a row count of 0.

However, when I search for the same tag path '[EHS]EHS/B2 Permit/Incoming Water/CH00243/Total' in the sqlth_te table I find 3 tags:

I then go and check that see if any of the IDs associated to the tagpath have data in the table sqlt_data_1_2025_04 . Of the 3 IDs associated with the tag path, only one has data in the table, this being ID 1951.

So I am sure the data is present in the system, and so something is happening when I try to grab it.

This situation is the same across all the tags. There are 3 IDs per tag path, with only one of them, the second one, having data.

Things I've tried to fix this:

  1. Setting the newest ID to retired in the sqlth_te table so that the second tag will be referenced when calling the system.tag.queryTagHistory(). This did nothing.

  2. Change the SCID of the row that has the ID corresponding to data to the SCID that corresponds the newest ID for the tag of interest. This did nothing.

  3. Change the SCID of the row that corresponds the newest ID to the SCID that corresponds the row that contains the ID that has data in sqlt_data_1_2025_04. This did nothing.

I am not sure where to go from this point. I was attempting to use this as reference: Ignition Database Table Reference
so that I could manipulate the system to access the correct ID and/or partition for a tag, but I can't seem to figure it out.

Any suggestions? Thank you

I'd first check why you have 3 entries with the same tag path. Compare with your production DB, see if you observe the same thing.
The difference in scid means that this tag's group has been changed, but having several entries for the same tagpath, with none of them being retired, seems very weird to me.

Tag history checks gateway names. If your copied gateway has a different name, then you have to fix all the history records to match.

Unfortunately I don't have access to production server backend. If I were to start over and have someone re-import the historical data from production while keeping the original tags in the test server, how would you do it and would it be a fix?

I tried this and it unfortunately did not cause system.tag.queryTagHistory() to grab the data. Let me show you a deeper dive into my tables, maybe this will provide some insight:

Sqlth_te when I run it for one tagpath:

As you can see scid = 1

sqlth_scinfo:

sqlth_drv:
Note I colored out the name column but I can confirm it's the name of the test server gateway.

sqlth_partitions:
Notice how there is a sqlt_data_3_2025_05. This has some data in it as well. I don't really know where it came from. Maybe the system created it for the tags in my test gateway and that is why I can't access the other partitions. However since I've changed drvid to drvid = 1 so that the scid = 1 traces to the correct partitions, I don't think causing the problem.

Should I just try to have the data reimported into the test server? If so, what should I look out for so that this problem doesn't occur again?

Thank you

Have you restarted after editing the metadata? (The historian subsystem caches this stuff.)

Try going to your _drv table, duplicate your first line but put id=2 then put the first line's provider as NULL instead. Then alter _scinfo and set both drvid entries to be 2.

I tried this but I am still getting 0 from:

history =system.tag.queryTagHistory([path],startDate=start, endDate= end, ignoreBadQuality=True,noInterpolation=True)

print(history.getRowCount())

I tried some other tag paths just as a sanity check and its 0 for those as well.

Yes I have, it doesn't make a change.

I have discovered why I have 3 entries with the same tag path for all my paths. Originally, the production server only has two per path, with one being retired. However, when this data was imported into my test server, the name column of sqlth_drv contained the production server's name, not the test server's. This caused a third ID/entry to be created in sqlth_te for all the tags in the test server that have history enabled, with these new entries having a scid = 2 rather than scid =1. Additionally, new sqlth_drv entries were automatically created with the name column being the test server name this time. Furthermore, a new partition was created for May historical data. All my partition tables are titled sqlt_data_1_2025_xx, but this new one has a partition of sqlt_data_3_2025_05. After figuring this out I thought I could simply change the name column of sqlth_drv to the test gateway name for all entries, change the scid of the entries to 1 in sqlth_te, retire entry containing previous ID in sqlth_te, and lastly change the entries in my partition tables so that old IDs are changed to the new ones that were automatically created. This however did not work :frowning: .

Do you have any recommendations on what to do? If I have the data re-imported but with the correct test gateway name in sqlth_drv will I have this problem again? Can I fix the issue without reimporting?

Hmmm. Sounds familiar.... :man_shrugging:

Consider opening a support ticket so IA can look over your shoulder. No telling how scrambled your data is.

Will do, thanks! If I do decide to just have the data reimported, but with the correct gateway name (test gateway name) in sqlth_drv, would this however fix my issue?

Also thinking back on your question about restarting, what do you mean exactly? I don't have capabilities to reset the gateway as decribed in this doc: Gateway Command-line Utility - gwcmd

However I can save the project on the gateway in the designer which does show some restart information in the logs:
{71B29E96-06C1-42DF-9147-A59C752E7A63}

Additionally, when I close out of the project on designer, then re-login into my test gateway (or any gateway), I can see that my projects are loading on the gateway.

Do either of these count as restarts?

Should, yes.

No. You have to restart the gateway service or the whole machine.

I probably should have pointed you here: