---
title: OceanBase 数据库合并超时问题排查方法-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于OceanBase 数据库合并超时问题排查方法相关的常见问题和使用技巧，帮助您快速解决OceanBase 数据库合并超时问题排查方法的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# OceanBase 数据库合并超时问题排查方法

更新时间：2026-06-15 09:16

适用版本： V2.1.x、V2.2.x、V3.1.x、V3.2.x、V4.0.x、V4.1.x、V4.2.x 内容类型：Troubleshoot  

本文主要介绍 OceanBase 数据库中合并问题的排查方法。

## 适用版本

OceanBase 数据库所有版本

## 排查步骤

### OceanBase 数据库 V4.X 之前版本

1. 确认合并配置项。

   OceanBase 数据库中包含以下合并相关的配置项。

      - `enable_manual_merge`：是否开启手动合并，取值为 `TRUE` 表示需要手动合并，默认为 `FALSE`。
      - `zone_merge_concurrency`：用于设置在合并时，支持多少个 Zone 并发。当值为 `0` 时，由系统根据部署情况自动选择最佳并发度，一般不需要设置。默认为 `1`，表示单次只有一个 Zone 进行合并。
      - `zone_merge_order`：用于设置 Zone 的轮转合并顺序。不指定时，由系统自动决定，一般不需要设置。
      - `enable_merge_by_turn`：用于设置是否开启轮转合并策略，设置为 `TRUE` 时表示开启轮转合并，默认为 `FALSE`。
      - `major_freeze_duty_time`：每日合并发起时间。
      - `enable_auto_leader_switch`：用于设置是否开启自动切主，默认为 `TRUE`。

   有关以上系统配置项的详细信息，请参见 OceanBase 数据库《参考指南》中的 **配置项参考** 章节。
 2. 确认合并状态。

   本例中，当前的 `frozen_version` 为 `25`，表示集群需要合并到 `25` 版本，但 `cn-shanghai-e` 这个 Zone 副本只合并到了 `24` 版本。

   ```shell
   obclient> select * from __all_zone where name = "frozen_version" or name = "last_merged_version";
   +----------------------------+----------------------------+---------------+---------------------+-------+------+
   | gmt_create                 | gmt_modified               | zone          | name                | value | info |
   +----------------------------+----------------------------+---------------+---------------------+-------+------+
   | 2020-12-07 16:01:30.793286 | 2020-12-30 02:00:00.445594 |               | frozen_version      |    25 |      |
   | 2020-12-07 16:01:30.793490 | 2020-12-29 02:01:12.449651 |               | last_merged_version |    24 |      |
   | 2020-12-07 16:01:30.794375 | 2020-12-29 02:01:11.880114 | cn-shanghai-e | last_merged_version |    24 |      |
   | 2020-12-07 16:01:30.795109 | 2020-12-30 02:01:15.563291 | cn-shanghai-f | last_merged_version |    25 |      |
   | 2020-12-07 16:01:30.795842 | 2020-12-30 02:01:22.694016 | cn-shanghai-g | last_merged_version |    25 |      |
   +----------------------------+----------------------------+---------------+---------------------+-------+------+
   5 rows in set (0.00 sec)

   ```

   继续查询 `__all_zone` 表，查看 `cn-shanghai-e` 的合并状态，发现状态为 `MERGING`，表示正在合并。

   ```shell
   obclient> select * from __all_zone where name = "merge_status";
   +----------------------------+----------------------------+---------------+---------------------+---------+------+
   | gmt_create                 | gmt_modified               | zone          | name                | value   | info |
   +----------------------------+----------------------------+---------------+---------------------+---------+------+
   | 2020-12-07 16:01:30.793286 | 2020-12-30 02:00:00.445594 |               | merge_status        | MERGING |      |
   | 2020-12-07 16:01:30.794375 | 2020-12-29 02:01:11.880114 | cn-shanghai-e | merge_status        | MERGING |      |
   | 2020-12-07 16:01:30.795109 | 2020-12-30 02:01:15.563291 | cn-shanghai-f | merge_status        |   IDLE  |      |
   | 2020-12-07 16:01:30.795842 | 2020-12-30 02:01:22.694016 | cn-shanghai-g | merge_status        |   IDLE  |      |
   +----------------------------+----------------------------+---------------+---------------------+---------+------+
   5 rows in set (0.00 sec)

   ```
 3. 排查切主相关问题。

   根据上面的信息，发现正在合并，此时查询该 Zone 的 `global_broadcast_version` 与 `broadcast_version`。 如果 `broadcast_version` 等于 `last_merged_version`，且 `last_merged_version` 落后于 `global_broadcast_version`，说明 RootService 没有发起相关 Zone 的合并。

   ```shell
   obclient> select * from __all_zone where name = "global_broadcast_version" or name = "broadcast_version";
   +----------------------------+----------------------------+---------------+--------------------------+---------+------+
   | gmt_create                 | gmt_modified               | zone          | name                     | value   | info |
   +----------------------------+----------------------------+---------------+--------------------------+---------+------+
   | 2020-12-07 16:01:30.793286 | 2020-12-30 02:00:00.445594 |               | global_broadcast_version |   25    |      |
   | 2020-12-07 16:01:30.794375 | 2020-12-29 02:01:11.880114 | cn-shanghai-e | broadcast_version        |   24    |      |
   | 2020-12-07 16:01:30.795109 | 2020-12-30 02:01:15.563291 | cn-shanghai-f | broadcast_version        |   25    |      |
   | 2020-12-07 16:01:30.795842 | 2020-12-30 02:01:22.694016 | cn-shanghai-g | broadcast_version        |   25    |      |
   +----------------------------+----------------------------+---------------+--------------------------+---------+------+
   5 rows in set (0.00 sec)

   ```

   对于 Root Service 未发起相关 Zone 合并的情况，按以下方法排查。

      1. 首先排查 RootService 合并调度线程是否有报错。

        如果有返回值，则说明合并调度线程存在错误。

        ```shell
        grep "daily.*merge.*ret=-" rootservice.log

        ```
      2. 然后检查集群是否正在补副本。

        如果以下查询有返回值，则说明正在进行副本的负载均衡。

        ```shell
        obclient> select count(*) from __all_virtual_replica_task;

        ```
 4. 确认未合并副本信息。

   本例继续假设当前要合并的目标版本是 `25`，查询 meta 表查看 `data_version != 25` 的副本以缩小排查范围。

      - 对于 OceanBase 数据库 V1.X 版本，查询 `__all_virtual_core_meta_table`、`__all_virtual_core_root_table`、`__all_root_table` 与 `__all_meta_table` 表。
      - 对于 OceanBase 数据库 V2.X 及后续版本，查询 `__all_virtual_core_meta_table`、`__all_virtual_core_root_table`、`__all_root_table` 和 `__all_virtual_meta_table` 表。

   ```shell
   obclient> select * from __all_virtual_meta_table where data_version != 25 limit 10;
   +-----------+------------------+--------------+---------------+----------+----------------------------+----------------------------+----------+---------+---------------+---------------+------+-----------------------------------------------------------------------------------------------------------+-----------+-----------+--------------+---------------+--------------+-----------------+--------------------+--------------------+-------------+---------+--------------+---------------+-----------------------+------------+--------------------+--------+-----------+--------------------+------------------+
   | tenant_id | table_id         | partition_id | svr_ip        | svr_port | gmt_create                 | gmt_modified               | sql_port | unit_id | partition_cnt | zone          | role | member_list                                                                                               | row_count | data_size | data_version | data_checksum | row_checksum | column_checksum | is_original_leader | is_previous_leader | create_time | rebuild | replica_type | required_size | status                | is_restore | partition_checksum | quorum | fail_list | recovery_timestamp | memstore_percent |
   +-----------+------------------+--------------+---------------+----------+----------------------------+----------------------------+----------+---------+---------------+---------------+------+-----------------------------------------------------------------------------------------------------------+-----------+-----------+--------------+---------------+--------------+-----------------+--------------------+--------------------+-------------+---------+--------------+---------------+-----------------------+------------+--------------------+--------+-----------+--------------------+------------------+
   |      1001 | 1100611139463766 |            0 | xxx.xxx.x.xa |     xxxx | 2020-12-29 10:34:15.176561 | 2020-12-29 10:34:15.205753 |     2881 |    1001 |             0 | cn-shanghai-e |    1 | xxx.xxx.x.xx:2882:1609209255175464,xxx.xxx.x.xx:2882:1609209255175464,xxx.xxx.x.xx:2882:1609209255175464 |         0 |         0 |           24 |             0 |            0 |                 |                  0 |   1609209255204831 |           0 |       0 |            0 |             0 | REPLICA_STATUS_NORMAL |          0 |                  0 |      3 |           |                  0 |              100 |
   +-----------+------------------+--------------+---------------+----------+----------------------------+----------------------------+----------+---------+---------------+---------------+------+-----------------------------------------------------------------------------------------------------------+-----------+-----------+--------------+---------------+--------------+-----------------+--------------------+--------------------+-------------+---------+--------------+---------------+-----------------------+------------+--------------------+--------+-----------+--------------------+------------------+
   1 row in set (0.07 sec)

   ```

   根据上面的信息，发现是 pkey 为`{tid:1100611139463766, partition_id:0}` 的表在 `xxx.xxx.x.xa:xxxx` 机器上未合并。

   也可以通过搜索 `rootservice.log` 定位是哪个表阻塞了合并。

### OceanBase 数据库 V4.X 版本

1. 找到未合并完成的租户 ID。

   ```sql
   select* from CDB_OB_MAJOR_COMPACTION where STATUS != "IDLE";

   ```
 2. 查询 server 级别进度表，看有多少分区没有合并完成。

   ```sql
   select * from __all_virtual_server_compaction_progress where tenant_id = xxx;

   ```

   ![1](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/knowledge-base/database/transfer-compaction/compaction/how-to-troubleshoot-oceanbase-database-merge-timeout-1.png)

   如果 comments 字段显示 `TABLET_COMPACTION_FINISHED`，表示存储层所有 Tablet 都合并完成。
 3. 看分区级别进度表，可以找到没有合并完成的分区及 TRACE_ID。

   ```sql
   select * from __all_virtual_tablet_compaction_progress where tenant_id = xxx;

   ```

   ![2](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/knowledge-base/database/transfer-compaction/compaction/how-to-troubleshoot-oceanbase-database-merge-timeout-2.png)
 4. 通过 SSTable 信息表可以看到 SSTable 的数据量和数据分布。

   ```sql
   select * from GV$OB_SSTABLES where tenant_id = xxx and tablet_id = xxx and svr_ip = "xxx";

   ```

   以下图为例，数据都集中在 MINI/MINOR SSTable中，MAJOR SSTable 中没有数据。撞上了并行合并的 BAD_CASE，导致合并比较慢。

   ![3](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/knowledge-base/database/transfer-compaction/compaction/how-to-troubleshoot-oceanbase-database-merge-timeout-3.png)

上一篇

[为什么导数的时候 minor freeze 会越来越慢](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000209926)

下一篇

[租户 Locality 变更失败，合并超时](https://www.oceanbase.com/knowledge-base/oceanbase-database-20000000005) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
