Will an ALTER TABLE ADD COLUMN on a slave break replication?ALTER TABLE on a large table with an indexed...

A Trivial Diagnosis

What is going on with gets(stdin) on the site coderbyte?

Make a Bowl of Alphabet Soup

A variation to the phrase "hanging over my shoulders"

How do you make your own symbol when Detexify fails?

Does "he squandered his car on drink" sound natural?

Why is so much work done on numerical verification of the Riemann Hypothesis?

The Digit Triangles

Is it necessary to use pronouns with the verb "essere"?

How can I write humor as character trait?

What is the difference between lands and mana?

Is there a RAID 0 Equivalent for RAM?

Creating two special characters

How can ping know if my host is down

C++ copy constructor called at return

How do I tell my boss that I'm quitting soon, especially given that a colleague just left this week

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

Find the next value of this number series

How does electrical safety system work on ISS?

US tourist/student visa

Biological Blimps: Propulsion

Can you use Vicious Mockery to win an argument or gain favours?

Is there a nicer/politer/more positive alternative for "negates"?

"It doesn't matter" or "it won't matter"?



Will an ALTER TABLE ADD COLUMN on a slave break replication?


ALTER TABLE on a large table with an indexed columnMySQL Replication: Slave with Different Column From MasterPreventing replication of alter table command to change engineMySQL Master Slave Replication and backupMaster and slave tables with different character sets - will replication break?After restarting Mysql replication, Slave commands are executedMySQL replicate-rewrite-db ALTER TABLE not rewrittenMaster-slave + master-master replication at the same timeReplication and table locks during alter tableMySQL replication with DRBD - Can we use Old master as slave after failover?













3















I need to add a last_modified column to a MyISAM table tbl_items. The crux of this problem is that tbl_items houses several gigabytes of data. Also of note, I am using a master-slave deployment with one slave.



Obviously, running the necessary ALTER TABLE command on the master is unacceptable since it locks the table for well over a half-hour. I cannot afford this kind of downtime at ANY time of day or night, most unfortunately.



A few sources have suggested some form of the following:




  1. Disable replication to the slave

  2. Run the ALTER TABLE command on the slave

  3. Switch replication back on and wait for slave to catch up

  4. Promote slave to master


Is this a viable solution? It would seem to me that all new tbl_items inserts would be lost between the beginning of step 2 and step 4; that is, is it possible for tbl_items data to replicate throughout the interval that it's missing the new column?



If that's the case, is there an alternate solution that eliminates the possibility of both downtime and data-loss?










share|improve this question



























    3















    I need to add a last_modified column to a MyISAM table tbl_items. The crux of this problem is that tbl_items houses several gigabytes of data. Also of note, I am using a master-slave deployment with one slave.



    Obviously, running the necessary ALTER TABLE command on the master is unacceptable since it locks the table for well over a half-hour. I cannot afford this kind of downtime at ANY time of day or night, most unfortunately.



    A few sources have suggested some form of the following:




    1. Disable replication to the slave

    2. Run the ALTER TABLE command on the slave

    3. Switch replication back on and wait for slave to catch up

    4. Promote slave to master


    Is this a viable solution? It would seem to me that all new tbl_items inserts would be lost between the beginning of step 2 and step 4; that is, is it possible for tbl_items data to replicate throughout the interval that it's missing the new column?



    If that's the case, is there an alternate solution that eliminates the possibility of both downtime and data-loss?










    share|improve this question

























      3












      3








      3








      I need to add a last_modified column to a MyISAM table tbl_items. The crux of this problem is that tbl_items houses several gigabytes of data. Also of note, I am using a master-slave deployment with one slave.



      Obviously, running the necessary ALTER TABLE command on the master is unacceptable since it locks the table for well over a half-hour. I cannot afford this kind of downtime at ANY time of day or night, most unfortunately.



      A few sources have suggested some form of the following:




      1. Disable replication to the slave

      2. Run the ALTER TABLE command on the slave

      3. Switch replication back on and wait for slave to catch up

      4. Promote slave to master


      Is this a viable solution? It would seem to me that all new tbl_items inserts would be lost between the beginning of step 2 and step 4; that is, is it possible for tbl_items data to replicate throughout the interval that it's missing the new column?



      If that's the case, is there an alternate solution that eliminates the possibility of both downtime and data-loss?










      share|improve this question














      I need to add a last_modified column to a MyISAM table tbl_items. The crux of this problem is that tbl_items houses several gigabytes of data. Also of note, I am using a master-slave deployment with one slave.



      Obviously, running the necessary ALTER TABLE command on the master is unacceptable since it locks the table for well over a half-hour. I cannot afford this kind of downtime at ANY time of day or night, most unfortunately.



      A few sources have suggested some form of the following:




      1. Disable replication to the slave

      2. Run the ALTER TABLE command on the slave

      3. Switch replication back on and wait for slave to catch up

      4. Promote slave to master


      Is this a viable solution? It would seem to me that all new tbl_items inserts would be lost between the beginning of step 2 and step 4; that is, is it possible for tbl_items data to replicate throughout the interval that it's missing the new column?



      If that's the case, is there an alternate solution that eliminates the possibility of both downtime and data-loss?







      mysql performance replication locking alter-table






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 12 '12 at 19:33









      joadhajoadha

      1613




      1613






















          3 Answers
          3






          active

          oldest

          votes


















          1














          Try these possible recommendation and solution:




          • For MyISAM tables, you can speed up index re-creation (the slowest part of the alteration process) by setting the myisam_sort_buffer_size system variable to a high value.


          • If you use ALTER TABLE on a MyISAM table, all nonunique indexes are created in a separate batch (as for REPAIR TABLE). This should make ALTER TABLE much faster when you have many indexes.
            This feature can be activated explicitly for a MyISAM table. ALTER TABLE ... DISABLE KEYS tells MySQL to stop updating nonunique indexes. ALTER TABLE ... ENABLE KEYS then should be used to re-create missing indexes. MySQL does this with a special algorithm that is much faster than inserting keys one by one, so disabling keys before performing bulk insert operations should give a considerable speedup. Using ALTER TABLE ... DISABLE KEYS requires the INDEX privilege in addition to the privileges mentioned earlier.



          While the nonunique indexes are disabled, they are ignored for statements such as SELECT and EXPLAIN that otherwise would use them.




          • If you are just changing a column name on a MyISAM table and want to avoid duplicating the entire table, try the following (no warranty provided but worked for me):


          For peace-of-mind -- try this with some dummy data first!




          1. Backup the .frm file from your master table (and the data if you can, but you're probably reading this because you can't).


          2. create table with the identical schema to the one you want to alter (type "show create table and just change the name to something). Lets say you called the table "rename_temp1"


          3. execute the "alter table change char(128) not null" [substituting your the old definition -- ensuring you keep column type the same]


          4. Ensuring you a have made a copy of your original .frm file -- copy the .frm file to .frm.


          5. voila -- all going well your column should be renamed without a full copy in/out (very useful for 140G tables...)


          6. probably best to run a myisamchck on the table before making live again







          share|improve this answer
























          • Thanks for the answer! I will upvote this once I gain the required rep level. I will be experimenting with myisam_sort_buffer_size.

            – joadha
            Apr 13 '12 at 14:01



















          1














          I think that, if your purpose is to avoid locking, you should use pt-online-schema-change (a tool from Percona Toolkit) or Gh-ost (from GitHub).



          Here is how pt-osc works:




          • Creates a ghost table identical to the original table, but empty

          • Runs ALTER TABLE on the ghost table

          • Creates triggers on the original table, which insert new rows in the new table, and updates and deletes them if they are already there.

          • It copies the rows in chunks, monitoring the server performance (it can slow down or pause its work if necessary)

          • Switch the table names


          gh-ost is very similar, the main difference is that it creates no triggers, and uses the binary log instead to detect the changes to the original table.



          To answer your question more directly - yes, it is possible to add a column on the slave. And most probably it will simply work, as long as it has a default value. But it is very likely that in the future you will regret this choice, because you'll need to do something that will break replication, like adding a column in the master. I recommend to sure to check the documentation and fully understand the dangers, before doing such a thing.






          share|improve this answer

































            0














            There is no fast way to ADD a column (until 5.6, rumor has it).



            One way that might work is as follows. It requires that you already have "dual-master, single-writer" set up.




            1. Take the backup master offline

            2. ALTER there

            3. Bring it back online -- but watch out! Anything that touches that table may cause replication to hang because the schema is different. In particular, you probably have to make the new column NULLable so that INSERTs won't fail. An INSERT without a list of column names will fail.

            4. Fail over.


            Another possibility... Facebook has a posting on how to do an online ALTER. It does have drawbacks...
            * FOREIGN KEYs may be a problem
            * It requires a TRIGGER; so you must not already have one.
            * There is a brief outage when it makes the final switchover. This is probably brief enough to be acceptable.



            Percona has a similar animal. Start with theirs.






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "182"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f16451%2fwill-an-alter-table-add-column-on-a-slave-break-replication%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Try these possible recommendation and solution:




              • For MyISAM tables, you can speed up index re-creation (the slowest part of the alteration process) by setting the myisam_sort_buffer_size system variable to a high value.


              • If you use ALTER TABLE on a MyISAM table, all nonunique indexes are created in a separate batch (as for REPAIR TABLE). This should make ALTER TABLE much faster when you have many indexes.
                This feature can be activated explicitly for a MyISAM table. ALTER TABLE ... DISABLE KEYS tells MySQL to stop updating nonunique indexes. ALTER TABLE ... ENABLE KEYS then should be used to re-create missing indexes. MySQL does this with a special algorithm that is much faster than inserting keys one by one, so disabling keys before performing bulk insert operations should give a considerable speedup. Using ALTER TABLE ... DISABLE KEYS requires the INDEX privilege in addition to the privileges mentioned earlier.



              While the nonunique indexes are disabled, they are ignored for statements such as SELECT and EXPLAIN that otherwise would use them.




              • If you are just changing a column name on a MyISAM table and want to avoid duplicating the entire table, try the following (no warranty provided but worked for me):


              For peace-of-mind -- try this with some dummy data first!




              1. Backup the .frm file from your master table (and the data if you can, but you're probably reading this because you can't).


              2. create table with the identical schema to the one you want to alter (type "show create table and just change the name to something). Lets say you called the table "rename_temp1"


              3. execute the "alter table change char(128) not null" [substituting your the old definition -- ensuring you keep column type the same]


              4. Ensuring you a have made a copy of your original .frm file -- copy the .frm file to .frm.


              5. voila -- all going well your column should be renamed without a full copy in/out (very useful for 140G tables...)


              6. probably best to run a myisamchck on the table before making live again







              share|improve this answer
























              • Thanks for the answer! I will upvote this once I gain the required rep level. I will be experimenting with myisam_sort_buffer_size.

                – joadha
                Apr 13 '12 at 14:01
















              1














              Try these possible recommendation and solution:




              • For MyISAM tables, you can speed up index re-creation (the slowest part of the alteration process) by setting the myisam_sort_buffer_size system variable to a high value.


              • If you use ALTER TABLE on a MyISAM table, all nonunique indexes are created in a separate batch (as for REPAIR TABLE). This should make ALTER TABLE much faster when you have many indexes.
                This feature can be activated explicitly for a MyISAM table. ALTER TABLE ... DISABLE KEYS tells MySQL to stop updating nonunique indexes. ALTER TABLE ... ENABLE KEYS then should be used to re-create missing indexes. MySQL does this with a special algorithm that is much faster than inserting keys one by one, so disabling keys before performing bulk insert operations should give a considerable speedup. Using ALTER TABLE ... DISABLE KEYS requires the INDEX privilege in addition to the privileges mentioned earlier.



              While the nonunique indexes are disabled, they are ignored for statements such as SELECT and EXPLAIN that otherwise would use them.




              • If you are just changing a column name on a MyISAM table and want to avoid duplicating the entire table, try the following (no warranty provided but worked for me):


              For peace-of-mind -- try this with some dummy data first!




              1. Backup the .frm file from your master table (and the data if you can, but you're probably reading this because you can't).


              2. create table with the identical schema to the one you want to alter (type "show create table and just change the name to something). Lets say you called the table "rename_temp1"


              3. execute the "alter table change char(128) not null" [substituting your the old definition -- ensuring you keep column type the same]


              4. Ensuring you a have made a copy of your original .frm file -- copy the .frm file to .frm.


              5. voila -- all going well your column should be renamed without a full copy in/out (very useful for 140G tables...)


              6. probably best to run a myisamchck on the table before making live again







              share|improve this answer
























              • Thanks for the answer! I will upvote this once I gain the required rep level. I will be experimenting with myisam_sort_buffer_size.

                – joadha
                Apr 13 '12 at 14:01














              1












              1








              1







              Try these possible recommendation and solution:




              • For MyISAM tables, you can speed up index re-creation (the slowest part of the alteration process) by setting the myisam_sort_buffer_size system variable to a high value.


              • If you use ALTER TABLE on a MyISAM table, all nonunique indexes are created in a separate batch (as for REPAIR TABLE). This should make ALTER TABLE much faster when you have many indexes.
                This feature can be activated explicitly for a MyISAM table. ALTER TABLE ... DISABLE KEYS tells MySQL to stop updating nonunique indexes. ALTER TABLE ... ENABLE KEYS then should be used to re-create missing indexes. MySQL does this with a special algorithm that is much faster than inserting keys one by one, so disabling keys before performing bulk insert operations should give a considerable speedup. Using ALTER TABLE ... DISABLE KEYS requires the INDEX privilege in addition to the privileges mentioned earlier.



              While the nonunique indexes are disabled, they are ignored for statements such as SELECT and EXPLAIN that otherwise would use them.




              • If you are just changing a column name on a MyISAM table and want to avoid duplicating the entire table, try the following (no warranty provided but worked for me):


              For peace-of-mind -- try this with some dummy data first!




              1. Backup the .frm file from your master table (and the data if you can, but you're probably reading this because you can't).


              2. create table with the identical schema to the one you want to alter (type "show create table and just change the name to something). Lets say you called the table "rename_temp1"


              3. execute the "alter table change char(128) not null" [substituting your the old definition -- ensuring you keep column type the same]


              4. Ensuring you a have made a copy of your original .frm file -- copy the .frm file to .frm.


              5. voila -- all going well your column should be renamed without a full copy in/out (very useful for 140G tables...)


              6. probably best to run a myisamchck on the table before making live again







              share|improve this answer













              Try these possible recommendation and solution:




              • For MyISAM tables, you can speed up index re-creation (the slowest part of the alteration process) by setting the myisam_sort_buffer_size system variable to a high value.


              • If you use ALTER TABLE on a MyISAM table, all nonunique indexes are created in a separate batch (as for REPAIR TABLE). This should make ALTER TABLE much faster when you have many indexes.
                This feature can be activated explicitly for a MyISAM table. ALTER TABLE ... DISABLE KEYS tells MySQL to stop updating nonunique indexes. ALTER TABLE ... ENABLE KEYS then should be used to re-create missing indexes. MySQL does this with a special algorithm that is much faster than inserting keys one by one, so disabling keys before performing bulk insert operations should give a considerable speedup. Using ALTER TABLE ... DISABLE KEYS requires the INDEX privilege in addition to the privileges mentioned earlier.



              While the nonunique indexes are disabled, they are ignored for statements such as SELECT and EXPLAIN that otherwise would use them.




              • If you are just changing a column name on a MyISAM table and want to avoid duplicating the entire table, try the following (no warranty provided but worked for me):


              For peace-of-mind -- try this with some dummy data first!




              1. Backup the .frm file from your master table (and the data if you can, but you're probably reading this because you can't).


              2. create table with the identical schema to the one you want to alter (type "show create table and just change the name to something). Lets say you called the table "rename_temp1"


              3. execute the "alter table change char(128) not null" [substituting your the old definition -- ensuring you keep column type the same]


              4. Ensuring you a have made a copy of your original .frm file -- copy the .frm file to .frm.


              5. voila -- all going well your column should be renamed without a full copy in/out (very useful for 140G tables...)


              6. probably best to run a myisamchck on the table before making live again








              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Apr 13 '12 at 11:02









              Mahesh PatilMahesh Patil

              2,494919




              2,494919













              • Thanks for the answer! I will upvote this once I gain the required rep level. I will be experimenting with myisam_sort_buffer_size.

                – joadha
                Apr 13 '12 at 14:01



















              • Thanks for the answer! I will upvote this once I gain the required rep level. I will be experimenting with myisam_sort_buffer_size.

                – joadha
                Apr 13 '12 at 14:01

















              Thanks for the answer! I will upvote this once I gain the required rep level. I will be experimenting with myisam_sort_buffer_size.

              – joadha
              Apr 13 '12 at 14:01





              Thanks for the answer! I will upvote this once I gain the required rep level. I will be experimenting with myisam_sort_buffer_size.

              – joadha
              Apr 13 '12 at 14:01













              1














              I think that, if your purpose is to avoid locking, you should use pt-online-schema-change (a tool from Percona Toolkit) or Gh-ost (from GitHub).



              Here is how pt-osc works:




              • Creates a ghost table identical to the original table, but empty

              • Runs ALTER TABLE on the ghost table

              • Creates triggers on the original table, which insert new rows in the new table, and updates and deletes them if they are already there.

              • It copies the rows in chunks, monitoring the server performance (it can slow down or pause its work if necessary)

              • Switch the table names


              gh-ost is very similar, the main difference is that it creates no triggers, and uses the binary log instead to detect the changes to the original table.



              To answer your question more directly - yes, it is possible to add a column on the slave. And most probably it will simply work, as long as it has a default value. But it is very likely that in the future you will regret this choice, because you'll need to do something that will break replication, like adding a column in the master. I recommend to sure to check the documentation and fully understand the dangers, before doing such a thing.






              share|improve this answer






























                1














                I think that, if your purpose is to avoid locking, you should use pt-online-schema-change (a tool from Percona Toolkit) or Gh-ost (from GitHub).



                Here is how pt-osc works:




                • Creates a ghost table identical to the original table, but empty

                • Runs ALTER TABLE on the ghost table

                • Creates triggers on the original table, which insert new rows in the new table, and updates and deletes them if they are already there.

                • It copies the rows in chunks, monitoring the server performance (it can slow down or pause its work if necessary)

                • Switch the table names


                gh-ost is very similar, the main difference is that it creates no triggers, and uses the binary log instead to detect the changes to the original table.



                To answer your question more directly - yes, it is possible to add a column on the slave. And most probably it will simply work, as long as it has a default value. But it is very likely that in the future you will regret this choice, because you'll need to do something that will break replication, like adding a column in the master. I recommend to sure to check the documentation and fully understand the dangers, before doing such a thing.






                share|improve this answer




























                  1












                  1








                  1







                  I think that, if your purpose is to avoid locking, you should use pt-online-schema-change (a tool from Percona Toolkit) or Gh-ost (from GitHub).



                  Here is how pt-osc works:




                  • Creates a ghost table identical to the original table, but empty

                  • Runs ALTER TABLE on the ghost table

                  • Creates triggers on the original table, which insert new rows in the new table, and updates and deletes them if they are already there.

                  • It copies the rows in chunks, monitoring the server performance (it can slow down or pause its work if necessary)

                  • Switch the table names


                  gh-ost is very similar, the main difference is that it creates no triggers, and uses the binary log instead to detect the changes to the original table.



                  To answer your question more directly - yes, it is possible to add a column on the slave. And most probably it will simply work, as long as it has a default value. But it is very likely that in the future you will regret this choice, because you'll need to do something that will break replication, like adding a column in the master. I recommend to sure to check the documentation and fully understand the dangers, before doing such a thing.






                  share|improve this answer















                  I think that, if your purpose is to avoid locking, you should use pt-online-schema-change (a tool from Percona Toolkit) or Gh-ost (from GitHub).



                  Here is how pt-osc works:




                  • Creates a ghost table identical to the original table, but empty

                  • Runs ALTER TABLE on the ghost table

                  • Creates triggers on the original table, which insert new rows in the new table, and updates and deletes them if they are already there.

                  • It copies the rows in chunks, monitoring the server performance (it can slow down or pause its work if necessary)

                  • Switch the table names


                  gh-ost is very similar, the main difference is that it creates no triggers, and uses the binary log instead to detect the changes to the original table.



                  To answer your question more directly - yes, it is possible to add a column on the slave. And most probably it will simply work, as long as it has a default value. But it is very likely that in the future you will regret this choice, because you'll need to do something that will break replication, like adding a column in the master. I recommend to sure to check the documentation and fully understand the dangers, before doing such a thing.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 4 mins ago

























                  answered Feb 26 '18 at 20:07









                  Federico RazzoliFederico Razzoli

                  804116




                  804116























                      0














                      There is no fast way to ADD a column (until 5.6, rumor has it).



                      One way that might work is as follows. It requires that you already have "dual-master, single-writer" set up.




                      1. Take the backup master offline

                      2. ALTER there

                      3. Bring it back online -- but watch out! Anything that touches that table may cause replication to hang because the schema is different. In particular, you probably have to make the new column NULLable so that INSERTs won't fail. An INSERT without a list of column names will fail.

                      4. Fail over.


                      Another possibility... Facebook has a posting on how to do an online ALTER. It does have drawbacks...
                      * FOREIGN KEYs may be a problem
                      * It requires a TRIGGER; so you must not already have one.
                      * There is a brief outage when it makes the final switchover. This is probably brief enough to be acceptable.



                      Percona has a similar animal. Start with theirs.






                      share|improve this answer




























                        0














                        There is no fast way to ADD a column (until 5.6, rumor has it).



                        One way that might work is as follows. It requires that you already have "dual-master, single-writer" set up.




                        1. Take the backup master offline

                        2. ALTER there

                        3. Bring it back online -- but watch out! Anything that touches that table may cause replication to hang because the schema is different. In particular, you probably have to make the new column NULLable so that INSERTs won't fail. An INSERT without a list of column names will fail.

                        4. Fail over.


                        Another possibility... Facebook has a posting on how to do an online ALTER. It does have drawbacks...
                        * FOREIGN KEYs may be a problem
                        * It requires a TRIGGER; so you must not already have one.
                        * There is a brief outage when it makes the final switchover. This is probably brief enough to be acceptable.



                        Percona has a similar animal. Start with theirs.






                        share|improve this answer


























                          0












                          0








                          0







                          There is no fast way to ADD a column (until 5.6, rumor has it).



                          One way that might work is as follows. It requires that you already have "dual-master, single-writer" set up.




                          1. Take the backup master offline

                          2. ALTER there

                          3. Bring it back online -- but watch out! Anything that touches that table may cause replication to hang because the schema is different. In particular, you probably have to make the new column NULLable so that INSERTs won't fail. An INSERT without a list of column names will fail.

                          4. Fail over.


                          Another possibility... Facebook has a posting on how to do an online ALTER. It does have drawbacks...
                          * FOREIGN KEYs may be a problem
                          * It requires a TRIGGER; so you must not already have one.
                          * There is a brief outage when it makes the final switchover. This is probably brief enough to be acceptable.



                          Percona has a similar animal. Start with theirs.






                          share|improve this answer













                          There is no fast way to ADD a column (until 5.6, rumor has it).



                          One way that might work is as follows. It requires that you already have "dual-master, single-writer" set up.




                          1. Take the backup master offline

                          2. ALTER there

                          3. Bring it back online -- but watch out! Anything that touches that table may cause replication to hang because the schema is different. In particular, you probably have to make the new column NULLable so that INSERTs won't fail. An INSERT without a list of column names will fail.

                          4. Fail over.


                          Another possibility... Facebook has a posting on how to do an online ALTER. It does have drawbacks...
                          * FOREIGN KEYs may be a problem
                          * It requires a TRIGGER; so you must not already have one.
                          * There is a brief outage when it makes the final switchover. This is probably brief enough to be acceptable.



                          Percona has a similar animal. Start with theirs.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 17 '12 at 23:02









                          Rick JamesRick James

                          43.6k22259




                          43.6k22259






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Database Administrators Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f16451%2fwill-an-alter-table-add-column-on-a-slave-break-replication%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

                              Always On Availability groups resolving state after failover - Remote harden of transaction...

                              update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...