Skip to content
Karol Bucek edited this page Nov 7, 2013 · 6 revisions

Profiling SQL

production:
  adapter: mysql
  database: borg
  host: localhost
  properties: # specific for MySQL
    profileSQL: true # will profile/explain each SQL operation
    #autoSlowLog: true # alternatively (less logging) use this

NOTE: logging won't use ActiveRecord::Base.logger but should instead print to Java's System.err by default.

Troubleshooting

Sample configuration (properties) to start with :

production:
  adapter: mysql
  database: borg
  properties:
    dumpQueriesOnException: true
    includeThreadDumpInDeadlockExceptions: true # on exceptions a system thread-dump will be taken
    #includeInnodbStatusInDeadlockExceptions: true # automatically "innodb status" on potential locks
    #includeThreadNamesAsStatementComment: true # Java thread names will be visible with "innodb status"
    #useUsageAdvisor: true # lots off output

Fail-Over

Since AR-JDBC relies on JDBC we inherit whatsoever the driver shoots at us, for the official MySQL Connector/J among others it's fail-over support. This might turn out useful for a number of high-availability scenarios. The support is very simple and you can use it anytime you use our MySQL adapter, just specify multiple hosts e.g. :

production
  adapter: mysql
  host: db1.host.org,db2.host.org
  database: zoo
  username: mia
  properties:
    # autoReconnect: false
    failOverReadOnly: true # default value
    secondsBeforeRetryMaster: 30 # default

Whenever the first (master) host goes down the following hosts will be used (in read-only mode by default) for queries. Please consult the official documentation for how fail-over behaves and what are it's costs (it will only fail-over during connection initialization as long as the autoReconnect property is not set to true) http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html