[ERROR]Space id in fsp header but in the page header一列

原创转载请注明出处



报错如下MYSQL不能正常启动

2017-09-22 10:39:05 21409 [Note] InnoDB: Database was not shutdown normally!
2017-09-22 10:39:05 21409 [Note] InnoDB: Starting crash recovery.
2017-09-22 10:39:05 21409 [Note] InnoDB: Reading tablespace information from the .ibd files...
2017-09-22 10:39:05 21409 [ERROR] InnoDB: Space id in fsp header 1416128883,but in the page header 824195850 

我曾经写过这样一个文章如下:
InnoDB: Error: space id and page n:o stored in the page?
http://blog.itpub.net/7728585/viewspace-2121548/
但是上面的文章只是人为模拟,实际上在生产情况中严重得多,基本是块的物理顺坏,今天又有网友问我这个问题,实际上遇到这种问题一般都涉及到块的物理损坏了,修复的可能性并不大,我们来看看源码抛错位置:

/**********************************************************************//**
Reads the space id from the first page of a tablespace.
@return space id, ULINT UNDEFINED if error */
ulint
fsp_header_get_space_id(
/*====================*/
   const page_t*   page)   /*!< in: first page of a tablespace */
{
   ulint   fsp_id;
   ulint   id;

   fsp_id = mach_read_from_4(FSP_HEADER_OFFSET + page + FSP_SPACE_ID);

   id = mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);

   DBUG_EXECUTE_IF("fsp_header_get_space_id_failure",
           id = ULINT_UNDEFINED;);

   if (id != fsp_id) {
       ib::error() << "Space ID in fsp header is " << fsp_id
           << ", but in the page header it is " << id << ".";
       return(ULINT_UNDEFINED);
   }

   return(id);
} 
  • FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID:PAGE HRADER中存储了space id在34后4字节,也就对应了报错中的but in the page header 824195850
  • FSP_SPACE_ID:File space header中存储了space id在38字节后4个字节,也就对应了报错中的Space id in fsp header 1416128883

File space header是每一个表空间的第一个块才会有的,存储的信息如下:

/*          SPACE HEADER
           ============

File space header data structure: this data structure is contained in the
first page of a space. The space for this header is reserved in every extent
descriptor page, but used only in the first. */

/*-------------------------------------*/
#define FSP_SPACE_ID        0   /* space id */
#define FSP_NOT_USED        4   /* this field contained a value up to
                   which we know that the modifications
                   in the database have been flushed to
                   the file space; not used now */
#define FSP_SIZE        8   /* Current size of the space in
                   pages */
#define FSP_FREE_LIMIT      12  /* Minimum page number for which the
                   free list has not been initialized:
                   the pages >= this limit are, by
                   definition, free; note that in a
                   single-table tablespace where size
                   < 64 pages, this number is 64, i.e.,
                   we have initialized the space
                   about the first extent, but have not
                   physically allocated those pages to the
                   file */
#define FSP_SPACE_FLAGS     16  /* fsp_space_t.flags, similar to
                   dict_table_t::flags */
#define FSP_FRAG_N_USED     20  /* number of used pages in the
                   FSP_FREE_FRAG list */
#define FSP_FREE        24  /* list of free extents */
#define FSP_FREE_FRAG       (24 + FLST_BASE_NODE_SIZE)
                   /* list of partially free extents not
                   belonging to any segment */
#define FSP_FULL_FRAG       (24 + 2 * FLST_BASE_NODE_SIZE)
                   /* list of full extents not belonging
                   to any segment */
#define FSP_SEG_ID      (24 + 3 * FLST_BASE_NODE_SIZE)
                   /* 8 bytes which give the first unused
                   segment id */
#define FSP_SEG_INODES_FULL (32 + 3 * FLST_BASE_NODE_SIZE)
                   /* list of pages containing segment
                   headers, where all the segment inode
                   slots are reserved */
#define FSP_SEG_INODES_FREE (32 + 4 * FLST_BASE_NODE_SIZE)
                   /* list of pages containing segment
                   headers, where not all the segment
                   header slots are reserved */ 

那么这个错误简单的说就是某个表空间ibd文件的第一个块的34后4字节和38字节后4个字节不能通过检测,但是要注意这仅仅是这8个字节一个检测。实际上这种错误基本对应着表空间文件的物理顺坏,一般来说其他字节也出现了问题,如果没有备份或者其他双机手段可能要导致这个表空间的数据丢失。好了我们回到案例。

随即我问这位朋友是否是独立表空间,他说是的,然后我们就需要找到到底哪个表空间出了问题。我曾经有一个读取二进制文件的工具,放到百度云盘:
http://pan.baidu.com/s/1num76RJ
可以直接读取这样的信息如下:

******************************************************************
This Tool Is Uesed For Find The Data In Binary format(Hexadecimal)
Usage:./bcview file blocksize offset cnt-bytes!
file: Is Your File Will To Find Data!
blocksize: Is N kb Block.Eg: 8 Is 8 Kb Blocksize(Oracle)!
                        Eg: 16 Is 16 Kb Blocksize(Innodb)!
offset:Is Every Block Offset Your Want Start!
cnt-bytes:Is After Offset,How Bytes Your Want Gets!
Edtor QQ:22389860!
Used gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
******************************************************************
----Current file size is :0.109375 Mb
----Current use set blockszie is 16 Kb
----Current file name is t6.ibd
current block:00000000--Offset:00036--cnt bytes:08--data is:001e0000001e0000 

我们可以得到数据

current block:00000000--Offset:00036--cnt bytes:08--data is:001e0000001e0000 

但是要扫描全部的ibd文件才能找到是哪个表空间检测出错,但是这个哥们shell也是比较好,写了一个如下的shell来完成:

find /opt/app/mysql5/var/ -iname \*.ibd > a
for i in `cat ./a`;do ./bcview $i 16 34 8 | head -15 >> a.log;done 

这样将所有表空间的第一个块的信息的34-42字节信息都提取出来了,我随即查看了一下,找到了报错的表空间:

current block:00000000--Offset:00034--cnt bytes:08--data is:31203b0a54686973 
  • 0X54686973 十进制为1416128883就是报错的Space id in fsp header 1416128883
  • 0X31203b0a 十进制为1416128883就是报错的but in the page header 824195850

显然他们是不相等,正常情况下这8个字节4字节4字节比较是相同的,然后我查看了这个文件中块的checksum也是不相等,这个时候只有2个正常的处理方式:

  1. 使用备份文件进行恢复
  2. 如果这个表不重要可以移除掉ibd文件保留frm文件,可以正常启动,启动后drop掉这个表

后记

显然这里也再次重申了备份的重要性,遇到这样的错误,最安全的方式还是进行数据恢复,当然某些工具可以直接提取数据文件里面的数据,但是现有的版本支持并不是太好,而且风险也是特别大。

作者微信

时间: 2024-09-17 08:59:07

[ERROR]Space id in fsp header but in the page header一列的相关文章

MYSQL Space id in fsp header,but in the page header错误

今天启动MYSQL的时候发现如下问题: 2015-12-14 20:51:59 2098 [ERROR] InnoDB: Space id in fsp header 131225,but in the page header 65 2015-12-14 20:51:59 2098 [ERROR] InnoDB: inconsistent data in space header in tablespace ./test/oneblock.ibd (table test/oneblock) in

InnoDB: Error: space id and page n:o stored in the page?

2016-06-08 04:38:11 7fa7ddd86700  InnoDB: Error: space id and page n:o stored in the page InnoDB: read in are 4294967295:4294967295, should be 22291:4096! InnoDB: Database page corruption on disk or a failed InnoDB: file read of page 4096. InnoDB: Yo

ERROR: invalid page header in block 27073 of relation base/21078/45300926

突然断网,检查后通知我们UPS断电,db所在主机重启 1.连上后,发现pg主从不同步,主不向从传日志,从报错: FATAL: could not connect to the primary server: could not connect to server: 发现从先启动成功,而主是后启动的,因此我们将从再次重启 service postgresql restart 开始正常传日志  2.过了一会,研发反应部分表的使用出现问题,主再次不传输日志,且无sender进程. 查看主库日志,发现报

MySQL8.0新特性:增加系统文件追踪space ID和物理文件的映射

Note1: 本文所有代码相关的内容都是基于MySQL8.0.3,而目前版本还处于RC和快速开发的状态,不排除后面的版本逻辑,函数名等发生变化. Note2: 主要代码在这个commit 中,感兴趣的也可以自行阅读代码 Note3: 本文仅是本人的阅码笔记,记录的比较凌乱... 前面我们提到了MySQL5.7的几个崩溃恢复产生的性能退化 为了解决崩溃恢复的效率问题, MySQL8.0对crash recovery的逻辑进行了进一步的优化. 在之前的版本中,InnoDB通过向redo log中写入

关于MYSQL INNODB index page header学习和实验总结

关于INNODB  index header 所用到的工具是自己写的mysqlblock和bcview, 我放到了百度云盘 http://pan.baidu.com/s/1num76RJ 供大家下载和使用 普通表空间(及设置了innodb_file_per_table每个表都对应一个idb文件)从第4个块开始通常是innodb的数据页. 前38字节为FILE HEADER 从38字节到74字节为INDEX HEADER,如下: number of directory slot          

page header or footer longer than a page

问题描述 pageheaderorfooterlongerthanapage..求指點 解决方案 解决方案二:在本地上預覽可以放在服務器上94不行...

changes of mysql 5.6.20

New option [Rev:5936][Rev:6045][Rev:6049]The new system variable binlog_impossible_mode controls what happens if the server cannot write to the binary log, for example, due to a file error. For backward compatibility, the default for binlog_impossibl

修复SQLSERVER2000数据库之实战经验

server|sqlserver|数据|数据库 修复SQLSERVER2000数据库之实战经验 ******************************************************************************** Author:黄山光明顶 mail:leimin@jxfw.com version:1.0.0 date:2004-1-30 (如需转载,请注明出处!,如果有问题请发MAIL给我:-)) ***************************

一次SQL Server 2000修复实践

server 我所讲的一个故事的背景是这样的,在某一个POS的项目中使用SQL SERVER 2000做前台数据库,IBM 的DB2做后台数据库.前台数据库的环境是这样的操作系统是WINDOWS 2000 SERVER(10 USERS),数据库是SQL SERVER 2000(E)+SP3,Application是POS的收银系统(是一种实时的交易系统).硬件的配置是:P4 XRON 2.4G*2,36G HDD*5 做的RAID5 ,1G MEMORY,HP DDS4 磁带机,数据库的容量一