[Django] #21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations

175 views
Skip to first unread message

Django

unread,
Sep 5, 2013, 3:08:01 AM9/5/13
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+--------------------
Reporter: FunkyBob | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 7, 2013, 11:35:46 AM9/7/13
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+--------------------------------------
Reporter: FunkyBob | Owner: jcatalan
Type: New feature | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by jcatalan):

* status: new => assigned
* needs_docs: => 0
* owner: => jcatalan
* needs_tests: => 0
* needs_better_patch: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:1>

Django

unread,
Sep 9, 2013, 10:56:40 AM9/9/13
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner: jcatalan
Type: New feature | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by timo):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:2>

Django

unread,
Jan 8, 2014, 8:08:41 AM1/8/14
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by andrewgodwin):

* status: assigned => new
* owner: jcatalan =>


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:3>

Django

unread,
Sep 14, 2015, 1:18:54 PM9/14/15
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (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".

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:4>

Django

unread,
Sep 14, 2015, 2:11:05 PM9/14/15
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by charettes):

@BlindHunter, concurrent index creation has many
[http://www.postgresql.org/docs/current/static/sql-createindex.html#SQL-
CREATEINDEX-CONCURRENTLY 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:5>

Django

unread,
Nov 3, 2015, 11:35:57 PM11/3/15
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (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?

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:6>

Django

unread,
Nov 3, 2015, 11:36:24 PM11/3/15
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by erikvanzijst):

* cc: erik.van.zijst, at, gmail (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:7>

Django

unread,
Dec 2, 2015, 6:07:52 PM12/2/15
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner:
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (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.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:8>

Django

unread,
Dec 3, 2015, 4:00:09 AM12/3/15
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+-------------------------------------
Reporter: FunkyBob | Owner:
Type: New feature | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:9>

Django

unread,
Jul 29, 2017, 9:56:48 AM7/29/17
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: (none)

Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Tim Graham):

* status: closed => new
* resolution: duplicate =>


Comment:

With #25833 resolved, it's not clear to me how this is a duplicate of that
issue. #28448 is a new ticket requesting support for concurrently indexes.
I'm reopening this ticket and closing that new ticket as a duplicate of
this one.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:10>

Django

unread,
Jan 19, 2019, 11:22:34 PM1/19/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: (none)
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by Dan Tao):

Now that #25833 is resolved, it seems to me there are (at least) two
possible ways to approach this:

1. Add a new `CreateIndexConcurrently` operation in the
django.contrib.postgres.operations module.
2. Add a new `concurrent` argument to the constructor for the base
`AddIndex` operation, and conditionally support this argument via feature
detection based on a new attribute (maybe something like
`supports_concurrent_index_creation`) on the base schema editor class.
Database backends that don't support concurrent index creation (i.e.
everything but PostgreSQL at present) would presumably raise
`NotSupportedError` or something along those lines.

The first option seems simpler to me, at least for now, unless there is
compelling evidence that another database backend will support concurrent
index creation in the near future.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:11>

Django

unread,
Jan 20, 2019, 12:18:39 AM1/20/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: (none)
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by Simon Charette):

> The first option seems simpler to me, at least for now, unless there is
compelling evidence that another database backend will support concurrent
index creation in the near future.

I agree with your conclusions; there's little benefit to add a
`concurrent` option to `CreateIndex` for now. If any supported database
adds support for this option in the future it should be easy enough to
deprecate `contrib.postgres.CreateIndexConcurrently`.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:12>

Django

unread,
Jan 26, 2019, 4:16:19 PM1/26/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: (none)
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Dan Tao):

* cc: Dan Tao (added)
* has_patch: 0 => 1


Comment:

I've opened a pull request to add the `CreateIndexConcurrently` operation
proposed in my previous comment:

https://github.com/django/django/pull/10901

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:13>

Django

unread,
Feb 13, 2019, 7:54:45 PM2/13/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: (none)
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Tim Graham):

* needs_docs: 0 => 1


Comment:

Please add documentation. See the
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-review-checklist patch review checklist].

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:14>

Django

unread,
Feb 14, 2019, 8:55:05 AM2/14/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: Dan Tao

Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Dan Tao):

* owner: (none) => Dan Tao


* status: new => assigned


Comment:

Per [https://docs.djangoproject.com/en/dev/internals/contributing/writing-
code/submitting-patches/#claiming-tickets the guidelines on claiming
tickets], I'm assigning this to myself.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:15>

Django

unread,
Feb 18, 2019, 9:22:18 PM2/18/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Dan Tao):

* needs_docs: 1 => 0


Comment:

I've
[https://github.com/django/django/pull/10901/commits/b98a0db0f0d33852a74c0ce53d44ddbd1af74d9b
added documentation], so I'm unsetting the **Needs documentation** flag.
Of course I am happy to add more docs or update what I've written based on
feedback.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:16>

Django

unread,
Mar 9, 2019, 9:02:28 PM3/9/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+---------------------------------------------

Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Asif Saifuddin Auvi):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:17>

Django

unread,
Mar 12, 2019, 11:12:18 AM3/12/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:18>

Django

unread,
Jul 25, 2019, 8:35:33 AM7/25/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by felixxm):

* needs_better_patch: 1 => 0


Comment:

[https://github.com/django/django/pull/11594 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:19>

Django

unread,
Jul 25, 2019, 10:37:01 AM7/25/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Mads Jensen):

* needs_better_patch: 0 => 1


Comment:

Since there are still things that need work, I'm marking this as WIP.

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:20>

Django

unread,
Aug 8, 2019, 2:55:32 PM8/8/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------
Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by Mads Jensen):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:21>

Django

unread,
Aug 9, 2019, 11:29:07 PM8/9/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+---------------------------------------------

Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Simon Charette):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:22>

Django

unread,
Aug 20, 2019, 5:58:19 AM8/20/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations
-----------------------------+------------------------------------

Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1

* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:23>

Django

unread,
Aug 21, 2019, 7:06:31 AM8/21/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations.
-------------------------------------+-------------------------------------

Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 1 => 0


* stage: Accepted => Ready for checkin

* component: Migrations => contrib.postgres


--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:24>

Django

unread,
Aug 21, 2019, 7:33:32 AM8/21/19
to django-...@googlegroups.com
#21039: Support Postgres "CREATE INDEX CONCURRENTLY" in migrations.
-------------------------------------+-------------------------------------
Reporter: FunkyBob | Owner: Dan Tao
Type: New feature | Status: closed
Component: contrib.postgres | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"85ac838d9e6975130b5c55299e9d7d1222a8e289" 85ac838d]:
{{{
#!CommitTicketReference repository=""
revision="85ac838d9e6975130b5c55299e9d7d1222a8e289"
Fixed #21039 -- Added AddIndexConcurrently/RemoveIndexConcurrently
operations for PostgreSQL.

Thanks to Simon Charettes for review.

Co-Authored-By: Daniel Tao <danie...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21039#comment:25>

Reply all
Reply to author
Forward
0 new messages