# Alarm on Database Errors (Database Disc Full)

**URL:** <https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916>\
**Category:** Ignition\
**Tags:** ignition81, database\
**Created:** [October 29, 2024, 6:31pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916 "2024-10-29T18:31:28Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 29, 2024, 6:31pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/1 "2024-10-29T18:31:28Z")

</div>

I have a database that filled up last week. The disk hand plenty of space so I've since expanded it but it may happen again.

I want to be able to generate an alarm if the database is full, or if tag history has other issues.

I see some database system tags in the tag browser, but I'm unsure which one(s) to check, or if there is some other way I should be doing it.

Is there more detail available on these tags in the manual?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/3/a35727b0f269e99878b5f3c32af5af2026be4b5c.png)

TIA

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [October 29, 2024, 7:39pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/2 "2024-10-29T19:39:03Z")

</div>

I haven't seen anything to detect this as far as a tag on Ignition. Even when the drive is full the database connection would still be alive and well. Remember, the database can never get full, it's the drive that runs out of space. You may need to have something on the database side that checks for drive space.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [October 29, 2024, 7:42pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/3 "2024-10-29T19:42:08Z")

</div>

If you are on windows, you might be able to use `system.util.execute` and `wmic`

[Monitor CPU load of DB Server - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/monitor-cpu-load-of-db-server/43939)

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 31, 2024, 5:55pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/4 "2024-10-31T17:55:40Z")

</div>

@paul-griffith

Any insight on this?

Maybe I could script a periodic query of the database to check the status and write to a tag if it's got an issue?

---

<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:** [October 31, 2024, 5:59pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/5 "2024-10-31T17:59:42Z")

</div>

The system tags are what we have to give you. If the disk is full, it's up to the DB to report that to clients (like Ignition) by failing incoming connections. If it doesn't do that, there's not a lot you can do inside of Ignition.

Maybe you can come up with some kind of query you can run periodically that reports from inside the DB, but it'll be specific to whatever your flavor of DB is.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [October 31, 2024, 6:23pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/6 "2024-10-31T18:23:47Z")

</div>

I found this query that might help with your task

```python
select 
    table_schema, sum((data_length+index_length)/1024/1024) AS MB 
from 
    information_schema.tables 
group by 1

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 31, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/7 "2024-10-31T18:54:52Z")

</div>

I'm not an expert in SQL. How would I use this with the default tag history tables?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [October 31, 2024, 7:00pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/8 "2024-10-31T19:00:16Z")

</div>

I saw your connection was named MySQL, so that query should give you every table size in a MySQL/MariaDB schema. If you are pointing your tag historian to your MySQL instance, it should include it.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 31, 2024, 7:32pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/9 "2024-10-31T19:32:39Z")

</div>

That was just a generic name, it's actually an MSSQL database

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [October 31, 2024, 7:47pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/10 "2024-10-31T19:47:17Z")

</div>

I don't know much about MSSQL, you'll have to refer to google  
[How To Check Disk Space in SQL Server (mssqltips.com)](https://www.mssqltips.com/sqlservertip/6731/how-to-check-disk-space-in-sql-server/)

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 5, 2024, 2:18pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/11 "2024-11-05T14:18:46Z")

</div>

I know some of these are partitions, event data, alarm data, etc. Which of these tables is the "active" tag history data table? (the one that I would need to check to see if the disk is full or not).

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/39be956a88eb7424f8161413ee187d13943883d7.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [November 5, 2024, 2:25pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/12 "2024-11-05T14:25:46Z")

</div>

Would it be better to enable/setup data pruning on your history provider? You should be able to estimate the storage needed from your history `Prune Age`.

---

<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:** [November 5, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/13 "2024-11-05T15:58:35Z")

</div>

> [@amarks](#):
>
> Which of these tables is the "active" tag history data table?

_Technically_, the answer is "whichever table is identified by a row in `sqlth_partitions` where `sqlth_partitions.start_time < CURRENT_TIMESTAMP() <= sqlth_partitions.end_time`".

Practically, the answer is "whichever table has the right drvid (the `_1_` in your screenshot) and the higher calendar index" until/unless you change your partitioning scheme.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 6, 2024, 2:18pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/14 "2024-11-06T14:18:42Z")

</div>

What do you think about a script like so?

- Run an update query to insert a row.
- If the update is successful, run another update query to remove the inserted row.
- If the update is unsuccessful, write to an alarm tag.
- Reset button clears the alarm tag.

Would that first update query throw an error if the database was full?

Or, is there a way to check store and forward engine statistics/diagnostics?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [July 7, 2025, 9:50pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/15 "2025-07-07T21:50:40Z")

</div>

I have found a query that answers part of what I was looking for. This query gets the disc size for the SQL database for `TagHistory`. The database is set to autogrow so this number should reduce as the database expands.

query (does require `view server state` permissions):

```python
{'disc':string}

SELECT 
    CONVERT(DECIMAL(18,2), vs.available_bytes / 1073741824.0) AS [Available Space (GB)]
FROM sys.master_files AS mf
CROSS APPLY sys.dm_os_volume_stats(mf.database_id, mf.file_id) AS vs
WHERE 
    DB_NAME(mf.database_id) = 'TagHistory'
    AND vs.volume_mount_point = :disc;

```

expression tag for disc size:

```python
runScript("Data.getDatabaseServerDiscUsable()")

```

expression tag for disc low with alarm configured:

```python
{[.]../Database_Drive_Available_Space} < {SQL_Alarm_Threshold}

```

script:

```python
def getDatabaseServerDiscUsable(discLetter = "F"):
	'''
		Get the usable disc space in GB on the SQL server disc (default F)
	'''
	
	
	return system.db.runNamedQuery('Get_DB_Disc_Avail', { 'disc' : discLetter+':\\' })[0][0]

```

---

<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:** [July 7, 2025, 10:27pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/16 "2025-07-07T22:27:18Z")

</div>

Why use an expression binding to call a script to call the named query, instead of using a query binding ?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [July 8, 2025, 6:39pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/17 "2025-07-08T18:39:53Z")

</div>

I've got the query parameterized so that I can reuse it and easily update the drive letter.

---

<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:** [July 9, 2025, 6:59am UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/18 "2025-07-09T06:59:16Z")

</div>

You can pass parameters to your query with query bindings too...

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [July 9, 2025, 1:53pm UTC](https://forum.inductiveautomation.com/t/alarm-on-database-errors-database-disc-full/97916/19 "2025-07-09T13:53:10Z")

</div>

¯\_(ツ)_/¯
