# Dangerous way to make SQLite config DB smaller

**URL:** <https://forum.inductiveautomation.com/t/dangerous-way-to-make-sqlite-config-db-smaller/103591>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [March 12, 2025, 5:06pm UTC](https://forum.inductiveautomation.com/t/dangerous-way-to-make-sqlite-config-db-smaller/103591 "2025-03-12T17:06:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [March 12, 2025, 5:06pm UTC](https://forum.inductiveautomation.com/t/dangerous-way-to-make-sqlite-config-db-smaller/103591/1 "2025-03-12T17:06:30Z")

</div>

I am in no way recommending anyone do this, but while doing some debug tasks that involved digging through Ignition's internal TAGCONFIG database I noticed that the JSON fields include a lot of white space.

Out of curiosity, I decided to minimize all of the JSON fields and see how much space it would save. I did an SQLite `VACUUM` both before and after to ensure it was a meaningful comparison. For reference, we have over 1.2 million tags...

Before = 960MB  
After = 790MB

This is not an insignificant change. I have not yet tried to reload this config back into Ignition, but I'm expecting it should go easily and will be trying it soon on a test system.

For the truly brave of heart:

```python
import json
import sqlite3

# SQLite has a built in json() function which is supposed to verify that its 
# argument X is valid JSON and return a minified version.
# I originally tried this with: UPDATE TAGCONFIG SET CFG=JSON(CFG)
# but it flagged some of my TAGCONFIG entries as invalid.
# Python's json.loads() had no such complaints about those same entries.
# So, we minify them using Python... :/

db_connection = sqlite3.connect('ignition_config.idb')
print('Loading...')
all_tags = [x for x in db_connection.execute('SELECT ID, CFG FROM TAGCONFIG')]
print('Scanning...')
param_list = []
for tag_id, cfg in all_tags:
	repack_cfg = json.dumps(json.loads(cfg), separators=(',', ':'))
	param_list.append((repack_cfg, tag_id))
print('Updating...')
db_connection.executemany('UPDATE TAGCONFIG SET CFG=? WHERE ID=?', param_list)
db_connection.commit()
print('Done!')
db_connection.close()

```

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [March 12, 2025, 5:23pm UTC](https://forum.inductiveautomation.com/t/dangerous-way-to-make-sqlite-config-db-smaller/103591/2 "2025-03-12T17:23:30Z")

</div>

And for what it's worth, I went back to look more carefully at the TAGCONFIG entries that sqlite flagged as not valid JSON, and all of them have NaN or Infinity jammed into a float value. I'm pretty sure I know how those values got into Ignition, even though Ignition tries to prevent it. And I can confirm Ignition has odd behavior when a float tag has one of those as a value. 😛

Maybe I should adjust those to more mundane float values...

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [March 12, 2025, 5:36pm UTC](https://forum.inductiveautomation.com/t/dangerous-way-to-make-sqlite-config-db-smaller/103591/3 "2025-03-12T17:36:35Z")

</div>

I can attest that just using json dumps for tag configs has worked reliably for me assuming the json itself is wellformed

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 13, 2025, 2:38pm UTC](https://forum.inductiveautomation.com/t/dangerous-way-to-make-sqlite-config-db-smaller/103591/4 "2025-03-13T14:38:07Z")

</div>

I'm pretty confident you could do this all-in-one via sqlite; it has a builtin `json` function that automatically minifies:

> **[JSON Functions And Operators](https://www.sqlite.org/json1.html#jmini)**

EDIT: Lol nevermind, you already have a comment addressing that.

* * *

Not really sure why we aren't doing that ourselves for storage... ~~definitely~~ probably just an oversight.
