The problem with MySQL foreign key constraints in Online Schema Changes (2021)
1–8 of 8 posts
Re: The problem with MySQL foreign key constraints in Online Schema Changes (2021)
#2Re: The problem with MySQL foreign key constraints in Online Schema Changes (2021)
#3Run into this way too many times at my last few jobs. MySQL has some serious land mines built in, which result in many companies just adopting the policy of never upgrading the schema during business hours.
You are basically required to implement pt-online-schema-change in order to reliabily do basic changes.
Re: The problem with MySQL foreign key constraints in Online Schema Changes (2021)
#4Doesnt Postgres have the same issue?
Dropping the constraints takes an AccessExclusiveLock for a very short time in both tables so yes, that would interrupt traffic but the online migration tools also do this to switch the tables so I give it a pass.
Re: The problem with MySQL foreign key constraints in Online Schema Changes (2021)
#5> Isn’t there some Instant DDL? Run into this way too many times at my last few jobs. MySQL has some serious land mines built in, which result in many companies just adopting the policy of never upgrading the schema during business hours. You are basically required to implement pt-online-schema-change in order to reliabily do basic changes.
The article is also four years old, and INSTANT now covers a few additional cases which it didn't at that time.
If your alter doesn't support INSTANT, at that point you can fall back to an online schema change tool, of which there are several battle-tested options. All of the largest MySQL users (including many of the biggest names in tech) do schema changes any time of day without issue by automating these tools. In comparison the equivalent tools for Postgres are far less mature.
Re: The problem with MySQL foreign key constraints in Online Schema Changes (2021)
#6Doesnt Postgres have the same issue?
You can create Foreign Keys as NOT VALID and then VALIDATE the constraint later. This only takes a RowShareLock. Dropping the constraints takes an AccessExclusiveLock for a very short time in both tables so yes, that would interrupt traffic but the online migration tools also do this to switch the tables so I give it a pass.
I am asking out of curiosity, as I have used pt online schema change extensively before, but am right now working mostly with postgres
Re: The problem with MySQL foreign key constraints in Online Schema Changes (2021)
#7> Isn’t there some Instant DDL? Run into this way too many times at my last few jobs. MySQL has some serious land mines built in, which result in many companies just adopting the policy of never upgrading the schema during business hours. You are basically required to implement pt-online-schema-change in order to reliabily do basic changes.
Re: The problem with MySQL foreign key constraints in Online Schema Changes (2021)
#8Earlier quoted context omitted.
You can create Foreign Keys as NOT VALID and then VALIDATE the constraint later. This only takes a RowShareLock. Dropping the constraints takes an AccessExclusiveLock for a very short time in both tables so yes, that would interrupt traffic but the online migration tools also do this to switch the tables so I give it a pass.
wouldnt that take an awful long time when validating the foreign keys again? You cant flip the tables again until all foreign keys are valid. I am asking out of curiosity, as I have used pt online schema change extensively before, but am right now working mostly with postgres
--https://www.postgresql.org/docs/current/sql-altertable.html