CV and personal site of Andy Hunt
Posted: Monday 01 March 2021 @ 13:13:37
The max_allowed_packet
setting MySQL "is the maximum size of a MySQL network protocol packet that the server can create or read" (DZone article: max_allowed_packet and Binary Log Corruption in MySQL). It affects the largest payload that can be delivered to the server, and thus the largest single piece of data that can be inserted (n.b. this is my loose understanding. I'm not a DBA, and don't have a lot of experience with operating MySQL). This is particularly problematic when the table has BLOB
columns, or you're inserting long strings.
One common indicator that your configured value is too low is seeing the following errors in MySQL's logs
ERROR 1153 (08S01) at line 96: Got a packet bigger than 'max_allowed_packet' bytes
A tenant reporting this is what lead to me learning something today: AWS RDS for MySQL has a default max_allowed_packet
setting of 4mb.
This is according to Amazon's own article Best practices for configuring parameters for Amazon RDS for MySQL, part 3: Parameters related to security, operational manageability, and connectivity timeout which suggests a value of 64mb.
If you're running a PHP CMS like Drupal, it may even be advisable to raise it to a value of 128mb.
To change the value, you'll need to ensure that the database is in a custom parameter group first. Then set the max_allowed_packet
parameter on the parameter group to the value in bytes.
MAX_ALLOWED_PACKET_SIZE="$((1024*1024*128))"
aws rds modify-db-parameter-group \
--db-parameter-group-name PARAMETER_GROUP_NAME \
--parameters "ParameterName=max_allowed_packet,ParameterValue=${MAX_ALLOWED_PACKET_SIZE},ApplyMethod=immediate"
The parameter has an ApplyType
value of dynamic
, which means the "the change is applied immediately regardless of the Apply Immediately setting"(Amazon article: Working with DB parameter groups). My experience is that the database will experience no downtime as a result of changing the parameter value. However, it isn't clear to me whether any connections to the database (e.g. applications) will need re-estabilishing.