tag:www.rhnh.net,2008:/mysql Mysql - Xavier Shay's Blog 2010-07-01T02:23:28Z Enki Xavier Shay notreal@rhnh.net tag:www.rhnh.net,2008:Post/817 2010-07-01T01:30:00Z 2010-07-01T02:23:28Z Debugging Deadlocks In Rails <p>Here is an 13 minute long screencast in which I show you how to go about tracking down a deadlock in a ruby on rails application. I make two assumptions:</p> <ol> <li>You are using MySQL</li> <li>You know the difference between <a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-lock-modes.html">shared and exclusive locks</a> (in short: a shared lock allows other transactions to read the row, an exclusive blocks out everyone)</li> </ol> <p><object width="600" height="375"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=12941188&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=12941188&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="600" height="375"></embed></object><br /> (If embedding doesn&#8217;t work or the text is too small to read, you can <a href="http://vimeo.com/12941188">grab a high resolution version direct from Vimeo</a>)</p> <p>This is only one specific example of a deadlock, in reality there are many ways this can occur. The process for tracking them down is always the same though. If you get stuck, read through the innodb documentation again. Something normally jumps out. If you are not sure what ruby code is generating what <span class="caps">SQL</span>, the <a href="http://github.com/ntalbott/query_trace">query trace plugin</a> is excellent. It gives you a stack trace for every single <span class="caps">SQL</span> statement ActiveRecord generates.</p> <p><em>This is a small taste of the type of thing I cover in my DB is your friend training course. July through September I am running full day sessions in the US and UK. Chances are I&#8217;m coming to your city. Check it out at <a href="http://www.dbisyourfriend.com/">http://www.dbisyourfriend.com</a> <img src="http://www.dbisyourfriend.com/favicon.ico" alt="" /></em></p> tag:www.rhnh.net,2008:Post/794 2009-03-09T15:25:00Z 2009-03-09T15:25:00Z Backup MySQL to S3 with Rails <p><strong><span class="caps">UPDATE</span>:</strong> This code is too old. Use <a href="https://github.com/yob/db2fog">db2fog</a> instead. It does the same thing but better.</p> <p>Here is some code I wrote over the weekend &#8211; <a href="http://github.com/xaviershay/db2s3">db2s3</a>. It&#8217;s a rails plugin that provides rake tasks for backing up your database and storing it on Amazon&#8217;s S3 cloud storage. S3 is a trivially cheap offsite backup solution &#8211; for small databases it costs about 4 cents per month, even if you&#8217;re sending full backups every hour.</p> <p>There are <a href="http://info-architects.net/2007/08/25/rake-task-for-mysql-backup-to-amazon-s3/">many</a> <a href="http://pauldowman.com/2009/02/08/mysql-s3-backup/">scripts</a> <a href="http://therailscoder.typepad.com/the_rails_coder_ruby_on_r/2008/04/automatic-mysql.html">around</a> that do this already, but they fail to address the biggest actual problem. The <a href="http://amazon.rubyforge.org">aws-s3</a> gem provides a really nice ruby interface to S3, and dumping a backup then storing it really isn&#8217;t that hard. The real problem is that <strong>I really hate system administration.</strong> I want to spend as little time as possible and I want things to Just Work.</p> <p>A script is great but there&#8217;s still too many things for me to do. Where does it go in my project? How do I set my credentials? How do I call it?</p> <p>That&#8217;s why a plugin was needed. It&#8217;s as little work as possible for a rails developer to backup their database, so they can get back to making their app awesome.</p> <p><a href="http://github.com/xaviershay/db2s3">db2s3</a>. Check it out.</p>