mirror of https://github.com/django/django.git
Clarifed table rewrites in migration docs.
Small nitpicks. All column-related ALTER TABLE commands take an exclusive table lock in PostgreSQL. The difference is that adding a column without default doesn't cause a table rewrite, so the lock is held only for a short time. The time taken is more accurately proportional to table size, not row count.
This commit is contained in:
parent
6685713869
commit
75ec1fdf16
|
@ -70,7 +70,7 @@ PostgreSQL
|
||||||
|
|
||||||
PostgreSQL is the most capable of all the databases here in terms of schema
|
PostgreSQL is the most capable of all the databases here in terms of schema
|
||||||
support; the only caveat is that adding columns with default values will
|
support; the only caveat is that adding columns with default values will
|
||||||
lock a table for a time proportional to the number of rows in it.
|
cause a full rewrite of the table, for a time proportional to its size.
|
||||||
|
|
||||||
For this reason, it's recommended you always create new columns with
|
For this reason, it's recommended you always create new columns with
|
||||||
``null=True``, as this way they will be added immediately.
|
``null=True``, as this way they will be added immediately.
|
||||||
|
@ -83,11 +83,11 @@ meaning that if a migration fails to apply you will have to manually unpick
|
||||||
the changes in order to try again (it's impossible to roll back to an
|
the changes in order to try again (it's impossible to roll back to an
|
||||||
earlier point).
|
earlier point).
|
||||||
|
|
||||||
In addition, MySQL will lock tables for almost every schema operation and
|
In addition, MySQL will fully rewrite tables for almost every schema operation
|
||||||
generally takes a time proportional to the number of rows in the table to
|
and generally takes a time proportional to the number of rows in the table to
|
||||||
add or remove columns. On slower hardware this can be worse than a minute
|
add or remove columns. On slower hardware this can be worse than a minute per
|
||||||
per million rows - adding a few columns to a table with just a few million
|
million rows - adding a few columns to a table with just a few million rows
|
||||||
rows could lock your site up for over ten minutes.
|
could lock your site up for over ten minutes.
|
||||||
|
|
||||||
Finally, MySQL has reasonably small limits on name lengths for columns, tables
|
Finally, MySQL has reasonably small limits on name lengths for columns, tables
|
||||||
and indexes, as well as a limit on the combined size of all columns an index
|
and indexes, as well as a limit on the combined size of all columns an index
|
||||||
|
|
Loading…
Reference in New Issue