SlideShare a Scribd company logo
Copyright 2015 Severalnines AB
Schema Changes for MySQL Replication & Galera Cluster
August 25, 2015
Krzysztof Książek
Severalnines
krzysztof@severalnines.com
1
Copyright 2015 Severalnines AB
! We want to help all non-DBA people who look after
MySQL infrastructures
! Share tips and good practices
! Watch the replays of the previous webinars on our
Slideshare page
! http://www.slideshare.net/Severalnines/videos
2
“Become a MySQL DBA” series
Copyright 2015 Severalnines AB
! Different methods to perform schema changes on MySQL Replication
and Galera
! rolling schema change
! online alters
! external tools, e.g., pt-online-schema-change
! Differences between MySQL 5.5 and 5.6
! Differences between MySQL Replication vs Galera
! Example real-life scenarios with MySQL Replication and Galera setups

3
Agenda
Copyright 2015 Severalnines AB
Schema changes in MySQL
4
Copyright 2015 Severalnines AB
! Application development
! New features to existing
modules
! New modules
! Data management and
archiving (partitions)
! Schema optimization
! Performance optimization
5
Why schemas need changes?
Copyright 2015 Severalnines AB
! Point-in-time schema changes
! Everything happens at a given point of time, over the
whole infrastructure
! Rolling schema changes
! Changes happen at different times across the
infrastructure
! Requirement is that schema versions have to be
compatible with each other
6
Types of schema changes
Copyright 2015 Severalnines AB
! Schema changes cause significant performance
overhead as they are I/O-heavy operations
! Schema changes may take long time to finish on larger
tables
! Direct schema changes don’t play well with MySQL
replication due to the lag inducted
! Direct schema changes don’t play well with Galera
! Rolling schema changes may require significant amount
of work
7
Schema changes - limitations
Copyright 2015 Severalnines AB
! Replication has it’s limitations, only some changes can be
replicated. RBR is very strict here
! Remove a column at the end of the table - yes
! Remove a column in the middle - no go
! Add a column at the end - works
! Add a column in the middle - not really
! Not every conversion between column types works -
refer to the documentation
8
Schema changes - limitations
Copyright 2015 Severalnines AB
! You can’t change the
schema and the code at
the exact time
! New schema have to be
compatible with old code
! Depreciate columns, not
remove
! Remove them two, three
iterations later, once you
confirm you _can_ remove
9
Schema changes - limitations
Copyright 2015 Severalnines AB
Ways to perform a schema change
10
Copyright 2015 Severalnines AB
! Online DDL
! Rolling schema upgrade
! Online schema change
! Rolling Schema Upgrade for Galera
! Total Order Isolation for Galera
11
Methods to perform a schema change
Copyright 2015 Severalnines AB
! DDL, historically, was a locking operation
! Some of them were fast, i.e. DROP (secondary) INDEX
! InnoDB plugin in 5.1 and 5.5 introduced Fast Index
Creation that allowed reads to be executed while
secondary index has been added
! MySQL 5.6 introduced online DDL’s for InnoDB
12
Online DDL
Copyright 2015 Severalnines AB
! Many operations are non-blocking for reads and writes
! Add an index
! Add a column
! Reorder columns
! Add a primary key
! and many others (check the documentation)
! https://dev.mysql.com/doc/refman/5.6/en/innodb-create-
index-overview.html#innodb-online-ddl-summary-grid
13
Online DDL
Copyright 2015 Severalnines AB
! Busy tables may be an issue
(innodb_online_alter_log_max_size)
! Lag will be an issue - online DDL is online on the master
only
! Not suitable for large tables in replication setup
14
Online DDL
Copyright 2015 Severalnines AB
! Run DDL from the bottom to the top of replication chain
! SET SESSION sql_log_bin=0 to avoid errant transactions
! Once you reach the master, failover and then alter the
old master
! Schema changes have to be compatible, you’ll be
running DML’s on a mix of altered and not altered tables
! Schema changes have to be compatible, you’ll be
reading from a mix of altered and not altered tables
15
Rolling Schema Upgrade
Copyright 2015 Severalnines AB
! Different tools (pt-online-schema-change, Online Schema
Change from FB), same idea
! Create a new table with desired schema
! Setup triggers to copy data from old to the new table
! Copy the data from old to new table in batches
! Rename table once the data has been copied
16
Online Schema Change - external tools
Copyright 2015 Severalnines AB
Online Schema Change - external tools
17
Copyright 2015 Severalnines AB
! pt-online-schema-change - the most popular tool
! Point-in-time change, you can use for any DDL
! Replicaton-aware, it can monitor lag and throttle itself
! Introduces additional load, slow down your system
! It has issues with foreign keys
! Can’t work with tables which have triggers
! Won’t work with tables without PK and unique key
18
pt-online-schema-change
Copyright 2015 Severalnines AB
! Otherwise it’s a very reliable tool
! Schema change may take a long time but it’s throttling
itself and can be paused at any time
! One of the most important tools in the DBA arsenal
! Sometimes it’s the only way to run a schema change
without downtime
19
pt-online-schema-change
Copyright 2015 Severalnines AB
Schema changes in Galera Cluster
20
Copyright 2015 Severalnines AB
! All changes happen at the
exact time in the cluster
! All changes are blocking
(you won’t benefit from
online DDL’s)
! Great for consistency
! You can run any change
this way
! Not suitable for larger tables
due to severe locking
21
Total Order Isolation
Copyright 2015 Severalnines AB
! Similar to the rolling schema upgrade we discussed earlier
! Process is partially automated - you need to set
wsrep_OSU_method to RSU and proceed with DDL
! Node will be in Desync state for a duration of the DDL
! Once DDL finishes, node applies remaining writesets
! Writesets are stored in gcache, both in memory and on
disk
22
Rolling Schema Upgrade
Copyright 2015 Severalnines AB
Rolling Schema Upgrade
23
Copyright 2015 Severalnines AB
Different scenarios for a schema
change
24
Copyright 2015 Severalnines AB
! If a change is non-blocking - online DDL
! pt-online-schema-change may also work
! pt-osc should not take more than a couple of minutes
! For Galera - TOI if you can accept few seconds of stall
! Otherwise - pt-online-schema-change is the only option
25
Small tables (up to 10s of a direct DDL)
Copyright 2015 Severalnines AB
! pt-online-schema-change is the best option here for both
MySQL and Galera
! pt-online-schema-change may take even couple of hours
to finish
! It’s less cumbersome than rolling upgrade
! Rolling schema upgrade may be the option of choice if
pt-osc can’t be used due to it’s limitations (no PK, triggers
in altered table, etc.)
26
Medium tables (20 - 30m, up to 1h)
Copyright 2015 Severalnines AB
! pt-osc will work but it will take long time (36 - 48h) to finish
! You need to have enough disk space for binlogs and
altered copy of the table
! Rolling schema upgrade may be a feasible option
! For Galera pt-osc can be also the best option
! RSU is another option but ensure you have large gcache
(or a space on disk for gcache files)
27
Large tables (more than 1h, up to 12h)
Copyright 2015 Severalnines AB
! Are you sure that you need such a large table?
! Try to avoid them by splitting data across many tables or
archiving old data
! Rolling schema upgrade is the way to go
! Use snapshots or xtrabackup to provision new nodes
! Galera may need large gcache (both in memory and on
disk)
! Process of joining desynced node will take a long time
28
Very large tables (more than 12h)
Copyright 2015 Severalnines AB
! Schema change speed depends on your hardware and
data structure
! Test the changes on development environment
! Is it worth using triggers or foreign keys and not have the
option to use pt-osc?
! You _do_ want to have PK defined in all tables - do it
before it grows too large to alter
! Schema changes will happen, get used to them
29
What to keep in mind?
Copyright 2015 Severalnines AB
! More blogs in “Become a MySQL DBA” series:
! http://www.severalnines.com/blog/become-mysql-
dba-blog-series-query-tuning-process
! http://www.severalnines.com/blog/become-mysql-
dba-blog-series-configuration-tuning-performance
! Contact: krzysztof@severalnines.com
30
Thank You!

More Related Content

PDF
Become a MySQL DBA - webinar series - slides: Which High Availability solution?
PDF
Webinar slides: Managing MySQL Replication for High Availability
PDF
Become a MySQL DBA - slides: Deciding on a relevant backup solution
PDF
Become a MySQL DBA: performing live database upgrades - webinar slides
PDF
Webinar slides: Replication Topology Changes for MySQL and MariaDB
PPTX
Webinar slides - ClusterControl 1.2.11: with support for MariaDB’s MaxScale a...
PDF
Webinar slides: ClusterControl 1.4: The MySQL Replication & MongoDB Edition -...
PPTX
Tips to drive maria db cluster performance for nextcloud
Become a MySQL DBA - webinar series - slides: Which High Availability solution?
Webinar slides: Managing MySQL Replication for High Availability
Become a MySQL DBA - slides: Deciding on a relevant backup solution
Become a MySQL DBA: performing live database upgrades - webinar slides
Webinar slides: Replication Topology Changes for MySQL and MariaDB
Webinar slides - ClusterControl 1.2.11: with support for MariaDB’s MaxScale a...
Webinar slides: ClusterControl 1.4: The MySQL Replication & MongoDB Edition -...
Tips to drive maria db cluster performance for nextcloud

What's hot (20)

PPTX
Maria DB Galera Cluster for High Availability
PDF
Webinar slides: Top 9 Tips for building a stable MySQL Replication environment
PDF
Zero Downtime Schema Changes - Galera Cluster - Best Practices
PPTX
High Availability with MariaDB Enterprise
PDF
Enterprise Drupal Application & Hosting Infrastructure Level Monitoring
DOCX
Master master vs master-slave database
PDF
Galera 3.0 Webinar Slides: Galera Monitoring & Management
PDF
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
PDF
Webinar slides: 9 DevOps Tips for Going in Production with Galera Cluster for...
PPTX
MySQL Multi Master Replication
PDF
Using and Benchmarking Galera in different architectures (PLUK 2012)
PDF
Methods of Sharding MySQL
PDF
Galera Cluster: Synchronous Multi-Master Replication for MySQL HA
PPTX
Management and Automation of MongoDB Clusters - Slides
PPTX
M|18 How DBAs at TradingScreen Make Life Easier With Automation
PDF
Planning for Disaster Recovery (DR) with Galera Cluster
PDF
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
PDF
Galera Cluster DDL and Schema Upgrades 220217
PPTX
Get the most out of Oracle Data Guard - OOW version
KEY
Drupal In The Cloud
Maria DB Galera Cluster for High Availability
Webinar slides: Top 9 Tips for building a stable MySQL Replication environment
Zero Downtime Schema Changes - Galera Cluster - Best Practices
High Availability with MariaDB Enterprise
Enterprise Drupal Application & Hosting Infrastructure Level Monitoring
Master master vs master-slave database
Galera 3.0 Webinar Slides: Galera Monitoring & Management
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
Webinar slides: 9 DevOps Tips for Going in Production with Galera Cluster for...
MySQL Multi Master Replication
Using and Benchmarking Galera in different architectures (PLUK 2012)
Methods of Sharding MySQL
Galera Cluster: Synchronous Multi-Master Replication for MySQL HA
Management and Automation of MongoDB Clusters - Slides
M|18 How DBAs at TradingScreen Make Life Easier With Automation
Planning for Disaster Recovery (DR) with Galera Cluster
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster DDL and Schema Upgrades 220217
Get the most out of Oracle Data Guard - OOW version
Drupal In The Cloud
Ad

Similar to Become a MySQL DBA - Webinars - Schema Changes for MySQL Replication & Galera Cluster (slides) (20)

PDF
Zero Downtime Schema Changes in Galera Cluster
PPTX
M|18 Battle of the Online Schema Change Methods
PDF
Online Schema Changes for Maximizing Uptime
PDF
High-availability with Galera Cluster for MySQL
PDF
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
PDF
MariaDB 10.11 key features overview for DBAs
PDF
How to Avoid Pitfalls in Schema Upgrade with Galera
PDF
HA with Galera
PDF
Reducing Risk When Upgrading MySQL
PDF
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDB
PPTX
Infrastructure review - Shining a light on the Black Box
PDF
Introducing Spirit - Online Schema Change
PDF
MySQL always-up with Galera Cluster
PDF
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
PDF
Scaling MySQL -- Swanseacon.co.uk
PDF
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
PDF
Loadays MySQL
PDF
Recent MariaDB features to learn for a happy life
PDF
20180420 hk-the powerofmysql8
PDF
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
Zero Downtime Schema Changes in Galera Cluster
M|18 Battle of the Online Schema Change Methods
Online Schema Changes for Maximizing Uptime
High-availability with Galera Cluster for MySQL
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
MariaDB 10.11 key features overview for DBAs
How to Avoid Pitfalls in Schema Upgrade with Galera
HA with Galera
Reducing Risk When Upgrading MySQL
Webinar slides: Migrating to Galera Cluster for MySQL and MariaDB
Infrastructure review - Shining a light on the Black Box
Introducing Spirit - Online Schema Change
MySQL always-up with Galera Cluster
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
Scaling MySQL -- Swanseacon.co.uk
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
Loadays MySQL
Recent MariaDB features to learn for a happy life
20180420 hk-the powerofmysql8
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
Ad

More from Severalnines (20)

PDF
The Long Term Cost of Managed DBaaS vs Sovereign DBaaS
PPTX
Sovereign DBaaS_ A Practical Vision for Self-Implementation of DBaaS.pptx
PDF
PostgreSQL on AWS Aurora/Azure Cosmos VS EC2/Azure VMs
PDF
Localhost Conference 2024_ Building a Flexible and Scalable Database Strategy...
PDF
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
PDF
Building a Sovereign DBaaS on K8s OpenInfra Summit Asia 2024.pdf
PDF
S-DBaaS Community Call | Introduction to Sovereign DBaaS: The why, what and how
PDF
WEBINAR SLIDES: CCX for Cloud Service Providers
PPTX
LIVE DEMO: CCX for CSPs, a drop-in DBaaS solution
PDF
Kubernetes at Scale: Going Multi-Cluster with Istio
PDF
DIY DBaaS: A guide to building your own full-featured DBaaS
PDF
Cloud's future runs through Sovereign DBaaS
PPTX
Working with the Moodle Database: The Basics
PPTX
SysAdmin Working from Home? Tips to Automate MySQL, MariaDB, Postgres & MongoDB
PDF
(slides) Polyglot persistence: utilizing open source databases as a Swiss poc...
PDF
Webinar slides: How to Migrate from Oracle DB to MariaDB
PDF
Webinar slides: How to Automate & Manage PostgreSQL with ClusterControl
PDF
Webinar slides: How to Manage Replication Failover Processes for MySQL, Maria...
PDF
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
PPTX
Disaster Recovery Planning for MySQL & MariaDB
The Long Term Cost of Managed DBaaS vs Sovereign DBaaS
Sovereign DBaaS_ A Practical Vision for Self-Implementation of DBaaS.pptx
PostgreSQL on AWS Aurora/Azure Cosmos VS EC2/Azure VMs
Localhost Conference 2024_ Building a Flexible and Scalable Database Strategy...
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
Building a Sovereign DBaaS on K8s OpenInfra Summit Asia 2024.pdf
S-DBaaS Community Call | Introduction to Sovereign DBaaS: The why, what and how
WEBINAR SLIDES: CCX for Cloud Service Providers
LIVE DEMO: CCX for CSPs, a drop-in DBaaS solution
Kubernetes at Scale: Going Multi-Cluster with Istio
DIY DBaaS: A guide to building your own full-featured DBaaS
Cloud's future runs through Sovereign DBaaS
Working with the Moodle Database: The Basics
SysAdmin Working from Home? Tips to Automate MySQL, MariaDB, Postgres & MongoDB
(slides) Polyglot persistence: utilizing open source databases as a Swiss poc...
Webinar slides: How to Migrate from Oracle DB to MariaDB
Webinar slides: How to Automate & Manage PostgreSQL with ClusterControl
Webinar slides: How to Manage Replication Failover Processes for MySQL, Maria...
Webinar slides: Backup Management for MySQL, MariaDB, PostgreSQL & MongoDB wi...
Disaster Recovery Planning for MySQL & MariaDB

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
KodekX | Application Modernization Development
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25 Week I
KodekX | Application Modernization Development
Chapter 3 Spatial Domain Image Processing.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
20250228 LYD VKU AI Blended-Learning.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx

Become a MySQL DBA - Webinars - Schema Changes for MySQL Replication & Galera Cluster (slides)

  • 1. Copyright 2015 Severalnines AB Schema Changes for MySQL Replication & Galera Cluster August 25, 2015 Krzysztof Książek Severalnines krzysztof@severalnines.com 1
  • 2. Copyright 2015 Severalnines AB ! We want to help all non-DBA people who look after MySQL infrastructures ! Share tips and good practices ! Watch the replays of the previous webinars on our Slideshare page ! http://www.slideshare.net/Severalnines/videos 2 “Become a MySQL DBA” series
  • 3. Copyright 2015 Severalnines AB ! Different methods to perform schema changes on MySQL Replication and Galera ! rolling schema change ! online alters ! external tools, e.g., pt-online-schema-change ! Differences between MySQL 5.5 and 5.6 ! Differences between MySQL Replication vs Galera ! Example real-life scenarios with MySQL Replication and Galera setups
 3 Agenda
  • 4. Copyright 2015 Severalnines AB Schema changes in MySQL 4
  • 5. Copyright 2015 Severalnines AB ! Application development ! New features to existing modules ! New modules ! Data management and archiving (partitions) ! Schema optimization ! Performance optimization 5 Why schemas need changes?
  • 6. Copyright 2015 Severalnines AB ! Point-in-time schema changes ! Everything happens at a given point of time, over the whole infrastructure ! Rolling schema changes ! Changes happen at different times across the infrastructure ! Requirement is that schema versions have to be compatible with each other 6 Types of schema changes
  • 7. Copyright 2015 Severalnines AB ! Schema changes cause significant performance overhead as they are I/O-heavy operations ! Schema changes may take long time to finish on larger tables ! Direct schema changes don’t play well with MySQL replication due to the lag inducted ! Direct schema changes don’t play well with Galera ! Rolling schema changes may require significant amount of work 7 Schema changes - limitations
  • 8. Copyright 2015 Severalnines AB ! Replication has it’s limitations, only some changes can be replicated. RBR is very strict here ! Remove a column at the end of the table - yes ! Remove a column in the middle - no go ! Add a column at the end - works ! Add a column in the middle - not really ! Not every conversion between column types works - refer to the documentation 8 Schema changes - limitations
  • 9. Copyright 2015 Severalnines AB ! You can’t change the schema and the code at the exact time ! New schema have to be compatible with old code ! Depreciate columns, not remove ! Remove them two, three iterations later, once you confirm you _can_ remove 9 Schema changes - limitations
  • 10. Copyright 2015 Severalnines AB Ways to perform a schema change 10
  • 11. Copyright 2015 Severalnines AB ! Online DDL ! Rolling schema upgrade ! Online schema change ! Rolling Schema Upgrade for Galera ! Total Order Isolation for Galera 11 Methods to perform a schema change
  • 12. Copyright 2015 Severalnines AB ! DDL, historically, was a locking operation ! Some of them were fast, i.e. DROP (secondary) INDEX ! InnoDB plugin in 5.1 and 5.5 introduced Fast Index Creation that allowed reads to be executed while secondary index has been added ! MySQL 5.6 introduced online DDL’s for InnoDB 12 Online DDL
  • 13. Copyright 2015 Severalnines AB ! Many operations are non-blocking for reads and writes ! Add an index ! Add a column ! Reorder columns ! Add a primary key ! and many others (check the documentation) ! https://dev.mysql.com/doc/refman/5.6/en/innodb-create- index-overview.html#innodb-online-ddl-summary-grid 13 Online DDL
  • 14. Copyright 2015 Severalnines AB ! Busy tables may be an issue (innodb_online_alter_log_max_size) ! Lag will be an issue - online DDL is online on the master only ! Not suitable for large tables in replication setup 14 Online DDL
  • 15. Copyright 2015 Severalnines AB ! Run DDL from the bottom to the top of replication chain ! SET SESSION sql_log_bin=0 to avoid errant transactions ! Once you reach the master, failover and then alter the old master ! Schema changes have to be compatible, you’ll be running DML’s on a mix of altered and not altered tables ! Schema changes have to be compatible, you’ll be reading from a mix of altered and not altered tables 15 Rolling Schema Upgrade
  • 16. Copyright 2015 Severalnines AB ! Different tools (pt-online-schema-change, Online Schema Change from FB), same idea ! Create a new table with desired schema ! Setup triggers to copy data from old to the new table ! Copy the data from old to new table in batches ! Rename table once the data has been copied 16 Online Schema Change - external tools
  • 17. Copyright 2015 Severalnines AB Online Schema Change - external tools 17
  • 18. Copyright 2015 Severalnines AB ! pt-online-schema-change - the most popular tool ! Point-in-time change, you can use for any DDL ! Replicaton-aware, it can monitor lag and throttle itself ! Introduces additional load, slow down your system ! It has issues with foreign keys ! Can’t work with tables which have triggers ! Won’t work with tables without PK and unique key 18 pt-online-schema-change
  • 19. Copyright 2015 Severalnines AB ! Otherwise it’s a very reliable tool ! Schema change may take a long time but it’s throttling itself and can be paused at any time ! One of the most important tools in the DBA arsenal ! Sometimes it’s the only way to run a schema change without downtime 19 pt-online-schema-change
  • 20. Copyright 2015 Severalnines AB Schema changes in Galera Cluster 20
  • 21. Copyright 2015 Severalnines AB ! All changes happen at the exact time in the cluster ! All changes are blocking (you won’t benefit from online DDL’s) ! Great for consistency ! You can run any change this way ! Not suitable for larger tables due to severe locking 21 Total Order Isolation
  • 22. Copyright 2015 Severalnines AB ! Similar to the rolling schema upgrade we discussed earlier ! Process is partially automated - you need to set wsrep_OSU_method to RSU and proceed with DDL ! Node will be in Desync state for a duration of the DDL ! Once DDL finishes, node applies remaining writesets ! Writesets are stored in gcache, both in memory and on disk 22 Rolling Schema Upgrade
  • 23. Copyright 2015 Severalnines AB Rolling Schema Upgrade 23
  • 24. Copyright 2015 Severalnines AB Different scenarios for a schema change 24
  • 25. Copyright 2015 Severalnines AB ! If a change is non-blocking - online DDL ! pt-online-schema-change may also work ! pt-osc should not take more than a couple of minutes ! For Galera - TOI if you can accept few seconds of stall ! Otherwise - pt-online-schema-change is the only option 25 Small tables (up to 10s of a direct DDL)
  • 26. Copyright 2015 Severalnines AB ! pt-online-schema-change is the best option here for both MySQL and Galera ! pt-online-schema-change may take even couple of hours to finish ! It’s less cumbersome than rolling upgrade ! Rolling schema upgrade may be the option of choice if pt-osc can’t be used due to it’s limitations (no PK, triggers in altered table, etc.) 26 Medium tables (20 - 30m, up to 1h)
  • 27. Copyright 2015 Severalnines AB ! pt-osc will work but it will take long time (36 - 48h) to finish ! You need to have enough disk space for binlogs and altered copy of the table ! Rolling schema upgrade may be a feasible option ! For Galera pt-osc can be also the best option ! RSU is another option but ensure you have large gcache (or a space on disk for gcache files) 27 Large tables (more than 1h, up to 12h)
  • 28. Copyright 2015 Severalnines AB ! Are you sure that you need such a large table? ! Try to avoid them by splitting data across many tables or archiving old data ! Rolling schema upgrade is the way to go ! Use snapshots or xtrabackup to provision new nodes ! Galera may need large gcache (both in memory and on disk) ! Process of joining desynced node will take a long time 28 Very large tables (more than 12h)
  • 29. Copyright 2015 Severalnines AB ! Schema change speed depends on your hardware and data structure ! Test the changes on development environment ! Is it worth using triggers or foreign keys and not have the option to use pt-osc? ! You _do_ want to have PK defined in all tables - do it before it grows too large to alter ! Schema changes will happen, get used to them 29 What to keep in mind?
  • 30. Copyright 2015 Severalnines AB ! More blogs in “Become a MySQL DBA” series: ! http://www.severalnines.com/blog/become-mysql- dba-blog-series-query-tuning-process ! http://www.severalnines.com/blog/become-mysql- dba-blog-series-configuration-tuning-performance ! Contact: krzysztof@severalnines.com 30 Thank You!