Making ZoneMinder crash safer
Posted: Fri Mar 05, 2010 4:43 pm
Hi,
I'm using ZM 1.24.2, i have one camera that is constantly recording.
At the moment i have no UPS and everytime there was a power outage the computer automatically restarted and 90% of the time ZM won't function properly because of corrupt database tables (Usually the Frames table)
MyISAM is the tables type used by the ZM database. MyISAM is very fast, but old and has a very low chance of surviving a crash during a write operation, and has no automatic crash recovery.
The tables with most write activity are Stats, Frames and Events.
The other tables are modified usually only when configuration changes (by user).
A general rule is to use MyISAM for tables that are 95% read and 5% write, all tables except Stats, Frames and Events meet this description.
InnoDB is a newer table type, ACID compliant, supports transitions, has an automatic crash recovery and most importantly, has a much higher chance of surviving a crash during a write operation.
I changed my Stats,Frames and Events tables to use InnoDB.
I did this by shutting down ZM, dumping the database into a SQL file called backup.
Did another database dump, this time to a SQL file called innodb. I then deleted all tables in the database and opened the innodb.sql file and changed the TYPE=MyISAM to TYPE=InnoDB in the CREATE TABLE statement for the tables Stats, Frames and Events.
Then i loaded this SQL file and fired up ZM and everything works great, had few power outages since but ZM always recovered like nothing happened.
InnoDB is by default compiled into MySQL in most distros, and InnoDB automatic crash recovery is enabled by default, but it won't hurt to make sure.
17th Sept 2010 EDIT:
There is an easier way to do it if you have phpmyadmin:
1) Backup your database by exporting it to a sql file and downloading it, or by making a copy of that database.
2) Switch the Events, Frames and Stats tables engine from MyISAM to InnoDB (from phpmyadmin of course), see the picture at this link: http://www.mikebernat.com/blog/MySQL_-_InnoDB_vs_MyISAM
mastertheknife.
I'm using ZM 1.24.2, i have one camera that is constantly recording.
At the moment i have no UPS and everytime there was a power outage the computer automatically restarted and 90% of the time ZM won't function properly because of corrupt database tables (Usually the Frames table)
MyISAM is the tables type used by the ZM database. MyISAM is very fast, but old and has a very low chance of surviving a crash during a write operation, and has no automatic crash recovery.
The tables with most write activity are Stats, Frames and Events.
The other tables are modified usually only when configuration changes (by user).
A general rule is to use MyISAM for tables that are 95% read and 5% write, all tables except Stats, Frames and Events meet this description.
InnoDB is a newer table type, ACID compliant, supports transitions, has an automatic crash recovery and most importantly, has a much higher chance of surviving a crash during a write operation.
I changed my Stats,Frames and Events tables to use InnoDB.
I did this by shutting down ZM, dumping the database into a SQL file called backup.
Did another database dump, this time to a SQL file called innodb. I then deleted all tables in the database and opened the innodb.sql file and changed the TYPE=MyISAM to TYPE=InnoDB in the CREATE TABLE statement for the tables Stats, Frames and Events.
Then i loaded this SQL file and fired up ZM and everything works great, had few power outages since but ZM always recovered like nothing happened.
InnoDB is by default compiled into MySQL in most distros, and InnoDB automatic crash recovery is enabled by default, but it won't hurt to make sure.
17th Sept 2010 EDIT:
There is an easier way to do it if you have phpmyadmin:
1) Backup your database by exporting it to a sql file and downloading it, or by making a copy of that database.
2) Switch the Events, Frames and Stats tables engine from MyISAM to InnoDB (from phpmyadmin of course), see the picture at this link: http://www.mikebernat.com/blog/MySQL_-_InnoDB_vs_MyISAM
mastertheknife.