ALTER TABLE without locking the table?

后端 未结 19 2070
梦毁少年i
梦毁少年i 2020-11-30 17:41

When doing an ALTER TABLE statement in MySQL, the whole table is read-locked (allowing concurrent reads, but prohibiting concurrent writes) for the duration of the statement

19条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 17:59

    I recommend Postgres if that's an option. With postgres there is essentially no downtime with the following procedures:

    • ALTER TABLE ADD COLUMN (if the column can be NULL)
    • ALTER TABLE DROP COLUMN
    • CREATE INDEX (must use CREATE INDEX CONCURRENTLY)
    • DROP INDEX

    Other great feature is that most DDL statements are transactional, so you could do an entire migration within a SQL transaction, and if something goes wrong, the entire thing gets rolled back.

    I wrote this a little bit ago, perhaps it can shed some more insight on the other merits.

提交回复
热议问题