SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
MySQL : maintaining
  (too) big tables
    Frédéric Descamps
th
11 April 2010
Frédéric Descamps

●   lefred on IRC and Twitter
●   Senior Linux and Open Source Consultant
    @inuits.be
●   Certified MySQL DBA since 2007
●   First GNU/Linux distro (as far as I remember):
    Slackware 3.0 (kernel 1.2.13)
●   Blog: http://www.lefred.be
How come we need to
maintain tables ?
●   A bit of history first:


     once upon a time, there
    was a developer who found
    a great idea
Then he decided to create a proof of concept
and he coded, coded, coded a lot...
During the period he
unfortunately didn't discuss
with the DBA's and the OPS




                       But he discussed with
                      many other people like
                      marketing manager, sales
                      manager, regional manager,
                      product manager and all
                      were very happy and asked
                      to code even more !
Then he coded, coded,
coded a lot...
And the result is
Why ?
●   Impossible to stop de database, it's too
    important !
●   There is too much data, tables are huge !!
    •   Tables > 400GB with 500M rows
    •   Primary keys are varchar(32)
●   Impossible to optimize, add an index to a table
    (>4h needed to add an index)
●   How do we alter the schema ?
●   How do we migrate to another version of
    MySQL ?
Analyze and optimize
How big ?
# ls ­lh dayview.ibd 
­rw­rw­­­­ 1 mysql mysql 29G Feb  3 22:20 dayview.ibd
dba's feeling ?
Two very important points to never forget as
    developer :
●   Don't underestimate the complexity of production
    environments
Don't !
●   Never say: “but on my
    laptop the query is
    very fast”
What now ?
●   The plan is to create a new server more
    manageable with minimal downtime of the
    production
     •   Reduce size if possible
     •   Make queries faster
●   The server will be a replica of the current
    production server with some different settings
The battle !
●   Restore last backup

  Ze Plan                       ●   Prepare the new
                                    database
                                ●   Dump & restore
                                    data using maatkit

databasezilla
                databasezilla   ●   Restart the
                   restore          replication
                                ●   Replace the
                                    production db by
                                    the new one (only
                                    downtime here)
Database size
●   Deleting historical data sometimes doesn't help
    really to save some space... ibdata won't shrink
●   Data could be fragmented
     •   To avoid the use of that huge ibdata we add
         this to the configuration of the new server:
innodb_file_per_table
MySQL version
●   Maybe it is time to also change the MySQL
    version to a newer one and even to change
    engine !
●   I advice you to try and use XtraDB from
    percona. This includes corrections and
    interresting patches (like those from Google)
    •   The list is available here :
        http://www.percona.com/docs/wiki/percona-
        xtradb:patch:start
Anything else to
change ?
●   Maybe other settings aren't optimal for your
    production environment. To have an overview
    of them, I'd recommand the use of these two
    tools :
    •   MySQLTuner
    •   tuning-primer
Example 1
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.37-community-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in InnoDB tables: 899G (Tables: 149)
[!!] Total fragmented tables: 82

-------- Performance Metrics -------------------------------------------------
[--] Up for: 23h 46m 1s (112M q [1K qps], 70K conn, TX: 44B, RX: 22B)
[--] Reads / Writes: 51% / 49%
[--] Total buffers: 12.4G global + 152.2M per thread (100 max threads)
[!!] Maximum possible memory usage: 27.3G (173% of installed RAM)
[OK] Slow queries: 0% (963/112M)
[OK] Highest usage of available connections: 52% (52/100)
[OK] Key buffer size / total MyISAM indexes: 256.0M/93.0K
[OK] Key buffer hit rate: 100.0% (215K cached / 3 reads)
[OK] Query cache efficiency: 43.3% (23M cached / 54M selects)
[!!] Query cache prunes per day: 3049150
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 754K sorts)
[!!] Joins performed without indexes: 19547
[OK] Temporary tables created on disk: 0% (1K on disk / 545K total)
[OK] Thread cache hit rate: 99% (53 created / 70K connections)
[OK] Table cache hit rate: 99% (802 open / 809 opened)
[OK] Open file limit used: 1% (59/4K)
[OK] Table locks acquired immediately: 100% (72M immediate / 72M locks)
[!!] InnoDB data size / buffer pool: 899.3G/12.0G
Example 2
MySQL Version 5.1.37-community-log x86_64

Uptime = 1 days 0 hrs 2 min 31 sec
Avg. qps = 1324
Total Questions = 114605776
Threads Connected = 47

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 10.000000 sec.
You have 972 out of 114605948 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is enabled
The expire_logs_days is not set.
The mysqld will retain the entire binary log until RESET MASTER or PURGE MASTER LOGS commands are run
manually
Setting expire_logs_days will allow you to remove old binary logs automatically
See http://dev.mysql.com/doc/refman/5.1/en/purge-master-logs.html
Binlog sync is not enabled, you could loose binlog records during a server crash

WORKER THREADS
Current thread_cache_size = 8
Current threads_cached = 4
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine
Example 2 (b)
MAX CONNECTIONS
Current max_connections = 100
Current threads_connected = 47
Historic max_used_connections = 52
The number of used connections is 52% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 0 bytes
Current InnoDB data space = 0 bytes
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 12.00 G
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 20.06 G
Configured Max Per-thread Buffers : 14.86 G
Configured Max Global Buffers : 12.33 G
Configured Max Memory Limit : 27.20 G
Physical Memory : 15.67 G

nMax memory limit exceeds 90% of physical memory
Example 2 (c)
KEY BUFFER
Current MyISAM index space = 8 K
Current key_buffer_size = 256 M
Key cache miss rate is 1 : 74223
Key buffer free ratio = 81 %
Your key_buffer_size seems to be too high.
Perhaps you can use these resources elsewhere

QUERY CACHE
Query cache is enabled
Current query_cache_size = 64 M
Current query_cache_used = 32 M
Current query_cache_limit = 2 M
Current Query cache Memory fill ratio = 51.30 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 64 M
Current read_rnd_buffer_size = 16 M
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 64.00 M
You have had 20057 queries where a join could not use an index properly
join_buffer_size >= 4 M
This is not advised
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
Example 2 (d)
OPEN FILES LIMIT
Current open_files_limit = 4096 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 1024 tables
Current table_definition_cache = 256 tables
You have a total of 0 tables
You have 843 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 64 M
Current tmp_table_size = 256 M
Of 554783 temp tables, 0% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine

TABLE SCANS
Current read_buffer_size = 8 M
Current table scan ratio = 162 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 0 : 114608692
Your table locking seems to be fine
Filesystem
●   xfs is much faster to store the binlogs and to
    delete them
Start the replication
     ●   Change to the right binlog and the right
         position before the backup

mysql> show slave statusG
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: xxxxx
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 10
              Master_Log_File: xxxx.000052
          Read_Master_Log_Pos: 426644104
               Relay_Log_File: mysqld1­relay­bin.000173
                Relay_Log_Pos: 426644245
        Relay_Master_Log_File: xxxx.000052
                                                             mysql> CHANGE MASTER TO MASTER_HOST='xxxxx', 
             Slave_IO_Running: Yes                           MASTER_USER='replica', MASTER_PASSWORD='xxxx', 
            Slave_SQL_Running: Yes                           MASTER_PORT=3306, MASTER_LOG_FILE='xxx.000052', 
              Replicate_Do_DB:                               MASTER_LOG_POS=426644104, 
          Replicate_Ignore_DB:                               MASTER_CONNECT_RETRY=10;
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 426644104
              Relay_Log_Space: 426644441
Monitor your production
●   While you will do any work on the database, I
    recommand you to use innotop, you will see
    directly if something is going wrong
●   Use cacti to see obviously strange behavior
Restore the backup
●   I won't explain you how to restore a backup,
    but on huge tables usually you don't have a
    dump of the data but only the files and the
    binlogs
●   So restore the last production backup you have
    on a new server (most of the time we use flash
    copies)
Dump & restore the data
●   Use maatkit parallel to dump and restore the
    data
●   While this operation, be careful to not delete
    the binlogs on te master that you will need to
    recover !
Remove historical data -
(scale back)
●   Now that you have a more performant
    database (as the indexes are rewritten) it's
    time to archive the old data
●   As the tables are still huges I don't recommand
    to do a massive delete of many rows matching
    a query
●   Use (again) maatkit to archive
ptxArchiver
●   I wrote a small script to use mk-archiver that
    follows a defined strucure to archive all the
    records linked together (foreignkeys)
$ ptxArchiver.pl ­t message ­w "timestamp < 
unix_timestamp(date_sub(now(),interval 17 
MONTH))*1000"

<tables>
   <message>
      <message>
        field=id
        p_field=origin
      </message>
   </message>
</tables>
Analyse your system
Keep the result of these
commands regularly:

iostat ­dx 5 5
vmstat 1 10
mpstat 1 10
top ­b ­n 1
cat /proc/meminfo
Analyse your MySQL
Analyse your MySQL
Check regurarly the output of these statements:
●   SHOW ENGINE INNODB STATUS;
    •   Returns information about semaphores, deadlocks, foreign
        keys, transactions, buffer pool, I/O, ...
    •   This info can be automaticaly stored in the mysql log file every
        15secs by creating the following table in mysql schema:

CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB;

●   SHOW GLOBAL STATUS;
●   SHOW TABLE STATUS;
Analyse your MySQL
●   Use mk-query-digest on slow query log, binlogs
    or processlist
    •   mk-query-digest --processlist 127.0.0.1,
●   Don't forget innotop
●   mysqlresources
●   mysqlsla
●   mysqlidxchk
●   mysqlreport
AnalyZe your tables
●   ANALYZE TABLE analyzes and stores the key
    distribution for a table.
●   For InnoDB the table is locked with a write lock.
●   This statement is much faster then OPTIMIZE
    TABLE.
●   For InnoDB the statistics are updated everytime
    that 1/16 of the data has been changed. For
    huge tables it is then needed to update those
    statistics manually more often.
innotop
Partitioning
●   MySQL since 5.1 is able to manage horizontal
    partitioning (records level). Since 5.5 you can
    partition a table using multiple columns in the
    range.
●   Of course to partition the huge tables a
    relevant column should be present in it (which
    is not the case when the records are refering to
    varchar(32) :'-(
Links
●   MySQLTuner - http://blog.mysqltuner.com/
●   tuning-primer - http://www.day32.com/MySQL/
●   ptxArchiver - http://www.lefred.be/?q=node/105
●   maatkit - http://www.maatkit.org
●   mysqlreport, mysqlsla, mysqlidxchx - http://hackmysql.com
●   mysqlresources - http://datacharmer.org/downloads/mysqlresources.zip
●   innotop -
    http://www.xaprb.com/blog/2006/07/02/innotop-mysql-innodb-monitor/
Thank you :-)

Más contenido relacionado

La actualidad más candente

Postgres in Amazon RDS
Postgres in Amazon RDSPostgres in Amazon RDS
Postgres in Amazon RDSDenish Patel
 
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesPostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesSperasoft
 
MySQL Live Migration - Common Scenarios
MySQL Live Migration - Common ScenariosMySQL Live Migration - Common Scenarios
MySQL Live Migration - Common ScenariosMydbops
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PGConf APAC
 
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...DataStax
 
Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...
Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...
Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...DataStax
 
Elephants in the Cloud
Elephants in the CloudElephants in the Cloud
Elephants in the CloudMike Fowler
 
Inside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTPInside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTPBob Ward
 
Everyday I’m scaling... Cassandra
Everyday I’m scaling... CassandraEveryday I’m scaling... Cassandra
Everyday I’m scaling... CassandraInstaclustr
 
SQL Server In-Memory OLTP: What Every SQL Professional Should Know
SQL Server In-Memory OLTP: What Every SQL Professional Should KnowSQL Server In-Memory OLTP: What Every SQL Professional Should Know
SQL Server In-Memory OLTP: What Every SQL Professional Should KnowBob Ward
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Denish Patel
 
Load testing Cassandra applications
Load testing Cassandra applicationsLoad testing Cassandra applications
Load testing Cassandra applicationsBen Slater
 
Overview of Postgres Utility Processes
Overview of Postgres Utility ProcessesOverview of Postgres Utility Processes
Overview of Postgres Utility ProcessesEDB
 
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and SpeedmentSpeed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and SpeedmentHazelcast
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPGConf APAC
 
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...Ashnikbiz
 
What is new in MariaDB 10.6?
What is new in MariaDB 10.6?What is new in MariaDB 10.6?
What is new in MariaDB 10.6?Mydbops
 
Fortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuFortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuMarco Tusa
 
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)Mydbops
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsMydbops
 

La actualidad más candente (20)

Postgres in Amazon RDS
Postgres in Amazon RDSPostgres in Amazon RDS
Postgres in Amazon RDS
 
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesPostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
 
MySQL Live Migration - Common Scenarios
MySQL Live Migration - Common ScenariosMySQL Live Migration - Common Scenarios
MySQL Live Migration - Common Scenarios
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
 
Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...
Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...
Running 400-node Cassandra + Spark Clusters in Azure (Anubhav Kale, Microsoft...
 
Elephants in the Cloud
Elephants in the CloudElephants in the Cloud
Elephants in the Cloud
 
Inside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTPInside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTP
 
Everyday I’m scaling... Cassandra
Everyday I’m scaling... CassandraEveryday I’m scaling... Cassandra
Everyday I’m scaling... Cassandra
 
SQL Server In-Memory OLTP: What Every SQL Professional Should Know
SQL Server In-Memory OLTP: What Every SQL Professional Should KnowSQL Server In-Memory OLTP: What Every SQL Professional Should Know
SQL Server In-Memory OLTP: What Every SQL Professional Should Know
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
 
Load testing Cassandra applications
Load testing Cassandra applicationsLoad testing Cassandra applications
Load testing Cassandra applications
 
Overview of Postgres Utility Processes
Overview of Postgres Utility ProcessesOverview of Postgres Utility Processes
Overview of Postgres Utility Processes
 
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and SpeedmentSpeed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability Improvements
 
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
FOSSASIA 2015 - 10 Features your developers are missing when stuck with Propr...
 
What is new in MariaDB 10.6?
What is new in MariaDB 10.6?What is new in MariaDB 10.6?
What is new in MariaDB 10.6?
 
Fortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuFortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleu
 
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)MySQL shell and It's utilities - Praveen GR (Mydbops Team)
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 

Destacado

Mysqlnd Query Cache
Mysqlnd Query CacheMysqlnd Query Cache
Mysqlnd Query CacheAnis Berejeb
 
Understanding MySql locking issues
Understanding MySql locking issuesUnderstanding MySql locking issues
Understanding MySql locking issuesOm Vikram Thapa
 
MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13Eli Aschkenasy
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance TuningMark Swarbrick
 

Destacado (6)

Mysqlnd Query Cache
Mysqlnd Query CacheMysqlnd Query Cache
Mysqlnd Query Cache
 
Pdt tics
Pdt ticsPdt tics
Pdt tics
 
Perf tuning2
Perf tuning2Perf tuning2
Perf tuning2
 
Understanding MySql locking issues
Understanding MySql locking issuesUnderstanding MySql locking issues
Understanding MySql locking issues
 
MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13MySQL Performance Optimization #JDNL13
MySQL Performance Optimization #JDNL13
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 

Similar a MySQL: Maintaining (too) big tables

The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesDave Stokes
 
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningSeveralnines
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsProper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsDave Stokes
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...Dave Stokes
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesRichard Douglas
 
Oracle Performance On Linux X86 systems
Oracle  Performance On Linux  X86 systems Oracle  Performance On Linux  X86 systems
Oracle Performance On Linux X86 systems Baruch Osoveskiy
 
Backing up Wikipedia Databases
Backing up Wikipedia DatabasesBacking up Wikipedia Databases
Backing up Wikipedia DatabasesJaime Crespo
 
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsLinuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsDave Stokes
 
Percona Live '18 Tutorial: The Accidental DBA
Percona Live '18 Tutorial: The Accidental DBAPercona Live '18 Tutorial: The Accidental DBA
Percona Live '18 Tutorial: The Accidental DBAJenni Snyder
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB plc
 
Buytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerBuytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerkuchinskaya
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedPGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedEqunix Business Solutions
 
Taking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout SessionTaking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout SessionSplunk
 
Intro to Azure SQL database
Intro to Azure SQL databaseIntro to Azure SQL database
Intro to Azure SQL databaseSteve Knutson
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAiougVizagChapter
 
Sql server 2005 memory internal
Sql server 2005 memory internalSql server 2005 memory internal
Sql server 2005 memory internalshuwutong
 
The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux AdminThe Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux AdminDave Stokes
 
MySQL Performance - Best practices
MySQL Performance - Best practices MySQL Performance - Best practices
MySQL Performance - Best practices Ted Wennmark
 

Similar a MySQL: Maintaining (too) big tables (20)

The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL Databases
 
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsProper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock Holmes
 
Oracle Performance On Linux X86 systems
Oracle  Performance On Linux  X86 systems Oracle  Performance On Linux  X86 systems
Oracle Performance On Linux X86 systems
 
Backing up Wikipedia Databases
Backing up Wikipedia DatabasesBacking up Wikipedia Databases
Backing up Wikipedia Databases
 
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsLinuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
 
Percona Live '18 Tutorial: The Accidental DBA
Percona Live '18 Tutorial: The Accidental DBAPercona Live '18 Tutorial: The Accidental DBA
Percona Live '18 Tutorial: The Accidental DBA
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
 
The Accidental DBA
The Accidental DBAThe Accidental DBA
The Accidental DBA
 
Buytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerBuytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemaker
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedPGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
 
Taking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout SessionTaking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout Session
 
Intro to Azure SQL database
Intro to Azure SQL databaseIntro to Azure SQL database
Intro to Azure SQL database
 
Running MySQL on Linux
Running MySQL on LinuxRunning MySQL on Linux
Running MySQL on Linux
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
Sql server 2005 memory internal
Sql server 2005 memory internalSql server 2005 memory internal
Sql server 2005 memory internal
 
The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux AdminThe Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
 
MySQL Performance - Best practices
MySQL Performance - Best practices MySQL Performance - Best practices
MySQL Performance - Best practices
 

Último

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 DevelopmentsTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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.pptxEarley Information Science
 
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...Enterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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 2024Rafal Los
 
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.pdfEnterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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 Processorsdebabhi2
 
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...Martijn de Jong
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
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 future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
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...
 

MySQL: Maintaining (too) big tables

  • 1. MySQL : maintaining (too) big tables Frédéric Descamps
  • 3. Frédéric Descamps ● lefred on IRC and Twitter ● Senior Linux and Open Source Consultant @inuits.be ● Certified MySQL DBA since 2007 ● First GNU/Linux distro (as far as I remember): Slackware 3.0 (kernel 1.2.13) ● Blog: http://www.lefred.be
  • 4. How come we need to maintain tables ? ● A bit of history first: once upon a time, there was a developer who found a great idea
  • 5. Then he decided to create a proof of concept and he coded, coded, coded a lot...
  • 6. During the period he unfortunately didn't discuss with the DBA's and the OPS But he discussed with many other people like marketing manager, sales manager, regional manager, product manager and all were very happy and asked to code even more !
  • 7. Then he coded, coded, coded a lot...
  • 9. Why ? ● Impossible to stop de database, it's too important ! ● There is too much data, tables are huge !! • Tables > 400GB with 500M rows • Primary keys are varchar(32) ● Impossible to optimize, add an index to a table (>4h needed to add an index) ● How do we alter the schema ? ● How do we migrate to another version of MySQL ?
  • 13. Two very important points to never forget as developer : ● Don't underestimate the complexity of production environments
  • 14. Don't ! ● Never say: “but on my laptop the query is very fast”
  • 15. What now ? ● The plan is to create a new server more manageable with minimal downtime of the production • Reduce size if possible • Make queries faster ● The server will be a replica of the current production server with some different settings
  • 17. Restore last backup Ze Plan ● Prepare the new database ● Dump & restore data using maatkit databasezilla databasezilla ● Restart the restore replication ● Replace the production db by the new one (only downtime here)
  • 18. Database size ● Deleting historical data sometimes doesn't help really to save some space... ibdata won't shrink ● Data could be fragmented • To avoid the use of that huge ibdata we add this to the configuration of the new server: innodb_file_per_table
  • 19. MySQL version ● Maybe it is time to also change the MySQL version to a newer one and even to change engine ! ● I advice you to try and use XtraDB from percona. This includes corrections and interresting patches (like those from Google) • The list is available here : http://www.percona.com/docs/wiki/percona- xtradb:patch:start
  • 20. Anything else to change ? ● Maybe other settings aren't optimal for your production environment. To have an overview of them, I'd recommand the use of these two tools : • MySQLTuner • tuning-primer
  • 21. Example 1 -------- General Statistics -------------------------------------------------- [--] Skipped version check for MySQLTuner script [OK] Currently running supported MySQL version 5.1.37-community-log [OK] Operating on 64-bit architecture -------- Storage Engine Statistics ------------------------------------------- [--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster [--] Data in InnoDB tables: 899G (Tables: 149) [!!] Total fragmented tables: 82 -------- Performance Metrics ------------------------------------------------- [--] Up for: 23h 46m 1s (112M q [1K qps], 70K conn, TX: 44B, RX: 22B) [--] Reads / Writes: 51% / 49% [--] Total buffers: 12.4G global + 152.2M per thread (100 max threads) [!!] Maximum possible memory usage: 27.3G (173% of installed RAM) [OK] Slow queries: 0% (963/112M) [OK] Highest usage of available connections: 52% (52/100) [OK] Key buffer size / total MyISAM indexes: 256.0M/93.0K [OK] Key buffer hit rate: 100.0% (215K cached / 3 reads) [OK] Query cache efficiency: 43.3% (23M cached / 54M selects) [!!] Query cache prunes per day: 3049150 [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 754K sorts) [!!] Joins performed without indexes: 19547 [OK] Temporary tables created on disk: 0% (1K on disk / 545K total) [OK] Thread cache hit rate: 99% (53 created / 70K connections) [OK] Table cache hit rate: 99% (802 open / 809 opened) [OK] Open file limit used: 1% (59/4K) [OK] Table locks acquired immediately: 100% (72M immediate / 72M locks) [!!] InnoDB data size / buffer pool: 899.3G/12.0G
  • 22. Example 2 MySQL Version 5.1.37-community-log x86_64 Uptime = 1 days 0 hrs 2 min 31 sec Avg. qps = 1324 Total Questions = 114605776 Threads Connected = 47 SLOW QUERIES The slow query log is enabled. Current long_query_time = 10.000000 sec. You have 972 out of 114605948 that take longer than 10.000000 sec. to complete Your long_query_time seems to be fine BINARY UPDATE LOG The binary update log is enabled The expire_logs_days is not set. The mysqld will retain the entire binary log until RESET MASTER or PURGE MASTER LOGS commands are run manually Setting expire_logs_days will allow you to remove old binary logs automatically See http://dev.mysql.com/doc/refman/5.1/en/purge-master-logs.html Binlog sync is not enabled, you could loose binlog records during a server crash WORKER THREADS Current thread_cache_size = 8 Current threads_cached = 4 Current threads_per_sec = 0 Historic threads_per_sec = 0 Your thread_cache_size is fine
  • 23. Example 2 (b) MAX CONNECTIONS Current max_connections = 100 Current threads_connected = 47 Historic max_used_connections = 52 The number of used connections is 52% of the configured maximum. Your max_connections variable seems to be fine. INNODB STATUS Current InnoDB index space = 0 bytes Current InnoDB data space = 0 bytes Current InnoDB buffer pool free = 0 % Current innodb_buffer_pool_size = 12.00 G Depending on how much space your innodb indexes take up it may be safe to increase this value to up to 2 / 3 of total system memory MEMORY USAGE Max Memory Ever Allocated : 20.06 G Configured Max Per-thread Buffers : 14.86 G Configured Max Global Buffers : 12.33 G Configured Max Memory Limit : 27.20 G Physical Memory : 15.67 G nMax memory limit exceeds 90% of physical memory
  • 24. Example 2 (c) KEY BUFFER Current MyISAM index space = 8 K Current key_buffer_size = 256 M Key cache miss rate is 1 : 74223 Key buffer free ratio = 81 % Your key_buffer_size seems to be too high. Perhaps you can use these resources elsewhere QUERY CACHE Query cache is enabled Current query_cache_size = 64 M Current query_cache_used = 32 M Current query_cache_limit = 2 M Current Query cache Memory fill ratio = 51.30 % Current query_cache_min_res_unit = 4 K MySQL won't cache query results that are larger than query_cache_limit in size SORT OPERATIONS Current sort_buffer_size = 64 M Current read_rnd_buffer_size = 16 M Sort buffer seems to be fine JOINS Current join_buffer_size = 64.00 M You have had 20057 queries where a join could not use an index properly join_buffer_size >= 4 M This is not advised You should enable "log-queries-not-using-indexes" Then look for non indexed joins in the slow query log.
  • 25. Example 2 (d) OPEN FILES LIMIT Current open_files_limit = 4096 files The open_files_limit should typically be set to at least 2x-3x that of table_cache if you have heavy MyISAM usage. Your open_files_limit value seems to be fine TABLE CACHE Current table_open_cache = 1024 tables Current table_definition_cache = 256 tables You have a total of 0 tables You have 843 open tables. The table_cache value seems to be fine TEMP TABLES Current max_heap_table_size = 64 M Current tmp_table_size = 256 M Of 554783 temp tables, 0% were created on disk Effective in-memory tmp_table_size is limited to max_heap_table_size. Created disk tmp tables ratio seems fine TABLE SCANS Current read_buffer_size = 8 M Current table scan ratio = 162 : 1 read_buffer_size seems to be fine TABLE LOCKING Current Lock Wait ratio = 0 : 114608692 Your table locking seems to be fine
  • 26. Filesystem ● xfs is much faster to store the binlogs and to delete them
  • 27. Start the replication ● Change to the right binlog and the right position before the backup mysql> show slave statusG *************************** 1. row ***************************                Slave_IO_State: Waiting for master to send event                   Master_Host: xxxxx                   Master_User: replica                   Master_Port: 3306                 Connect_Retry: 10               Master_Log_File: xxxx.000052           Read_Master_Log_Pos: 426644104                Relay_Log_File: mysqld1­relay­bin.000173                 Relay_Log_Pos: 426644245         Relay_Master_Log_File: xxxx.000052 mysql> CHANGE MASTER TO MASTER_HOST='xxxxx',               Slave_IO_Running: Yes MASTER_USER='replica', MASTER_PASSWORD='xxxx',              Slave_SQL_Running: Yes MASTER_PORT=3306, MASTER_LOG_FILE='xxx.000052',                Replicate_Do_DB:  MASTER_LOG_POS=426644104,            Replicate_Ignore_DB:  MASTER_CONNECT_RETRY=10;            Replicate_Do_Table:         Replicate_Ignore_Table:        Replicate_Wild_Do_Table:    Replicate_Wild_Ignore_Table:                     Last_Errno: 0                    Last_Error:                   Skip_Counter: 0           Exec_Master_Log_Pos: 426644104               Relay_Log_Space: 426644441
  • 28. Monitor your production ● While you will do any work on the database, I recommand you to use innotop, you will see directly if something is going wrong ● Use cacti to see obviously strange behavior
  • 29. Restore the backup ● I won't explain you how to restore a backup, but on huge tables usually you don't have a dump of the data but only the files and the binlogs ● So restore the last production backup you have on a new server (most of the time we use flash copies)
  • 30. Dump & restore the data ● Use maatkit parallel to dump and restore the data ● While this operation, be careful to not delete the binlogs on te master that you will need to recover !
  • 31. Remove historical data - (scale back) ● Now that you have a more performant database (as the indexes are rewritten) it's time to archive the old data ● As the tables are still huges I don't recommand to do a massive delete of many rows matching a query ● Use (again) maatkit to archive
  • 32. ptxArchiver ● I wrote a small script to use mk-archiver that follows a defined strucure to archive all the records linked together (foreignkeys) $ ptxArchiver.pl ­t message ­w "timestamp <  unix_timestamp(date_sub(now(),interval 17  MONTH))*1000" <tables>    <message>       <message>         field=id         p_field=origin       </message>    </message> </tables>
  • 34. Keep the result of these commands regularly: iostat ­dx 5 5 vmstat 1 10 mpstat 1 10 top ­b ­n 1 cat /proc/meminfo
  • 36. Analyse your MySQL Check regurarly the output of these statements: ● SHOW ENGINE INNODB STATUS; • Returns information about semaphores, deadlocks, foreign keys, transactions, buffer pool, I/O, ... • This info can be automaticaly stored in the mysql log file every 15secs by creating the following table in mysql schema: CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB; ● SHOW GLOBAL STATUS; ● SHOW TABLE STATUS;
  • 37. Analyse your MySQL ● Use mk-query-digest on slow query log, binlogs or processlist • mk-query-digest --processlist 127.0.0.1, ● Don't forget innotop ● mysqlresources ● mysqlsla ● mysqlidxchk ● mysqlreport
  • 38. AnalyZe your tables ● ANALYZE TABLE analyzes and stores the key distribution for a table. ● For InnoDB the table is locked with a write lock. ● This statement is much faster then OPTIMIZE TABLE. ● For InnoDB the statistics are updated everytime that 1/16 of the data has been changed. For huge tables it is then needed to update those statistics manually more often.
  • 40. Partitioning ● MySQL since 5.1 is able to manage horizontal partitioning (records level). Since 5.5 you can partition a table using multiple columns in the range. ● Of course to partition the huge tables a relevant column should be present in it (which is not the case when the records are refering to varchar(32) :'-(
  • 41.
  • 42. Links ● MySQLTuner - http://blog.mysqltuner.com/ ● tuning-primer - http://www.day32.com/MySQL/ ● ptxArchiver - http://www.lefred.be/?q=node/105 ● maatkit - http://www.maatkit.org ● mysqlreport, mysqlsla, mysqlidxchx - http://hackmysql.com ● mysqlresources - http://datacharmer.org/downloads/mysqlresources.zip ● innotop - http://www.xaprb.com/blog/2006/07/02/innotop-mysql-innodb-monitor/