# How to restore tag history from one database to another?

**URL:** <https://forum.inductiveautomation.com/t/how-to-restore-tag-history-from-one-database-to-another/64602>\
**Category:** Ignition\
**Created:** [September 28, 2022, 2:17pm UTC](https://forum.inductiveautomation.com/t/how-to-restore-tag-history-from-one-database-to-another/64602 "2022-09-28T14:17:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattn1](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mattn1](https://forum.inductiveautomation.com/u/mattn1)\
**Post date:** [September 28, 2022, 2:17pm UTC](https://forum.inductiveautomation.com/t/how-to-restore-tag-history-from-one-database-to-another/64602/1 "2022-09-28T14:17:04Z")

</div>

Hey all,

I have a customer that had filled a database unexpectedly. My first reaction when I arrived onsite was to start storing current data to another database.

I then figured out what was going on with db1, extended the memory in the needed partition.

So now I need to restore db1 as the database, but I want to include the tag history db2 has captured in the mean time.

I would imagine I just do a dump of the sqlt\_data\_1\_2022\_09 table and then insert that into the db1.

Will I run into any indexing issues? I really don’t understand how the tag historian schema works, will I run into any primary key index issues?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 28, 2022, 2:22pm UTC](https://forum.inductiveautomation.com/t/how-to-restore-tag-history-from-one-database-to-another/64602/2 "2022-09-28T14:22:12Z")

</div>

Historized tags are referenced in sqlth\_te. The sqlt\_data\_X\_XXX\_XX partitions have a `tagid` foreign key, which matches the `id` primary key from sqlth\_te.  
If you want to insert stuff in a sqlt\_data partition, you’ll need to make sure that the ids from both databases’ sqlth\_te match. Which is probably not the case, and will make your life a nightmare if you try to move things from one db to another.

I have no good solution to suggest here, I’m just warning you that simply copying stuff from one sqlt\_data to another won’t be enough.

---

<div class="post-metadata">

**Author:** ![mattn1](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mattn1](https://forum.inductiveautomation.com/u/mattn1)\
**Post date:** [September 28, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/how-to-restore-tag-history-from-one-database-to-another/64602/3 "2022-09-28T14:28:52Z")

</div>

Thanks for the info.

I guess I will go ahead and restore db1 and start collecting current data from there.

It will be painful but I guess could make a chart that shows the id info from sqlth\_te on db1 and db2 then manually edit the tag id to match db1 on the sqlt\_data\_1\_2022\_09.

edit:  
I had also reached out to support this morning and just got a response. Sounds like they are directing me the same way. They included a helpful link to an ignition database document.

> Ignition has a lot of systems built in that will query the database automatically without requiring you to build a query. Because of this, there will be a couple tables that are created in order to store the tag history data from the tags. The sqlth\_te contains information about the tag but the tag's data will not be stored in this table. It will have the id, tag path and so on. The sqlt\_data\_X\_X table will contain the actual tag history data from the tags.
> 
> Since you also have 2 different databases and one holding new data and the other one is holding old data, you could combine the 2 databases and adjust the tag id for the data inside the database. Basically you would be changing tag id to merge all the data.
> 
> Here is a detailed documentation on database tables and it also has a flow chart showing how all the tables are connected to each other. [Ignition Database Table Reference - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Ignition+Database+Table+Reference)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 28, 2022, 2:35pm UTC](https://forum.inductiveautomation.com/t/how-to-restore-tag-history-from-one-database-to-another/64602/4 "2022-09-28T14:35:35Z")

</div>

Good luck with that (Most of my historian partitions have more than 15 million entries)

You could use the `tagpath` column to match tags and correct the `id`, but that’s out of what I can do with SQL 😃
