I have been encountering this error in trying to do anything administrative in the past week: user warning: Got a packet bigger than 'max_allowed_packet' bytes query: UPDATE cache_menu SET data = '...'
I'm on a shared hosting plan where I cannot increase my max_allowed_packet value, unless I want to go from $18/month to $250/month in hosting fees. Not an option. I tried reducing the size of my primary menu which shows on every page, by moving the admin menu to the currently disabled secondary menu. I thought that worked at first, but it didn't. I have all of my caching options under settings > performance disabled, but that doesn't help either.
My site is small with less than 300 users, but it is loaded with a lot of content types, organic groups and node privacy by role, which I suspect is the biggest problem. Unfortunately, I need all of those.
Can I safely disable the cache_menu function? If yes, how? If no, does anyone have any suggestions on how to reduce the size of that update menu_cache query? Please help!
Comments
Comment #1
vm commentedMany hosts tell you that you can't adjust the default php settings and promote moving to a VPS or Dedicated.
Have you actually tried using a custom php.ini to change these to verifiy that you actually can not change the settings ?
side note, you should be updating to drupal 6.5 to remain as secure as possible.
Comment #2
cindyr commentedA custom php.ini? How would I do that, use settings.php? Can you suggest what the syntax should be to set max_allowed_packet=16M?
I can also connect to my database using the mysql client, but didn't see any way to alter the database settings that way either.
Comment #3
vm commentedmy apologies, I was thinking of post_max_size. max_allowed_packet very well may need to be changed on the server in my.conf or my.ini if on a windows server.
I don't know that you can shut off menu cache on demand without hacking core. Will do some more research for you. In the meantime you may get more help by posting the question to the forums.
Comment #4
cindyr commentedThanks. I've tried everything and spent hours on research. It looks to me like the only way to do it is to alter the MySQL settings on the database server, which I don't have access to. Or, disable cache_menu. My guess is that's only a temporary fix though, as there are likely other queries that are running close to the 1MB max_allowed_packet size...
I'll check with the forums for a quick fix. And harrass my host some more...
Comment #5
gpk commentedThat's actually a MySQL constraint. Looks like your host has artificially reduced the max packet size. The server default looks to be 1MB. If you suggest to them that you might just go elsewhere then perhaps they won't try to fleece you for another $232 per month.
http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html.
The easiest way round this might be to install an alternative cacheing module that uses files instead of the DB.
Comment #6
cindyr commented"Alternative cacheing modules"... I've been at this for over a year and I still feel like a newbie! Thanks for the suggestion, I'll start investigating...
Comment #7
pwolanin commentedwhich should consider whether it makes sense at all to cache the whole router.
Comment #8
kbahey commentedYou can disable the menu cache, but it may have a bit of a performance impact.
Anyway, try this and see if it slows down the site.
1. Copy includes/cache.inc to includes/cache-no-menu.inc
2. Edit includes/cache-no-menu.inc so that the the cache_set() function that previously looked like this:
Now looks like this:
Then edit your settings.php file to add the following line:
This should make all cache_set operations for cache_menu not do a db query and solve your issue.
Comment #9
pwolanin commented@Khalid it seems that the single entry for the full menu router is the main issue. We should look anyhow into whether that's useful to cache.
Comment #10
gpk commentedYes it must be the "router:" entry that is causing the problem, so the new cache_set() could be further refined:
Should certainly lessen any performance impact.
[update] @cindyr: what is the current 'max_allowed_packet' setting for your hosting plan?
Comment #11
cindyr commented[update] @cindyr: what is the current 'max_allowed_packet' setting for your hosting plan?
1 Mb
Thanks to everyone for looking into this...
Comment #12
cindyr commentedTHIS FIXED IT!!! WAHOO!!! I thought I was going to have to move my site to another host, and I was soooooo not looking forward to that process! THANK YOU!!!!
And no, there doesn't seem to be any degradation in load time, nothing noticeable.
Comment #13
cindyr commentedOK, I just tried it with #10's edit, and there seems to be no difference. It works great now. I'm using Nice Menus for my menus, and even with that everything loads quickly and works great. Thank you to everyone!
Comment #14
gpk commented@11: From http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html:
So I take back all my nasty comments about your host at #5 - the server is using the default MySQL setting. Looks like we may be seeing more of this problem now that OG and other "heavyweight" modules are coming on-stream for 6.x.
See also #317775: Caching entire {menu_router} table causes MySQL error/slow rebuilds and slows menu_link_save.
Comment #15
PerryM commentedoops wrong place
Comment #16
ainigma32 commentedSolution was provided so I'm setting this to fixed.
- Arie
Comment #18
kenorb commentedAnybody found some solution without disabling cache_menu?
Comment #19
gpk commented@18: see #10. Only inhibits cacheing of the menu router table, so the performance hit will be less. But does require you to re-patch cache.inc each time you upgrade. Alternatively you could use the option in settings.php to specify your version of cache.inc (you could perhaps put it in sites/all/cache) as an alternative cacheing system, which might reduce the (small) maintenance overhead.
Comment #20
kenorb commented#8 worked for me, solution #10 still caused the error.
Comment #21
gpk commentedIt could be the links:navigation:tree-data:* entries. Try something like
Or use a contrib module that provides an alternative cacheing mechanism (e.g. files) to selected tables.
I have quite a few modules on one site and the router: entry is about 400K, and the navigation links entries up to 90K. I wonder what it pushing your site over the limit. (What is your max packet size BTW?)
Comment #22
kenorb commentedFor cache_form as well:
#357938: max_allowed_packet on admin/build/modules page
#231143: Taxonomy term lists in node edit forms
Comment #23
gpk commentedAnother approach:
http://dev.mysql.com/doc/refman/5.0/en/dynamic-system-variables.html says that the dynamic system variable max_allowed_packet exists in both global and session scope. To change the value in global scope you need the SUPER privilege. I don't know what is needed to change a value in session scope, but I can do it on my shared server, as follows:
Does this work for you? You could try wrapping the query in db_query() and putting it at the top of cache_set().
You can get the current value with this query:
Comment #24
kenorb commentedNice, I'll try this.
Comment #25
kenorb commentedComment #26
ainigma32 commentedThere is no patch.
- Arie
Comment #27
kenorb commentedPaste followed line before your line of the issue:
Line of the problem you can get from the message:
There is no patch, because it's general problem and this issue can be in different places in different modules.
Comment #28
vm commentedI believe this should be left as active until such time as an actual patch is created. As it stands there are some workarounds but not a fix that be patched into core. Though to get something like this put into core it would have to be patched against 7.x and backported I believe.
At the very least a patch that would allow one to turn off menu cache in the admin UI if necessary?
Comment #29
gpk commentedYes, the fix at #23 / #27 is very much a workaround in the context of this support request.
>patch that would allow one to turn off menu cache
This fix actually doesn't do that any more but reconfigures the active MySQL connection (i.e. for the duration of the current page request) - it increases the max packet size so that the limit is less likely to be breached.
A permanent fix for core would want to put the query somewhere else; hard to say where would be best, but since we are talking about a MySQL option here it would need to be somewhere in the MySQL DB layer. I imagine other DB APIs have a similar restriction; which might or might not be breached as easily as this one. At this stage it might even be best to handle the fix via a contrib. module (e.g. in hook_init()).
Comment #30
kenorb commentedFor those who tried to disable cache_form table, it's very bad idea and some forms are not submitted properly.
http://drupal.org/node/93779#comment-1254794
Comment #31
kenorb commentedTry this.
#361967: Increase MAX_JOIN_SIZE and MAX_ALLOWED_PACKET settings in system.install
You can increase max_allowed_packet, but only if they support it.
Comment #32
pwolanin commentedsee patch: http://drupal.org/node/251792
this shoudl resolve the problem also.
Comment #33
gpk commentedThanks, AFAICS #251792: Implement a locking framework for long operations will fix the problem in many (most?) but not all cases. It will help because as a performance enhancement unrelated to this issue it does away with the caching of the router: blob. But per #20 and #21 there may (especially on large sites) be other blobs (links:navigation:tree-data:...) over 1MB.
Comment #34
pwolanin commentedI'd be rather surprised if of the other cached items are nearly as large as the router - I guess if you set a bunch of links to be always expanded and when you're deep in the admin menu.
Comment #35
gpk commented>I'd be rather surprised if of the other cached items are nearly as large as the router
Well yes, I'm being a bit pessimistic - the biggest I've seen for other cached menu items is 90K (#21), tho' kenorb (#20) managed to get something other than router: over 1MB.
So #251792: Implement a locking framework for long operations will be at least a "90% solution".
Comment #36
gpk commentedAlso see http://drupal.org/node/379976 which is essentially the relevant part of the solution proposed at #31.
Comment #37
kenorb commentedOther solution if you have problem with big packet stored into cache_menu or cache_router table, is good to change cache engine to non-database like: www.drupal.org/project/fastpath_fscache
I think there are already lot of solutions described in this thread, so marking it as fixed.
Comment #39
dadderley commentedThank you kbahey for your solution in comment 8
I developed a site on my development server and started to migrate it to my production server. I exported my DB (using phpMyAdmin) and then tried to import it to the production server using phpMyAdmin. I tried this numerous times, What would happen all the time was that it would successfully import 24 of 161 tables, stop and give this error "Mysql Error 1153: Got a packet bigger than ‘max_allowed_packet’ byte".
I did a bunch of googling and it appeared that the solution was to go into the server's "/etc/my.cnf" file and change the value of "max_allowed_packet" from 1MB to 16MB. As a test I tried this on my local MAMP's sql. I tried importing my DB with no success. I could not import the DB, it had the same behavior as my production server.
I did some more googling and came up with this thread. I followed the procedure in comment 8 (http://drupal.org/node/321154#comment-1059946), flushed all the caches and exported my DB from my development server. The result was a considerably smaller exported DB. I tried importing this into my production server again using phpMyAdmin.
Bingo! Worked right away! It did this quickly with no errors.
This is very cool. Thanks
Comment #40
vallab444 commentedHi, Khalid/ Giles:
from all the discussion happening on the forum, I for sure knew that I was running into a wall, with my shared hosting a/c.
However, your fix saved me, and probably my weekend too. It works just as well as before, minus the worry-lines. Thanks a ton !!
cheers
-vallabh
Comment #41
bassplaya commented@ kenorb #37
you call this fixed? I call this "hacked".. if it isn't fixed in core so that it will be included automatically in the drupal download I call it a hack.. of course I use the hack that kbahey describes in #8 but still it's a hack. And then they mention that you will have to save that file otherwise you will override it when you upgrade.. that's totally not the drupal way. Yes, I'm happy it works but still 2 years later.. I will not remember that.. unless I would log everything so detailed.. but if everybody does that.. what's the use of the "drupal way"?
So why is it closed then? Because there are enough hacks that make the problem go away?
There must be a reason why the issue was there in the first place.. I'm running a site with almost "no" content and 15 content types with in total maybe 100 different fields and installed about 50 modules. More than that I haven't done with the site and I get the problem.
I don't understand why this is so easily set to fixed.
Please comment cause I really want to understand why.
Cheers.
Comment #42
kenorb commented#37 is just workaround.
Problem:
Got a packet bigger than 'max_allowed_packet' bytes query: UPDATE cache_menu SET data = '...'
Why does it happen?
On high traffic websites normally you shouldn't use database cache, because it's killing your site performance.
Proper solution:
Implement cache engine on your server, i.e.
http://drupal.org/project/memcache
If you have high traffic, you should be conscience of upgrading your environment. You can't run high traffic website on the slow server without any caching. It's how Drupal is designed.
Comment #43
Hetta commentedOK, I've about 28000 book pages plus 18000 taxonomy terms. cache_menu is killing the mysql server, cos I only HAVE about 20 GB of hard disk space on the /srv /var /tmp partition. (And haven't needed even half of that, until cache_menu hit the fan).
Running a local wget means that the cache_menu table is another 2.5 GB larger every half hour or so ... not funny. I'm not putting that beast onto the live server.
I haven't seen just how large the table will get, as it really honestly killed my localhost: "not enough memory to run [whatnot]".
I'll be killing off cache_menu by following the hints in #8 and #10.
Thanks for those!
Comment #44
EricW commentedDoes anyone know if cache_menu will be rebuilt if the data in it is deleted? That way we could just export the database with all tables except cache_menu (cache_*?) and avoid the 1MB max packet limit on import.
I just tried it, and it appears to have worked fine. I truncated the cache_menu table (in phpMyAdmin) and immediately after a page load the data was re-cached.
Comment #45
Hetta commentedAll caches are rebuilt if emptied out. That includes cache_menu.
Comment #46
Sylvain_G commented#8 http://drupal.org/node/321154#comment-1059946 worked for me. Still have to mesure side effects
Comment #47
suffering drupal commentedHello!
Working with D 6.17, had the same issue,
user warning: Got a packet bigger than 'max_allowed_packet' bytes query: UPDATE cache_menu SET data = '...'
on administrative pages (actually I believe specifically on "edit" pages, dont remember well, dizzy of all the erros, warnings and problems Drupal gives me)
Anyway -> # 8 resolved, #10 brought it back.... (like #20)
Didn't have the energy and time to read further than that. Maybe tomorrow, next week or next life...
For the moment #8
Comment #48
gpk commented@47: That follows. If you find that site performance is suffering (on account of menus not being cached) then have a look at http://drupal.org/node/379976 and especially the module mentioned there. A proper fix would be to get your host to increase the max_allowed_packet on your server.
Comment #49
suffering drupal commentedYou are right, I actually DO NOT WANT to avoid caching of menus, I just want to have NO ERROR when going to edit/admin pages!!
Tried increasing max-package thing, through drupal tweaks, and went up to 32M but it didn't make the error disappear. So I'm kinda forced to apply that patch.
Anyway increasing max-package still feels like a kind of bug-solution: the basic problem really is that all that stuff shouldn't even be cached when going to edit/administration pages in the first place.
Maximum caching for visitors ok, but not so necessary on admin pages. Or at least be able to differentiate and choose!! How come there is more caching for admins than for anonyms anyway??
By the way I seem to have additional caching-problems using domain access. Anonymous users get the same cached homepage on ALL domains, see: http://drupal.org/node/866668
Now that I think of it, could that be caused precisely by this patch??
Also Javascripts don't show in blocks through the include command in PHP (reservation forms). Saw something about that somewhere, but don't remember, too many accumulated problems.
Comment #50
gpk commented>still feels like a kind of bug-solution
The 1MB default packet limit causes problems for many systems, not just Drupal. Your host should be able to increase it. Incidentally I have a big site and the biggest 2 entries are only about 500KB.. one is for admin_menu module and the other is links:navigation:tree-data ... once you've found out which entries are causing the problem you could trying something like #21.
Note that http://drupal.org/requirements recommends 16MB max_allowed_packet.
>be able to differentiate and choose
Sounds like a feature request: http://drupal.org/node/add/project-issue/drupal
>there is more caching for admins than for anonyms anyway
Not sure I'd agree. Drupal uses caching in various places to improve performance both for anon and logged-in users.
Comment #51
altbzh commentedHye,
How #8, #10, #21 become with Drupal 6.22 ?
Thank you