Forums

MySQL db slow - Django2 migrate

Hello,

It's been two days I'm working on a django project each migrate take more than 20minutes to finish. Doing a simple show databases; statement takes more than 20sec.

Is there any parameters I can tweak to improve MySQL perf ?

Thanks, Regards,

show databases specifically can be slow on PythonAnywhere, but other DB stuff should not be. What's the migration doing?

Hello, I have absolutely the same problem. Even simple migrations (adding a column) take several minutes. Also, pages that use the database began to load several times slower.

Thanks for letting us know. You're both using the same underlying server, and it looks like there are some out-of-control queries running there that we can't kill using our normal tools. We're rebooting it.

OK, it's back now. Could you check and see if things are any better now?

I'm just doing the initial tables creation, nothing fancy or heavy. Thanks, I just noticed the reboot, it interrupted my migrate command... Try again and keep you posted.

Works just fine now, it took only few seconds, thanks! :)

Excellent, thanks for confirming! We'll keep an eye on that server just in case it's not just a one-off problem.

Hi, I'm having the same problem where simple migrations are very slow (several minutes) on mysql. Is it possible there's a similar server problem currently? Thanks!

There isn't a server issues at the moment. Be aware that "simple" migrations to humans may not be simple to database servers. For instance, operations on indexes may involve re-indexing the table.

Hi, I'm experiencing similar problem.

Migrations like Applying admin.0001_initial take several seconds.

With sqlite it takes few seconds to run all migrations. With mysql it is a minute or two.

Is it a newly created database?

Yes, it is freshly created database through web interface.

It does appear that MySQL migrations do take longer than SQLite migrations. Possibly because MySQL is a more fully-featured database, so there is more to do. Since migrations are not run very often, it's probably not something to worry about too much.

Thanks. It seams like a reasonable explanation.

Just wanted to make sure it is expected behavior.

Have a nice day.

I'm having the same sort of issue — multiple minutes making an initial migration for a database with only one tiny model. A two-second process locally. I have no problem waiting but if something's wrong on the server then this might just serve as a heads-up. :-)

Thanks for the information, we will take a look.

Same here - initial migration of 2 tables take at least several minutes

Ok. Thanks for the report.

hello there same here python manage.py migrate taking a lot of time please help

Is this for the initial migrate of a new project? If it's not, then a migrate that takes a long time could just be that you have migrations that update a large number of rows. That could take a long time because there are migrations that take a long time.

this is initial migrations

Please guys help me out

With what? We cannot make your migration faster. We are investigating why some migrations may be slow, but there's nothing we can do about slow migrations right now. Have you checked whether your migrations are making large updates to many rows and indexes?

no they are not, I read above messages and it says you reboot something and everything workked good

That was because the slowness that the users were experiencing was caused by specific things that were happening on their database server. Those things are not happening on the server that your databases run on.

This same thing is happening to me. I am setting up a brand new Django web app, added one model, and the initial migrate is taking more than 20 minutes.

I get this message in the console -

Running migrations: Applying contenttypes.0001_initial... OK

Which makes it look like all is well, except that it just freezes there and locks up the terminal.

Sometimes initial migrations can take up some time at PythonAnywhere, but we can see that they're finished now. Let us know if you experience more issues with migrations in the future.

Same problem here! Updating a model attribute is taking several minutes. Preparing coffee meanwhile :P

I am experiencing the same problem migration has been going on for about 40 minutes now and I'm still stuck at applying admin migrations.

From what we can see from our side, it looks like they're probably completed now -- how long did they take in all?

I'm experiencing this problem as well. I aborted an attempted migration twice today because I thought it had stalled.

I'm now altering the schema directly via MySQL (to eliminate the question of whether something was silently failing in the Django migration machinery).

I am adding a single boolean column to a table with 100,000 rows, and it has been running for 25 minutes now. Locally this migration (not the same database, but the same number of rows) takes about two seconds.

I'm upset about this because it has now turned into a significant downtime event for my site.

Why is MySQL so slow on PythonAnywhere? I've noticed it before but never at this frankly pathological level.

Are you sure you didn't have other processes accessing the table? The migration may have been trying to lock the table but always being bounced out by something else already doing something. Also, perhaps you have indexes that might be updated by the migration and that can take a significant time.

Well, the server was live, so there were requests coming in. That hasn't caused problems when running migrations in the past, but perhaps volume was greater this time. The manual-MySQL attempt did time out with Lock wait timeout exceeded.

Next time I run a migration I'll halt the app first.

Great! Glad we found a solution.

SlowMySQL server for me! Possible to check it/reboot?

~30 minute initial migration for my project. I've had to do this about 3 times in the last 3 days.

Migrations could be slow, that's a known issue related to multiple databases on the shared server.