SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
Recovery of lost or corrupted InnoDB tables MySQL User Conference 2010, Santa Clara [email_address] Percona Inc. http://MySQLPerformanceBlog.com
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],- - Three things are certain: Death, taxes and lost data. Guess which has occurred?
1. InnoDB format overview
How MySQL stores data in InnoDB ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 
How MySQL stores data in InnoDB ,[object Object],     TABLE: name test/site_folders, id 0 119, columns 9, indexes 1, appr.rows 1       COLUMNS: id: DATA_INT len 4 prec 0; name: type 12 len 765 prec 0; sites_count: DATA_INT len 4 prec 0;                            created_at: DATA_INT len 8 prec 0; updated_at: DATA_INT len 8 prec 0;                     DB_ROW_ID: DATA_SYS prtype 256 len 6 prec 0; DB_TRX_ID: DATA_SYS prtype 257 len 6 prec 0;                     DB_ROLL_PTR: DATA_SYS prtype 258 len 7 prec 0;            INDEX: name PRIMARY, id  0 254 , fields 1/7, type 3            root page 271, appr.key vals 1, leaf pages 1, size pages 1            FIELDS:  id DB_TRX_ID DB_ROLL_PTR name sites_count created_at updated_at  mysql> CREATE TABLE innodb_table_monitor(x int) engine=innodb Error log:
InnoDB page format Fil Trailer  Page Directory FREE SPACE USER RECORDS   INFINUM+SUPREMUM RECORDS PAGE_HEADER FIL HEADER
InnoDB page format Fil Header   the latest archived log file number at the time that  FIL_PAGE_FILE_FLUSH_LSN  was written (in the log)  4  FIL_PAGE_ARCH_LOG_NO   "the file has been flushed to disk at least up to this lsn" (log serial number), valid only on the first page of the file  8  FIL_PAGE_FILE_FLUSH_LSN   current defined types are:  FIL_PAGE_INDEX ,  FIL_PAGE_UNDO_LOG ,  FIL_PAGE_INODE ,  FIL_PAGE_IBUF_FREE_LIST   2  FIL_PAGE_TYPE   log serial number of page's latest log record  8  FIL_PAGE_LSN   offset of next page in key order  4  FIL_PAGE_NEXT   offset of previous page in key order  4  FIL_PAGE_PREV   ordinal page number from start of space  4  FIL_PAGE_OFFSET   4 ID of the space the page is in  4  FIL_PAGE_SPACE   Remarks   Size   Name   Data are stored in  FIL_PAGE_INODE  == 0x03
InnoDB page format Page  Header  "file segment header for the non-leaf pages in a B-tree" (this is irrelevant here)  10  PAGE_BTR_SEG_TOP   "file segment header for the leaf pages in a B-tree" (this is irrelevant here)  10  PAGE_BTR_SEG_LEAF   identifier of the index the page belongs to  8  PAGE_INDEX_ID   level within the index (0 for a leaf page)  2  PAGE_LEVEL   the highest ID of a transaction which might have changed a record on the page (only set for secondary indexes)  8  PAGE_MAX_TRX_ID   number of user records  2  PAGE_N_RECS   number of consecutive inserts in the same direction, e.g. "last 5 were all to the left"  2  PAGE_N_DIRECTION   either  PAGE_LEFT ,  PAGE_RIGHT , or  PAGE_NO_DIRECTION   2  PAGE_DIRECTION   record pointer to the last inserted record  2  PAGE_LAST_INSERT   "number of bytes in deleted records"  2  PAGE_GARBAGE   record pointer to first free record  2  PAGE_FREE   number of heap records; initial value = 2  2  PAGE_N_HEAP   record pointer to first record in heap  2  PAGE_HEAP_TOP   number of directory slots in the Page Directory part; initial value = 2  2  PAGE_N_DIR_SLOTS   Remarks   Size   Name   index_id Highest bit is row format(1 -COMPACT, 0 - REDUNDANT )
InnoDB page format (REDUNDANT) Extra bytes   pointer to next record in page  16 bits  next 16 bits   1 if each Field Start Offsets is 1 byte long (this item is also called the "short" flag)  1 bit  1byte_offs_flag  number of fields in this record, 1 to 1023  10 bits  n_fields  record's order number in heap of index page  13 bits  heap_no  number of records owned by this record  4 bits  n_owned  1 if record is predefined minimum record  1 bit  min_rec_flag  1 if record is deleted  1 bit  deleted_flag  _ORDINAR Y,  _NODE_PTR ,  _INFIMUM ,  _SUPREMUM 2  bit s   record_status Description   Size   Name
InnoDB page format (COMPACT) Extra bytes   a relative pointer to the next record in the page 16 next 16 bits   000=conventional, 001=node pointer (inside B-tree),  010=infimum, 011=supremum, 1xx=reserved 3 record type the order number of this record in the heap of the index page 1 3 heap_no  the number of records owned by this record (this term is explained in page0page.h)  4   n_owned  4 bits used to delete mark a record, and mark a predefined minimum record in alphabetical order 4   record_statu s deleted_fla g min_rec_flag  Description   Size , bits Name
How to check row format? ,[object Object],[object Object],[object Object]
Rows in an InnoDB page ,[object Object],[object Object],[object Object],[object Object],infimum next supremum 0 100 data... next 101 data... next 102 data... next 103 data... next
Records are saved in insert order ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Row format EXAMPLE: CREATE TABLE ` t1 ` ( ` ID ` int( 11 ) unsigned NOT NULL, ` NAME ` varchar(120), ` N_FIELDS ` int(10), PRIMARY KEY  (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 depends on content  Field Contents  6  bytes (5  bytes  if COMPACT format) Extra Bytes  (F*1) or (F*2) bytes  Field Start Offsets  Size   Name
REDUNDANT A row:  (10 , ‘abcdef’, 20 ) 4 6 7 Actualy stored as:  (10 , TRX_ID, PTR_ID, ‘abcdef’, 20 ) 6 4 Field Offsets … . next Extra 6 bytes: 0x00 00 00 0A record_status deleted_flag  min_rec_flag  n_owned  heap_no  n_fields  1byte_offs_flag   Fields ... ... abcdef 0x80 00 00 14
COMPACT A row:  (10 , ‘abcdef’, 20 ) 6 NULLS Actualy stored as:  (10 , TRX_ID, PTR_ID, ‘abcdef’, 20 ) Field Offsets … . next Extra 5 bytes: 0x00 00 00 0A Fields ... ... abcdef 0x80 00 00 14 A bit per NULL-able field
Data types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BLOB and other long fields ,[object Object],[object Object],[object Object],[object Object]
2 . Internal system tables SYS_INDEXES and SYS_TABLES
Why are SYS_* tables needed? ,[object Object],[object Object]
How MySQL stores data in InnoDB ,[object Object],[object Object],CREATE TABLE `SYS_INDEXES` ( ` TABLE_ID ` bigint(20) unsigned NOT NULL default '0', ` ID ` bigint(20) unsigned NOT NULL default '0', ` NAME ` varchar(120) default NULL, ` N_FIELDS ` int(10) unsigned default NULL, ` TYPE ` int(10) unsigned default NULL, ` SPACE ` int(10) unsigned default NULL, ` PAGE_NO ` int(10) unsigned default NULL, PRIMARY KEY  (`TABLE_ID`,`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 CREATE TABLE `SYS_TABLES` ( ` NAME ` varchar(255) NOT NULL default '', ` ID ` bigint(20) unsigned NOT NULL default '0', ` N_COLS ` int(10) unsigned default NULL, ` TYPE ` int(10) unsigned default NULL, ` MIX_ID ` bigint(20) unsigned default NULL, ` MIX_LEN ` int(10) unsigned default NULL, ` CLUSTER_NAME ` varchar(255) default NULL, ` SPACE ` int(10) unsigned default NULL, PRIMARY KEY  (`NAME`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 index_id = 0-3 index_id = 0-1 Name:  PRIMARY GEN_CLUSTER_ID or unique index name
How MySQL stores data in InnoDB NAME   ID  …   "archive/msg_store"  40  8 1 0 0 NULL 0 "archive/msg_store"  40  8 1 0 0 NULL 0 "archive/msg_store"  40  8 1 0 0 NULL 0 TABLE_ID   ID   NAME   … 40   196389  "PRIMARY" 2 3 0 21031026 4 0   196390 "msg_hash" 1 0 0 21031028 SYS_TABLES SYS_INDEXES Example:
3. InnoDB Primary and Secondary keys
Primary key ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Secondary key ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
4. Typical failure scenarios
Deleted records ,[object Object],[object Object],[object Object],[object Object]
How delete is performed? ,[object Object],[object Object],[object Object]
Dropped table/database ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Corrupted InnoDB tablespace ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Wrong UPDATE statement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
5. InnoDB recovery tool
Recovery prerequisites ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
table_defs.h { /* int(11) unsigned */ name: “ I D", type: FT_UINT, fixed_length: 4, has_limits: TRUE, limits: { can_be_null: FALSE, uint_min_val: 0, uint_max_val: 4294967295ULL }, can_be_null: FALSE }, { /* varchar(120) */ name: "NAME", type: FT_CHAR, min_length: 0, max_length: 120, has_limits: TRUE, limits: { can_be_null: TRUE, char_min_len: 0, char_max_len: 120, char_ascii_only: TRUE }, can_be_null: TRUE }, ,[object Object]
How to get CREATE info from .frm files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
InnoDB recovery tool ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
InnoDB recovery tool server #  ./page_parser -4 -f /var/lib/mysql/ibdata1 Opening file: /var/lib/mysql/ibdata1 Read data from fn=3... Read page #0.. saving it to pages-1259793800/0-18219008/0-00000000.page Read page #1.. saving it to pages-1259793800/0-0/1-00000001.page Read page #2.. saving it to pages-1259793800/4294967295-65535/2-00000002.page Read page #3.. saving it to pages-1259793800/0-0/3-00000003.page page_parser
Page signature check ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
InnoDB recovery tool server #  ./constraints_parser -4 -f pages-1259793800/0-16/51-00000051.page constraints_parser Table structure is defined in  "include/table_defs.h" See HOWTO for details http://code.google.com/p/innodb-tools/wiki/InnodbRecoveryHowto Filters inside table_defs.h are very important
Check InnoDB page before reading recs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Import result ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Questions ? ,[object Object],[object Object],[object Object],[object Object],[object Object],- - Applause :-)

Weitere ähnliche Inhalte

Was ist angesagt?

MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxNeoClova
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)Aurimas Mikalauskas
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger InternalsNorberto Leite
 
Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceMariaDB plc
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우PgDay.Seoul
 
MySQL Performance for DevOps
MySQL Performance for DevOpsMySQL Performance for DevOps
MySQL Performance for DevOpsSveta Smirnova
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
 
PostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec PatroniPostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec Patronislardiere
 
MySQL GTID 시작하기
MySQL GTID 시작하기MySQL GTID 시작하기
MySQL GTID 시작하기I Goo Lee
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresEDB
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재PgDay.Seoul
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerMongoDB
 
Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)Anastasia Lubennikova
 
InnoDB Performance Optimisation
InnoDB Performance OptimisationInnoDB Performance Optimisation
InnoDB Performance OptimisationMydbops
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLMorgan Tocker
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Mydbops
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015PostgreSQL-Consulting
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 

Was ist angesagt? (20)

MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
 
Optimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performanceOptimizing MariaDB for maximum performance
Optimizing MariaDB for maximum performance
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우
 
MySQL Performance for DevOps
MySQL Performance for DevOpsMySQL Performance for DevOps
MySQL Performance for DevOps
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
PostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec PatroniPostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec Patroni
 
MySQL GTID 시작하기
MySQL GTID 시작하기MySQL GTID 시작하기
MySQL GTID 시작하기
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with Postgres
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTiger
 
Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)
 
InnoDB Performance Optimisation
InnoDB Performance OptimisationInnoDB Performance Optimisation
InnoDB Performance Optimisation
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 

Ähnlich wie Recovery of lost or corrupted inno db tables(mysql uc 2010)

Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)guest808c167
 
Open sql2010 recovery-of-lost-or-corrupted-innodb-tables
Open sql2010 recovery-of-lost-or-corrupted-innodb-tablesOpen sql2010 recovery-of-lost-or-corrupted-innodb-tables
Open sql2010 recovery-of-lost-or-corrupted-innodb-tablesArvids Godjuks
 
cPanelCon 2014: InnoDB Anatomy
cPanelCon 2014: InnoDB AnatomycPanelCon 2014: InnoDB Anatomy
cPanelCon 2014: InnoDB AnatomyRyan Robson
 
Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2Massimo Cenci
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...Marco Gralike
 
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...Insight Technology, Inc.
 
InnoDB: архитектура транзакционного хранилища (Константин Осипов)
InnoDB: архитектура транзакционного хранилища (Константин Осипов)InnoDB: архитектура транзакционного хранилища (Константин Осипов)
InnoDB: архитектура транзакционного хранилища (Константин Осипов)Ontico
 
Page Cache in Linux 2.6.pdf
Page Cache in Linux 2.6.pdfPage Cache in Linux 2.6.pdf
Page Cache in Linux 2.6.pdfycelgemici1
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performanceguest9912e5
 
0104 abap dictionary
0104 abap dictionary0104 abap dictionary
0104 abap dictionaryvkyecc1
 
PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)Ange Albertini
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesMarco Gralike
 
cPanelCon 2015: InnoDB Alchemy
cPanelCon 2015: InnoDB AlchemycPanelCon 2015: InnoDB Alchemy
cPanelCon 2015: InnoDB AlchemyRyan Robson
 
vFabric SQLFire Introduction
vFabric SQLFire IntroductionvFabric SQLFire Introduction
vFabric SQLFire IntroductionJags Ramnarayan
 

Ähnlich wie Recovery of lost or corrupted inno db tables(mysql uc 2010) (20)

Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)
 
Open sql2010 recovery-of-lost-or-corrupted-innodb-tables
Open sql2010 recovery-of-lost-or-corrupted-innodb-tablesOpen sql2010 recovery-of-lost-or-corrupted-innodb-tables
Open sql2010 recovery-of-lost-or-corrupted-innodb-tables
 
Data recovery talk on PLUK
Data recovery talk on PLUKData recovery talk on PLUK
Data recovery talk on PLUK
 
cPanelCon 2014: InnoDB Anatomy
cPanelCon 2014: InnoDB AnatomycPanelCon 2014: InnoDB Anatomy
cPanelCon 2014: InnoDB Anatomy
 
Optimizando MySQL
Optimizando MySQLOptimizando MySQL
Optimizando MySQL
 
Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2
 
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...OakTable World 2015  - Using XMLType content with the Oracle In-Memory Column...
OakTable World 2015 - Using XMLType content with the Oracle In-Memory Column...
 
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
 
InnoDB: архитектура транзакционного хранилища (Константин Осипов)
InnoDB: архитектура транзакционного хранилища (Константин Осипов)InnoDB: архитектура транзакционного хранилища (Константин Осипов)
InnoDB: архитектура транзакционного хранилища (Константин Осипов)
 
Page Cache in Linux 2.6.pdf
Page Cache in Linux 2.6.pdfPage Cache in Linux 2.6.pdf
Page Cache in Linux 2.6.pdf
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
 
Mips
MipsMips
Mips
 
Explain that explain
Explain that explainExplain that explain
Explain that explain
 
0104 abap dictionary
0104 abap dictionary0104 abap dictionary
0104 abap dictionary
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)PE102 - a Windows executable format overview (booklet V1)
PE102 - a Windows executable format overview (booklet V1)
 
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex DatatypesUKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
UKOUG Tech14 - Using Database In-Memory Column Store with Complex Datatypes
 
cPanelCon 2015: InnoDB Alchemy
cPanelCon 2015: InnoDB AlchemycPanelCon 2015: InnoDB Alchemy
cPanelCon 2015: InnoDB Alchemy
 
Implementation
ImplementationImplementation
Implementation
 
vFabric SQLFire Introduction
vFabric SQLFire IntroductionvFabric SQLFire Introduction
vFabric SQLFire Introduction
 

Mehr von Aleksandr Kuzminsky

Mehr von Aleksandr Kuzminsky (7)

ProxySQL at Scale on AWS.pdf
ProxySQL at Scale on AWS.pdfProxySQL at Scale on AWS.pdf
ProxySQL at Scale on AWS.pdf
 
Omnibus as a Solution for Dependency Hell
Omnibus as a Solution for Dependency HellOmnibus as a Solution for Dependency Hell
Omnibus as a Solution for Dependency Hell
 
Efficient Indexes in MySQL
Efficient Indexes in MySQLEfficient Indexes in MySQL
Efficient Indexes in MySQL
 
Efficient Use of indexes in MySQL
Efficient Use of indexes in MySQLEfficient Use of indexes in MySQL
Efficient Use of indexes in MySQL
 
Netstore overview
Netstore overviewNetstore overview
Netstore overview
 
Undrop for InnoDB
Undrop for InnoDBUndrop for InnoDB
Undrop for InnoDB
 
Undrop for InnoDB
Undrop for InnoDBUndrop for InnoDB
Undrop for InnoDB
 

Kürzlich hochgeladen

UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIUdaiappa Ramachandran
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataSafe Software
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncObject Automation
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdfJamie (Taka) Wang
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?SANGHEE SHIN
 

Kürzlich hochgeladen (20)

UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation Inc
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?
 

Recovery of lost or corrupted inno db tables(mysql uc 2010)

  • 1. Recovery of lost or corrupted InnoDB tables MySQL User Conference 2010, Santa Clara [email_address] Percona Inc. http://MySQLPerformanceBlog.com
  • 2.
  • 3. 1. InnoDB format overview
  • 4.
  • 5.  
  • 6.
  • 7. InnoDB page format Fil Trailer Page Directory FREE SPACE USER RECORDS INFINUM+SUPREMUM RECORDS PAGE_HEADER FIL HEADER
  • 8. InnoDB page format Fil Header the latest archived log file number at the time that FIL_PAGE_FILE_FLUSH_LSN was written (in the log) 4 FIL_PAGE_ARCH_LOG_NO "the file has been flushed to disk at least up to this lsn" (log serial number), valid only on the first page of the file 8 FIL_PAGE_FILE_FLUSH_LSN current defined types are: FIL_PAGE_INDEX , FIL_PAGE_UNDO_LOG , FIL_PAGE_INODE , FIL_PAGE_IBUF_FREE_LIST 2 FIL_PAGE_TYPE log serial number of page's latest log record 8 FIL_PAGE_LSN offset of next page in key order 4 FIL_PAGE_NEXT offset of previous page in key order 4 FIL_PAGE_PREV ordinal page number from start of space 4 FIL_PAGE_OFFSET 4 ID of the space the page is in 4 FIL_PAGE_SPACE Remarks Size Name Data are stored in FIL_PAGE_INODE == 0x03
  • 9. InnoDB page format Page Header "file segment header for the non-leaf pages in a B-tree" (this is irrelevant here) 10 PAGE_BTR_SEG_TOP "file segment header for the leaf pages in a B-tree" (this is irrelevant here) 10 PAGE_BTR_SEG_LEAF identifier of the index the page belongs to 8 PAGE_INDEX_ID level within the index (0 for a leaf page) 2 PAGE_LEVEL the highest ID of a transaction which might have changed a record on the page (only set for secondary indexes) 8 PAGE_MAX_TRX_ID number of user records 2 PAGE_N_RECS number of consecutive inserts in the same direction, e.g. "last 5 were all to the left" 2 PAGE_N_DIRECTION either PAGE_LEFT , PAGE_RIGHT , or PAGE_NO_DIRECTION 2 PAGE_DIRECTION record pointer to the last inserted record 2 PAGE_LAST_INSERT "number of bytes in deleted records" 2 PAGE_GARBAGE record pointer to first free record 2 PAGE_FREE number of heap records; initial value = 2 2 PAGE_N_HEAP record pointer to first record in heap 2 PAGE_HEAP_TOP number of directory slots in the Page Directory part; initial value = 2 2 PAGE_N_DIR_SLOTS Remarks Size Name index_id Highest bit is row format(1 -COMPACT, 0 - REDUNDANT )
  • 10. InnoDB page format (REDUNDANT) Extra bytes pointer to next record in page 16 bits next 16 bits 1 if each Field Start Offsets is 1 byte long (this item is also called the "short" flag) 1 bit 1byte_offs_flag number of fields in this record, 1 to 1023 10 bits n_fields record's order number in heap of index page 13 bits heap_no number of records owned by this record 4 bits n_owned 1 if record is predefined minimum record 1 bit min_rec_flag 1 if record is deleted 1 bit deleted_flag _ORDINAR Y, _NODE_PTR , _INFIMUM , _SUPREMUM 2 bit s record_status Description Size Name
  • 11. InnoDB page format (COMPACT) Extra bytes a relative pointer to the next record in the page 16 next 16 bits 000=conventional, 001=node pointer (inside B-tree), 010=infimum, 011=supremum, 1xx=reserved 3 record type the order number of this record in the heap of the index page 1 3 heap_no the number of records owned by this record (this term is explained in page0page.h) 4 n_owned 4 bits used to delete mark a record, and mark a predefined minimum record in alphabetical order 4 record_statu s deleted_fla g min_rec_flag Description Size , bits Name
  • 12.
  • 13.
  • 14.
  • 15. Row format EXAMPLE: CREATE TABLE ` t1 ` ( ` ID ` int( 11 ) unsigned NOT NULL, ` NAME ` varchar(120), ` N_FIELDS ` int(10), PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 depends on content Field Contents 6 bytes (5 bytes if COMPACT format) Extra Bytes (F*1) or (F*2) bytes Field Start Offsets Size Name
  • 16. REDUNDANT A row: (10 , ‘abcdef’, 20 ) 4 6 7 Actualy stored as: (10 , TRX_ID, PTR_ID, ‘abcdef’, 20 ) 6 4 Field Offsets … . next Extra 6 bytes: 0x00 00 00 0A record_status deleted_flag min_rec_flag n_owned heap_no n_fields 1byte_offs_flag Fields ... ... abcdef 0x80 00 00 14
  • 17. COMPACT A row: (10 , ‘abcdef’, 20 ) 6 NULLS Actualy stored as: (10 , TRX_ID, PTR_ID, ‘abcdef’, 20 ) Field Offsets … . next Extra 5 bytes: 0x00 00 00 0A Fields ... ... abcdef 0x80 00 00 14 A bit per NULL-able field
  • 18.
  • 19.
  • 20. 2 . Internal system tables SYS_INDEXES and SYS_TABLES
  • 21.
  • 22.
  • 23. How MySQL stores data in InnoDB NAME ID … "archive/msg_store" 40 8 1 0 0 NULL 0 "archive/msg_store" 40 8 1 0 0 NULL 0 "archive/msg_store" 40 8 1 0 0 NULL 0 TABLE_ID ID NAME … 40 196389 "PRIMARY" 2 3 0 21031026 4 0 196390 "msg_hash" 1 0 0 21031028 SYS_TABLES SYS_INDEXES Example:
  • 24. 3. InnoDB Primary and Secondary keys
  • 25.
  • 26.
  • 27. 4. Typical failure scenarios
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. InnoDB recovery tool server # ./page_parser -4 -f /var/lib/mysql/ibdata1 Opening file: /var/lib/mysql/ibdata1 Read data from fn=3... Read page #0.. saving it to pages-1259793800/0-18219008/0-00000000.page Read page #1.. saving it to pages-1259793800/0-0/1-00000001.page Read page #2.. saving it to pages-1259793800/4294967295-65535/2-00000002.page Read page #3.. saving it to pages-1259793800/0-0/3-00000003.page page_parser
  • 39.
  • 40. InnoDB recovery tool server # ./constraints_parser -4 -f pages-1259793800/0-16/51-00000051.page constraints_parser Table structure is defined in "include/table_defs.h" See HOWTO for details http://code.google.com/p/innodb-tools/wiki/InnodbRecoveryHowto Filters inside table_defs.h are very important
  • 41.
  • 42.
  • 43.