Online Schema Changes for Maximizing Uptime. David Turner - Dropbox Ben Black - Tango



Similar documents
5 Percona Toolkit tools that could save your day. Stéphane Combaudon FOSDEM February 3rd, 2013

MySQL Replication. openark.org

Percona Server features for OpenStack and Trove Ops

MySQL Cluster Deployment Best Practices

Welcome to Virtual Developer Day MySQL!

High Availability Solutions for the MariaDB and MySQL Database

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

InnoDB Data Recovery. Daniel Guzmán Burgos November 2014

Real-time reporting at 10,000 inserts per second. Wesley Biggs CTO 25 October 2011 Percona Live

New Features in MySQL 5.0, 5.1, and Beyond

Zero Downtime Deployments with Database Migrations. Bob Feldbauer

Linas Virbalas Continuent, Inc.

Tushar Joshi Turtle Networks Ltd

Testing and Verifying your MySQL Backup Strategy

Using MySQL for Big Data Advantage Integrate for Insight Sastry Vedantam

Determining your storage engine usage

MySQL always-up with Galera Cluster

Detecting (and even preventing) SQL Injection Using the Percona Toolkit and Noinject!


Monitoring MySQL. Kristian Köhntopp

High-availability with Galera Cluster for MySQL

Oracle Total Recall with Oracle Database 11g Release 2

Synchronous multi-master clusters with MySQL: an introduction to Galera

How to Optimize the MySQL Server For Performance

MySQL Backup and Recovery: Tools and Techniques. Presented by: René Senior Operational DBA

MySQL performance in a cloud. Mark Callaghan

MySQL Enterprise Backup

Managing MySQL Scale Through Consolidation

Choosing Storage Systems

DBA Tutorial Kai Voigt Senior MySQL Instructor Sun Microsystems Santa Clara, April 12, 2010

The Future of PostgreSQL High Availability Robert Hodges - Continuent, Inc. Simon Riggs - 2ndQuadrant

<Insert Picture Here> MySQL Update

50238: Introduction to SQL Server 2008 Administration

Preparing for the Big Oops! Disaster Recovery Sites for MySQL. Robert Hodges, CEO, Continuent MySQL Conference 2011

Data Compression in Blackbaud CRM Databases

Monitoring MySQL. Geert Vanderkelen MySQL Senior Support Engineer Sun Microsystems

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

Technical Overview Simple, Scalable, Object Storage Software

Database Administration with MySQL

Vembu BDR v Release Notes. Major features in v Other features in Vembu BDR. Cloud Disaster Recovery Service. VMware UltraBlaze.

MS SQL Server 2014 New Features and Database Administration

Dbvisit Replicate. Dbvisit Replicate Overview

MySQL backups: strategy, tools, recovery scenarios. Akshay Suryawanshi Roman Vynar

Database Migration from MySQL to RDM Server

MySQL Storage Engines

Computer Visions Course Outline

Partitioning under the hood in MySQL 5.5

1Z0-117 Oracle Database 11g Release 2: SQL Tuning. Oracle

High Availability, Disaster Recovery and Extreme Read Scaling using Binlog Servers. Jean-François Gagné jeanfrancois DOT gagne AT booking.

How, What, and Where of Data Warehouses for MySQL

IRF2000 IWL3000 SRC1000 Application Note - Apps with OSGi - Condition Monitoring with WWH push

Best Practices for Using MySQL in the Cloud

Module 14: Scalability and High Availability

David Dye. Extract, Transform, Load

File System & Device Drive. Overview of Mass Storage Structure. Moving head Disk Mechanism. HDD Pictures 11/13/2014. CS341: Operating System

Implementing a Microsoft SQL Server 2005 Database

High Availability and Scalability for Online Applications with MySQL

Oracle Database 11 g Performance Tuning. Recipes. Sam R. Alapati Darl Kuhn Bill Padfield. Apress*

MariaDB Cassandra interoperability

Full Text Search in MySQL 5.1 New Features and HowTo

8- Management of large data volumes

Architectures Haute-Dispo Joffrey MICHAÏE Consultant MySQL

Part 3. MySQL DBA I Exam

Efficient Pagination Using MySQL

Percona Toolkit Documentation

MySQL Administration and Management Essentials

Stellar Phoenix. SQL Database Repair 6.0. Installation Guide

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

MySQL Cluster New Features. Johan Andersson MySQL Cluster Consulting johan.andersson@sun.com

Percona Toolkit Documentation

Oracle EXAM - 1Z Oracle Database 11g Release 2: SQL Tuning. Buy Full Product.

Take An Internal Look at Hadoop. Hairong Kuang Grid Team, Yahoo! Inc

XtraBackup: Hot Backups and More

XtraBackup. Vadim Tkachenko CTO, Co-Founder, Percona Inc Percona Live SF Feb 2011

6231A - Maintaining a Microsoft SQL Server 2008 Database

MySQL Fabric: High Availability Solution for Connector/Python

How To Create A Replica In A Database On A Microsoft Powerbook (Ahem) On A Linux Server (A.K.A.A)

SQL Server Training Course Content

Who did what, when, where and how MySQL Audit Logging. Jeremy Glick & Andrew Moore 20/10/14

Dynamics NAV/SQL Server Configuration Recommendations

White Paper. Optimizing the Performance Of MySQL Cluster

General DBA Best Practices

Efficient database auditing

StreamServe Persuasion SP5 Oracle Database

Upgrading a Microsoft Dynamics NAV 2009 R2 or Microsoft Dynamics NAV 2009 SP1 Database to Microsoft Dynamics NAV 2015

Microsoft SQL Server Guide. Best Practices and Backup Procedures

Parallel Replication for MySQL in 5 Minutes or Less

Managing your Domino Clusters

W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

Overview of Databases On MacOS. Karl Kuehn Automation Engineer RethinkDB

NIMSOFT SLM DATABASE

MODULE FRAMEWORK : Dip: Information Technology Network Integration Specialist (ITNIS) (Articulate to Edexcel: Adv. Dip Network Information Specialist)

MySQL. Leveraging. Features for Availability & Scalability ABSTRACT: By Srinivasa Krishna Mamillapalli

Dave Stokes MySQL Community Manager

A SURVEY OF POPULAR CLUSTERING TECHNOLOGIES

How to choose High Availability solutions for MySQL MySQL UC 2010 Yves Trudeau Read by Peter Zaitsev. Percona Inc MySQLPerformanceBlog.

SQL Server Storage: The Terabyte Level. Brent Ozar, Microsoft Certified Master, MVP Consultant & Trainer, SQLskills.com

<Insert Picture Here> Edition-based redefinition: the key to online application upgrade

Transcription:

Online Schema Changes for Maximizing Uptime David Turner - Dropbox Ben Black - Tango

About us Dropbox Tango Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again! Tango is the only mobile application in the world that combines cross-platform video communication, social discovery, and content on one integratedmobile platform to connect you with the world around you in a meaningful way.

Where we re headed Schema changes and Defrags: including best practices MySQL online DDL Percona online schema change

Best Practices Backups Benchmark* Schema Repository Deployment Strategy Monitor

Old school schema changes and defrags Alter tables and reclaim space Blocking alters Customer workarounds

Blocking alters writes my_table my_table_new selects

Blocking alters writes my_table my_table_new selects

Problems with blocking alters Unable to write to the table The larger the table the longer the writes are blocked.

Customer work arounds alter table master slave Slave Lag Less efficient slave

Additional customer workarounds Openark Facebook Percona

MySQL fast index creation Innodb 5.1 Plugin or MySQL 5.5 No more rebuilds for secondary indexes Drop and add indexes faster Faster table loads(sk last) Better secondary indexes* Still blocking writes

MySQL 5.6 Innodb online DDL: are we there yet? More inplace operations Online alters for operations Slaves lag for length of operations No throttle option

MySQL Online DDL Exclusive lock writes my_table my_table_new selects log lockwait_timeout innodb_online_alter_log_max_size

MySQL Online DDL Exclusive lock writes my_table my_table_new selects log lockwait_timeout innodb_online_alter_log_max_size

MySQL Online DDL Exclusive lock writes my_table my_table_new selects log lockwait_timeout innodb_online_alter_log_max_size

Why MySQL Online DDL Int to bigint Alters performed on slaves Zero tolerance for data loss Recoveries can suck Table checksums RBR and triggers Less io than other tools Avoid additional load on master no throttling parameters All IOD operations block the sql_thread on the slaves 5.6.17 defrags and algorithm=inplace

Alter online lock modes Exclusive alter table my_tbl engine=innodb, lock=exclusive; Shared alter table my_tbl engine=innodb, lock=shared; Default Know your stuff and test None alter table my_tbl add index sk1(pid), lock=none;

Alter online algorithms Inplace Copy alter table my_tbl add column, algorithm=inplace, lock=none; alter table my_tbl engine=innodb, algorithm=copy, lock=shared; all algorithm=copy allow only shared or exclusive lock.

More examples # Defrag / Optimize (Newer version is supposed to offer this.) # Defragging a table requires a copy and does not allow concurrent dml. alter table ${table} engine=innodb, algorithm=copy, lock=shared; # Index ops alter table ${table} add index sk1 (zone), algorithm=inplace, lock=none; alter table ${table} drop index sk1, algorithm=inplace, lock=none; # Column ops alter table ${table} add column c3 int, add column c1 int, add column c4 int, algorithm=inplace, lock=none; alter table ${table} drop column c4,algorithm=inplace, lock=none; alter table ${table} modify c1 int default 0, algorithm=inplace, lock=none; alter table ${table} change c3 c2 int, algorithm=inplace, lock=none; alter table ${table} modify column c2 int after c1, algorithm=inplace, lock=none; alter table ${table} modify column c2 int default null, algorithm=inplace, lock=none; alter table ${table} modify c2 bigint, algorithm=copy, lock=shared; alter table ${table} drop column c1, drop column c2, algorithm=inplace, lock=none;

Innodb online DDL: additional info Foreign keys Create fk with foreign_key_checks=0 Child table restrictions Alter on child blocks concurrent dml Alter on child could be blocked by transaction on the parent* Alter on completion on parent could be blocked by dml on same parent if it causes dml on child. Partitioning Autoincrement - alter instantaneous, add requires lock=shared A table of info: http://dev.mysql.com/doc/refman/5.6/en/innodb-createindex-overview.html Full text indexes still require shared lock

Innodb online DDL variables innodb_online_alter_log_max_size lock_wait_timeout sort_buffer_size others(benchmark)

Innodb Crash Recovery Secondary indexes Clustered indexes(don t crash!)

Summary Backup and benchmark Upgrade to 5.6.17

You want to do what to that 300G table? App down for Maintenance/blocking DDL Disable writes/read-only for altered table Alter slave and swap masters MySQL Online DDL and serialized replication/lag

OSC Tools or how I learned to love the alter... copy original table structure to new table alter new table create triggers to copy dml from original table to new table copy data in original table to new table in chunks swap table names and drop original table

table id PK 1) copy table 2) alter _table_new 3) create triggers 4) copy data in chunks 5) swap tables/drop orig Copy chunks _table_new id PK new_col DML triggers (upd,del,ins) DML

pt-online-schema-change Percona toolkit is your friend. Open source and you can see the tables, sql, triggers and what it is doing. Pay attention to version you are using!!! FK issues, log_bin with 2.0

Whoomp! There it is! time./pt-online-schema-change --dry-run --user=bblack --askpass --max-lag=2 --check-interval=1 --progress=time,10 --maxload Threads_running:50 --critical-load Threads_running:6000 -- alter "DROP COLUMN col4" --host=127.0.0.1 D=my_db, t=my_table --alter-foreign-keys-method=drop_swap --recursionmethod dsn=d=percona,t=dsns --no-check-replication-filters -- set-vars innodb_lock_wait_timeout=10 --chunk-time=.2 tee /tmp/clientinfo_alter.log screen - use it along with tee and time

It's all ball bearings nowadays --progress time,10 (default 30 seconds) --max-lag and --check-interval (both default 1s) --recursion-method (how to find slaves) show processlist show hosts dsn table (great for ignoring some slaves)

Other params --chunk-time=.2 (default.5) --max-load and --critical-load (Threads_running=25,50) --alter-foreign-keys-method=drop_swap --no-check-replication-filters

What could possibly go wrong? PK/UK required FK names will change on altered table FK's reference table to alter --alter-foreign-keys-method drop_swap sets foreign_key_checks=0 drops original table (hardlink!!!) renames new table NOTIFICATION EMAILS (don t kick off on Friday and go home)

What could possibly go wrong? non xfs table drops (create the hardlink!) Can even cause innodb to crash mysqld PKs with gaps Largest table to alter vs free disk space Disk space (2x for RBR) Global mutexes (table drops can take several seconds) table metadata locks (triggers) No triggers allowed on the table to alter

NOOOOOO!! Running PT-OSC against a slave with RBR Replication started erroring after pt-osc why??? And how about syncing a table using pt-osc with RBR?

Trust but verify show create table altered_table\g show create table _altered_table_new\g show table status like %altered_table% ; ls -alh /data/schema/*altered_table*.ibd

Set it and forget it??? watch w df -h ls -alh ibd files mysql -e"show processlist;" egrep -v "Sleep repl" slave lag How is it affecting the application? external monitoring

I think I m paranoid watch -n 1 'w head -1;echo "";mysql -e"show engine innodb status\g" grep -i history;echo ""; df -h grep local;echo "";mysql -e"show processlist;" wc -l;echo "";mysql -e"show processlist;" grep -v Sleep grep -v repl'

The kids aren t alright [01:11 root@host ~]$ cat /home/bblack/chech_repl.sh echo "master001" `mysql -hmaster001 -e"show slave status\g" grep Seconds` echo "slave001" `mysql -hslave001 -e"show slave status\g" grep Seconds` [01:14 bblack@host ~]$ watch./chech_repl.sh master001 Seconds_Behind_Master: 0 slave001 Seconds_Behind_Master: 0 Slaves on non-3306? Use either hosts recursion method with report-host set OR - set up an ssh tunnel on 3306 that redirects

Are we there yet? pt-online-schema-change prints progress to std err mysql> show table status like %table_name% ; ls -alh /data/schema/*table_name*.ibd mysql> select max(id) from table_name; mysql> show processlist; -- to find id of current chunk

Sneaky little hobbitses. Wicked, tricksy To do a noop and optimize the table --alter "engine=innodb" 100-200MB cutoff for blocking alters Overhead for adding indexes Never do pt-osc for dropping indexes

We re Hiring! Dropbox - see us at our booth dturner@dropbox.com Tango bblack@tango.me