Rails 3.2.3 mysql error "max_prepared_stmt_count"

mysql, ruby-on-rails-3.2

Solution

Ok, i'm tentatively weighing in on an answer here. I used femtoRgon's tip to check the status. Then i added these two lines to my database.yml file

  pool: 30
  prepared_statements: false

I restarted mysql. Now after having the app run for a while I see this:

mysql> show global status like 'com_stmt%';

| Com_stmt_close          | 189017 |

| Com_stmt_execute        | 189017 |

| Com_stmt_fetch          | 0      |

| Com_stmt_prepare        | 189017 |

| Com_stmt_reprepare      | 0      |

| Com_stmt_reset          | 0      |

| Com_stmt_send_long_data | 0      |

No discrepancies anywhere... Plus where I USED to see this:

Ecard Load (0.1ms)  SELECT `ecards`.* FROM `ecards` WHERE `ecards`.`id` = ? LIMIT 1  [["id", "34"]] 

I now see this:

Ecard Load (0.4ms)  SELECT `ecards`.* FROM `ecards` WHERE `ecards`.`id` = 34 LIMIT 1

I think that shows that I'm no longer using prepare statements? Would love any thoughts - I guess I'll have to keep monitoring to see how things go...

Problem

I am running a `Rails 3.2.3` app deployed with apache2/passenger on a virtual host with a mysql database server. I got this error after a lot of traffic was hitting the site: ``` ActiveRecord::StatementInvalid (Mysql::Error: Can't create more than max_prepared_stmt_count statements (current value: 16382) ``` I'm thinking it has something to do with the amount of traffic, but if so I have to find a way around this. Anyone had this error before? I can't figure out how to stop it. Here's what i see in mysql: mysql> show global status like 'com_stmt%'; | Com_stmt_close | 1720319 | Com_stmt_execute | 2094137 | | Com_stmt_fetch | 0 | | Com_stmt_prepare | 1768924 | | Com_stmt_reprepare | 0 | | Com_stmt_reset | 0 | | Com_stmt_send_long_data | 0 | +-------------------------+---------+ I am running resque gem.

Original source