We have a Django site (Django 1.4) running under NGINX and uwsgi. The site uses MYSQL 5.6.39 which runs on a separate AWS RDS instance. It runs fine for about a week but then suddenly we get the dreaded MYSQL 2006 error - MYSQL server has gone away. We have also noticed that there seems to be a sudden large increase in write IOPS around the time that this occurs.
After searching online, the following suggestions have been made:
- increase max_allowed_packet to something like 128M
- increase wait_timeout and interactive_timeout to 86400
- use lazy=1 in our uwsgi config file on our webapp server
We are in the process of trying these, but this issue is hard to debug since we have to wait a week of running to replicate it. So:
- Are there any other parameters we should set to make this issue go away?
- Is there anything we can do in our Django app to make this issue go away? For example should we close the DB connection at the start of every view?
- Would this whole problem just go away if we switched to a different DB like Postgres?