djangodjango-southdjango-migrations

Do django db_index migrations run concurrently?


I'm looking to add a multi-column index to a postgres database. I have a non blocking SQL command to do this which looks like this:

CREATE INDEX CONCURRENTLY shop_product_fields_index ON shop_product (id, ...);

When I add db_index to my model and run the migration, will it also run concurrently or will it block writes? Is a concurrent migration possible in django?


Solution

  • There are AddIndexConcurrently and RemoveIndexConcurrently in Django 3.0:

    https://docs.djangoproject.com/en/dev/ref/contrib/postgres/operations/#django.contrib.postgres.operations.AddIndexConcurrently

    Create a migration and then change migrations.AddIndex to AddIndexConcurrently. Import it from django.contrib.postgres.operations.