Error - 'max_user_connections' active connections in lock_may_be_available()
An active drupal 7 website, one fine day was throwing the following error PDOException: SQLSTATE  User ******** already has more than 'max_user_connections' active connections in lock_may_be_available() (line 167 of ******************/includes/lock.inc). There were no changes done on the website nor to my webhosting so it was quite surprizing to suddenly see this error. However my website was not down. It was still working, Every time I get the error I would use refresh button in my browser and the page would appear correctly. However I did the following
- mysqli_reap_async_query() is disabled on this server. Ask hosting provider to re-enable this function for you.
- MYSQLI_ASYNC is not available on this server. Ask hosting provider to make it available
- IN My query_cache_type query_cache_type should be OFF. Current value: ON
- realpath_cache_size should be 128K at a minimum. Current value: 16K Increase the realpath_cache_size value inside /opt/alt/php53/etc/php.ini. Will require a restart of PHP.
- realpath_cache_ttl should be 3600 at a minimum. Current value: 120 Increase the realpath_cache_ttl value inside /opt/alt/php53/etc/php.ini. Will require a restart of PHP.
Drupal uses pconnect() when connecting to the database for a slight performance improvement if PHP is configured to allow pconnect.
But there are times when PHP should be configured to disallow persistent connections to the database.
Each apache process can potentially obtain a persistent connection to each database the server is hosting. If there are lots of apache processes and lots of databases it is common to see the database throwing "too many connections" errors maybe like this:
PDOException: SQLSTATE  User foo already has more than 'max_user_connections' active connections in lock_may_be_available()
If this occurs there are a couple of options:
- Increase the number of available connections the database will allow. If most connections are idle most of the time, this is a viable solution.
- Disable pconnect via the
XXsql.allow_persistent = Offattribute in your php.ini. The performance hit from this setting is very slight.