Generate report - log file sync

本文深入探讨了一段SQL查询代码,旨在优化日志同步过程中的性能。通过分析日志文件同步事件的时间等待和等待次数,作者识别了性能瓶颈并提供了优化建议。

 

set term off heading on verify off pagesize 1000
set markup html on entmap ON preformat off spool on

spool c:\temp\event_log_file_sync.html

select s.BEGIN_INTERVAL_TIME, m.INSTANCE_NUMBER, m.SNAP_ID, EVENT_NAME, m.EVENT_TIME_WAITED, m.TOTAL_WAITS, m.PCT, AVG_WAIT
    FROM    (SELECT ee.instance_number,
                    ee.snap_id,
                    ee.event_name,
                    ROUND (ee.event_time_waited / 1000000) event_time_waited,
                    ee.total_waits,
                    ROUND (
                       (ee.event_time_waited * 100) / et.total_time_waited,
                       1)
                       pct,
                    ROUND ( (ee.event_time_waited / ee.total_waits) / 1000)
                       avg_wait
               FROM    (SELECT ee1.instance_number,
                               ee1.snap_id,
                               ee1.event_name,
                               ee1.time_waited_micro - ee2.time_waited_micro
                                  event_time_waited,
                               ee1.total_waits - ee2.total_waits total_waits
                          FROM    dba_hist_system_event ee1
                               JOIN
                                  dba_hist_system_event ee2
                               ON     ee1.snap_id = ee2.snap_id + 1
                                  AND ee1.instance_number = ee2.instance_number
                                  AND ee1.event_id = ee2.event_id
                                  AND ee1.wait_class_id <> 2723168908
                                  AND ee1.time_waited_micro
                                      - ee2.time_waited_micro > 0
                        UNION
                        SELECT st1.instance_number,
                               st1.snap_id,
                               st1.stat_name event_name,
                               st1.VALUE - st2.VALUE event_time_waited,
                               1 total_waits
                          FROM    dba_hist_sys_time_model st1
                               JOIN
                                  dba_hist_sys_time_model st2
                               ON     st1.instance_number = st2.instance_number
                                  AND st1.snap_id = st2.snap_id + 1
                                  AND st1.stat_id = st2.stat_id
                                  AND st1.stat_name = 'DB CPU'
                                  AND st1.VALUE - st2.VALUE > 0) ee
                    JOIN
                       (SELECT et1.instance_number,
                               et1.snap_id,
                               et1.VALUE - et2.VALUE total_time_waited
                          FROM    dba_hist_sys_time_model et1
                               JOIN
                                  dba_hist_sys_time_model et2
                               ON     et1.snap_id = et2.snap_id + 1
                                  AND et1.instance_number = et2.instance_number
                                  AND et1.stat_id = et2.stat_id
                                  AND et1.stat_name = 'DB time'
                                  AND et1.VALUE - et2.VALUE > 0) et
                    ON ee.instance_number = et.instance_number
                       AND ee.snap_id = et.snap_id) m
         JOIN
            dba_hist_snapshot s
         ON m.snap_id = s.snap_id AND m.instance_number = s.instance_number
   WHERE TO_CHAR (BEGIN_INTERVAL_TIME+0.003, 'YYYYMMDDHH24MI') > CONCAT('&&1', '&&2') AND TO_CHAR (BEGIN_INTERVAL_TIME-0.003, 'YYYYMMDDHH24MI') < CONCAT('&&1', '&&3') AND event_name = 'log file sync'
ORDER BY m.instance_number, m.snap_id, event_time_waited desc;

spool off
2025-09-15T08:21:09.471534Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2025-09-15T08:21:09.471574Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2025-09-15T08:21:09.732610Z 0 [Warning] InnoDB: New log files created, LSN=45790 2025-09-15 16:21:09 0xe5c InnoDB: Assertion failure in thread 3676 in file fsp0fsp.cc line 3301 InnoDB: Failing assertion: !is_system_tablespace(space->id) InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html InnoDB: about forcing recovery. 08:21:09 UTC - mysqld got exception 0x80000003 ; This could be because you hit a bug. It is also possible that this binary or one of the libraries it was linked against is corrupt, improperly built, or misconfigured. This error can also be caused by malfunctioning hardware. Attempting to collect some information that could help diagnose the problem. As this is a crash and something is definitely wrong, the information collection process might fail. key_buffer_size=8388608 read_buffer_size=65536 max_used_connections=0 max_threads=151 thread_count=0 connection_count=0 It is possible that mysqld could use up to key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 58352 K bytes of memory Hope that's ok; if not, decrease some variables in the equation. Thread pointer: 0x0 Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... 7ff7bf8beeb2 mysqld.exe!my_errno() 7ffc8fbaec9d MSVCR120.dll!raise() 7ffc8fbb4874 MSVCR120.dll!abort() 7ff7bf9da744 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bf9f2255 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bf9f21f1 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bf9ec9d6 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bf9ec7d1 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bfb15217 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bf989b56 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bf8f8b00 mysqld.exe!?reserve@?$vector@EV?$allocator@E@std@@@std@@QEAAX_K@Z() 7ff7bf18457e mysqld.exe!?ha_initialize_handlerton@@YAHPEAUst_plugin_int@@@Z() 7ff7bf2806d8 mysqld.exe!?plugin_foreach_with_mask@@YA_NPEAVTHD@@PEAP6AD0PEAUst_plugin_int@@PEAX@ZHI2@Z() 7ff7bf281c40 mysqld.exe!?plugin_register_builtin_and_init_core_se@@YA_NPEAHPEAPEAD@Z() 7ff7bf137303 mysqld.exe!?init_connection_acceptor@?$Connection_acceptor@VShared_mem_listener@@@@QEAA_NXZ() 7ff7bf13c4d5 mysqld.exe!?win_main@@YAHHPEAPEAD@Z() 7ff7bf139cb5 mysqld.exe!?mysql_service@@YAHPEAX@Z() 7ff7bf13a06c mysqld.exe!?mysqld_main@@YAHHPEAPEAD@Z() 7ff7bfc2eef7 mysqld.exe!my_wildcmp_mb() 7ffca5217034 KERNEL32.DLL!BaseThreadInitThunk() 7ffca62bcec1 ntdll.dll!RtlUserThreadStart() The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains information that should help you find out what is causing the crash. 2025-09-15T08:25:20.003827Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2025-09-15T08:25:20.003875Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2025-09-15T08:25:20.016963Z 0 [Note] D:\work\w\sql\mysql\mysql-5.7.29.0\exe\MySQL Server 5.7\bin\mysqld (mysqld 5.7.29-log) starting as process 2468 ... 2025-09-15T08:25:20.020077Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-09-15T08:25:20.020351Z 0 [Note] InnoDB: Uses event mutexes 2025-09-15T08:25:20.020517Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2025-09-15T08:25:20.020741Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2025-09-15T08:25:20.020936Z 0 [Note] InnoDB: Adjusting innodb_buffer_pool_instances from 8 to 1 since innodb_buffer_pool_size is less than 1024 MiB 2025-09-15T08:25:20.021453Z 0 [Note] InnoDB: Number of pools: 1 2025-09-15T08:25:20.021704Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2025-09-15T08:25:20.022836Z 0 [Note] InnoDB: Initializing buffer pool, total size = 8M, instances = 1, chunk size = 8M 2025-09-15T08:25:20.023428Z 0 [Note] InnoDB: Completed initialization of buffer pool 2025-09-15T08:25:20.040506Z 0 [ERROR] InnoDB: Header page consists of zero bytes in datafile: .\ibdata1, Space ID:0, Flags: 0. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html for how to resolve the issue. 2025-09-15T08:25:20.041009Z 0 [ERROR] InnoDB: Corrupted page [page id: space=0, page number=0] of datafile '.\ibdata1' could not be found in the doublewrite buffer. 2025-09-15T08:25:20.041364Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption 2025-09-15T08:25:20.374320Z 0 [ERROR] Plugin 'InnoDB' init function returned error. 2025-09-15T08:25:20.374601Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2025-09-15T08:25:20.374824Z 0 [ERROR] Failed to initialize builtin plugins. 2025-09-15T08:25:20.375005Z 0 [ERROR] Aborting 2025-09-15T08:25:20.375139Z 0 [Note] Binlog end 2025-09-15T08:25:20.375322Z 0 [Note] Shutting down plugin 'CSV' 2025-09-15T08:25:20.375648Z 0 [Note] D:\work\w\sql\mysql\mysql-5.7.29.0\exe\MySQL Server 5.7\bin\mysqld: Shutdown complete 2025-09-15T08:25:35.643857Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2025-09-15T08:25:35.643902Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2025-09-15T08:25:35.644796Z 0 [Note] D:\work\w\sql\mysql\mysql-5.7.29.0\exe\MySQL Server 5.7\bin\mysqld (mysqld 5.7.29-log) starting as process 9380 ... 2025-09-15T08:25:35.647922Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-09-15T08:25:35.648178Z 0 [Note] InnoDB: Uses event mutexes 2025-09-15T08:25:35.648349Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2025-09-15T08:25:35.648579Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2025-09-15T08:25:35.648778Z 0 [Note] InnoDB: Adjusting innodb_buffer_pool_instances from 8 to 1 since innodb_buffer_pool_size is less than 1024 MiB 2025-09-15T08:25:35.649296Z 0 [Note] InnoDB: Number of pools: 1 2025-09-15T08:25:35.649543Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2025-09-15T08:25:35.650683Z 0 [Note] InnoDB: Initializing buffer pool, total size = 8M, instances = 1, chunk size = 8M 2025-09-15T08:25:35.651269Z 0 [Note] InnoDB: Completed initialization of buffer pool 2025-09-15T08:25:35.665915Z 0 [ERROR] InnoDB: Header page consists of zero bytes in datafile: .\ibdata1, Space ID:0, Flags: 0. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html for how to resolve the issue. 2025-09-15T08:25:35.666408Z 0 [ERROR] InnoDB: Corrupted page [page id: space=0, page number=0] of datafile '.\ibdata1' could not be found in the doublewrite buffer. 2025-09-15T08:25:35.666760Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption 2025-09-15T08:25:35.999666Z 0 [ERROR] Plugin 'InnoDB' init function returned error. 2025-09-15T08:25:35.999965Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2025-09-15T08:25:36.000286Z 0 [ERROR] Failed to initialize builtin plugins. 2025-09-15T08:25:36.000472Z 0 [ERROR] Aborting 2025-09-15T08:25:36.000611Z 0 [Note] Binlog end 2025-09-15T08:25:36.000797Z 0 [Note] Shutting down plugin 'CSV' 2025-09-15T08:25:36.001116Z 0 [Note] D:\work\w\sql\mysql\mysql-5.7.29.0\exe\MySQL Server 5.7\bin\mysqld: Shutdown complete
09-16
从你提供的日志来看,MySQL 服务无法启动的根本原因是 **InnoDB 数据文件损坏**,尤其是: ``` [ERROR] InnoDB: Header page consists of zero bytes in datafile: .\ibdata1, Space ID:0, Flags: 0. [ERROR] InnoDB: Corrupted page [page id: space=0, page number=0] of datafile '.\ibdata1' could not be found in the doublewrite buffer. [ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption ``` 这说明 InnoDB 的系统表空间文件 `ibdata1` 损坏或为空,MySQL 无法从中恢复数据字典信息,导致服务启动失败。 --- ## ✅ 解决方案:强制恢复或重建 InnoDB 数据 ### ✅ 方案一:使用 `innodb_force_recovery` 模式尝试恢复数据 你可以在 `my.ini` 中添加如下配置: ```ini [mysqld] innodb_force_recovery = 1 ``` 你可以逐步尝试从 1 到 6 的值,数字越大恢复力度越强(但风险也越高): | 值 | 说明 | |----|------| | 1 | 跳过崩溃恢复 | | 2 | 防止主线程运行 | | 3 | 不执行事务回滚 | | 4 | 不加载表元数据 | | 5 | 忽略表空间缺失 | | 6 | 不进行 InnoDB 初始化 | > ⚠️ 注意:设置 `innodb_force_recovery` 后不要进行写操作,只能读取数据。 #### 操作步骤: 1. 修改 `my.ini` 添加 `innodb_force_recovery = 1` 2. 启动 MySQL: ```bash net start MySQL57 ``` 3. 如果成功启动,立即使用 `mysqldump` 导出数据: ```bash mysqldump -u root -p --all-databases > backup.sql ``` 4. 停止 MySQL,删除 `ibdata1`、`ib_logfile*` 和所有数据库文件 5. 重新初始化并恢复数据 --- ### ✅ 方案二:手动重建 InnoDB 表空间(数据丢失) 如果你不需要恢复数据,可以完全重建 InnoDB 数据目录: #### 步骤如下: 1. **停止 MySQL 服务**: ```bash net stop MySQL57 ``` 2. **备份当前数据目录(可选)**: ```bash xcopy "D:\work\w\sql\mysql\mysql-5.7.29.0\exe\MySQL Server 5.7\data" "D:\backup\mysql_data" /E /I ``` 3. **删除 InnoDB 数据文件**: 删除以下文件(在 `data` 目录中): - `ibdata1` - `ib_logfile0` - `ib_logfile1` > ⚠️ 注意:删除这些文件会导致所有数据丢失! 4. **重新初始化数据目录**: ```bash mysqld --initialize --console ``` 或使用无密码初始化: ```bash mysqld --initialize-insecure ``` 5. **重新启动 MySQL 服务**: ```bash net start MySQL57 ``` 6. **登录 MySQL 并重建用户和数据库**: ```bash mysql -u root -p ``` --- ## ✅ 方案三:使用 MySQL 5.7 的 `--innodb-directories` 恢复数据文件(高级) 如果你有 `.ibd` 文件(每个表的独立表空间),可以尝试将它们挂载到新的实例中: ```sql CREATE TABLE test_table ( id INT PRIMARY KEY ) DATA DIRECTORY = 'D:/path/to/your/tablespace/'; ``` 但这要求你知道表结构,并且 `.ibd` 文件未损坏。 --- ## ✅ 总结处理流程 | 步骤 | 操作 | |------|------| | 1 | 修改 `my.ini` 设置 `innodb_force_recovery = 1~6` 尝试启动 | | 2 | 成功后立即导出数据 | | 3 | 删除损坏的 InnoDB 文件(`ibdata1`, `ib_logfile*`) | | 4 | 重新初始化数据目录 | | 5 | 恢复数据或重新创建数据库 | --- ## ✅ 推荐配置优化(避免未来再次损坏) 在 `my.ini` 中添加: ```ini [mysqld] innodb_file_per_table=1 innodb_log_file_size=64M innodb_buffer_pool_size=128M innodb_flush_log_at_trx_commit=1 sync_binlog=1 ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值