Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
Django hangs on applying huge migration

I have a table in Postgres 9.5 with about 7KK rows. Django version is 1.10.5. Database and App are different servers with Ubuntu 16.04.2 within one local network.

Django's gunicorn server is stopped, so no other operations are being executed. I'm going to add one field there:

migrations.AlterField(
            model_name='balanceentry',
            name='reason',
            field=models.CharField(
                choices=[(b'default', b'Default'), (b'referral', b'Referral'), (b'referrer', b'Referrer'),
                         (b'random', b'Random'), (b'android_offer', b'Android Offer'), (b'ios_offer', b'iOS Offer'),
                         (b'offerwall', b'Offerwall'), (b'withdrawal', b'Withdrawal')],
                default=b'default', db_index=True, max_length=32),
        ),

And then I'm applying it:

$ ./manage.py migrate users 0026_auto_20170419_1758
Operations to perform:
  Target specific migration: 0026_auto_20170419_1758, from users
Running migrations:
  Applying users.0026_auto_20170419_1758...

And monitoring Postgres with pg_top.

It's doing ALTER for about 15 minutes, then I see this:

34567 postgres  20    0  401M   39M sleep   2:17  0.10%  0.00% postgres: *** *** ip(45200) idle in transaction

This does not change for about 10 minutes (only WCPU is changing from 0% to about 0.1% and back).

Then this record disappears (I think this means that client is disconnected), but ./manage.py migrate ... does not change its status at all, it just stays "running" with no changes (I've waited for about 2 hours).

I tried to restart postgres service, if I do this, it rolls back transaction (I think), frees some disk space, but migrate management command still hangs. It does not even react on Ctrl-C, I can only kill it with -9.

I also noticed that about 1-2 GB free disk space disappears after every attempt.

So, how can I fix this issue?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I am unable to make comment, because of too little reputation, so it will have to be an answer.

I do not have a solution, but an idea to a workaround. You can type python manage.py sqlmigrate which will show the SQL it performs, and then manually run it towards the database. If this can succeed, you need to add an entry in the database-table django_migrations with the migration name and app for the migration.

I have no idea if this will work, but you might be able to pinpoint the error in the SQL statement and optimize it a bit.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda