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

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

划线反馈

# OceanBase 数据库时钟源排查指南

更新时间：2026-06-08 02:41

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

OceanBase 集群的正常运行依赖稳定的时钟源，同集群内 OBServer 服务器间如果发生较大系统时间偏差（例如异常时钟跃变），可能导致预期外集群级稳定性风险，导致表分区无法选主成功，进而影响数据库访问。本文主要介绍 OceanBase 数据库及相关产品时钟源检查的方法。

## 适用版本

OceanBase 数据库所有版本

## 基础设施层检查

由于虚机相比物理机存在时间不稳定风险，可能导致链路中时钟源自守时，整个时钟源链路要求使用物理设备。 时钟源服务架构为：

OBServer -> 本地时钟源 -> 上级时钟源 -> 外部时钟源

其中，外部时钟源选择北斗 + GPS 或北斗 + 原子钟；本地和上级时钟源选择物理机。

时钟源要求满足以下标准：

- 支持 NTP v1、v2、v3、v4，(RFC1119&1305)、SNTP(RFC2030)、Telnet(RFC854)、TIME(RFC868) 与 DAYTIME(RFC867)
 - 用户容量：NTP 请求量支持 20000 次/秒，可支持数万台客户端
 - 守时精度小于 3 ms/年
 - 日平均准确度优于 1E-12
 - 日漂移率优于 3E-12
 - 秒稳定度优于 1E-11

## OceanBase 一般部署形态的检查方法

本节内容适用于打通 SSH 并安装 PGM 工具的场景。

1. 各 OBServer 服务器间打通 SSH 连接。

   在任一 OBServer 服务器执行以下命令，其中 `dest_ip` 为其余各 OBServer 的 IP 地址。

   ```unknow
   [admin@hostname ~]$ ssh-keygen -t rsa
   [admin@hostname ~]$ cat id_dsa.pub >> ~/.ssh/authorized_keys
   [admin@hostname ~]$ chmod 644 authorized_keys
   [admin@hostname ~]$ scp -r ~/.ssh dest_ip:~/

   ```
 2. 在各 OBServer 服务器上安装 PGM 工具。

   ```unknow
   [root@hostname /]# yum install -y pgm

   ```
 3. 通过 admin 用户登录任意一台 OBServer 服务器，在本地创建一个包含所有 OBServer 的 IP 地址的文件 `oblist`。

   ```unknow
   xxx.xxx.xx.xx1
   xxx.xxx.xx.xx2
   xxx.xxx.xx.xx3

   ```
 4. 检查当前的 Chronyc 的同步状态。如果状态为 `Normal`，则表示时钟同步。

   ```unknow
   [admin@hostname ~]$ sudo pgm -b -f oblist -l root "chronyc -n tracking"|grep -E "SUCCESS|Leap"
   [1] 14:52:03 [SUCCESS] xxx.xxx.xx.xx1
   Leap status          : Normal
   [2] 14:52:03 [SUCCESS] xxx.xxx.xx.xx2
   Leap status          : Normal
   [3] 14:52:03 [SUCCESS] xxx.xxx.xx.xx3
   Leap status          : Normal

   ```
 5. 检查 OBServer 服务器当前的 Chronyc Offset。

   多次执行以下命令，如果结果小于 `100000 us`，则表示时钟同步在可接受范围内。

   ```unknow
   [admin@hostname ~]$ sudo pgm -b -f oblist -l root "chronyc sources -v"|grep -E "SUCCESS|^\^\*"
   MS Name/IP address            strarum Poll Reach LastRX Last sample
   ==================================================================================
   ^- am35.ntp1.tbsite.net             6  4    377      15 -251us [ -251us]   -/-  128ms
   ^* ntp2.tbsite.net                  6  4    377      16 -322us [ -340us]   -/-  126ms

   ```
 6. 横向检查当前 OBServer 服务器间操作系统的时间对比。

   如果打印出的信息中第三列小于 `100`，且第三列正值减去负值之差小于 `100`，则表示各操作系统间时钟同步。

   ```unknow
   [admin@hostname ~]$  sudo pgm -f oblist -l root "clockdiff -o `head -1 oblist`" |awk '$3 !=0'
   [1] 18:11:31 [SUCCESS] xxx.xxx.xx.xx1
   1624950809 0 1
   [2] 18:11:31 [SUCCESS] xxx.xxx.xx.xx2
   1624950809 0 0
   [3] 18:11:31 [SUCCESS] xxx.xxx.xx.xx3
   1624950809 1 2

   ```

## OceanBase 数据库其他部署形态的检查方法

本节内容适用于对于不具备 SSH 打通与 PGM 工具的场景，可以通过以下方式检查各 OBServer 服务器间的时钟同步状态。

1. 检查各 OBServer 服务器操作系统间的时间对比。 如果打印出的信息中第三列小于 `100`，且第三列正值减去负值之差小于 `100`，则表示各操作系统间时钟同步。

   ```unknow
   [admin@hostname ~]$ cat oblist|while read line; do clockdiff -o $line; done
   1624950809 0 0
   1624950809 0 0
   1624950809 0 0

   ```
 2. 检查 Chronyc 同步情况。

   如果 `Leap status` 状态为 `Normal`，则表示时钟同步。

   ```unknow
   [admin@hostname ~]$  chronyc -n tracking

   ```
 3. 检查 OBServer 服务器当前的 Chronyc Offset。

   如果 `Sample` 列方括号中的值小于 `100000 us`，则表示时钟同步在可接受范围内。

   ```unknow
   [admin@hostname ~]$ chronyc sources -v

   ```
 4. 运行 `ntpstat` 与 `ntpq` 检查 NTP 服务器状态。

   如果 `ntpstat` 结果为 `synchronised to NTP server`，并且 `ntpq` 命令的结果中 `offset` 的值小于 `100ms`，则表示 NTP 服务时钟同步。

   ```javascript
   [root@hostname /]# ntpstat
   synchronised to NTP server (xx.xxx.xx.xxx) at stratum 4
      time correct to within 4 ms
      polling server every 32 s
   [root@hostname /]# ntpq -p|grep -E "\*|\=|remote"
      remote         refid           st t when poll reach    delay     offset     jitter
   ==========================================================================
   *xxxxxxxxxxx       xxxxx           2 u   16  64  377       1.333     0.046   0.033

   ```

上一篇

[如何调整 OBServer 的操作系统时间](https://www.oceanbase.com/knowledge-base/oceanbase-database-20000000070)

下一篇

[ntpdate 强制快速同步时间](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000210118) ![有帮助](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) 咨询热线
