SlideShare a Scribd company logo
More on gdb for MySQL DBAs
or
Using gdb to study MySQL internals and as a last resort
Valerii Kravchuk, MySQL Support Engineer
vkravchuk@gmail.com
www.percona.com
Who am I?
Valerii (aka Valeriy) Kravchuk:
● MySQL Support Engineer in MySQL AB, Sun and Oracle, 2005 - 2012
○ Bugs Verification Team all this time
○ Support issues related to bugs, crashes, InnoDB, performance...
○ Trainings (mostly informal) for new team members
○ All kinds of decision making committees…
● Principal Support Engineer in Percona, 2012 - 2016
○ Did more or less the same as before, but better (I hope)...
○ Plus I tried to speak and write about MySQL in publi
● Independent since January 27, 2016
● http://mysqlentomologist.blogspot.com - my blog about MySQL (mostly
bugs)
● https://www.facebook.com/valerii.kravchuk - my Facebook page, a lot about
MySQL (mostly bugs…)
● http://bugs.mysql.com - my personal playground. 28 bugs reported since
February, 2015
www.percona.com
What is this session about?
● Some historical remarks and URLs to known use
cases/blog posts about gdb and MySQL troubleshooting
● Multi-threaded executables and gdb (threads, frames)
● Basic gdb commands and “tricks”
● Few words on pt-pmp use
● Important MySQL data structures to explore
(mostly THD)
● Using gdb to study InnoDB and metadata locks
● A couple of real life use cases, working with core dump
and alive mysqld
● Discussion
www.percona.com
Usually gdb is used by developers to study core
dumps...
● Mostly like these:
gdb /path/to/mysqld /path/to/coredump
● Bug #76432 - “handle_fatal_signal (sig=11) in
__strlen_sse2_pminub on CHANGE MASTER”
● Bug #69898 - “change_master() invokes
ha_innobase::truncate() in a DML transaction” - a lot
of useful gdb-related reading inside.
See also related Bug #69825 and Bug #73155 (still
“Verified”)
www.percona.com
...or (surprise!) to debug their code
● Running “under gdb”:
gdb --args bin/mysqlcheck -u root -p -S/tmp/mysql.sock
--all-databases --optimize
(gdb) thread apply all bt
● Attaching gdb to the process already running:
gdb -p `pidof mysqld`
● Some examples:
○ Percona Server Bug #1483251 - “savepoints and replication”. Check
how Vlad Lesin uses backtrace to understand the reason of the bug
○ Percona Server Bug #1426345 - “Prepared statements in stored
procedures crash query response time plugin”. Check how Nickolay
Ihalainen pinpoint the root cause of the bug by comparing values of
various variables in gdb
www.percona.com
But production DBAs also may benefit from gdb!
● First of all, gdb allows to inspect the values of variables
in the mysqld process memory, and thus you can check
some details about user threads and statements
executed that may not be easily available via SQL
(missing feature, can’t connect, hangs, bug)
● Also gdb allows to change the values of variables, both
global and session ones (missing feature, read only
ones) directly or indirectly (by calling functions in the
code)
● Finally, attaching gdb allows to get a backtrace for
further study of the root cause of the problem
www.percona.com
Domas is famous for these tricks...
● http://dom.as/2009/02/15/poor-mans-contention-profiling/ -
this is what ended up as http://poormansprofiler.org/ and
pt-pmp
● http://dom.as/2009/07/30/evil-replication-management/ -
mysql> system gdb -p $(pidof mysqld) -ex "set
opt_log_slave_updates=1" -batch
● http://dom.as/2010/01/02/read-ahead/ -
gdb -ex "set srv_startup_is_before_trx_rollback_phase=1"
-batch -p $(pidof mysqld)
● http://dom.as/2009/12/29/when-bad-things-happen/
www.percona.com
More examples of gdb use for MySQL DBAs
● Remember the names:
Domas Mituzas, Shane Bester, Roel Van De Paar, Mark Callaghan,
Aurimas Mikalauskas, Zhai Weixiang, ...
● http://www.percona.com/blog/2012/09/09/obtain-last-executed-statement-from-
optimized-core-dump/
● http://www.percona.com/blog/2013/11/11/how-to-extract-all-running-queries-
including-the-last-executed-statement-from-a-core-file/
● http://mysqlbugs.blogspot.com.au/2012/09/how-to-obtain-all-executing-queries.
html
● http://www.percona.com/blog/2010/03/23/too-many-connections-no-problem/
www.percona.com
What MySQL DBA can do with gdb
● Check stack traces (and variables), per thread:
thread apply all bt [full]
● Print variables, up to complex one:
thread 1
print do_command::thd->query_string.string.str
● Set new values for variables (global and per thread, even those formally
read-only in MySQL while it’s running):
set max_connections=5000
set opt_log_slave_updates=1
● Call functions (that may do complex changes):
call rpl_filter->add_do_db(strdup("hehehe"))
● Set breakpoints and watchpoints
● Work interactively or use gdb as a command line utility (-batch)
● Use macros, Python scripting, more…
● All these may not work, fail, hang, crash, produce obscure errors…
● You have to read and understand the source code
www.percona.com
pt-pmp (Poor Man’s Profiler)
● http://www.percona.com/doc/percona-toolkit/2.2/pt-pmp.html
pt-pmp [-i 1] [-s 0] [-b mysqld] [-p pidofmysqld] [-l 0] [-k file] [--version]
● It is based on original idea by Domas (http://poormansprofiler.org/) with
some more bash/awk on top applied
● One of the recent examples how it is used (semi-sync replication
performance): http://bugs.mysql.com/bug.php?id=75570
● When mysqld hangs or is slow, you can get some insight quickly: http://bugs.
mysql.com/bug.php?id=75028 (HandlerSocket “hangs” on shutdown)
● When there are stalls, use pt-pmp to find out why (or what threads mostly
do at the moment): http://bugs.mysql.com/bug.php?id=69810
● pt-pmp surely slows server down :) Hint (partial workaround is in the bug):
https://bugs.launchpad.net/percona-toolkit/+bug/1320168
www.percona.com
Multi-threaded mysqld process and gdb
● process/thread/frame concepts:
(gdb) thread 2
[Switching to thread 2 (Thread 0x7fe771550700 (LWP 2544))]
#0 0x0000000000605774 in Item_func_numhybrid::val_int (
this=<value optimized out>)
at /home/openxs/bzr2/percona-5.6/sql/item_func.cc:1013
1013 }
(gdb) bt
...
#12 0x00000000006f8a45 in dispatch_command (command=COM_QUERY,
thd=0x7fe760f94000, packet=0x7fe77154fac0 "", packet_length=0)
at /home/openxs/bzr2/percona-5.6/sql/sql_parse.cc:1434
...
(gdb) frame 12
#12 0x00000000006f8a45 in dispatch_command (command=COM_QUERY,
thd=0x7fe760f94000, packet=0x7fe77154fac0 "", packet_length=0)
at /home/openxs/bzr2/percona-5.6/sql/sql_parse.cc:1434
warning: Source file is more recent than executable.
1434 mysql_parse(thd, thd->query(), thd->query_length(), &parser_state);
(gdb) p thd->query_string.string.str
$2 = 0x7fe75301d010 "select benchmark(5", '0' <repeats 13 times>, ", 2*2)"
● https://sourceware.org/gdb/onlinedocs/gdb/Variables.html
www.percona.com
THD structure
grep -rn THD sql/sql_class.h
class THD :public MDL_context_owner,
public Statement,
public Open_tables_state
HASH user_vars; // hash for user vars
struct system_variables variables; // Changeable local
vars
struct system_status_var status_var;// Per thread stat
vars
struct system_status_var *initial_status_var; /* used by
show status */
Security_context main_security_ctx;
...
CSET_STRING query_string; // inherited from Statement…
...
www.percona.com
THD structure (continued)
(gdb) p thd->main_security_ctx->user
$7 = 0x7fe753019058 "root"
(gdb) p thd->main_security_ctx->host
$8 = {Ptr = 0xc16759 "localhost", str_length = 9,
Alloced_length = 0,
alloced = false, str_charset = 0x1393de0}
www.percona.com
Real life case: checking core dump
gdb -ex 'set pagination 0'
…
-ex 'thread apply all bt full'
/path/to/mysqld /var/tmp/core.<pid> | tee core.<pid>.bt
● Make sure you know how to get core when mysqld
crashes:
http://www.percona.com/blog/2011/08/26/getting-mysql-core-file-on-linux/
● Let’s check one example, we need crashing bug for this:
https://bugs.launchpad.net/percona-server/+bug/1384658
www.percona.com
Real life case: attaching to alive mysqld
This is how it goes:
[root@centos openxs]# mysql -uroot -e "show variables like
'innodb_autoinc_lock_mode'"
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| innodb_autoinc_lock_mode | 0 |
+--------------------------+-------+
[root@centos openxs]# mysql -uroot -e "set global
innodb_autoinc_lock_mode=1"
ERROR 1238 (HY000) at line 1: Variable 'innodb_autoinc_lock_mode' is a
read only variable
[root@centos openxs]# gdb -ex "set innobase_autoinc_lock_mode=1" -batch -p
`pidof mysqld`
…
[Thread debugging using libthread_db enabled]
0x00007ff31d6830d3 in poll () from /lib64/libc.so.6
… check the variable value again now
[root@centos openxs]# ps aux | grep mysqld
[root@centos openxs]# kill -SIGCONT `pidof mysqld`
www.percona.com
How to study InnoDB locks with gdb
● Read the code (or blogs, or backtraces) to find out what
functions are called when InnoDB locks are requested:
○ lock_table - table level locks
○ lock_rec_lock - row level locks
● Make sure there is debug info for mysqld binary you use
● Attach gdb to running mysqld process in test env:
[root@centos ~]# gdb -p `pidof mysqld`
...
(gdb) b lock_table
...
(gdb) b lock_rec_lock
...
(gdb) c
● Run SQL you want to study and check sequence of calls,
backtraces, variables...
www.percona.com
How to study metadata locks with gdb
● Read the code (or blogs, or backtraces) to find out what
functions are called when metadata locks are requested:
○ MDL_request::init - metadata lock request
○ MDL_context::aquire_lock - attempt to aquire lock
● Make sure there is debug info for mysqld binary you use
● Attach gdb to running mysqld process in test env:
[root@centos ~]# gdb -p `pidof mysqld`
...
(gdb) b MDL_request::init
...
(gdb) c
● Run SQL you want to study and check sequence of calls,
backtraces, variables...
www.percona.com
Results of using gdb to study MySQL internals
● Exploring metadata locks with gdb:
○ http://mysqlentomologist.blogspot.com/2016/01/exploring-metadata-locks-with-gdb-first.html
○ http://mysqlentomologist.blogspot.com/2016/01/exploring-metadata-locks-with-gdb.html
○ http://mysqlentomologist.blogspot.com/2016/01/exploring-metadata-locks-with-gdb-how.html
● Exploring InnoDB locks with gdb:
○ http://mysqlentomologist.blogspot.com/2015/03/using-gdb-to-understand-what-locks-and_31.html
○ http://mysqlentomologist.blogspot.com/2015/04/using-gdb-to-understand-what-locks-and.html
○ http://www.slideshare.net/valeriikravchuk1/understanding-innodb-locks-and-deadlocks
● Bug reports and documentation requests to make MySQL
and its manual better:
○ Bug #79665 - Manual does NOT explain locks set by INSERT ... ON DUPLICATE KEY UPDATE
properly
○ Bug #77390 - Manual does not explain a "deadlock" case of online ALTER
○ Bug #76588 - Metadata lock is NOT released when SELECT completes in case of autocommit=0
○ Bug #76563 - Manual does NOT explain when exactly AUTO-INC lock is set for "bulk inserts"
○ Bug #76533 - AUTO_INC lock seems to be NOT set for INSERT INTO t(val) SELECT val FROM t
● Immediate DBA problems solved without restart etc
www.percona.com
Is gdb an ultimate answer for MySQL DBA?
No, it’s like a temporary, one time solution or last resort.
Instead you may (or should, whenever possible):
● Use real profilers at OS level (like prof or oprofile)
● Use troubleshooting tools at MySQL level (like P_S)
● Implement missing feature (like setting some variable
dynamically) or request it from developers
● Consider upgrade to version or fork that already has a
feature you miss
● Plan your work and do maintenance properly
● Read the manual and source code
www.percona.com
Thank you!
Questions and Answers?
Please, report bugs at:
http://bugs.mysql.com
Use “Affects Me” button!
Ad

More Related Content

What's hot (20)

Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)
Valerii Kravchuk
 
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL DevroomFlame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Valeriy Kravchuk
 
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS -  FOSDEM 2022 MariaDB DevroomMariaDB Server on macOS -  FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Valeriy Kravchuk
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Valeriy Kravchuk
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014
FromDual GmbH
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
The New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreThe New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and more
MariaDB Corporation
 
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Valeriy Kravchuk
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
Antony T Curtis
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite Plugins
Sveta Smirnova
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
MySQLConference
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
Antony T Curtis
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
Sveta Smirnova
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
Antony T Curtis
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
Sveta Smirnova
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
Sveta Smirnova
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Performance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingPerformance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshooting
Sveta Smirnova
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)
Valerii Kravchuk
 
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL DevroomFlame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Flame Graphs for MySQL DBAs - FOSDEM 2022 MySQL Devroom
Valeriy Kravchuk
 
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS -  FOSDEM 2022 MariaDB DevroomMariaDB Server on macOS -  FOSDEM 2022 MariaDB Devroom
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Valeriy Kravchuk
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Valeriy Kravchuk
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014
FromDual GmbH
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
The New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreThe New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and more
MariaDB Corporation
 
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Valeriy Kravchuk
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
Antony T Curtis
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite Plugins
Sveta Smirnova
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
MySQLConference
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
Antony T Curtis
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
Sveta Smirnova
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
Antony T Curtis
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
Sveta Smirnova
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
Sveta Smirnova
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Performance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingPerformance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshooting
Sveta Smirnova
 

Similar to More on gdb for my sql db as (fosdem 2016) (20)

Troubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer PerspectiveTroubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer Perspective
Marcelo Altmann
 
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitationsMySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
FromDual GmbH
 
MySQL Parallel Replication by Booking.com
MySQL Parallel Replication by Booking.comMySQL Parallel Replication by Booking.com
MySQL Parallel Replication by Booking.com
Jean-François Gagné
 
Upgrade to MySQL 5.6 without downtime
Upgrade to MySQL 5.6 without downtimeUpgrade to MySQL 5.6 without downtime
Upgrade to MySQL 5.6 without downtime
Olivier DASINI
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
PgTraining
 
PL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptxPL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptx
Vinicius M Grippa
 
Kettunen, miaubiz fuzzing at scale and in style
Kettunen, miaubiz   fuzzing at scale and in styleKettunen, miaubiz   fuzzing at scale and in style
Kettunen, miaubiz fuzzing at scale and in style
DefconRussia
 
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
Jean-François Gagné
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
libfetion
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
Kris Buytaert
 
The Accidental DBA
The Accidental DBAThe Accidental DBA
The Accidental DBA
PostgreSQL Experts, Inc.
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
Juan Berner
 
Replication skeptic
Replication skepticReplication skeptic
Replication skeptic
Giuseppe Maxia
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
Kris Buytaert
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
Emily Ikuta
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
Jean-François Gagné
 
Troubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer PerspectiveTroubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer Perspective
Marcelo Altmann
 
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitationsMySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
Jean-François Gagné
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
FromDual GmbH
 
MySQL Parallel Replication by Booking.com
MySQL Parallel Replication by Booking.comMySQL Parallel Replication by Booking.com
MySQL Parallel Replication by Booking.com
Jean-François Gagné
 
Upgrade to MySQL 5.6 without downtime
Upgrade to MySQL 5.6 without downtimeUpgrade to MySQL 5.6 without downtime
Upgrade to MySQL 5.6 without downtime
Olivier DASINI
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
PgTraining
 
PL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptxPL22 - Backup and Restore Performance.pptx
PL22 - Backup and Restore Performance.pptx
Vinicius M Grippa
 
Kettunen, miaubiz fuzzing at scale and in style
Kettunen, miaubiz   fuzzing at scale and in styleKettunen, miaubiz   fuzzing at scale and in style
Kettunen, miaubiz fuzzing at scale and in style
DefconRussia
 
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
Jean-François Gagné
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
libfetion
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
Kris Buytaert
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
Juan Berner
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
Kris Buytaert
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
Emily Ikuta
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
Jean-François Gagné
 
Ad

Recently uploaded (20)

Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Ad

More on gdb for my sql db as (fosdem 2016)

  • 1. More on gdb for MySQL DBAs or Using gdb to study MySQL internals and as a last resort Valerii Kravchuk, MySQL Support Engineer [email protected]
  • 2. www.percona.com Who am I? Valerii (aka Valeriy) Kravchuk: ● MySQL Support Engineer in MySQL AB, Sun and Oracle, 2005 - 2012 ○ Bugs Verification Team all this time ○ Support issues related to bugs, crashes, InnoDB, performance... ○ Trainings (mostly informal) for new team members ○ All kinds of decision making committees… ● Principal Support Engineer in Percona, 2012 - 2016 ○ Did more or less the same as before, but better (I hope)... ○ Plus I tried to speak and write about MySQL in publi ● Independent since January 27, 2016 ● http://mysqlentomologist.blogspot.com - my blog about MySQL (mostly bugs) ● https://www.facebook.com/valerii.kravchuk - my Facebook page, a lot about MySQL (mostly bugs…) ● http://bugs.mysql.com - my personal playground. 28 bugs reported since February, 2015
  • 3. www.percona.com What is this session about? ● Some historical remarks and URLs to known use cases/blog posts about gdb and MySQL troubleshooting ● Multi-threaded executables and gdb (threads, frames) ● Basic gdb commands and “tricks” ● Few words on pt-pmp use ● Important MySQL data structures to explore (mostly THD) ● Using gdb to study InnoDB and metadata locks ● A couple of real life use cases, working with core dump and alive mysqld ● Discussion
  • 4. www.percona.com Usually gdb is used by developers to study core dumps... ● Mostly like these: gdb /path/to/mysqld /path/to/coredump ● Bug #76432 - “handle_fatal_signal (sig=11) in __strlen_sse2_pminub on CHANGE MASTER” ● Bug #69898 - “change_master() invokes ha_innobase::truncate() in a DML transaction” - a lot of useful gdb-related reading inside. See also related Bug #69825 and Bug #73155 (still “Verified”)
  • 5. www.percona.com ...or (surprise!) to debug their code ● Running “under gdb”: gdb --args bin/mysqlcheck -u root -p -S/tmp/mysql.sock --all-databases --optimize (gdb) thread apply all bt ● Attaching gdb to the process already running: gdb -p `pidof mysqld` ● Some examples: ○ Percona Server Bug #1483251 - “savepoints and replication”. Check how Vlad Lesin uses backtrace to understand the reason of the bug ○ Percona Server Bug #1426345 - “Prepared statements in stored procedures crash query response time plugin”. Check how Nickolay Ihalainen pinpoint the root cause of the bug by comparing values of various variables in gdb
  • 6. www.percona.com But production DBAs also may benefit from gdb! ● First of all, gdb allows to inspect the values of variables in the mysqld process memory, and thus you can check some details about user threads and statements executed that may not be easily available via SQL (missing feature, can’t connect, hangs, bug) ● Also gdb allows to change the values of variables, both global and session ones (missing feature, read only ones) directly or indirectly (by calling functions in the code) ● Finally, attaching gdb allows to get a backtrace for further study of the root cause of the problem
  • 7. www.percona.com Domas is famous for these tricks... ● http://dom.as/2009/02/15/poor-mans-contention-profiling/ - this is what ended up as http://poormansprofiler.org/ and pt-pmp ● http://dom.as/2009/07/30/evil-replication-management/ - mysql> system gdb -p $(pidof mysqld) -ex "set opt_log_slave_updates=1" -batch ● http://dom.as/2010/01/02/read-ahead/ - gdb -ex "set srv_startup_is_before_trx_rollback_phase=1" -batch -p $(pidof mysqld) ● http://dom.as/2009/12/29/when-bad-things-happen/
  • 8. www.percona.com More examples of gdb use for MySQL DBAs ● Remember the names: Domas Mituzas, Shane Bester, Roel Van De Paar, Mark Callaghan, Aurimas Mikalauskas, Zhai Weixiang, ... ● http://www.percona.com/blog/2012/09/09/obtain-last-executed-statement-from- optimized-core-dump/ ● http://www.percona.com/blog/2013/11/11/how-to-extract-all-running-queries- including-the-last-executed-statement-from-a-core-file/ ● http://mysqlbugs.blogspot.com.au/2012/09/how-to-obtain-all-executing-queries. html ● http://www.percona.com/blog/2010/03/23/too-many-connections-no-problem/
  • 9. www.percona.com What MySQL DBA can do with gdb ● Check stack traces (and variables), per thread: thread apply all bt [full] ● Print variables, up to complex one: thread 1 print do_command::thd->query_string.string.str ● Set new values for variables (global and per thread, even those formally read-only in MySQL while it’s running): set max_connections=5000 set opt_log_slave_updates=1 ● Call functions (that may do complex changes): call rpl_filter->add_do_db(strdup("hehehe")) ● Set breakpoints and watchpoints ● Work interactively or use gdb as a command line utility (-batch) ● Use macros, Python scripting, more… ● All these may not work, fail, hang, crash, produce obscure errors… ● You have to read and understand the source code
  • 10. www.percona.com pt-pmp (Poor Man’s Profiler) ● http://www.percona.com/doc/percona-toolkit/2.2/pt-pmp.html pt-pmp [-i 1] [-s 0] [-b mysqld] [-p pidofmysqld] [-l 0] [-k file] [--version] ● It is based on original idea by Domas (http://poormansprofiler.org/) with some more bash/awk on top applied ● One of the recent examples how it is used (semi-sync replication performance): http://bugs.mysql.com/bug.php?id=75570 ● When mysqld hangs or is slow, you can get some insight quickly: http://bugs. mysql.com/bug.php?id=75028 (HandlerSocket “hangs” on shutdown) ● When there are stalls, use pt-pmp to find out why (or what threads mostly do at the moment): http://bugs.mysql.com/bug.php?id=69810 ● pt-pmp surely slows server down :) Hint (partial workaround is in the bug): https://bugs.launchpad.net/percona-toolkit/+bug/1320168
  • 11. www.percona.com Multi-threaded mysqld process and gdb ● process/thread/frame concepts: (gdb) thread 2 [Switching to thread 2 (Thread 0x7fe771550700 (LWP 2544))] #0 0x0000000000605774 in Item_func_numhybrid::val_int ( this=<value optimized out>) at /home/openxs/bzr2/percona-5.6/sql/item_func.cc:1013 1013 } (gdb) bt ... #12 0x00000000006f8a45 in dispatch_command (command=COM_QUERY, thd=0x7fe760f94000, packet=0x7fe77154fac0 "", packet_length=0) at /home/openxs/bzr2/percona-5.6/sql/sql_parse.cc:1434 ... (gdb) frame 12 #12 0x00000000006f8a45 in dispatch_command (command=COM_QUERY, thd=0x7fe760f94000, packet=0x7fe77154fac0 "", packet_length=0) at /home/openxs/bzr2/percona-5.6/sql/sql_parse.cc:1434 warning: Source file is more recent than executable. 1434 mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); (gdb) p thd->query_string.string.str $2 = 0x7fe75301d010 "select benchmark(5", '0' <repeats 13 times>, ", 2*2)" ● https://sourceware.org/gdb/onlinedocs/gdb/Variables.html
  • 12. www.percona.com THD structure grep -rn THD sql/sql_class.h class THD :public MDL_context_owner, public Statement, public Open_tables_state HASH user_vars; // hash for user vars struct system_variables variables; // Changeable local vars struct system_status_var status_var;// Per thread stat vars struct system_status_var *initial_status_var; /* used by show status */ Security_context main_security_ctx; ... CSET_STRING query_string; // inherited from Statement… ...
  • 13. www.percona.com THD structure (continued) (gdb) p thd->main_security_ctx->user $7 = 0x7fe753019058 "root" (gdb) p thd->main_security_ctx->host $8 = {Ptr = 0xc16759 "localhost", str_length = 9, Alloced_length = 0, alloced = false, str_charset = 0x1393de0}
  • 14. www.percona.com Real life case: checking core dump gdb -ex 'set pagination 0' … -ex 'thread apply all bt full' /path/to/mysqld /var/tmp/core.<pid> | tee core.<pid>.bt ● Make sure you know how to get core when mysqld crashes: http://www.percona.com/blog/2011/08/26/getting-mysql-core-file-on-linux/ ● Let’s check one example, we need crashing bug for this: https://bugs.launchpad.net/percona-server/+bug/1384658
  • 15. www.percona.com Real life case: attaching to alive mysqld This is how it goes: [root@centos openxs]# mysql -uroot -e "show variables like 'innodb_autoinc_lock_mode'" +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | innodb_autoinc_lock_mode | 0 | +--------------------------+-------+ [root@centos openxs]# mysql -uroot -e "set global innodb_autoinc_lock_mode=1" ERROR 1238 (HY000) at line 1: Variable 'innodb_autoinc_lock_mode' is a read only variable [root@centos openxs]# gdb -ex "set innobase_autoinc_lock_mode=1" -batch -p `pidof mysqld` … [Thread debugging using libthread_db enabled] 0x00007ff31d6830d3 in poll () from /lib64/libc.so.6 … check the variable value again now [root@centos openxs]# ps aux | grep mysqld [root@centos openxs]# kill -SIGCONT `pidof mysqld`
  • 16. www.percona.com How to study InnoDB locks with gdb ● Read the code (or blogs, or backtraces) to find out what functions are called when InnoDB locks are requested: ○ lock_table - table level locks ○ lock_rec_lock - row level locks ● Make sure there is debug info for mysqld binary you use ● Attach gdb to running mysqld process in test env: [root@centos ~]# gdb -p `pidof mysqld` ... (gdb) b lock_table ... (gdb) b lock_rec_lock ... (gdb) c ● Run SQL you want to study and check sequence of calls, backtraces, variables...
  • 17. www.percona.com How to study metadata locks with gdb ● Read the code (or blogs, or backtraces) to find out what functions are called when metadata locks are requested: ○ MDL_request::init - metadata lock request ○ MDL_context::aquire_lock - attempt to aquire lock ● Make sure there is debug info for mysqld binary you use ● Attach gdb to running mysqld process in test env: [root@centos ~]# gdb -p `pidof mysqld` ... (gdb) b MDL_request::init ... (gdb) c ● Run SQL you want to study and check sequence of calls, backtraces, variables...
  • 18. www.percona.com Results of using gdb to study MySQL internals ● Exploring metadata locks with gdb: ○ http://mysqlentomologist.blogspot.com/2016/01/exploring-metadata-locks-with-gdb-first.html ○ http://mysqlentomologist.blogspot.com/2016/01/exploring-metadata-locks-with-gdb.html ○ http://mysqlentomologist.blogspot.com/2016/01/exploring-metadata-locks-with-gdb-how.html ● Exploring InnoDB locks with gdb: ○ http://mysqlentomologist.blogspot.com/2015/03/using-gdb-to-understand-what-locks-and_31.html ○ http://mysqlentomologist.blogspot.com/2015/04/using-gdb-to-understand-what-locks-and.html ○ http://www.slideshare.net/valeriikravchuk1/understanding-innodb-locks-and-deadlocks ● Bug reports and documentation requests to make MySQL and its manual better: ○ Bug #79665 - Manual does NOT explain locks set by INSERT ... ON DUPLICATE KEY UPDATE properly ○ Bug #77390 - Manual does not explain a "deadlock" case of online ALTER ○ Bug #76588 - Metadata lock is NOT released when SELECT completes in case of autocommit=0 ○ Bug #76563 - Manual does NOT explain when exactly AUTO-INC lock is set for "bulk inserts" ○ Bug #76533 - AUTO_INC lock seems to be NOT set for INSERT INTO t(val) SELECT val FROM t ● Immediate DBA problems solved without restart etc
  • 19. www.percona.com Is gdb an ultimate answer for MySQL DBA? No, it’s like a temporary, one time solution or last resort. Instead you may (or should, whenever possible): ● Use real profilers at OS level (like prof or oprofile) ● Use troubleshooting tools at MySQL level (like P_S) ● Implement missing feature (like setting some variable dynamically) or request it from developers ● Consider upgrade to version or fork that already has a feature you miss ● Plan your work and do maintenance properly ● Read the manual and source code
  • 20. www.percona.com Thank you! Questions and Answers? Please, report bugs at: http://bugs.mysql.com Use “Affects Me” button!