---
title: github-fill
description: 一键诊断分析日志 本文适用于独立部署 obdiag 的场景，使用 obdiag analyze log 命令可对 OceanBase 的日志进行分析，找出发生过的错误信息。 如果是 obd 部署的集群，可直接通过 obd 侧诊断命令组对所选集群进行信息收集，详细命令可参考 诊断工具命令组 。 使用说明 obdiag …
---
切换语言

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

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*5ZXST55u540AAAAAAAAAAAAADiGDAQ/original) 敏捷诊断工具V 2.4.0

# 一键诊断分析日志

更新时间：2026-04-13 17:11:17

[编辑](https://github.com/oceanbase/odt-doc/edit/V2.4.0/zh-CN/450.analyze/501.analyze_log.md)  

本文适用于独立部署 obdiag 的场景，使用 `obdiag analyze log` 命令可对 OceanBase 的日志进行分析，找出发生过的错误信息。

如果是 obd 部署的集群，可直接通过 obd 侧诊断命令组对所选集群进行信息收集，详细命令可参考 [诊断工具命令组](https://www.oceanbase.com/docs/community-obd-cn-10000000002049483)。

## 使用说明

```shell
obdiag analyze log [options]

```

使用该命令可以一键在线分析 OceanBase 集群的日志，或者通过 `--files` 开启离线分析模式。

选项说明如下：

| 选项名 | 是否必选 | 数据类型 | 默认值 | 说明 |
| --- | --- | --- | --- | --- |
| --from | 否 | string | 默认为空 | 日志收集的开始时间，格式为: `yyyy-mm-dd hh:mm:ss`。   #### 说明    若使用的 obdiag 为 V2.0.0 之前版本，配置该选项时无需加引号，否则会报错。V2.0.0 及之后版本不再限制配置该选项时是否加引号。 |
| --to | 否 | string | 默认为空 | 日志收集的结束时间，格式为: `yyyy-mm-dd hh:mm:ss`。   #### 说明    若使用的 obdiag 为 V2.0.0 之前版本，配置该选项时无需加引号，否则会报错。V2.0.0 及之后版本不再限制配置该选项时是否加引号。 |
| --since | 否 | string | 默认为空 | 日志收集最近的某段时间，格式为: `<n> <m\|h\|d>`，其中，n 表示待输入的时间数字，m 表示分钟，h 表示小时，d 表示天，例如 `30m` 表示分析最近 30 分钟的日志。 |
| --scope | 否 | string | all | 选择分析的 OceanBase 集群日志类型，可配置值为 `observer、election、rootservice、all`。 |
| --grep | 否 | string | 默认为空 | 选择查询的关键字。 |
| --store_dir | 否 | string | 默认为命令执行的当前路径 | 存储结果的本地路径。 |
| --log_level | 否 | string | WARN | 选择分析的 OceanBase 集群日志等级，可配置的日志等级从低到高依次为 `DEBUG, TRACE, INFO, WDIAG, WARN, EDIAG, ERROR`。分析的时候会分析包含选定等级以及以上等级的日志。 |
| --files | 否 | string | 默认为空 | `--files` 是离线分析日志文件模式，一旦指定 `--files` 则进入离线分析日志模式，需要传递本 OceanBase 日志或者日志路径，离线分析模式下 `--from`、`--to`、`--since`、`--ob_install_dir` 设置将不需要设置。 |
| -c | 否 | string | `~/.obdiag/config.yml` | 配置文件路径。 |
| --inner_config | 否 | string | 默认为空 | obdiag 自用的配置。 |
| --config | 否 | string | 默认为空 | obdiag 被诊断集群的配置，固定样式：--config key1=value1 --config key2=value2。 |

#### 说明

- 本文所指的在线分析指的是 OceanBase 集群在线运行状态，日志分布在各个 OBServer 节点上。
 - 本文所指的离线分析模式是 `--files` 参数传递下，可以分析已经收集到 obdiag 部署机器上的 OBServer 日志。

## 使用示例

### 方式一：无配置文件使用（开箱即用）

#### 说明

本节命令中使用的详细配置介绍可参见 [obdiag 配置](https://www.oceanbase.com/docs/common-obdiag-cn-1000000001326824)。

- 在线分析日志示例：

  ```shell
  obdiag analyze log --from "2023-10-08 10:25:00" --to "2023-10-08 11:30:00" \
    --config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
    --config obcluster.servers.nodes[1].ip=xx.xx.xx.xx.2 \
    --config obcluster.servers.global.ssh_username=test \
    --config obcluster.servers.global.ssh_password=****** \
    --config obcluster.servers.global.home_path=/home/admin/oceanbase

  ```

  输出如下：

  ```shell
  ...
  FileListInfo:
  +----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  | Node           | LogList                                                                                                                                                                                                               |
  +================+=======================================================================================================================================================================================================================+
  | xx.xx.xx.xx   | ['observer.log.20231008104204260', 'observer.log.20231008111305072', 'observer.log.20231008114410668', 'observer.log.wf.20231008104204260', 'observer.log.wf.20231008111305072', 'observer.log.wf.20231008114410668'] |
  +----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  ...

  Analyze OceanBase Online Log Summary:
  +----------------+-----------+------------------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | Node           | Status    | FileName                                                                     |   ErrorCode | Message                                                                                                                       |   Count |
  +================+===========+==============================================================================+=============+===============================================================================================================================+=========+
  | xx.xx.xx.xx    | Completed | analyze_pack_20231008171201/xx_xx_xx_xx/observer.log.20231008104204260       |       -5006 | You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use |       2 |
  +----------------+-----------+------------------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | xx.xx.xx.xx    | Completed | analyze_pack_20231008171201/xx_xx_xx_xx/observer.log.20231008111305072       |       -5006 | You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use |       8 |
  +----------------+-----------+------------------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | xx.xx.xx.xx    | Completed | analyze_pack_20231008171201/xx_xx_xx_xx/observer.log.20231008114410668       |       -5006 | You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use |      10 |
  +----------------+-----------+------------------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | xx.xx.xx.xx    | Completed | analyze_pack_20231008171201/xx_xx_xx_xx/observer.log.20231008114410668       |       -4009 | IO error                                                                                                                      |      20 |
  +----------------+-----------+------------------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  For more details, please run cmd 'cat analyze_pack_20231008171201/result_details.txt'

  ```
 - 快捷分析最近一段时间的日志：

  ```shell
  # 在线分析最近一小时的日志，该指令执行的时候会从远程主机上拉取最近一小时的日志进行分析，诊断出出现过的错误
  obdiag analyze log --since 1h \
    --config obcluster.servers.nodes[0].ip=xx.xx.xx.1 \
    --config obcluster.servers.nodes[1].ip=xx.xx.xx.xx.2 \
    --config obcluster.servers.nodes[2].ip=xx.xx.xx.xx.3 \
    --config obcluster.servers.global.home_path=/home/admin/oceanbase

  # 在线分析最近一小时的日志，该指令执行的时候会从远程主机上拉取最近一小时的日志进行分析，诊断出出现过的错误
  # 提供 sys 租户的连接信息，让 obdiag 自动帮你获取集群各节点的 ip 地址
  obdiag analyze log --since 1h \
    --config db_host=xx.xx.xx.xx \
    --config db_port=xxxx \
    --config tenant_sys.user=root@sys \
    --config tenant_sys.password=*** \
    --config obcluster.servers.global.ssh_username=test \
    --config obcluster.servers.global.ssh_password=****** \
    --config obcluster.servers.global.home_path=/home/admin/oceanbase

  # 在线分析最近 30 分钟的日志，该指令执行的时候会从远程主机上拉取最近30分钟的日志进行分析，诊断出出现过的错误
  # 提供 sys 租户的连接信息，让 obdiag 自动帮你获取集群各节点的 ip 地址
  obdiag analyze log --since 30m \
    --config db_host=xx.xx.xx.xx \
    --config db_port=xxxx \
    --config tenant_sys.user=root@sys \
    --config tenant_sys.password=*** \
    --config obcluster.servers.global.ssh_username=test \
    --config obcluster.servers.global.ssh_password=****** \
    --config obcluster.servers.global.home_path=/home/admin/oceanbase

  ```
 - 离线分析日志示例

  ```shell
  $ ls -lh test/
  -rw-r--r--  1 admin  staff   256M Oct  8 17:24 observer.log.20231008104204260
  -rw-r--r--  1 admin  staff   256M Oct  8 17:24 observer.log.20231008111305072
  -rw-r--r--  1 admin  staff   256M Oct  8 17:24 observer.log.20231008114410668
  -rw-r--r--  1 admin  staff    18K Oct  8 17:24 observer.log.wf.20231008104204260
  -rw-r--r--  1 admin  staff    19K Oct  8 17:24 observer.log.wf.20231008111305072
  -rw-r--r--  1 admin  staff    18K Oct  8 17:24 observer.log.wf.20231008114410668

  $ obdiag analyze log --files test/

  Analyze OceanBase Offline Log Summary:
  +-----------+-----------+-----------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | Node      | Status    | FileName                                                              |   ErrorCode | Message                                                                                                                       |   Count |
  +===========+===========+=======================================================================+=============+===============================================================================================================================+=========+
  | 127.0.0.1 | Completed | analyze_pack_20231008172144/127_0_0_1_/observer.log.20231008104204260 |       -5006 | You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use |       2 |
  +-----------+-----------+-----------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | 127.0.0.1 | Completed | analyze_pack_20231008172144/127_0_0_1_/observer.log.20231008111305072 |       -5006 | You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use |       8 |
  +-----------+-----------+-----------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | 127.0.0.1 | Completed | analyze_pack_20231008172144/127_0_0_1_/observer.log.20231008114410668 |       -5006 | You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use |      10 |
  +-----------+-----------+-----------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  | 127.0.0.1 | Completed | analyze_pack_20231008172144/127_0_0_1_/observer.log.20231008114410668 |       -4009 | IO error                                                                                                                      |      20 |
  +-----------+-----------+-----------------------------------------------------------------------+-------------+-------------------------------------------------------------------------------------------------------------------------------+---------+
  For more details, please run cmd 'cat analyze_pack_20231008172144/result_details.txt'

  ```
 - 离线分析指定 observer 日志：

  ```shell
  # 离线分析指定的日志文件
  obdiag analyze log --files observer.log.20230831142211247

  ```

### 方式二：有配置文件使用

需要确保已经在 obdiag 配置文件 `~/.obdiag/config.yml` 中配置好需要收集节点的登录信息。相关的详细配置介绍，参见 [obdiag 配置](https://www.oceanbase.com/docs/common-obdiag-cn-1000000001326824)。。

  ```shell
  obdiag analyze log --from "2023-10-08 10:25:00" --to "2023-10-08 11:30:00"

  ```shell
  # 在线分析最近一小时的日志，该指令执行的时候会从远程主机上拉取最近一小时的日志进行分析，诊断出出现过的错误
  obdiag analyze log --since 1h

  # 在线分析最近 30 分钟的日志，该指令执行的时候会从远程主机上拉取最近30分钟的日志进行分析，诊断出出现过的错误
  obdiag analyze log --since 30m

  ```
 - 离线分析指定 observer 日志：

  ```

 上一篇 下一篇 ![有帮助](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) 咨询热线
