Opened 3 years ago

Closed 9 months ago

#21039 closed New feature (duplicate)

Support Postgres "CREATE INDEX CONCURRENTLY" in migrations

Reported by: FunkyBob Owned by:
Component: Migrations Version: master
Severity: Normal Keywords:
Cc: erik.van.zijst, at, gmail Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a migration creates a new index, it's sometimes preferable to use a concurrent index creation so it won't interfere with the operation of the DB:

http://www.postgresql.org/docs/9.2/static/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY

It would be nice to have an option to enable this in migrations.

Change History (9)

comment:1 Changed 3 years ago by jcatalan

  • Needs documentation unset
  • Needs tests unset
  • Owner set to jcatalan
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 3 years ago by timo

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by andrewgodwin

  • Owner jcatalan deleted
  • Status changed from assigned to new

This won't make it into 1.7, as it's too big of a change.

comment:4 Changed 12 months ago by BlindHunter

Why don't we want to always add CONCURRENTLY statement ? It's a bit slower but allows us to execute zero downtime updates without dirty hacks like create "fake" migration which adds indexes and add them in management commands with "create index concurrently".

comment:5 Changed 12 months ago by charettes

@BlindHunter, concurrent index creation has many documented caveats hence why it's not enabled by default.

I don't think we should expect newcomers to Django/PostgreSQL to make sure all their index have been correctly created even if their migration ran fine. That's the reason we're planing to make it an opt-in feature and not the default behavior, just like it's not the default in PostgreSQL itself.

In the meanwhile I suggest you create your own subclass of Alter(Index|Unique) operations and override database_forward to issue the desired SQL.

comment:6 Changed 10 months ago by erikvanzijst

In the meanwhile I suggest you create your own subclass of Alter(Index|Unique) operations and override database_forward to issue the desired SQL.

CREATE INDEX CONCURRENTLY doesn't run inside a transaction. Can Operation subclasses execute SQL outside the current transaction?

comment:7 Changed 10 months ago by erikvanzijst

  • Cc erik.van.zijst at gmail added

comment:8 Changed 9 months ago by shaib

#25833 is more general, but it would allow this to be written easily as user code. I'd even consider closing this ticket as a duplicate of #25833.

comment:9 Changed 9 months ago by aaugustin

  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top