SlideShare une entreprise Scribd logo
1  sur  43
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 :-)

Contenu connexe

Tendances

Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performanceoysteing
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningOSSCube
 
Oracle RAC - New Generation
Oracle RAC - New GenerationOracle RAC - New Generation
Oracle RAC - New GenerationAnil Nair
 
Postgresql stored procedure
Postgresql stored procedurePostgresql stored procedure
Postgresql stored procedureJong Woo Rhee
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfSrirakshaSrinivasan2
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Mydbops
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQLMydbops
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder
 
MySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to HaveMySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to HaveSveta Smirnova
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by exampleMauro Pagano
 
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0Frederic Descamps
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionMarkus Michalewicz
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0Mydbops
 
Oracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best Practices
Oracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best PracticesOracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best Practices
Oracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best PracticesMarkus Michalewicz
 
Oracle RAC features on Exadata
Oracle RAC features on ExadataOracle RAC features on Exadata
Oracle RAC features on ExadataAnil Nair
 
Exadata master series_asm_2020
Exadata master series_asm_2020Exadata master series_asm_2020
Exadata master series_asm_2020Anil Nair
 
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
FOSDEM 2022 MySQL Devroom:  MySQL 8.0 - Logical Backups, Snapshots and Point-...FOSDEM 2022 MySQL Devroom:  MySQL 8.0 - Logical Backups, Snapshots and Point-...
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...Frederic Descamps
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slidesMohamed Farouk
 

Tendances (20)

Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
 
Oracle RAC - New Generation
Oracle RAC - New GenerationOracle RAC - New Generation
Oracle RAC - New Generation
 
Postgresql stored procedure
Postgresql stored procedurePostgresql stored procedure
Postgresql stored procedure
 
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdfOracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
Oracle_Multitenant_19c_-_All_About_Pluggable_D.pdf
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
MySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to HaveMySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to Have
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by example
 
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion Edition
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0
 
Oracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best Practices
Oracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best PracticesOracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best Practices
Oracle Real Application Clusters (RAC) 12c Rel. 2 - Operational Best Practices
 
MySQL 8
MySQL 8MySQL 8
MySQL 8
 
Oracle RAC features on Exadata
Oracle RAC features on ExadataOracle RAC features on Exadata
Oracle RAC features on Exadata
 
Exadata master series_asm_2020
Exadata master series_asm_2020Exadata master series_asm_2020
Exadata master series_asm_2020
 
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
FOSDEM 2022 MySQL Devroom:  MySQL 8.0 - Logical Backups, Snapshots and Point-...FOSDEM 2022 MySQL Devroom:  MySQL 8.0 - Logical Backups, Snapshots and Point-...
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slides
 

Similaire à 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
 

Similaire à 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
 

Plus de Aleksandr Kuzminsky

Plus de 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
 

Dernier

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Dernier (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

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.