Skip to content

Move InfluxDB data directory to a SDcard

For my openHAB system I installed InfluxDB (on a separate) Raspberry Pi. The Pi has a 32 GB SDcard, but that is not enough for storing all the data, and that Pi has additional work to do as well. For that reason I also attached a 1 TB disk to the Pi, and mounted it on /data. Now all I have to do is move the InfluxDB data directory to /data.

 

Continue reading "Move InfluxDB data directory to a SDcard"

Rename a database in MySQL

Ever tried to rename a database in MySQL? Obviously not.

Why not? MySQL does not support renaming databases. Funny, eh?

They once tried to implement this feature but failed and removed the code again. Note the sudden major feature shifts in minor releases.

So, how to rename a database? Dump the database, create a new database and import the dump. Both steps can be executed together:

mysqldump old_database | mysql new_database

Support your database!

Happened on IRC, just minutes ago:

22:35:09 -!- michi7x7 has joined #postgresql
22:35:14 < michi7x7> hi all
22:35:44 < michi7x7> i have a problem with a mysql-query, but #mysql is full of mysql-lover-noobs

Users start asking the PostgreSQL-guys for MySQL-support. Times are changing ;-)

MySQL: SQLSTATE[HY000]: General error: 3 Error writing file '/tmp/xyz' (Errcode: 28)

If you run MySQL and this error occurs:

 SQLSTATE[HY000]: General error: 3 Error writing file '/tmp/MYh0VgDS' (Errcode: 28)

then check if your server isn't using the famous "overflow" filesystem for /tmp, limited to 1 MB space.

The MySQL error message is - as usual - misleading and non-descriptive.

There are many other possible causes for this error code, so this one here might just be a hint.

MySQL creates rows out of nothing

After issuing a REPAIR TABLE:

 mysql> repair table search_archive_count_checked;
+----------------------------------+--------+----------+----------------------------------------------+
| Table                            | Op     | Msg_type | Msg_text                                     |
+----------------------------------+--------+----------+----------------------------------------------+
| xxx.search_archive_count_checked | repair | warning  | Number of rows changed from 335540 to 365874 |
| xxx.search_archive_count_checked | repair | status   | OK                                           |
+----------------------------------+--------+----------+----------------------------------------------+
2 rows in set (36.75 sec)

I'm surprised: this is the first database which is able to create rows out of nothing. Violation of the conversation of energy data, eh? ;-)

MySQL Kundenkonferenz aka Sun Roadshow 2008

Am 21. Oktober 2008 war ich auf der MySQL Kundenkonferenz 2008 in München.

Es ist schon erstaunlich wie man aus einer anscheinend guten Konferenz (Aussage mehrerer Teilnehmer über die vorherige Veranstaltung) eine reine Werbeveranstaltung machen kann. Gleich zu Beginn gab es eine lange Warteschlange im Foyer des Hilton Hotels, die Damen am Empfang waren mit den über 200 Teilnehmern anscheinend etwas überfordert. Kommt halt nicht jeden Tag vor das alle Teilnehmer kurz vor Konferenzbeginn ankommen. Das Frühstück bzw. das Essen überhaupt war gut, aber für jemanden der keinen Kaffee trinkt blieb dann nur Wasser oder ein paar Sorten Tee zum selbst zubereiten übrig.

Etwas verspätet begann die Veranstaltung mit der Eröffnung durch Kaj Arnö sowie einem Vortrag von Robin Schumacher über die nächsten Schritte bei MySQL. Version 5.1 soll demnach noch dieses Jahr, Version 6 dann nächstes Jahr erscheinen. Zum häufiger nachgefragten Thema "Storage Engines" wurden den ganzen Tag über nicht viele Aussagen getroffen.

Die Fachvorträge waren meines Erachtens ihren Namen nicht wert. Der Memcached Vortrag glänzte mit einigen Folien die die Struktur solch eines Setups beschreiben. Effektiv etwas neues oder auch mal einen Blick ins Detail gab es jedoch nicht, auch wurde viel Wert auf MySQL gelegt und der Memcached mehr oder weniger nebenbei abgehandelt. Der Vortrag über den MySQL Proxy blieb ebenfalls weit hinter den Erwartungen zurück: es gab oberflächliche Informationen, wie und wo man den Proxy einsetzen könnte. Dazu wurden Vorzüge wie z.B. Sharding beschrieben. Im gesamten Vortrag habe ich jedoch Hinweise auf die möglichen Nachteile vermisst die bei solch einem Setup auftreten können - erst Recht wenn der Proxy transparent zwischen Kundenanwendungen und Datenbanken geschaltet wird.

Der Vortrag über den Stand der MySQL-Integration in Sun beschreibt im wesentlichen was zu erwarten war: alles läuft nach Plan.

Am Nachmittag gab es dann das unerwartete Highlight des Tages: Miriam Tuerk hält einen spannenden deutsch/englisch-gemischten Vortrag über Infobright. Die Technologie dahinter ist im wesentlichen eine Storage-Engine welche für Data Warehouse Anwendungen optimiert ist. Diverse Metadaten werden gleich beim Schreiben der Daten mitgespeichert und im besten Fall können Anfragen aus diesen Metadaten beantwortet werden. Laut Aussage von David Lutz (Infobright) ist das Konzept auch gut zur Auswertung großer Mengen an Logdateien geeignet, also werde ich dem ganzen mal einen Versuch gönnen. Erwähnenswert ist außerdem dass das für mich die erste sinnvolle Anwendung der austauschbaren Storage-Engines in MySQL darstellt.

Der "MySQL Performance Tuning" Vortrag fiel dann wieder zurück auf das Niveau des gesamten Tages: einige wenig aussagekräftige Folien und der Informationsgehalt des Vortrags war an sich Null. Selbst die Vorführung des "Enterprise Monitor" Tools wollte nicht recht gelingen.

Die Fragestunde zum Schluß zeigte viele interessante und tiefgreifend technische Fragen die offensichtlich während der Konferenz keinen Platz gefunden haben. Das verleitet mich zu der Annahme das diverse Teilnehmer ebenfalls mit einer anderen Erwartungshaltung nach München gekommen sind. Robin Schumacher war hierbei in seinem Element und konnte/durfte die meisten Fragen beantworten.

Das sonst übliche "Netzwerken" nach dem Ende der Konferenz viel erstaunlich kurz aus. Innerhalb weniger Minuten waren die meisten Teilnehmer verschwunden - was wiederum Platz für Fragen bei den MySQL Leuten ergab. Dabei zeigte sich dann dass das niedrige Niveau der Konferenz keineswegs an den Vortragenden selbst lag: auf alle technischen Fragen gab es eine Antwort.

Die Folien zur Konferenz sollten spätestens zwei Wochen später auf der Webseite verfügbar sein. Sehr lange zwei Wochen später lag dann heute eine E-Mail in meinem Postfach: [Link zu den Folien]. Wenn ich mir andere Veranstaltungen - auch und gerade im Open Source Bereich - anschaue dann sind dort die Folien teilweise am gleichen Tag verfügbar.

Bleibt zu hoffen das die nächste Userkonferenz nicht wieder zur Produktshow verkommt.

Unterlagen für Vortrag und Workshop beim Open Source Tag in Magdeburg

Die Vortragsunterlagen für meinen Vortrag und meinen Workshop beim Open Source Tag an der Universität in Magdeburg sind online:

Vortrag: Welche Datenbank? Warum PostgreSQL? (PDF)

Workshop: PostgreSQL optimieren. (PDF)

Understanding SQL

Just have to port a phpkit database to something else. It seems, the phpkit ppl did not really understand what SQL is for.

The 'phpkit_config' table in this case contains 255(!) columns and a lot of this columns seems to be for extensions.

This is a very good example where you should use normalization: you don't add more and more columns to one table but you have a key/value table and for new entries you add a new key with a value. No need to change the table at all.

Performance issues

Last year, tweakers.net did some performance tests with MySQL and PostgreSQL and they found out that MySQL did not scale very well with many concurrent connections.


Now Kris Kennaway did some tests on his own and posted the results to the FreeBSD performance list. The resulting graphs look very similar.

Primary key in Mysql doubled

Got a nice problem: a table, which has the following primary key: id, id.

You can use or dump this table without problems ... but you cannot reinsert the dump into the same (4.1) or a newer (5.0) mysql version.

This is the table dump, created with "SHOW CREATE TABLE tablename":

----- cut -----
CREATE TABLE tablename (
id int(11) NOT NULL auto_increment,
title_en text,
...
PRIMARY KEY (id,id)
) TYPE=MyISAM DEFAULT CHARSET=latin1;
----- cut -----

Now i try to reinsert this table into another database:

----- cut -----
mysql> CREATE TABLE tablename (
-> id int(11) NOT NULL auto_increment,
-> title_en text,
...
-> PRIMARY KEY (id,id)
-> ) TYPE=MyISAM DEFAULT CHARSET=latin1;
ERROR 1060 (42S21): Duplicate column name 'id'
----- cut -----

What the ...


Should i repeat myself?

Pitfalls of missing transactions when handling multiple inserts in Mysql

Imagine, you have a table and a colum is defined NOT NULL. You (and i) expect, that NULL arguments will not go into the table but instead get rejected.


----- cut -----

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.41-log Source distribution

mysql> CREATE TABLE notnulltest (id INT, test TEXT NOT NULL);
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO notnulltest (id, test) VALUES (1, NULL);
ERROR 1048 (23000): Column 'test' cannot be null
mysql> INSERT INTO notnulltest (id, test) VALUES (1, NULL), (2, NULL);
Query OK, 2 rows affected, 2 warnings (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 2

mysql> SELECT id, test FROM notnulltest;
+------+------+
| id | test |
+------+------+
| 1 | |
| 2 | |
+------+------+
2 rows in set (0.00 sec)

mysql> SELECT id, test FROM notnulltest WHERE test IS NULL;
Empty set (0.00 sec)
----- cut -----


So whats going on here?


Since Mysql had no transactions (in the past), it tries to avoid any error in multi-column inserts. Without transactions, the insert cannot be rolled back, so an error would leave an unknown number of inserted rows around and the application had to deal with the problem. For Mysql it seems a far better solution to modify your data so it fit's the requirements.


Worth mentioning, this is the default behaviour in a recent (5.0.41) mysql version, installed from source, with no config modifications.

f* Mysql

Today I woke up because the Nagios used by our isp sent me a sms: something does not work well on one of the association servers. According to the sms, the webserver was not responding. Ok, the webserver is never the cause of the problem, something else is going wrong.

 

Logged in over ssh, at least this works well. ps told me that the nightly database backup is hanging around, a script which fills some tables is also waiting. Mysql shell does not really work. Disc space? Ok, enough free space.

 

Shutting down webserver and database, killed all scripts hanging around and restarted the db. After a while, I got an error mail:

 

 

xxxxxxx.xxxxxx_gaestebuch
warning  : Table is marked as crashed and last repair failed
warning  : Size of indexfile is: 281307136      Should be: 267612160
error    : Found 5174283 keys of 5174282
error    : Corrupt

 

Nice ...

Ok, Let's repair the beast. myisamchk seems to work his way through the table, until I got this message:

 

myisamchk: warning: 301 records have been removed

 

So this wannabe database just deleted 301 datasets for whatever reason. Nice to see how data integrity is not handled at all.

 

I'm happy at all that the new platform is coming around, betatest just started yesterday. It's time to kick Mysql in the ass and use a real database.