I am trying to get my mariadb database size into HA via the sql sensor. HA 2022.6.4 and the mariadb addon. The addon works fine, but the SQL sensor won’t configure. It keeps telling me the SQL query is invalid in the dialog. (Never mind the aggravation that every time that happens you have to complete the full form again - who thought of that as a positive UX?)
The query is straight out of the docs, for the size of the database
'SELECT table_schema "database", Round(Sum(data_length + index_length) / 1024, 1) "value" FROM information_schema.tables WHERE table_schema="homeassistant" GROUP BY table_schema;'
the only difference with the docs is specifying table_schema="homeassistant"
, which is what is says to do in the docs, to take into account what I named my database.
Change
table_schema="hass"
to the name that you use as the database name, to ensure that your sensor will work properly.
The other panels in the setup dialog are filled in as follows:
Select SQL Query - DB Size
Database URL - left blank as this is the default recorder database
The SQL integration will connect to default recorder if Database URL is not specified. (docs)
Column - value
Use
value
as column for value.
I have tried to use single quotes 'SELECT... '
double quotes "SELECT..."
and no quotes SELECT...
in the query - the docs use all three, but none of them work. I is always the same response.
If I enter the mariadb addon container, the query works fine
MariaDB [(none)]> SELECT table_schema "database", Round(Sum(data_length + index_length) / 1024, 1) "value" FROM information_schema.tables WHERE table_schema="homeassistant" GROUP BY table_schema;
+---------------+-----------+
| database | value |
+---------------+-----------+
| homeassistant | 9951920.0 |
+---------------+-----------+
1 row in set (0.001 sec)
Any help appreciated!