<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rian&#039;s Really Good Technoblog! &#187; Databases</title>
	<atom:link href="http://riansreallygoodtechnoblog.com/category/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://riansreallygoodtechnoblog.com</link>
	<description>Technology tidbits from adapters to z... z... uh... zip files!</description>
	<lastBuildDate>Thu, 22 Jul 2010 01:09:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>More Backing Up MySQL: Know Your Cat: Storage Engines</title>
		<link>http://riansreallygoodtechnoblog.com/2009/11/02/more-backing-up-mysql-know-your-cat-storage-engines/</link>
		<comments>http://riansreallygoodtechnoblog.com/2009/11/02/more-backing-up-mysql-know-your-cat-storage-engines/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 19:05:20 +0000</pubDate>
		<dc:creator>rian</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Disaster Recovery]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[fulltext]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[myisam]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[storage engines]]></category>

		<guid isPermaLink="false">http://riansreallygoodtechnoblog.com/?p=10</guid>
		<description><![CDATA[Last time, I wrote about options for backing up MySQL, but I talked about them as though there is one kind of database, the MySQL database.  However, that&#8217;s not at all true.  There are two main types of storage engine used in MySQL&#8211; MyISAM and InnoDB.  In fact, there are many more, but these are [...]]]></description>
			<content:encoded><![CDATA[<p><a title="In case you missed it..." href="http://riansreallygoodtechnoblog.com/2009/10/31/backing-up-mysql-more-than-one-way-to-skin-a-cat/" target="_blank">Last time</a>, I wrote about options for backing up MySQL, but I talked about them as though there is one kind of database, the MySQL database.  However, that&#8217;s not at all true.  There are two main types of storage engine used in MySQL&#8211; MyISAM and InnoDB.  In fact, there are many more, but these are the two most commonly used without special requirements.<em> This is about the point where those of you not interested in the more, well, &#8220;technical&#8221; aspects of databases might want to go outside for a walk. <span id="more-10"></span></em></p>
<p>In reality, you could use MySQL for years and really know little or nothing about these database engines.  I did.  After all, if you&#8217;re setting up a database to manage, say, your office equipment in a small business, you&#8217;ll maybe have a couple of hundred rows?  You may only access the database once a week.  Who cares what the engine is?  MySQL will default to MyISAM (usually), and that will work fine.  You&#8217;ll never notice, nor care.</p>
<p>However, when you begin to approach almost any kind of consistency, performance, or resource constraint, you&#8217;ll want to think about which engine you&#8217;re using.  This, in turn, will affect your backup process.</p>
<p><strong>The 10,000 foot comparison of MyISAM and InnoDB</strong></p>
<p>I always find that it&#8217;s nice to look at these things in a table:</p>
<table style="text-align: left; width: 100%;" border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top;"></td>
<td style="vertical-align: top;">MyISAM</td>
<td style="vertical-align: top;">InnoDB</td>
</tr>
<tr>
<td style="vertical-align: top;">ACID (i.e., transactional)</td>
<td style="vertical-align: top;">No</td>
<td style="vertical-align: top;">Yes</td>
</tr>
<tr>
<td style="vertical-align: top;">Foreign Keys</td>
<td style="vertical-align: top;">No</td>
<td style="vertical-align: top;">Yes</td>
</tr>
<tr>
<td style="vertical-align: top;">Full-text Searches</td>
<td style="vertical-align: top;">Yes</td>
<td style="vertical-align: top;">No</td>
</tr>
<tr>
<td style="vertical-align: top;">Locking</td>
<td style="vertical-align: top;">Table</td>
<td style="vertical-align: top;">Row</td>
</tr>
<tr>
<td style="vertical-align: top;">Memory Use</td>
<td style="vertical-align: top;">Less</td>
<td style="vertical-align: top;">More</td>
</tr>
<tr>
<td style="vertical-align: top;">Speed Winner</td>
<td style="vertical-align: top;">Possibly in light load</td>
<td style="vertical-align: top;">Usually</td>
</tr>
<tr>
<td style="vertical-align: top;">Backup</td>
<td style="vertical-align: top;">mysqldump, mysqlhotcopy, replication, files</td>
<td style="vertical-align: top;">mysqldump, replication, files*, ibbackup**</td>
</tr>
</tbody>
</table>
<p><em>* you technically <span style="text-decoration: underline;">can</span> do a files-based backup with InnoDB (in fact, I do), but it&#8217;s a bit more involved.  See below for a discussion.</em></p>
<p><em>** ibbackup is a commercial product sold by the developers of the innodb engine, now a subsidiary of, gulp, Oracle.  The price? According to their site: &#8220;&#8230;please contact innodb_sales_ww at oracle.com&#8230;&#8221; i.e., &#8220;how much ya got?&#8221;</em></p>
<p>Let&#8217;s hit these in order:</p>
<p><strong>ACID</strong>: atomicity, consistency, uh&#8230; isohedron, um&#8230; danger?  Whatever.  It&#8217;s an acronym that means that the engine has mechanisms in place to ensure that &#8220;transactions&#8221; are performed reliably.  The classic example is the bank transfer.  You need to know that if you take the money out of account A, it gets into account B.  If not, the whole thing is called off.  MyISAM does not implement these mechanisms.  InnoDB does.</p>
<p><strong>Foreign Keys (FK)</strong>: Similarly to ACID, FK assures that your data makes sense in relation to your model.  For example, if you&#8217;re looking at an 8-track tape collection (I&#8217;m super old), you can&#8217;t have a recording without the recording&#8217;s artist.  So, before the recording table gets &#8220;They Only Come Out at Night&#8221; inserted, the artist table must contain Edgar Winter.  If you delete Edgar from the artist table, you&#8217;d better be sure that &#8220;TOCOAN&#8221; is also out of the recording table.  So, unlike ACID, which enforces proper operation of the database, FK enforces proper/logical USE of the database.  MyISAM does not support FK.  InnoDB does.</p>
<p><strong>Full-text Searches</strong>: In short, if you have a large text-type field, MyISAM supports special functions to index that field so that it can be searched against keywords with natural language and keyword expansion extensions if desired.  InnoDB doesn&#8217;t.</p>
<p><strong>Locking</strong>: MyISAM does not support row-level locking.  That means that if you want to lock a field to prevent it from changing during an operation, you need to lock the entire table that it&#8217;s in.  That means all write operations stop until you&#8217;re done.  In a heavy load situation, that&#8217;s, as they say, &#8220;bad&#8221;.  This is one of the main reasons that InnoDB whoops MyISAM in its ability to support concurrent access, particularly at heavy loads.</p>
<p><strong>Memory</strong> Use: All those fancy features of InnoDB aren&#8217;t free.  One cost is additional memory use.  For instance, InnoDB maintains &#8220;clustered&#8221; indexes and includes the primary key in any secondary indexes.  This speeds data access and improves CPU and IO efficiency, but at a cost of storing all that information in memory.  MyISAM stores  data and indexes in separate files.  Less efficient, but easier on the RAM.</p>
<p><strong>Speed Winner</strong>: Oh boy, I hate to even get into this one, but most of the benchmarks I&#8217;ve seen show InnoDB to win speed contests in most cases.  This becomes particularly true at high load levels.  This makes a lot of sense if you consider the concurrency and efficiency characteristics.  Or, if you have some anecdotal evidence to the contrary, let&#8217;s just agree that you&#8217;re right, and I&#8217;m wrong.  (But I&#8217;m not.)</p>
<p><strong>BACKUP!</strong>: Finally.  OK, so the big difference is that it&#8217;s not quite as easy to just copy the InnoDB files and expect anything good to happen.  With MyISAM, you can.  This means, according to the MySQL peeps, that you also cannot use the mysqlhotcopy utility with InnoDB since it uses the file mechanism to make the backup. You can, however, use the mysqldump utility with either.  Both are easier to do with a logical volume snap or replicated slave server to shutdown during the backup.  I also included InnoBase&#8217;s ibbackup program in case you&#8217;ve got some money burning a hole in your pocket.  Given the available options, I&#8217;m not sure I see the point in such a thing, but if you need some of the features it provides and don&#8217;t want to roll your own, it might be worth looking into.</p>
<p>So, that brings us back to my solution.  Given that I personally prefer to default my storage to InnoDB unless there&#8217;s a reason not to, I went with the replication model&#8211; create a slave server and calmly shut that down, make the backup, and restart the slave.  The thing I like about this approach is that it requires a minimum of fuss, causes no downtime, provides a running backup server, and does nothing that precludes me from using whatever type of storage engine I choose or mixing them together.</p>
<p><strong>Two Pronged Approach to Backups:</strong></p>
<p>Firstly, I turn on binary logging on the slave.  Then, when I shut the database down, I copy the relevant files (ibdata, .ibd, ib_logfile, .frm, and the my.cnf) to the backup staging area.  After that I can start the database back up, and it&#8217;ll sync itself back to the master.  There&#8217;s definitely some exposure to Murphy&#8217;s Law in there (e.g., the master takes on more data while the slave is shut down and then crashes before it syncs) but the probability of that is pretty minuscule.</p>
<p>Then, on a less frequent basis, I take a mysqldump of the database.  It takes a lot longer, but it&#8217;s got the advantages of not being binary, so it&#8217;s readable and less likely to become completely corrupted.  It&#8217;s sort of a backup-backup in case I need to fall back from a corrupt binary backup.</p>
<p>OK, maybe that&#8217;s enough on that topic.  Can hardly wait to see what I write about next&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://riansreallygoodtechnoblog.com/2009/11/02/more-backing-up-mysql-know-your-cat-storage-engines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backing up MySQL: More than one way to skin a cat.</title>
		<link>http://riansreallygoodtechnoblog.com/2009/10/31/backing-up-mysql-more-than-one-way-to-skin-a-cat/</link>
		<comments>http://riansreallygoodtechnoblog.com/2009/10/31/backing-up-mysql-more-than-one-way-to-skin-a-cat/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 03:46:41 +0000</pubDate>
		<dc:creator>rian</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Disaster Recovery]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[logical volumes]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://riansreallygoodtechnoblog.com/?p=8</guid>
		<description><![CDATA[Moving to MySQL
I&#8217;m currently involved in moving an application from SQL Server (2000) to MySQL.  The reasoning isn&#8217;t terribly relevant, but primarily it&#8217;s an open source v. closed source issue.  This (aging) J2EE app required a proprietary bridge between the application server (Java on Linux) and the database (SQL Server on Windows 2000 Server).  That [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Moving to MySQL</strong></p>
<p>I&#8217;m currently involved in moving an application from SQL Server (2000) to MySQL.  The reasoning isn&#8217;t terribly relevant, but primarily it&#8217;s an open source v. closed source issue.  This (aging) J2EE app required a proprietary bridge between the application server (Java on Linux) and the database (SQL Server on Windows 2000 Server).  That odd adapter has caused us all stress over the years.  Being proprietary, we didn&#8217;t know <em>exactly</em> how it worked nor whether it would be around tomorrow.<span id="more-8"></span></p>
<p>The cost was also a consideration.  Updating the server to the current version would likely cost us thousands of dollars just for the RDBMS itself.  We&#8217;d likely move to the latest OS and upgrade the hardware, too.  It got very pricey, very quickly.</p>
<p>We came to the conclusion that a better solution would be to migrate the whole mess over to MySQL on a Linux server.  I am intimately familiar with MySQL and knew that for very little dough we could provide a fast data store with replication for fail-over, and we&#8217;d eliminate that vaguely disconcerting feeling that relying on closed source proprietary software creates.</p>
<p><strong>A More DIY Model of Disaster Recovery</strong></p>
<p>However, one of the nice things that MSSQL does provide is a backup mechanism from within that database manager itself.  MySQL does not.  I needed to evaluate my options given the situation and choose the most reliable, simplest-to-implement backup solution that wouldn&#8217;t cost additional money nor require disruptive, time-consuming reconfiguration of existing systems.</p>
<p>It appears to me that there are three common methods for backing up a simple MySQL database:</p>
<ol>
<li>mysqldump<br />
Shut down the database, dump out a text file with all of the SQL statements required to recreate the database, and restart.  Then, back up the file like any other file.</li>
<li>LVM snapshots<br />
Lock the tables, create a logical volume snapshot of the data partition, and unlock the tables.  Then back up the snapshot and remove it when completed.</li>
<li>Replication<br />
Create a slave database server that replicates the target server, and simply stop the slave, back up the data, and restart the slave.</li>
</ol>
<p>Mysqldump has the advantage of being very simple to setup and script.  Also, the backup is a text file, and so a ding to the file isn&#8217;t likely to destroy it completely.  With a binary backup, a data ding could render the whole thing useless.  Still, it requires a fair amount downtime, which is bad, and the backup files can be very large, which just makes backups and restores take that much longer.</p>
<p>LVM snapshots sound great.  There&#8217;s very little downtime (just enough to create the snapshot), and the backup is the actual datafile.  It&#8217;s likely to be smaller and restore takes essentially no time since the data file can just be dropped back into a running server and used.  Still, snapshots only work when the filesystem is built on logical volumes (another good topic to discuss, I think).  We were looking at some older systems that used standard physical partitions, and I was not enthusiastic about shutting them down, backing everything up, and reinstalling on LVM just to accomplish this.</p>
<p>So, I settled on replication.  MySQL provides a very slick ability to create a master-slave replication arrangement wherein one server maintains an identical copy of the master database (god willing).  There&#8217;s just a bit of setup, but with this arrangement, there&#8217;s no downtime for the master, and the slave can be backed up in any convenient way without concern for the time involved.  Also, should something befall the master, it is quite likely that the application server can just be pointed to the slave and carry on as though nothing happened.</p>
<p>As it happened, we had a machine in our colocation cabinet just sucking power, doing nothing.  I set up a replication slave on it in just a few minutes.  Then, I wrote a quick script to shut it down, run the backup, and restart the slave.  I added that to the cron table, and we had our backups licked.</p>
<p>Now, obviously, I&#8217;m not talking about a very complex setup here.  This is an application that is critical to the business, but not what I consider heavily used.  Should it ever graduate to the level of something like a load-balanced cluster, I&#8217;ll have to revisit this topic.  In the meantime, we&#8217;re securely covered with a backup process that doesn&#8217;t require downtime and provides the side-benefit of a spinning fail-over server as an even faster disaster recovery path.</p>
<p><strong>A Condescending Lecture on Backups</strong></p>
<p>Backup, backup, backup&#8230; it&#8217;s so often overlooked until it&#8217;s too late.  Do yourself a favor, spend a little money and time and back up more than you think you need to.  When the Bad Thing happens, a good backup strategy can mean the difference between a routine mechanical replacement and restore (<em>everyone&#8217;s happy!</em>) and an uncertain scrounging of data or total loss (<em>ain&#8217;t nobody happy</em>).  Make it a priority.</p>
<p>And like most things, the best way to start is to just start.  Now.  Don&#8217;t worry if it&#8217;s not perfect.  Just take a disk image if that&#8217;s all you can do.  Then, consider what would happen if various nasty scenarios occurred.  Then think about how you might recover.  What if the machine&#8217;s stolen (it happens)?  What if the machine bursts into flames (that&#8217;s happened to me)?  What if an earthquake crushes the colo (<em>probably not, but what if</em>)?</p>
<p>Classify your data by criticality and back it up accordingly.  I recently nearly lost my company books when a power surge took out my active drive and the routine backup drive.  I was lazy and calculated the probability that both of those drives would fail at the same time and decided without really thinking about it that I&#8217;d get around to good backups&#8230; later&#8230; sometime&#8230; Luckily for me, I&#8217;d had at least the forethought to take an image of my drives and store them offline.  I&#8217;d forgotten that I&#8217;d done that and spent the better part of a day engaged in self-loathing.  Now, I regularly take some time to consider how I might improve my backups&#8211; net-based, portable disks swapped offsite, RAIDed online storage, or maybe all of the above.  It&#8217;s done wonders for my comfort factor to know that if my backups turn out to be insufficient, it&#8217;s likely that I&#8217;ll be more worried about the zombies than my business records.</p>
<p>Oh, happy Halloween.</p>
]]></content:encoded>
			<wfw:commentRss>http://riansreallygoodtechnoblog.com/2009/10/31/backing-up-mysql-more-than-one-way-to-skin-a-cat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
