Monday, May 21, 2012

Sonar analysis and mysql max_allowed_packet size



Recently I had the problem where sonar was failing my CI plans with the following error:


"Packet for query is too large (1363557 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable."


I wasn't sure whether this was the sonar server i.e. the web frontend or the mysql server that I was using for the backend database, however off to google and a couple of checks later outlines it being a mysql server with the best example being:


http://dev.mysql.com/doc/refman//5.5/en/set-statement.html


It's also worth checking first if this variable is actually able to be changed at runtime:


http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_max_allowed_packet


So from the above two links I was able then to go off to the mysql server and set the value:


First of all check that the current value is what is expected:


mysql> show variables like "max_allowed%";


| Variable_name                   | Value       |
| max_allowed_packet          | 1048576   |


1 row in set (0.00 sec)


Good, our variable is as expected from the error we received in the first place. Now from the first link above set the value to 16M:


mysql> SET GLOBAL max_allowed_packet=16*1024*1024;
Query OK, 0 rows affected (0.00 sec)


and verify:


mysql> show variables like "max_allowed%";


| Variable_name                  | Value         |
| max_allowed_packet        | 1048576    |


1 row in set (0.00 sec)




Eh, hold on - that's not right, seems like the multiplier isn't working, so off to the calculator to work it out ourselves and try again:


mysql> SET GLOBAL max_allowed_packet=16777216;
Query OK, 0 rows affected (0.00 sec)


mysql> show variables like "max_allowed%";


| Variable_name                | Value    |
| max_allowed_packet      | 16777216 |


1 row in set (0.00 sec)


Nice!


Since we changed this just in memory we need go to our my.cnf file to make sure the change is persisted at server restart:


my.cnf
[mysqld]
max_allowed_packet=16M


You should now not get the error on the sonar upload.