<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Repariere SQL-Datenbank]]></title><description><![CDATA[<p dir="auto">Hallo,</p>
<p dir="auto">um die SQL-Datenbank mal wieder auf einen konsistenten Stand zu bringen bin ich wie folgt vorgegangen:</p>
<p dir="auto">Erweitere die Datenbank:</p>
<p dir="auto">(PS: mit mysql iobroker -pPASSWORT -e "sql…" kann man SQL-Kommandos starten )</p>
<p dir="auto">Achtung: Ja nach DB-Größe laufen die Kommandos durchaus ein paar Minuten</p>
<pre><code>ALTER TABLE `datapoints` ADD `type0` BIGINT NOT NULL COMMENT 'Number' ;
ALTER TABLE `datapoints` ADD `type1` BIGINT NOT NULL COMMENT 'String' ;
ALTER TABLE `datapoints` ADD `type2` BIGINT NOT NULL COMMENT 'Bool' ;

</code></pre>
<p dir="auto"><img src="/assets/uploads/files/609_sql0.jpg" alt="609_sql0.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto">Fülle die neuen Spalten. Wenn mehr als eine gefüllt ist, ist der Datenpunkt korrupt.</p>
<pre><code>UPDATE datapoints SET datapoints.type0 = (SELECT count(*) FROM ts_number WHERE id =  datapoints.id  group by id)
UPDATE datapoints SET datapoints.type1 = (SELECT count(*) FROM ts_string WHERE id =  datapoints.id  group by id)
UPDATE datapoints SET datapoints.type2 = (SELECT count(*) FROM ts_bool WHERE id =  datapoints.id  group by id)

</code></pre>
<p dir="auto">Jetzt suche alle, die nicht konsistent sind:</p>
<pre><code>SELECT * FROM datapoints WHERE (type = 0 and (type1&gt;0 or type2&gt;0)) or (type = 1 and (type0&gt;0 or type2&gt;0)) or (type = 2 and (type1&gt;0 or type0&gt;0))
</code></pre>
<p dir="auto">Das waren bei mir mal so schlappe 120 Datenpunkte (basierend auf den div. Fehlern im sql-Adapter).</p>
<p dir="auto">Jetzt muß man leider per Hand jeden durchgehen und den richtigen Typ setzen.</p>
<p dir="auto">Ein Anhaltspunkt ist meistens dafür wo die meisten Datenpunkte geschrieben wurden.</p>
<pre><code>type 0 = Number
type 1 = String (Zeichenkette)
type 2 = bool (Wahrheitswert)

</code></pre>
<p dir="auto">Leider bleiben jetzt noch die leeren Datenpunkte (also wo noch nie etwas geloggt wurde oder die zu alt sind und nicht mehr verwendet)</p>
<pre><code>SELECT * FROM `datapoints` where type0+type1+type2=0
</code></pre>
<p dir="auto">Auch hier muss man nach den obigen Muster vorgehen. Oder man löscht die Punkte (da hier in den letzten Jahren nichts passiert ist).</p>
<p dir="auto">(EXECUTE, PRESS und STATE sind meist bool)</p>
<p dir="auto">Wenn die typen alle stimmen, dann:</p>
<pre><code>DELETE FROM ts_number WHERE id not in (select id from datapoints where type=0)
DELETE FROM ts_string WHERE id not in (select id from datapoints where type=1)
DELETE FROM ts_bool WHERE id not in (select id from datapoints where type=2)

</code></pre>
<p dir="auto">Jetzt sollte</p>
<pre><code>SELECT * FROM datapoints WHERE (type = 0 and (type1&gt;0 or type2&gt;0)) or (type = 1 and (type0&gt;0 or type2&gt;0)) or (type = 2 and (type1&gt;0 or type0&gt;0))
</code></pre>
<p dir="auto">keine Zeilen mehr als Ergebnis liefern.</p>
<p dir="auto">Für mich habe ich</p>
<pre><code>mysql iobroker -pPASSWORT -e "UPDATE datapoints SET datapoints.type0 = (SELECT count(*) FROM ts_number WHERE id =  datapoints.id  group by id)"
mysql iobroker -pPASSWORT -e "UPDATE datapoints SET datapoints.type1 = (SELECT count(*) FROM ts_string WHERE id =  datapoints.id  group by id)"
mysql iobroker -pPASSWORT -e "UPDATE datapoints SET datapoints.type2 = (SELECT count(*) FROM ts_bool WHERE id =  datapoints.id  group by id)"

</code></pre>
<p dir="auto">in eine Batchdatei geschrieben und lasse das einmal Nachts ausführen, so habe ich immer eine aktuelle Statistik.</p>
]]></description><link>https://forum.iobroker.net/topic/10916/repariere-sql-datenbank</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Apr 2026 18:44:55 GMT</lastBuildDate><atom:link href="https://forum.iobroker.net/topic/10916.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Feb 2018 07:55:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Tue, 22 May 2018 21:24:09 GMT]]></title><description><![CDATA[<p dir="auto"><s><a class="plugin-mentions-user plugin-mentions-a" href="/user/apollon77" aria-label="Profile: apollon77">@<bdi>apollon77</bdi></a>:</s></p>
<blockquote>
<p dir="auto">In deiner sql-datenbank! Ist eine Datenbank tabelle `<br />
Ja, gefunden. War tatsächlich datapoints.</p>
</blockquote>
<p dir="auto">Da ich mein Passwort nicht mehr wusste für die Datenbank, habe ich neues erstellen müssen. Nun kriege ich leider sql nicht mehr ans Laufen, vorher ging immer "sudo mysqladmin flush-hosts"… nun hat root kein Zugriff mehr 'Acces denied for user 'root'@'localhost' (using password : no).... morgen probiere ich weiter...</p>
]]></description><link>https://forum.iobroker.net/post/153665</link><guid isPermaLink="true">https://forum.iobroker.net/post/153665</guid><dc:creator><![CDATA[lobomau]]></dc:creator><pubDate>Tue, 22 May 2018 21:24:09 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Tue, 22 May 2018 17:36:09 GMT]]></title><description><![CDATA[<p dir="auto">In deiner sql-datenbank! Ist eine Datenbank tabelle</p>
]]></description><link>https://forum.iobroker.net/post/153629</link><guid isPermaLink="true">https://forum.iobroker.net/post/153629</guid><dc:creator><![CDATA[apollon77]]></dc:creator><pubDate>Tue, 22 May 2018 17:36:09 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Tue, 22 May 2018 16:59:05 GMT]]></title><description><![CDATA[<p dir="auto"><s><a class="plugin-mentions-user plugin-mentions-a" href="/user/apollon77" aria-label="Profile: apollon77">@<bdi>apollon77</bdi></a>:</s></p>
<blockquote>
<p dir="auto">Es gibt die Tabelle iobroker.datapoints (glaube ich mich zu entsinnen oder leicht anders) wo die ids zu Objekt-IDs zugeordnet sind. Da findest du die Info. `<br />
Danke für den Tipp. Kannst du mir grob sagen wo ich suchen kann nach dieser Tabelle? In einem der Ordner unter /opt/iobroker/ oder unter Objekte?</p>
</blockquote>
]]></description><link>https://forum.iobroker.net/post/153619</link><guid isPermaLink="true">https://forum.iobroker.net/post/153619</guid><dc:creator><![CDATA[lobomau]]></dc:creator><pubDate>Tue, 22 May 2018 16:59:05 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Tue, 22 May 2018 16:12:05 GMT]]></title><description><![CDATA[<p dir="auto">Es gibt die Tabelle iobroker.datapoints (glaube ich mich zu entsinnen oder leicht anders) wo die ids zu Objekt-IDs zugeordnet sind. Da findest du die Info.</p>
]]></description><link>https://forum.iobroker.net/post/153611</link><guid isPermaLink="true">https://forum.iobroker.net/post/153611</guid><dc:creator><![CDATA[apollon77]]></dc:creator><pubDate>Tue, 22 May 2018 16:12:05 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Tue, 22 May 2018 09:33:12 GMT]]></title><description><![CDATA[<p dir="auto">Ich habe immer folgende Fehlermeldung. Jemand eine Idee wie ich das Objekt mit der id=593 finde? Vielleicht finde ich dann die Ursache?</p>
<pre><code>sql.0	2018-05-22 11:30:29.219	error	Cannot delete DELETE FROM `ioBroker`.undefined WHERE id=593 AND ts &lt; 1495445400200;: Error: ER_NO_SUCH_TABLE: Table 'ioBroker.undefined' doesn't exist
</code></pre>
]]></description><link>https://forum.iobroker.net/post/153559</link><guid isPermaLink="true">https://forum.iobroker.net/post/153559</guid><dc:creator><![CDATA[lobomau]]></dc:creator><pubDate>Tue, 22 May 2018 09:33:12 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Sat, 17 Feb 2018 09:06:10 GMT]]></title><description><![CDATA[<p dir="auto"><s><a class="plugin-mentions-user plugin-mentions-a" href="/user/apollon77" aria-label="Profile: apollon77">@<bdi>apollon77</bdi></a>:</s></p>
<blockquote>
<p dir="auto">Der Typ in der dB der gesetzt ist gewinnt an sich es sei denn ein „speichern als“ ist gesetzt. Wenn beiden nicht da ist dann wird der offizielle Typ des Objekts genommen. So sollte es sein. `</p>
</blockquote>
<p dir="auto">Ja, das scheint auch so zu sein. Bis getern 18:45 hat er aber unter Number gespeichert. Und auch gelesen.</p>
<p dir="auto">Ab dann hat er sich für String entschieden. Was ja auch funktioniert. Mich hat es nur gewundert, das es nur für diese Wert so ist.</p>
]]></description><link>https://forum.iobroker.net/post/132690</link><guid isPermaLink="true">https://forum.iobroker.net/post/132690</guid><dc:creator><![CDATA[sissiwup]]></dc:creator><pubDate>Sat, 17 Feb 2018 09:06:10 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Sat, 17 Feb 2018 06:16:15 GMT]]></title><description><![CDATA[<p dir="auto">Der Typ in der dB der gesetzt ist gewinnt an sich es sei denn ein „speichern als“ ist gesetzt. Wenn beiden nicht da ist dann wird der offizielle Typ des Objekts genommen. So sollte es sein.</p>
]]></description><link>https://forum.iobroker.net/post/132665</link><guid isPermaLink="true">https://forum.iobroker.net/post/132665</guid><dc:creator><![CDATA[apollon77]]></dc:creator><pubDate>Sat, 17 Feb 2018 06:16:15 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Sat, 17 Feb 2018 05:47:29 GMT]]></title><description><![CDATA[<p dir="auto">Hallo,</p>
<p dir="auto">fast sauber, nur:</p>
<pre><code>id      name    type    type0   type1   type2   Zeit
541     tankerkoenig.0.stations.cheapest.e5.short       1       36866   20      0       0000-00-00 00:00:00
547     tankerkoenig.0.stations.cheapest.e10.short      1       36638   20      0       0000-00-00 00:00:00
554     tankerkoenig.0.stations.cheapest.diesel.short   1       36736   20      0       0000-00-00 00:00:00
557     tankerkoenig.0.stations.0.e10.short     1       26838   3       0       0000-00-00 00:00:00
559     tankerkoenig.0.stations.0.e5.short      1       27166   3       0       0000-00-00 00:00:00
568     tankerkoenig.0.stations.0.diesel.short  1       27041   3       0       0000-00-00 00:00:00
598     tankerkoenig.0.stations.1.diesel.short  1       27719   3       0       0000-00-00 00:00:00
608     tankerkoenig.0.stations.8.diesel.short  1       37852   19      0       0000-00-00 00:00:00
613     tankerkoenig.0.stations.8.e5.short      1       37618   19      0       0000-00-00 00:00:00
614     tankerkoenig.0.stations.5.e5.short      1       28453   7       0       0000-00-00 00:00:00
617     tankerkoenig.0.stations.1.e5.short      1       27883   3       0       0000-00-00 00:00:00
631     tankerkoenig.0.stations.2.e10.short     1       37516   20      0       0000-00-00 00:00:00
632     tankerkoenig.0.stations.2.e5.short      1       37541   20      0       0000-00-00 00:00:00
634     tankerkoenig.0.stations.8.e10.short     1       37476   19      0       0000-00-00 00:00:00
644     tankerkoenig.0.stations.9.e5.short      1       25786   2       0       0000-00-00 00:00:00
647     tankerkoenig.0.stations.9.diesel.short  1       25216   2       0       0000-00-00 00:00:00
649     tankerkoenig.0.stations.9.e10.short     1       25292   2       0       0000-00-00 00:00:00
673     tankerkoenig.0.stations.2.diesel.short  1       37535   19      0       0000-00-00 00:00:00
683     tankerkoenig.0.stations.3.e10.short     1       28897   6       0       0000-00-00 00:00:00
693     tankerkoenig.0.stations.3.diesel.short  1       29077   7       0       0000-00-00 00:00:00
695     tankerkoenig.0.stations.4.e5.short      1       28897   7       0       0000-00-00 00:00:00
699     tankerkoenig.0.stations.6.e10.short     1       27042   3       0       0000-00-00 00:00:00
705     tankerkoenig.0.stations.6.e5.short      1       27402   4       0       0000-00-00 00:00:00
711     tankerkoenig.0.stations.7.e5.short      1       28626   3       0       0000-00-00 00:00:00
715     tankerkoenig.0.stations.7.e10.short     1       28297   3       0       0000-00-00 00:00:00
719     tankerkoenig.0.stations.7.diesel.short  1       28402   3       0       0000-00-00 00:00:00
730     tankerkoenig.0.stations.3.e5.short      1       29203   6       0       0000-00-00 00:00:00
731     tankerkoenig.0.stations.5.e10.short     1       28338   7       0       0000-00-00 00:00:00
738     tankerkoenig.0.stations.6.diesel.short  1       26843   4       0       0000-00-00 00:00:00
744     tankerkoenig.0.stations.4.e10.short     1       28596   7       0       0000-00-00 00:00:00
748     tankerkoenig.0.stations.4.diesel.short  1       28746   7       0       0000-00-00 00:00:00
754     tankerkoenig.0.stations.5.diesel.short  1       28384   7       0       0000-00-00 00:00:00
</code></pre>
<p dir="auto">Warum da short von number auf string gewechselt ist?</p>
<p dir="auto">Im Datenpunkt steht allerdings auch Zeichenkette.</p>
<p dir="auto">Es sind keine "NULL" Werte mehr aufgetaucht. (Danke für den Schalter).</p>
]]></description><link>https://forum.iobroker.net/post/132663</link><guid isPermaLink="true">https://forum.iobroker.net/post/132663</guid><dc:creator><![CDATA[sissiwup]]></dc:creator><pubDate>Sat, 17 Feb 2018 05:47:29 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Fri, 16 Feb 2018 15:45:09 GMT]]></title><description><![CDATA[<p dir="auto"><s><a class="plugin-mentions-user plugin-mentions-a" href="/user/apollon77" aria-label="Profile: apollon77">@<bdi>apollon77</bdi></a>:</s></p>
<blockquote>
<p dir="auto">Interessant ist ob es jetzt "sauber "bleibt. Das würde mich besonders interessieren `</p>
</blockquote>
<p dir="auto">Ich werte das jetzt automatisch einmal am Tag aus. Wir werden sehen …</p>
]]></description><link>https://forum.iobroker.net/post/132548</link><guid isPermaLink="true">https://forum.iobroker.net/post/132548</guid><dc:creator><![CDATA[sissiwup]]></dc:creator><pubDate>Fri, 16 Feb 2018 15:45:09 GMT</pubDate></item><item><title><![CDATA[Reply to Repariere SQL-Datenbank on Fri, 16 Feb 2018 09:41:00 GMT]]></title><description><![CDATA[<p dir="auto">Interessant ist ob es jetzt "sauber "bleibt. Das würde mich besonders interessieren</p>
]]></description><link>https://forum.iobroker.net/post/132438</link><guid isPermaLink="true">https://forum.iobroker.net/post/132438</guid><dc:creator><![CDATA[apollon77]]></dc:creator><pubDate>Fri, 16 Feb 2018 09:41:00 GMT</pubDate></item></channel></rss>