Introduction to troubleshooting Basic techniques. Sveta Smirnova Principal Support Engineer March, 10, 2016

Similar documents
Effective Testing for Live Applications. March, 29, 2018 Sveta Smirnova

Oracle Exam 1z0-883 MySQL 5.6 Database Administrator Version: 8.0 [ Total Questions: 100 ]

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

1Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

MySQL Query Tuning 101. Sveta Smirnova, Alexander Rubin April, 16, 2015

ITS. MySQL for Database Administrators (40 Hours) (Exam code 1z0-883) (OCP My SQL DBA)

Load Testing Tools. for Troubleshooting MySQL Concurrency Issues. May, 23, 2018 Sveta Smirnova

How to get MySQL to fail

Troubleshooting Slow Queries. Sveta Smirnova Principal Support Engineer April, 28, 2016

MySQL for Database Administrators Ed 3.1

Troubleshooting Locking Issues. Sveta Smirnova Principal Technical Services Engineer May, 12, 2016

1Z Oracle. MySQL 5 Database Administrator Certified Professional Part I

MySQL Storage Engines Which Do You Use? April, 25, 2017 Sveta Smirnova

MySQL Database Administrator Training NIIT, Gurgaon India 31 August-10 September 2015

Troubleshooting Best Practices

Oracle 1Z MySQL 5.6 Database Administrator. Download Full Version :

MySQL 5.0 Certification Study Guide

MySQL for Developers. Duration: 5 Days

MySQL for Developers. Duration: 5 Days

Manual Trigger Sql Server 2008 Examples Insert Update

MySQL Architecture and Components Guide

Load Data Fast! BILL KARWIN PERCONA LIVE OPEN SOURCE DATABASE CONFERENCE 2017

Manual Trigger Sql Server 2008 Update Inserted Rows

Tips from the Trenches Preventing downtime for the over extended DBA. Andrew Moore Senior Remote DBA Percona Managed Services

Mysql Information Schema Update Time Null >>>CLICK HERE<<< doctrine:schema:update --dump-sql ALTER TABLE categorie

XA Transactions in MySQL

What's New in MySQL 5.7?

CO MySQL for Database Administrators

MariaDB 10.3 vs MySQL 8.0. Tyler Duzan, Product Manager Percona

MySQL Utilities, part 1. Sheeri Cabral. Senior DB Admin/Architect,

Drop Table If Exists Sql Command Not Properly Ended

MySQL for Developers Ed 3

Type Java.sql.sqlexception Error Code 0 Sql State S1000

<Insert Picture Here> Boosting performance with MySQL partitions

Course Outline. MySQL Database Administration & Design. Course Description: Pre-requisites: Course Content:

Course Details Duration: 3 days Starting time: 9.00 am Finishing time: 4.30 pm Lunch and refreshments are provided.

MySQL for Database Administrators Ed 4

Diagnosing Failures in MySQL Replication

'information_schema' When Using Lock Tables

Mysql Insert Manual Datetime Format Java >>>CLICK HERE<<<

mysql Sun Certified MySQL 5.0 Database(R) Administrator Part 1

Riding the Binlog: an in Deep Dissection of the Replication Stream. Jean-François Gagné jeanfrancois DOT gagne AT booking.com

MySQL 5.0 Reference Manual :: B Errors, Error Codes, and Common Problems :: B.3 Server Error Codes and

Migrating To MySQL The Live Database Upgrade Guide

MySQL 5.7 For Operational DBAs an Introduction. Peter Zaitsev, CEO, Percona February 16, 2016 Percona Technical Webinars

SQL Data Definition Language: Create and Change the Database Ray Lockwood

MySQL for Developers Ed 3

MySQL 5.6: Advantages in a Nutshell. Peter Zaitsev, CEO, Percona Percona Technical Webinars March 6, 2013

Using MySQL on the Winthrop Linux Systems

Common MySQL Scalability Mistakes AUTHOR

Replication features of 2011

MySQL Replication Tips and Tricks

What s New in MariaDB Server Max Mether VP Server

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

#MySQL #oow16. MySQL Server 8.0. Geir Høydalsvik

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

1Z MySQL 5 Database Administrator Certified Professional Exam, Part II Exam.

Mysql Cluster Global Schema Lock

Practical Performance Tuning using Digested SQL Logs. Bob Burgess Salesforce Marketing Cloud

MySQL Performance Schema in Action. April, 23, 2018 Sveta Smirnova, Alexander Rubin

Scale out Read Only Workload by sharing data files of InnoDB. Zhai weixiang Alibaba Cloud

Model Question Paper. Credits: 4 Marks: 140

MySQL for Developers with Developer Techniques Accelerated

How To Rock with MyRocks. Vadim Tkachenko CTO, Percona Webinar, Jan

Meet the Sergei Golubchik MariaDB Corporation

MySQL Security, Privileges & User Management Kenny Gryp Percona Live Washington DC /

<Insert Picture Here> New MySQL Enterprise Backup 4.1: Better Very Large Database Backup & Recovery and More!

IT Best Practices Audit TCS offers a wide range of IT Best Practices Audit content covering 15 subjects and over 2200 topics, including:

Enhancing MySQL Security. Vinicius Grippa Percona

Oracle 1Z0-053 Exam Questions & Answers

Delegates must have a working knowledge of MariaDB or MySQL Database Administration.

Why Choose Percona Server For MySQL? Tyler Duzan

Mysql Tutorial Create Database User Grant All Specification

MySQL Multi-Source Replication

Introduction to Troubleshooting Performance What Affects Query Execution? Sveta Smirnova Principal Support Engineer April, 7, 2016

What s New in MySQL 5.7 Geir Høydalsvik, Sr. Director, MySQL Engineering. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Upgrading MySQL Best Practices. Apr 11-14, 2011 MySQL Conference and Expo Santa Clara,CA by Peter Zaitsev, Percona Inc

Performance Schema for MySQL Troubleshooting. April, 25, 2017 Sveta Smirnova

How to Use JSON in MySQL Wrong

Using the VMware vcenter Orchestrator Client. vrealize Orchestrator 5.5.1

Preventing and Resolving MySQL Downtime. Jervin Real, Michael Coburn Percona

MyRocks in MariaDB. Sergei Petrunia MariaDB Tampere Meetup June 2018

Could Not Fetch Schema Routine Status Mysql

Manual Trigger Sql Server Example Update Column Value

MySQL usage of web applications from 1 user to 100 million. Peter Boros RAMP conference 2013

Chapter 8: Working With Databases & Tables

Emergency Bug Fixes (9.7.0)... 1 Fixed Limitations (9.7.0)... 2 Known Limitations (9.7.0)... 3 Informatica Global Customer Support...

Upgrading to MySQL 8.0+: a More Automated Upgrade Experience. Dmitry Lenev, Software Developer Oracle/MySQL, November 2018

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Manual Trigger Sql Server 2008 Insert Multiple Rows At Once

Switching to Innodb from MyISAM. Matt Yonkovit Percona

Migrating to Aurora MySQL and Monitoring with PMM. Percona Technical Webinars August 1, 2018

DATABASE SYSTEMS. Database programming in a web environment. Database System Course, 2016

Manual Trigger Sql Server 2008 Examples Update

MySQL 8.0: Atomic DDLs Implementation and Impact

itexamdump 최고이자최신인 IT 인증시험덤프 일년무료업데이트서비스제공

Optimizing BOINC project databases

Performance Schema. for MySQL Troubleshooting. March, 1, 2018 Sveta Smirnova

Getting started with MySQL Proxy

Sql Server Syllabus. Overview

Transcription:

Introduction to troubleshooting Basic techniques Sveta Smirnova Principal Support Engineer March, 10, 2016

Table of Contents Introduction How to find problematic query Solving issues Syntax errors Logic errors Hidden updates Lost connection Next webinars 2 www.percona.com

Introduction 3 www.percona.com

What is basic troubleshooting issue? You run a query Receive results which you don t expect Wrong dataset No answer from server Anything else These results are consistent Repeatable each time when you run the same query 4 www.percona.com

Typical workflow with the basic issue Find the query Identify class of the problem Fix Syntax error Logical error Data, inserted earlier No answer from the server 5 www.percona.com

MySQL architecture Connectors: C, JDBC, ODBC, Python,... Connection Pool: Authentication, Caches SQL interface Parser Optimizer Caches and Buffers: Global Engine-specific Storage engines: InnoDB, TokuDB,... File system: Data, Index, logs, other files Base Installation layout Log files Connectors Clients, APIs Optimizer Cache and buffers Storage engines Management 6 www.percona.com

Typical installation layout datadir Schema directory Table and trigger files: *.frm, *.ibd, *.MYD, *.par, etc. Schema... InnoDB shared tablespace Log files InnoDB redo log files Binary, relay log files Error log Slow query log General query log Configurable You can setup custom path for each component Including custom paths for tables 7 www.percona.com

Plugins Storage engines Authentication Audit Query rewrite More 8 www.percona.com

Storage engines Own data Own index format Own locking model Own diagnostic Own log files CHECK TABLE 9 www.percona.com

How to find problematic query 10 www.percona.com

Where is the query? Log files of your application General query log performance schema.events statements * tables Scriptable Proxies Audit Plugin User complains 11 www.percona.com

General Query Log mysql> set global log_output= table, global general_log=1; Query OK, 0 rows affected (0,00 sec) mysql> select * from mysql.general_log where argument like %Gender% -> and argument not like %general_log% \G ****************** 1. row ****************** event_time: 2016-02-25 03:35:39.903867 user_host: root[root] @ localhost[127.0.0.1] thread_id: 1 server_id: 1 command_type: Query argument: select * from employees where first_name = Gender 1 row in set (0.00 sec) 12 www.percona.com

performance schema.events statements * mysql> select sql_text from performance_schema.events_statements_history_long -> where sql_text like %gender% and current_schema= employees ; +-----------------------------------------------------------------+ sql_text +-----------------------------------------------------------------+ select * from employees where first_name = Gender select * from performance_schema.events_statements_history_long where sql_text like %gender% and current_schema= employees +-----------------------------------------------------------------+ 2 rows in set (0.00 sec) 13 www.percona.com

MySQL Proxy: all queries, finished with error function read_query( packet ) proxy.queries:append(1, packet ) return proxy.proxy_send_query end function read_query_result(inj) if inj.resultset.query_status == proxy.mysqld_packet_err then print(os.date("%d%m%y %H:%M:%S").. "\t".. "Query \"".. inj.query:sub(2).. "\" finished with error") end end 14 www.percona.com

Audit Log mysql> INSTALL PLUGIN audit_log SONAME audit_log.so ; Query OK, 0 rows affected (0.09 sec) mysql> \! cat /home/sveta/build/ps-5.6/mysql-test/var/mysqld.1/data/audit.log <AUDIT_RECORD NAME="Query" RECORD="3_2016-02-26T11:03:39" TIMESTAMP="2016-02-26T11:03:57 UTC" COMMAND_CLASS="select" CONNECTION_ID="1" STATUS="0" - Check this field for non-0 status! SQLTEXT="select * from mysql.user where user like %sveta% " USER="root[root] @ localhost [127.0.0.1]" HOST="localhost" OS_USER="" IP="127.0.0.1" /> 15 www.percona.com

Solving issues 16 www.percona.com

Query found: what to do next? Check kind of the error Syntax Can happen even to experienced users if complicated query created by an application Logic: stored data is correct SELECT returns wrong result DML updates wrong set of rows Hidden update: wrong data was already in the DB First noted after SELECT returned not expected result Source of the problem was an update which happened few steps ago Connection lost Wrong option usage Server crash Check what affects the query - Future webinars Fix! 17 www.percona.com

Query found: what to do next? Check kind of the error Check what affects the query - Future webinars Fix! Storage engine Configuration options Privileges Replication 17 www.percona.com

Syntax errors 18 www.percona.com

Syntax error select * fro t1 where f1 in (1,2,1); select max (f1) from t1; select * from t1 where "f1"=1; return " ". str_pad(md5(rand()), rand(1, $column[ character_maximum_length ]), md5(rand()), STR_PAD_BOTH). " "; 19 www.percona.com

Syntax error select * fro t1 where f1 in (1,2,1); select max (f1) from t1; Correct syntax: max(f1) no space Works with SQL Mode IGNORE SPACE only select * from t1 where "f1"=1; return " ". str_pad(md5(rand()), rand(1, $column[ character_maximum_length ]), md5(rand()), STR_PAD_BOTH). " "; 19 www.percona.com

Syntax error select * fro t1 where f1 in (1,2,1); select max (f1) from t1; select * from t1 where "f1"=1; Works with SQL Mode ANSI QUOTES only return " ". str_pad(md5(rand()), rand(1, $column[ character_maximum_length ]), md5(rand()), STR_PAD_BOTH). " "; 19 www.percona.com

Syntax error select * fro t1 where f1 in (1,2,1); select max (f1) from t1; select * from t1 where "f1"=1; return " ". str_pad(md5(rand()), rand(1, $column[ character_maximum_length ]), md5(rand()), STR_PAD_BOTH). " "; In the application 19 www.percona.com

Error message: always check! mysql> select * fro t1 where f1 in (1,2,1); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near fro t1 where f1 in (1,2,1) at line 1 mysql> select max (f1) from t1; ERROR 1630 (42000): FUNCTION test.max does not exist. Check the Function Name Parsing and Resolution section in the Reference Manual 20 www.percona.com

Warnings are important mysql> select * from t1 where "f1"=1; Empty set, 1 warning (0.05 sec) mysql> show warnings; +---------+------+--------------------------------------+ Level Code Message +---------+------+--------------------------------------+ Warning 1292 Truncated incorrect DOUBLE value: f1 +---------+------+--------------------------------------+ 1 row in set (0.00 sec) 21 www.percona.com

Errors information in the application Error information C API, Connector/C, PHP mysql errno mysql error Warnings C API, Connector/C, PHP mysql info mysql sqlstate mysql warning count 22 www.percona.com

Errors information in the application Error information JDBC, Connector/C++ SQLException Warnings JDBC, Connector/C++ SQLWarning 22 www.percona.com

Errors information in the application Error information ODBC Warnings ODBC SQLGetDiagField SQLGetDiagRec SQLGetDiagField SQLGetDiagRec 22 www.percona.com

Errors information in the application Error information Connector/Python errors.*error Warnings Connector/Python raise on warnings option errors.warning is not used! 22 www.percona.com

Perror: what does the error mean? sveta@thinkie> perror 1292 MySQL error code 1292 (ER_TRUNCATED_WRONG_VALUE): Truncated incorrect %-.32s value: %-.128s sveta@thinkie> perror 2 OS error code 2: No such file or directory - SQL error - OS error sveta@thinkie> perror 150 - Engine error MySQL error code 150: Foreign key constraint is incorrectly formed 23 www.percona.com

Error handling in stored routines GET DIAGNOSTICS GET DIAGNOSTICS rows = ROW COUNT, conditions = NUMBER; GET DIAGNOSTICS CONDITION 1 code = RETURNED SQLSTATE, msg = MESSAGE TEXT; SIGNAL/RESIGNAL Can be used for custom errors 24 www.percona.com

Logic errors 25 www.percona.com

Logic errors You expect query to work correctly But it does not This can be caused by Error in how you interpret the query should work MySQL bug How to start fixing such a query? Simplyfy it Consider each of parts which complicate the query Find out what it does Fix Hardest to teach Requires practice 26 www.percona.com

Example 1: movies The issue mysql> select title from movies where title=8; +----------------+ title +----------------+ 8 8 1/2 8 Simple Rules 8 Seconds +----------------+ 4 rows in set, 3 warnings (0.00 sec) 27 www.percona.com

Example 1: movies The issue Investigation mysql> show warnings; +---------+------+---------------------------------------------------+ Level Code Message Warning 1292 Truncated incorrect DOUBLE value: 8 Warning 1292 Truncated incorrect DOUBLE value: 8 Simple Rules Warning 1292 Truncated incorrect DOUBLE value: 8 Seconds +---------+------+---------------------------------------------------+ 3 rows in set (0.00 sec) 27 www.percona.com

The issue Investigation Test Example 1: movies mysql> select 8 = 8 Simple Rules, 8 = 8 Simple Rules ; +----------------------+------------------------+ 8 = 8 Simple Rules 8 = 8 Simple Rules +----------------------+------------------------+ 1 0 +----------------------+------------------------+ 1 row in set, 1 warning (0.00 sec) 27 www.percona.com

The issue Investigation Test Fix Example 1: movies mysql> select title from movies where title= 8 ; +-------+ title +-------+ 8 +-------+ 1 row in set (0.00 sec) 27 www.percona.com

Example 2: too many leaders The issue mysql> select count(emp_no) from employees where hire_date in -> (select hire_date from titles where title= Technique Leader ) -> union select count(*) from employees; +---------------+ count(emp_no) +---------------+ 300024 300024 +---------------+ 1 row in set (3 min 7.20 sec) 28 www.percona.com

Example 2: too many leaders The issue More stranges mysql> select count(emp_no) from employees where hire_date in -> (select hire_date from titles where title= Senior engineer ); +---------------+ count(emp_no) +---------------+ 300024 +---------------+ 1 row in set (17 min 32.49 sec) 28 www.percona.com

Example 2: too many leaders The issue More stranges Investigation mysql> explain extended select count(emp_no) from employees -> where hire_date in -> (select hire_date from titles where title= Technique Leader )\G... mysql> show warnings\g ************************ 1. row ************************ Level: Note Code: 1276 Message: Field or reference employees.employees.hire_date of SELECT #2 was resolved in SELECT #1... 28 www.percona.com

Example 2: too many leaders The issue More stranges Investigation Why so? mysql> desc titles; +-----------+-------------+------+-----+-------+-------+ Field Type Null Key Default Extra +-----------+-------------+------+-----+-------+-------+ emp_no int(11) NO PRI NULL title varchar(50) NO PRI NULL from_date date NO PRI NULL to_date date YES NULL +-----------+-------------+------+-----+-------+-------+ 28 4 rows in set (0.11 sec) www.percona.com

Preparation Example 3: MySQL bug mysql> alter table titles add index(title, emp_no); Query OK, 0 rows affected (8.39 sec) Records: 0 Duplicates: 0 Warnings: 0 29 www.percona.com

Example 3: MySQL bug Preparation The issue mysql> select max(emp_no), title from titles -> where title = Technique Leader -> or emp_no = 10005 -> group by title; +-------------+------------------+ max(emp_no) title +-------------+------------------+ 499942 Technique Leader +-------------+------------------+ 1 row in set (0.00 sec) 29 www.percona.com

Example 3: MySQL bug Preparation The issue But! mysql> select title from titles where emp_no = 10005; +--------------+ title +--------------+ Senior Staff Staff +--------------+ 2 rows in set (0.00 sec) 29 www.percona.com

Example 3: MySQL bug Preparation The issue Investigation mysql> explain select max(emp_no), title from titles where -> title = Technique Leader or emp_no = 10005 group by title\g *************************** 1. row ***************************... possible_keys: PRIMARY,emp_no,title key: title... Extra: Using where; Using index for group-by 1 row in set, 1 warning (0.00 sec) 29 www.percona.com

Example 3: MySQL bug Preparation The issue Investigation Test and Fix mysql> select max(emp_no), title from titles ignore index(title) where -> title = Technique Leader or emp_no = 10005 group by title; +-------------+------------------+ max(emp_no) title +-------------+------------------+ 10005 Senior Staff 10005 Staff 499942 Technique Leader 29 +-------------+------------------+ 3 rows in set (0.54 sec) www.percona.com

Example 3: MySQL bug Preparation The issue Investigation Test and Fix Based on https://bugs.mysql.com/bug.php?id=70359 29 www.percona.com

Hidden updates 30 www.percona.com

What do I call hidden update? Query behaves correctly, but returns wrong data Reason can be Wrong update, happened earlier No change when update expected How to find what really happened? Logs of your application Binary log - May not have variables affecting resut! General query log, p s.events statements * tables Scriptable Proxies Looks similar to wrong syntax issue? We need to watch change time now 31 www.percona.com

Hidden update exmaple The issue mysql> select count(*) from titles where title = Senior Engineer ; +----------+ count(*) +----------+ 0 +----------+ 1 row in set (0.00 sec) 32 www.percona.com

Hidden update exmaple The issue Investigation $mysqlbinlog -v master-bin.000001 # at 308 #160305 23:25:16 server id 1 end_log_pos 467 CRC32 0xeef31919 Query thread_id=3 exec_time=69 error_code=0 use employees /*!*/; SET TIMESTAMP=1457213116/*!*/; update titles set title = Junior Engineer where title = Senior Engineer /*!*/; # at 467... 32 www.percona.com

The issue Investigation Possible resolutions Hidden update exmaple In our case we can simply run update titles set title = Senior Engineer where title = Junior Engineer ; In more general case Restore table from backup Apply all binary logs, created after backup was made 32 www.percona.com

Lost connection 33 www.percona.com

Two main reasons Server crash: new connection cannot be established Check error log file Will be discussed in future webinar You can reconnect Network issues and timeouts Effect of max allowed packet You could see ERROR 1064 (42000) at line XXX: You have an error in your SQL syntax; instead of proper ERROR 1153 (08S01) at line XXX: Got a packet bigger than max allowed packet bytes Fixed in latest versions 34 www.percona.com

connect timeout Timeout symptoms Controls initial communication Check status variable Aborted connects 35 www.percona.com

connect timeout interactive timeout wait timeout Timeout symptoms How much time to wait activity from the client before aborting connection How much time can a thread be in Sleep state Check status variable Aborted clients 35 www.percona.com

connect timeout interactive timeout wait timeout net read timeout net write timeout Timeout symptoms How long to wait communication from a client which reads/writes result 35 www.percona.com

Timeout issues: how to fix Most obvious and dangerous way: increase timeout Can just hide the issue, but not fix it Better way Temporarily increase timeout Check if it solves the issue or make it happen more seldom Find out the reason why the issue happened in the first time Check and fix network 36 www.percona.com

Next webinars 37 www.percona.com

Performance Introduction to troubleshooting performance end of March Slow queries everything about EXPLAIN, query execution, etc. Locking issues Storage engines Options Hardware 38 www.percona.com

Production Privileges Replication Crashes 39 www.percona.com

Effective testing Tools Workflow Advanced testing techniques Troubleshooting and monitoring best practices Last webinar, end of the year 40 www.percona.com

Summary 41 www.percona.com

Summary Answers from the server are important Always check error messages and warnings Be ready to use log files 42 www.percona.com

More Informaiton MySQL Server Logs Percona Audit Plugin Writing Audit Plugins MySQL Proxy 43 www.percona.com

Place for your questions??? 44 www.percona.com

Thank you! http://www.slideshare.net/svetasmirnova https://twitter.com/svetsmirnova 45 www.percona.com