SlideShare a Scribd company logo
1 of 51
Download to read offline
1 / 51
2 / 51
FOSDEM, February 2018
MySQL Point-in-Time Recovery like a Rockstar
Accelerate MySQL point-in-time recovery for large workloads
 
 
 
Frédéric Descamps - MySQL Community Manager - Oracle
3 / 51
 
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purpose only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied up in
making purchasing decisions. The development, release and timing of any features or
functionality described for Oracle´s product remains at the sole discretion of Oracle.
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
4 / 51
about.me/lefred
Who am I ?
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
5 / 51
Frédéric Descamps
@lefred
MySQL Evangelist
Hacking MySQL since 3.23
devops believer
living in Belgium 🇧🇪
http://lefred.be
 
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
6 / 51
what is PITR ?
point-in-time recovery
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
7 / 51
PITR: Definition
from Wikipedia (thank you Jaime)
Point-in-time recovery (PITR) in the context of computers involves systems whereby an
administrator can restore or recover a set of data or a particular setting from a time in
the past.
Once PITR logging starts for a PITR-capable database, a database administrator can
restore that database from backups to the state that it had at any time since.
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
8 / 51
PITR: Definition
from Wikipedia (thank you Jaime)
Point-in-time recovery (PITR) in the context of computers involves systems whereby an
administrator can restore or recover a set of data or a particular setting from a time in
the past.
Once PITR logging starts for a PITR-capable database, a database administrator can
restore that database from backups to the state that it had at any time since.
Please donate to wikimedia : https://goo.gl/ZYVFhf
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
9 / 51
MySQL PITR
requirements
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
10 / 51
Requirements
To be able to perform point-in-time recovery with MySQL, you need to have:
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
11 / 51
Requirements
To be able to perform point-in-time recovery with MySQL, you need to have:
decent backups
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
12 / 51
Requirements
To be able to perform point-in-time recovery with MySQL, you need to have:
decent backups
binary logs enabled
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
13 / 51
Requirements
To be able to perform point-in-time recovery with MySQL, you need to have:
decent backups
binary logs enabled
keeping your binlogs at least since the last successful backup
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
14 / 51
MySQL PITR
Procedure
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
15 / 51
Procedure
The procedure to perform a PITR with MySQL is the following:
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
16 / 51
Procedure
The procedure to perform a PITR with MySQL is the following:
find the binary log file and the position of the event you want restore up to
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
17 / 51
Procedure
The procedure to perform a PITR with MySQL is the following:
find the binary log file and the position of the event you want restore up to
restore the last backup
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
18 / 51
Procedure
The procedure to perform a PITR with MySQL is the following:
find the binary log file and the position of the event you want restore up to
restore the last backup
find the binlog position of the last restored event
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
19 / 51
Procedure
The procedure to perform a PITR with MySQL is the following:
find the binary log file and the position of the event you want restore up to
restore the last backup
find the binlog position of the last restored event
replay all events present in the binary logs since the backup up to the position of
the transaction we want to skip
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
20 / 51
Procedure
The procedure to perform a PITR with MySQL is the following:
find the binary log file and the position of the event you want restore up to
restore the last backup
find the binlog position of the last restored event
replay all events present in the binary logs since the backup up to the position of
the transaction we want to skip
see the manual: https://dev.mysql.com/doc/refman/5.7/en/point-in-time-recovery.html
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
21 / 51
MySQL PITR
Example
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
22 / 51
Example
We have one database with 16 tables
sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql
--mysql-user=root --mysql-host=localhost --table-size=100000
--tables=16 prepare
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
23 / 51
Example
We have one database with 16 tables
sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql
--mysql-user=root --mysql-host=localhost --table-size=100000
--tables=16 prepare
We have one physical backup
/opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1
--backup-dir=mysqlbackup backup
/opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1
--backup-dir=mysqlbackup apply-log
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
24 / 51
Example
We have one database with 16 tables
sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql
--mysql-user=root --mysql-host=localhost --table-size=100000
--tables=16 prepare
We have one physical backup
/opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1
--backup-dir=mysqlbackup backup
/opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1
--backup-dir=mysqlbackup apply-log
Any other backup solution can be used
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
25 / 51
Example (2)
We write data using 8 threads for 1h:
sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql
--mysql-user=root --mysql-host=localhost --table-size=100000
--tables=16 --threads=8 --report-interval=10 --time=3600 run
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
26 / 51
Example (2)
We write data using 8 threads for 1h:
sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql
--mysql-user=root --mysql-host=localhost --table-size=100000
--tables=16 --threads=8 --report-interval=10 --time=3600 run
And let's modify a record with something we can track ;-)
mysql> update sbtest3 set pad='fred' where id = 126551;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
27 / 51
Suddenly...
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
28 / 51
Suddenly...
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
29 / 51
Suddenly...
mysql> update sbtest4 set pad="oups";
Query OK, 1066269 rows affected (8.52 sec)
Rows matched: 1066269 Changed: 1066269 Warnings: 0
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
30 / 51
UPDATE without WHERE clause !?!
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
31 / 51
Find what we need to avoid after restore
mysql> show master status;
+------------------+-----------+...+------------------------------------------------+
| File | Position | | Executed_Gtid_Set |
+------------------+-----------+...+------------------------------------------------+
| imac2-bin.000005 | 622915384 | | 25d97ef9-005b-11e8-bf1b-685b359e77d5:1-1072032 |
+------------------+-----------+...+------------------------------------------------+
1 row in set (0.00 sec)
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
32 / 51
Let's verify...
mysql> pager grep -A 1 -B 2 'sbtest.sbtest4' | grep -B 4 Update
mysql> show binlog events in 'imac2-bin.000005';
--
| imac2-bin.000005 | 277145452 | Gtid | ... |
SET @@SESSION.GTID_NEXT= '25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032' |
| imac2-bin.000005 | 277145513 | Query | ... | BEGIN |
| imac2-bin.000005 | 277145583 | Table_map | ... | table_id: 154 (sbtest.sbtest4)|
| imac2-bin.000005 | 277145638 | Update_rows | ... | table_id: 154 |
mysql> pager sed -n -e '/25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032/,/COMMIT/ p'
| grep COMMIT
mysql> show binlog events in 'imac2-bin.000005';
| imac2-bin.000005 | 622915357 | Xid | ... | 622915384 | COMMIT /* xid=1072253 */
This is good, let's then keep the position 277145452
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
33 / 51
Stop MySQL and save the binlogs
[root@imac2 ~]# systemctl stop mysqld
[root@imac2 ~]# mkdir /mnt/mysql/binlogs
[root@imac2 ~]# cd /var/lib/mysql
[root@imac2 mysql]# cp imac2-bin.* /mnt/mysql/binlogs/
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
34 / 51
Stop MySQL and save the binlogs
[root@imac2 ~]# systemctl stop mysqld
[root@imac2 ~]# mkdir /mnt/mysql/binlogs
[root@imac2 ~]# cd /var/lib/mysql
[root@imac2 mysql]# cp imac2-bin.* /mnt/mysql/binlogs/
Restore the backup
[root@imac2 mysql]# rm -rf *
[root@imac2 mysql]# /opt/mysql/meb-4.1/bin/mysqlbackup
--backup-dir=/tmp/mysqlbackup copy-back
...
mysqlbackup completed OK! with 3 warnings
[root@imac2 mysql]# chown -R mysql. *
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
35 / 51
Point-in-Time Recovery
Now we can start MySQL and replay the binlogs from the backup position, until the
"EVENT" (277145452)
# grep binlog_position backup_variables.txt
binlog_position=imac2-bin.000004:888830919
[root@imac2 binlogs]# time mysqlbinlog -j 888830919
--stop-position 277145452 imac2-bin.00000[4-5] | mysql
real 305m18.867s
I only needed to replay events from imac2-bin.00000[4-5] in fact, but it could be way
more than that
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
36 / 51
Point-in-Time Recovery
Now we can start MySQL and replay the binlogs from the backup position, until the
"EVENT" (277145452)
# grep binlog_position backup_variables.txt
binlog_position=imac2-bin.000004:888830919
[root@imac2 binlogs]# time mysqlbinlog -j 888830919
--stop-position 277145452 imac2-bin.00000[4-5] | mysql
real 305m18.867s
I only needed to replay events from imac2-bin.00000[4-5] in fact, but it could be way
more than that
-rw-r----- 1 root root 1.1G Jan 23 21:27 imac2-bin.000004
-rw-r----- 1 root root 595M Jan 23 21:27 imac2-bin.000005
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
37 / 51
Was it really like a rockstar ?
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
38 / 51
Was it really like a rockstar ?
NO !
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
39 / 51
Why not ?
If you have a large amount of large binary logs and your workload is not single threaded
like mysqlbinlog... this process can take for eveeeeeeeeer !
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
40 / 51
Let's do it like a rockstar !
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
41 / 51
Find and Set the last executed GTID during
backup
[root@imac2 mysql]# cat backup_variables.txt | grep gtid
gtid_executed=25d97ef9-005b-11e8-bf1b-685b359e77d5:1-6001
The name of the file depends of your backup tool
After restoring the backup, restart MySQL with this change in my.cnf:
skip-slave-start
Finally set the GTID AND ALSO the GTID of the transaction we want to avoid:
mysql> reset master;
mysql> SET @@GLOBAL.GTID_PURGED='25d97ef9-005b-11e8-bf1b-685b359e77d5:1-6001,
25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032';
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
42 / 51
MySQL PITR
Now the cool stuff !
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
43 / 51
We will copy all the saved binlogs and rename them as relaylogs !
[root@imac2 mysql]# for i in $(ls /mnt/mysql/binlogs/*.0*)
do
ext=$(echo $i | cut -d'.' -f2)
cp $i imac2-relay-bin.$ext
done
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
44 / 51
We will copy all the saved binlogs and rename them as relaylogs !
[root@imac2 mysql]# for i in $(ls /mnt/mysql/binlogs/*.0*)
do
ext=$(echo $i | cut -d'.' -f2)
cp $i imac2-relay-bin.$ext
done
Don't forget to create the index file too:
[root@imac2 mysql]# ls ./imac2-relay-bin.0* >imac2-relay-bin.index
[root@imac2 mysql]# chown mysql. *relay*
[root@imac2 mysql]# cat imac2-relay-bin.index
./imac2-relay-bin.000001
./imac2-relay-bin.000002
./imac2-relay-bin.000003
./imac2-relay-bin.000004
./imac2-relay-bin.000005
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
45 / 51
Get ready to do PITR like a rockstar !
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
46 / 51
Get ready to do PITR like a rockstar !
mysql> SET GLOBAL server_id = 99;
#replicate-same-server-id=1 won't work because of #89375
mysql> SET GLOBAL SLAVE_PARALLEL_TYPE='LOGICAL_CLOCK';
mysql> SET GLOBAL SLAVE_PARALLEL_WORKERS=8;
mysql> CHANGE MASTER TO RELAY_LOG_FILE='imac2-relay-bin.000001',
RELAY_LOG_POS=4, MASTER_HOST='dummy';
mysql> START SLAVE SQL_THREAD;
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
47 / 51
Get ready to do PITR like a rockstar !
mysql> SET GLOBAL server_id = 99;
#replicate-same-server-id=1 won't work because of #89375
mysql> SET GLOBAL SLAVE_PARALLEL_TYPE='LOGICAL_CLOCK';
mysql> SET GLOBAL SLAVE_PARALLEL_WORKERS=8;
mysql> CHANGE MASTER TO RELAY_LOG_FILE='imac2-relay-bin.000001',
RELAY_LOG_POS=4, MASTER_HOST='dummy';
mysql> START SLAVE SQL_THREAD;
And you can even monitor it:
mysql> select * from
performance_schema.replication_applier_status_by_workerG
mysql> show global variables like 'gtid_executed';
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
48 / 51
it took less than 22 mins !
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
49 / 51
if you are brave and want to go at light speed
Try https://github.com/lefred/MyUndelete
50 / 51
Thank you !
Any Questions ?
http://lefred.be
Copyright @ 2018 Oracle and/or its affiliates. All rights reserved.
51 / 51

More Related Content

What's hot

What's hot (20)

Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
 
Percona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replicationPercona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replication
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
 
Automated master failover
Automated master failoverAutomated master failover
Automated master failover
 
Open Source 101 2022 - MySQL Indexes and Histograms
Open Source 101 2022 - MySQL Indexes and HistogramsOpen Source 101 2022 - MySQL Indexes and Histograms
Open Source 101 2022 - MySQL Indexes and Histograms
 
Mysql-MHA
Mysql-MHAMysql-MHA
Mysql-MHA
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
MySQL GTID 시작하기
MySQL GTID 시작하기MySQL GTID 시작하기
MySQL GTID 시작하기
 
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!MySQL Innovation Day Chicago  - MySQL HA So Easy : That's insane !!
MySQL Innovation Day Chicago - MySQL HA So Easy : That's insane !!
 
MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼MariaDB MaxScale monitor 매뉴얼
MariaDB MaxScale monitor 매뉴얼
 
Percona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL ArchitecturesPercona Live 2022 - MySQL Architectures
Percona Live 2022 - MySQL Architectures
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationPercona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
 
InnoDb Vs NDB Cluster
InnoDb Vs NDB ClusterInnoDb Vs NDB Cluster
InnoDb Vs NDB Cluster
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기
 
Percona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ MumbaiPercona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ Mumbai
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
MySQL Group Replication - HandsOn Tutorial
MySQL Group Replication - HandsOn TutorialMySQL Group Replication - HandsOn Tutorial
MySQL Group Replication - HandsOn Tutorial
 
MySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & OperationsMySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL InnoDB Cluster - Advanced Configuration & Operations
 
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL ShellMySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
MySQL InnoDB Cluster: Management and Troubleshooting with MySQL Shell
 
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
 

Similar to FOSDEM MySQL & Friends Devroom, February 2018 MySQL Point-in-Time Recovery like a Rockstar

20618782218718364253 emea12 vldb
20618782218718364253 emea12 vldb20618782218718364253 emea12 vldb
20618782218718364253 emea12 vldb
Locuto Riorama
 
2012 replication
2012 replication2012 replication
2012 replication
sqlhjalp
 

Similar to FOSDEM MySQL & Friends Devroom, February 2018 MySQL Point-in-Time Recovery like a Rockstar (20)

LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
LinuxFest Northwest 2022 - The Evolution of a MySQL Database SystemLinuxFest Northwest 2022 - The Evolution of a MySQL Database System
LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
 
Percona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database SystemPercona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database System
 
MySQL 8 High Availability with InnoDB Clusters
MySQL 8 High Availability with InnoDB ClustersMySQL 8 High Availability with InnoDB Clusters
MySQL 8 High Availability with InnoDB Clusters
 
Using The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change StreamUsing The Mysql Binary Log As A Change Stream
Using The Mysql Binary Log As A Change Stream
 
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a nutshell  hands-on tutorialMySQL InnoDB Cluster and Group Replication in a nutshell  hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
 
MySQL Shell/AdminAPI - MySQL Architectures Made Easy For All!
MySQL Shell/AdminAPI - MySQL Architectures Made Easy For All!MySQL Shell/AdminAPI - MySQL Architectures Made Easy For All!
MySQL Shell/AdminAPI - MySQL Architectures Made Easy For All!
 
MySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demoMySQL 8.0 InnoDB Cluster demo
MySQL 8.0 InnoDB Cluster demo
 
Replication Whats New in Mysql 8
Replication Whats New in Mysql 8Replication Whats New in Mysql 8
Replication Whats New in Mysql 8
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 
State of The Dolphin - May 2021
State of The Dolphin - May 2021State of The Dolphin - May 2021
State of The Dolphin - May 2021
 
oracle upgrade 2015_509_Swonger_ppt.pptx
oracle upgrade 2015_509_Swonger_ppt.pptxoracle upgrade 2015_509_Swonger_ppt.pptx
oracle upgrade 2015_509_Swonger_ppt.pptx
 
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
 
20618782218718364253 emea12 vldb
20618782218718364253 emea12 vldb20618782218718364253 emea12 vldb
20618782218718364253 emea12 vldb
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 
State of the Dolphin - May 2022
State of the Dolphin - May 2022State of the Dolphin - May 2022
State of the Dolphin - May 2022
 
Multi Source Replication With MySQL 5.7 @ Verisure
Multi Source Replication With MySQL 5.7 @ VerisureMulti Source Replication With MySQL 5.7 @ Verisure
Multi Source Replication With MySQL 5.7 @ Verisure
 
2012 scale replication
2012 scale replication2012 scale replication
2012 scale replication
 
Kafka High Availability in multi data center setup with floating Observers wi...
Kafka High Availability in multi data center setup with floating Observers wi...Kafka High Availability in multi data center setup with floating Observers wi...
Kafka High Availability in multi data center setup with floating Observers wi...
 
2012 replication
2012 replication2012 replication
2012 replication
 

More from Frederic Descamps

More from Frederic Descamps (20)

MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...
MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...
MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...
 
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code ExtensionMySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
 
RivieraJUG - MySQL Indexes and Histograms
RivieraJUG - MySQL Indexes and HistogramsRivieraJUG - MySQL Indexes and Histograms
RivieraJUG - MySQL Indexes and Histograms
 
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
RivieraJUG - MySQL 8.0 - What's new for developers.pdfRivieraJUG - MySQL 8.0 - What's new for developers.pdf
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
 
MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8MySQL User Group NL - MySQL 8
MySQL User Group NL - MySQL 8
 
Percona Live 2022 - MySQL Shell for Visual Studio Code
Percona Live 2022 - MySQL Shell for Visual Studio CodePercona Live 2022 - MySQL Shell for Visual Studio Code
Percona Live 2022 - MySQL Shell for Visual Studio Code
 
Pi Day 2022 - from IoT to MySQL HeatWave Database Service
Pi Day 2022 -  from IoT to MySQL HeatWave Database ServicePi Day 2022 -  from IoT to MySQL HeatWave Database Service
Pi Day 2022 - from IoT to MySQL HeatWave Database Service
 
Confoo 2022 - le cycle d'une instance MySQL
Confoo 2022  - le cycle d'une instance MySQLConfoo 2022  - le cycle d'une instance MySQL
Confoo 2022 - le cycle d'une instance MySQL
 
Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0
 
Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0
 
Deploying Magento on OCI with MDS
Deploying Magento on OCI with MDSDeploying Magento on OCI with MDS
Deploying Magento on OCI with MDS
 
MySQL Router REST API
MySQL Router REST APIMySQL Router REST API
MySQL Router REST API
 
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
 
Cloud native - Why to use MySQL 8.0 and how to use it on oci with MDS
Cloud native -  Why to use MySQL 8.0 and how to use it on oci with MDSCloud native -  Why to use MySQL 8.0 and how to use it on oci with MDS
Cloud native - Why to use MySQL 8.0 and how to use it on oci with MDS
 
MySQL Database Service Webinar: Installing Drupal in oci with mds
MySQL Database Service Webinar: Installing Drupal in oci with mdsMySQL Database Service Webinar: Installing Drupal in oci with mds
MySQL Database Service Webinar: Installing Drupal in oci with mds
 
the State of the Dolphin - October 2020
the State of the Dolphin - October 2020the State of the Dolphin - October 2020
the State of the Dolphin - October 2020
 
MySQL 8.0 Document Store - Discovery of a New World
MySQL 8.0 Document Store - Discovery of a New WorldMySQL 8.0 Document Store - Discovery of a New World
MySQL 8.0 Document Store - Discovery of a New World
 
Oracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with Terraform
Oracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with TerraformOracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with Terraform
Oracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with Terraform
 
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDSMySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
 
MySQL Database Service Webinar - Installing WordPress in OCI with MDS
MySQL Database Service Webinar - Installing WordPress in OCI with MDSMySQL Database Service Webinar - Installing WordPress in OCI with MDS
MySQL Database Service Webinar - Installing WordPress in OCI with MDS
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

FOSDEM MySQL & Friends Devroom, February 2018 MySQL Point-in-Time Recovery like a Rockstar

  • 3. FOSDEM, February 2018 MySQL Point-in-Time Recovery like a Rockstar Accelerate MySQL point-in-time recovery for large workloads       Frédéric Descamps - MySQL Community Manager - Oracle 3 / 51
  • 4.   Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purpose only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied up in making purchasing decisions. The development, release and timing of any features or functionality described for Oracle´s product remains at the sole discretion of Oracle. Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 4 / 51
  • 5. about.me/lefred Who am I ? Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 5 / 51
  • 6. Frédéric Descamps @lefred MySQL Evangelist Hacking MySQL since 3.23 devops believer living in Belgium 🇧🇪 http://lefred.be   Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 6 / 51
  • 7. what is PITR ? point-in-time recovery Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 7 / 51
  • 8. PITR: Definition from Wikipedia (thank you Jaime) Point-in-time recovery (PITR) in the context of computers involves systems whereby an administrator can restore or recover a set of data or a particular setting from a time in the past. Once PITR logging starts for a PITR-capable database, a database administrator can restore that database from backups to the state that it had at any time since. Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 8 / 51
  • 9. PITR: Definition from Wikipedia (thank you Jaime) Point-in-time recovery (PITR) in the context of computers involves systems whereby an administrator can restore or recover a set of data or a particular setting from a time in the past. Once PITR logging starts for a PITR-capable database, a database administrator can restore that database from backups to the state that it had at any time since. Please donate to wikimedia : https://goo.gl/ZYVFhf Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 9 / 51
  • 10. MySQL PITR requirements Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 10 / 51
  • 11. Requirements To be able to perform point-in-time recovery with MySQL, you need to have: Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 11 / 51
  • 12. Requirements To be able to perform point-in-time recovery with MySQL, you need to have: decent backups Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 12 / 51
  • 13. Requirements To be able to perform point-in-time recovery with MySQL, you need to have: decent backups binary logs enabled Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 13 / 51
  • 14. Requirements To be able to perform point-in-time recovery with MySQL, you need to have: decent backups binary logs enabled keeping your binlogs at least since the last successful backup Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 14 / 51
  • 15. MySQL PITR Procedure Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 15 / 51
  • 16. Procedure The procedure to perform a PITR with MySQL is the following: Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 16 / 51
  • 17. Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 17 / 51
  • 18. Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 18 / 51
  • 19. Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup find the binlog position of the last restored event Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 19 / 51
  • 20. Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup find the binlog position of the last restored event replay all events present in the binary logs since the backup up to the position of the transaction we want to skip Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 20 / 51
  • 21. Procedure The procedure to perform a PITR with MySQL is the following: find the binary log file and the position of the event you want restore up to restore the last backup find the binlog position of the last restored event replay all events present in the binary logs since the backup up to the position of the transaction we want to skip see the manual: https://dev.mysql.com/doc/refman/5.7/en/point-in-time-recovery.html Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 21 / 51
  • 22. MySQL PITR Example Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 22 / 51
  • 23. Example We have one database with 16 tables sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 prepare Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 23 / 51
  • 24. Example We have one database with 16 tables sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 prepare We have one physical backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup apply-log Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 24 / 51
  • 25. Example We have one database with 16 tables sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 prepare We have one physical backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup backup /opt/mysql/meb-4.1/bin/mysqlbackup --host=127.0.0.1 --backup-dir=mysqlbackup apply-log Any other backup solution can be used Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 25 / 51
  • 26. Example (2) We write data using 8 threads for 1h: sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 --threads=8 --report-interval=10 --time=3600 run Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 26 / 51
  • 27. Example (2) We write data using 8 threads for 1h: sysbench /usr/share/sysbench/oltp_insert.lua --db-driver=mysql --mysql-user=root --mysql-host=localhost --table-size=100000 --tables=16 --threads=8 --report-interval=10 --time=3600 run And let's modify a record with something we can track ;-) mysql> update sbtest3 set pad='fred' where id = 126551; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 27 / 51
  • 28. Suddenly... Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 28 / 51
  • 29. Suddenly... Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 29 / 51
  • 30. Suddenly... mysql> update sbtest4 set pad="oups"; Query OK, 1066269 rows affected (8.52 sec) Rows matched: 1066269 Changed: 1066269 Warnings: 0 Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 30 / 51
  • 31. UPDATE without WHERE clause !?! Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 31 / 51
  • 32. Find what we need to avoid after restore mysql> show master status; +------------------+-----------+...+------------------------------------------------+ | File | Position | | Executed_Gtid_Set | +------------------+-----------+...+------------------------------------------------+ | imac2-bin.000005 | 622915384 | | 25d97ef9-005b-11e8-bf1b-685b359e77d5:1-1072032 | +------------------+-----------+...+------------------------------------------------+ 1 row in set (0.00 sec) Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 32 / 51
  • 33. Let's verify... mysql> pager grep -A 1 -B 2 'sbtest.sbtest4' | grep -B 4 Update mysql> show binlog events in 'imac2-bin.000005'; -- | imac2-bin.000005 | 277145452 | Gtid | ... | SET @@SESSION.GTID_NEXT= '25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032' | | imac2-bin.000005 | 277145513 | Query | ... | BEGIN | | imac2-bin.000005 | 277145583 | Table_map | ... | table_id: 154 (sbtest.sbtest4)| | imac2-bin.000005 | 277145638 | Update_rows | ... | table_id: 154 | mysql> pager sed -n -e '/25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032/,/COMMIT/ p' | grep COMMIT mysql> show binlog events in 'imac2-bin.000005'; | imac2-bin.000005 | 622915357 | Xid | ... | 622915384 | COMMIT /* xid=1072253 */ This is good, let's then keep the position 277145452 Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 33 / 51
  • 34. Stop MySQL and save the binlogs [root@imac2 ~]# systemctl stop mysqld [root@imac2 ~]# mkdir /mnt/mysql/binlogs [root@imac2 ~]# cd /var/lib/mysql [root@imac2 mysql]# cp imac2-bin.* /mnt/mysql/binlogs/ Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 34 / 51
  • 35. Stop MySQL and save the binlogs [root@imac2 ~]# systemctl stop mysqld [root@imac2 ~]# mkdir /mnt/mysql/binlogs [root@imac2 ~]# cd /var/lib/mysql [root@imac2 mysql]# cp imac2-bin.* /mnt/mysql/binlogs/ Restore the backup [root@imac2 mysql]# rm -rf * [root@imac2 mysql]# /opt/mysql/meb-4.1/bin/mysqlbackup --backup-dir=/tmp/mysqlbackup copy-back ... mysqlbackup completed OK! with 3 warnings [root@imac2 mysql]# chown -R mysql. * Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 35 / 51
  • 36. Point-in-Time Recovery Now we can start MySQL and replay the binlogs from the backup position, until the "EVENT" (277145452) # grep binlog_position backup_variables.txt binlog_position=imac2-bin.000004:888830919 [root@imac2 binlogs]# time mysqlbinlog -j 888830919 --stop-position 277145452 imac2-bin.00000[4-5] | mysql real 305m18.867s I only needed to replay events from imac2-bin.00000[4-5] in fact, but it could be way more than that Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 36 / 51
  • 37. Point-in-Time Recovery Now we can start MySQL and replay the binlogs from the backup position, until the "EVENT" (277145452) # grep binlog_position backup_variables.txt binlog_position=imac2-bin.000004:888830919 [root@imac2 binlogs]# time mysqlbinlog -j 888830919 --stop-position 277145452 imac2-bin.00000[4-5] | mysql real 305m18.867s I only needed to replay events from imac2-bin.00000[4-5] in fact, but it could be way more than that -rw-r----- 1 root root 1.1G Jan 23 21:27 imac2-bin.000004 -rw-r----- 1 root root 595M Jan 23 21:27 imac2-bin.000005 Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 37 / 51
  • 38. Was it really like a rockstar ? Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 38 / 51
  • 39. Was it really like a rockstar ? NO ! Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 39 / 51
  • 40. Why not ? If you have a large amount of large binary logs and your workload is not single threaded like mysqlbinlog... this process can take for eveeeeeeeeer ! Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 40 / 51
  • 41. Let's do it like a rockstar ! Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 41 / 51
  • 42. Find and Set the last executed GTID during backup [root@imac2 mysql]# cat backup_variables.txt | grep gtid gtid_executed=25d97ef9-005b-11e8-bf1b-685b359e77d5:1-6001 The name of the file depends of your backup tool After restoring the backup, restart MySQL with this change in my.cnf: skip-slave-start Finally set the GTID AND ALSO the GTID of the transaction we want to avoid: mysql> reset master; mysql> SET @@GLOBAL.GTID_PURGED='25d97ef9-005b-11e8-bf1b-685b359e77d5:1-6001, 25d97ef9-005b-11e8-bf1b-685b359e77d5:1072032'; Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 42 / 51
  • 43. MySQL PITR Now the cool stuff ! Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 43 / 51
  • 44. We will copy all the saved binlogs and rename them as relaylogs ! [root@imac2 mysql]# for i in $(ls /mnt/mysql/binlogs/*.0*) do ext=$(echo $i | cut -d'.' -f2) cp $i imac2-relay-bin.$ext done Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 44 / 51
  • 45. We will copy all the saved binlogs and rename them as relaylogs ! [root@imac2 mysql]# for i in $(ls /mnt/mysql/binlogs/*.0*) do ext=$(echo $i | cut -d'.' -f2) cp $i imac2-relay-bin.$ext done Don't forget to create the index file too: [root@imac2 mysql]# ls ./imac2-relay-bin.0* >imac2-relay-bin.index [root@imac2 mysql]# chown mysql. *relay* [root@imac2 mysql]# cat imac2-relay-bin.index ./imac2-relay-bin.000001 ./imac2-relay-bin.000002 ./imac2-relay-bin.000003 ./imac2-relay-bin.000004 ./imac2-relay-bin.000005 Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 45 / 51
  • 46. Get ready to do PITR like a rockstar ! Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 46 / 51
  • 47. Get ready to do PITR like a rockstar ! mysql> SET GLOBAL server_id = 99; #replicate-same-server-id=1 won't work because of #89375 mysql> SET GLOBAL SLAVE_PARALLEL_TYPE='LOGICAL_CLOCK'; mysql> SET GLOBAL SLAVE_PARALLEL_WORKERS=8; mysql> CHANGE MASTER TO RELAY_LOG_FILE='imac2-relay-bin.000001', RELAY_LOG_POS=4, MASTER_HOST='dummy'; mysql> START SLAVE SQL_THREAD; Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 47 / 51
  • 48. Get ready to do PITR like a rockstar ! mysql> SET GLOBAL server_id = 99; #replicate-same-server-id=1 won't work because of #89375 mysql> SET GLOBAL SLAVE_PARALLEL_TYPE='LOGICAL_CLOCK'; mysql> SET GLOBAL SLAVE_PARALLEL_WORKERS=8; mysql> CHANGE MASTER TO RELAY_LOG_FILE='imac2-relay-bin.000001', RELAY_LOG_POS=4, MASTER_HOST='dummy'; mysql> START SLAVE SQL_THREAD; And you can even monitor it: mysql> select * from performance_schema.replication_applier_status_by_workerG mysql> show global variables like 'gtid_executed'; Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 48 / 51
  • 49. it took less than 22 mins ! Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 49 / 51
  • 50. if you are brave and want to go at light speed Try https://github.com/lefred/MyUndelete 50 / 51
  • 51. Thank you ! Any Questions ? http://lefred.be Copyright @ 2018 Oracle and/or its affiliates. All rights reserved. 51 / 51