DEV Community

Why don't database systems have built-in mechanisms for avoiding locks while migrating?

As your app or website becomes popular, it becomes tricky to do database migrations that alter columns without downtime. You basically have to create a new table or column, copy all the data over, and then drop the old version.

Is there any reason why database management systems couldn't do this themselves in many cases? When changing a column's type, why doesn't the database create a new column behind the scenes, write all new values there, while copying old values over in a background process?

Top comments (1)

Collapse
 
kant312 profile image
Quentin Delcourt

I don't know if such a system has been implemented already, but I suppose that, to take your example, it would be difficult for the system to assume how to transform the data it's being passed to the new version of the table.

I suppose you saw these questions on SO:
stackoverflow.com/questions/463677...

dba.stackexchange.com/questions/27...

It seems to be really tricky to implement.