title: Debugging MySQL Deadlocks on Amazon RDS
body: <p>I'm getting an increasing number of "Deadlock" and "Lock timeout" issues on my MySQL database (an Amazon RDS instance).  The database was working very well until a couple of days ago. No changes to the server code (that executes the queries) were made for more than a week. I know what the exceptions are, but I'm at a loss as to the best way to debug and find the specific queries/statements that are causing the issues.</p>
  
  <p>Info on setup:</p>
  
  <ul>
  <li>MySQL Amazon RDS instance (small)</li>
  <li>Everything default in RDS profile/MySQL settings except for character encoding, which is changed to UTF-8</li>
  <li>Server making the queries is Tomcat Java server with Hibernate</li>
  <li>Information on exceptions is read from the Tomcat server log</li>
  <li>Queries / Min between 50 - 5000</li>
  </ul>
  
  <p>My best guess is there's something in the settings (either Hibernate or MySQL) that's causing this issue. The server will run fine and then latency will go through the roof causing all sorts of negative behavior. When this happens, the CPU utilization of the instance will be near 100%.</p>
  
  <p>The hibernate settings are:</p>
  
  <pre><code>&lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
      &lt;property name="driverClass"&gt;&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;&lt;/property&gt;
      &lt;property name="jdbcUrl"&gt;&lt;value&gt;XXXX&lt;/value&gt;&lt;/property&gt;
      &lt;property name="user"&gt;&lt;value&gt;XXXX&lt;/value&gt;&lt;/property&gt;
      &lt;property name="password"&gt;&lt;value&gt;XXXX&lt;/value&gt;&lt;/property&gt;
      &lt;property name="initialPoolSize"&gt;&lt;value&gt;3&lt;/value&gt;&lt;/property&gt;
      &lt;property name="minPoolSize"&gt;&lt;value&gt;3&lt;/value&gt;&lt;/property&gt;
      &lt;property name="maxPoolSize"&gt;&lt;value&gt;50&lt;/value&gt;&lt;/property&gt;
      &lt;property name="idleConnectionTestPeriod"&gt;&lt;value&gt;200&lt;/value&gt;&lt;/property&gt;
      &lt;property name="acquireIncrement"&gt;&lt;value&gt;1&lt;/value&gt;&lt;/property&gt;
      &lt;property name="maxStatements"&gt;&lt;value&gt;0&lt;/value&gt;&lt;/property&gt;
      &lt;property name="numHelperThreads"&gt;&lt;value&gt;6&lt;/value&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Any idea where to start debugging of if something in the settings might be causing this problem would be appreciated.</p>