---
title: "ob_tenant_long_trans_exist OceanBase 租户存在长事务 - 云平台 OCP V4.3.0 | OceanBase 文档中心"
description: ob_tenant_long_trans_exist OceanBase 租户存在长事务 告警描述 该告警监测租户中是否存在持续时长超过阈值（默认为 1200 秒）的事务，存在则上报告警。 告警原理 下表列出了该告警监控逻辑中涉及的关键参数。 参数 值 监控指标 long_trans_max_duration_sec…
---
切换语言

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

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*lJTmRZ61jSUAAAAAAAAAAAAADiGDAQ/original) 云平台 OCPV 4.3.0

# ob_tenant_long_trans_exist OceanBase 租户存在长事务

更新时间：2026-04-14 11:55:54

[编辑](https://github.com/oceanbase/ocp-doc/edit/V4.3.0/zh-CN/1900.reference-guide/100.alarm-reference/200.ob-alert/5100.ob_tenant_long_trans_exist.md)  

## 告警描述

该告警监测租户中是否存在持续时长超过阈值（默认为 1200 秒）的事务，存在则上报告警。

## 告警原理

下表列出了该告警监控逻辑中涉及的关键参数。

| 参数 | 值 |
| --- | --- |
| 监控指标 | long_trans_max_duration_seconds |
| 数据来源 | - **采集 SQL：**     - OceanBase 版本为 V2.2.7 以下时：``select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) QUERY_TIMEOUT(%d) */ tenant_id, 0 as tenant_id_xa, trans_id, -1 as tx_id, -1 as ls_id, `partition`, floor(unix_timestamp(ctx_create_time) *1000000) as ctx_create_time, session_id, participants, trans_type, part_trans_action, sql_no, 0 as log_size_byte, 'NULL' as globalid from __all_virtual_trans_stat where svr_ip = ? and svr_port = ? and is_exiting != 1``     - OceanBase 版本为 V2.2.7 以上、V3.2 以下时：``select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) QUERY_TIMEOUT(%d) */ a.tenant_id, b.tenant_id as tenant_id_xa, a.trans_id, -1 as tx_id, -1 as ls_id, `partition`, floor(ctx_create_time) as ctx_create_time, session_id, participants, trans_type, part_trans_action, sql_no, 0 as log_size_byte, 'NULL' as globalid from (select tenant_id, svr_ip, trans_id, `partition`, unix_timestamp(ctx_create_time) *1000000 as ctx_create_time, session_id, participants, trans_type, part_trans_action, sql_no from __all_virtual_trans_stat where svr_ip = ? and svr_port = ? and is_exiting != 1) a left join __all_virtual_global_transaction b on a.tenant_id = b.tenant_id and a.trans_id = b.trans_id``     - OceanBase 版本为 V3.2 及以上、V4.0 以下时：``select /*+ MONITOR_AGENT READ_CONSISTENCY(WEAK) QUERY_TIMEOUT(%d) */ a.tenant_id, b.tenant_id as tenant_id_xa, a.trans_id, -1 as tx_id, -1 as ls_id, `partition`, floor(ctx_create_time) as ctx_create_time, session_id, participants, trans_type, part_trans_action, sql_no, log_size_byte, 'NULL' as globalid from (select tenant_id, svr_ip, trans_id, `partition`, unix_timestamp(ctx_create_time) *1000000 as ctx_create_time, session_id, participants, (pending_log_size + flushed_log_size) as log_size_byte, trans_type, part_trans_action, sql_no from __all_virtual_trans_stat where svr_ip = ? and svr_port = ? and is_exiting != 1) a left join __all_virtual_global_transaction b on a.tenant_id = b.tenant_id and a.trans_id = b.trans_id``     - OceanBase 版本为 V4.0 及以上、V4.1 以下时：`select /*+ MONITOR_AGENT QUERY_TIMEOUT(%d) */tenant_id, 0 as tenant_id_xa, 'NULL' as trans_id, tx_id, ls_id, 'NULL' as 'partition', floor(unix_timestamp(ctx_create_time) *1000000) as ctx_create_time, session_id, participants, (case tx_type when 'DISTRIBUTED' then 2 when 'LOCAL' then 1 when 'UNDECIDED' then -1 else 0 end) as trans_type, (case action when 'START TASK' then 1 when 'END TASK' then 2 when 'COMMIT' then 3 when 'ABORT' then 4 when 'DIED' then 5 when 'END' then 6 else 0 end) as part_trans_action, -1 as sql_no, (pending_log_size + flushed_log_size) as log_size_byte, 'NULL' as globalid from v$ob_transaction_participants where svr_ip = ? and svr_port = ?`     - OceanBase 版本为 V4.1 及以上时：`select /*+ MONITOR_AGENT QUERY_TIMEOUT(%d) */ tenant_id, 0 as tenant_id_xa, 'NULL' as trans_id, tx_id, ls_id, 'NULL' as 'partition', floor(unix_timestamp(ctx_create_time) *1000000) as ctx_create_time, session_id, participants, (case tx_type when 'DISTRIBUTED' then 2 when 'LOCAL' then 1 when 'UNDECIDED' then -1 else 0 end) as trans_type, (case action when 'START TASK' then 1 when 'END TASK' then 2 when 'COMMIT' then 3 when 'ABORT' then 4 when 'DIED' then 5 when 'END' then 6 else 0 end) as part_trans_action, -1 as sql_no, (pending_log_size + flushed_log_size) as log_size_byte, globalid from v$ob_transaction_participants where svr_ip = ? and svr_port = ?` - **事务延迟：**   `select max((collect_time - ctx_create_time)/1000000) as trans_max_duration_seconds from ob_hist_trans_stat where ctx_trans_state=2` |
| 采集指标 | collect_time,ctx_create_time |
| 监控表达式 | max((collect_time - ctx_create_time)/1000000) |
| 采集周期 | 60 秒 |

#### 说明

系统参数 `ocp.alarm.datasource.trans-min-duration-seconds` 决定阈值大于多少秒时会产生告警，故告警阈值需不低于该系统参数的设定值，默认为 60 秒。

## 规则信息

| 监控指标 | 默认阈值（单位：秒） | 监控指标来源 | 检测周期 | 消除周期 |
| --- | --- | --- | --- | --- |
| long_trans_max_duration_seconds | 1200 | 租户指标 | 60 秒 | 5 分钟 |

## 告警信息

| 告警触发方式 | 告警等级 | 范围 |
| --- | --- | --- |
| 基于监控指标的表达式 | 严重 | 租户 |

## 告警模板

- 告警概述

     - 模板：${alarm_target} ${alarm_name}
     - 样例：ob_cluster=obcluster-1:tenant_name=orac2:trans_hash={hash:10801753558860391353, inc:59202486, addr:"xxx.xxx.xxx.xxx:2882", t:1646993121179509} OceanBase 租户存在长事务
 - 告警详情

     - 模板：集群：${ob_cluster_name}，租户：${tenant_name} 存在长事务。会话 ID：${session_id}，事务 ID：${trans_hash}，事务类型：${trans_type}，事务创建时间：${trans_create_time}，事务最长持续时长：${value_shown}
     - 样例：集群：obcluster-1，租户：orac2 存在长事务。会话 ID：3221635048，事务 ID：{hash:10801753558860391353, inc:59202486, addr:"xxx.xxx.xxx.xxx:2882", t:1646993121179509}，事务类型：distribute，事务创建时间：2022-03-11T18:05:21.184+08:00，事务最长持续时长：25 天 19 小时 57 分 24.66 秒。

## 对系统的影响

长事务的存在易造成大量的阻塞和锁超时，影响其他事务的执行。

## 可能原因

少数派、磁盘满、内存爆或业务中存在大事务等都有可能出现长事务。

## 处理方法

1. 确认是否出现少数派情况。

   少数派出现一般因为 OBServer 节点异常或网络故障，会同时有 [ob_cannot_connected OceanBase 服务器无法连接](https://www.oceanbase.com/docs/common-ocp-1000000000827209)告警上报。

   如有该告警上报，则先参考该告警文档处理。然后再观察 5 分钟后本节所述告警是否消除。
 2. 确认是否磁盘空间不足。

   若磁盘空间不足，则会有下述告警同时上报，可先参考下述告警对应文档解决后，再观察 5 分钟后本节所述告警是否消除。

      - [ob_host_data_disk_percent_over_threshold OceanBase 主机数据目录磁盘使用率超限](https://www.oceanbase.com/docs/common-ocp-1000000000827262)
      - [ob_host_log_disk_percent_over_threshold OceanBase 主机日志目录磁盘使用率超限](https://www.oceanbase.com/docs/common-ocp-1000000000827268)
      - [ob_host_install_disk_percent_over_threshold OceanBase 主机安装目录磁盘使用率超限](https://www.oceanbase.com/docs/common-ocp-1000000000827204)
 3. 确认是否内存不足。

   若内存不足，则可能会伴随 [ob_host_mem_percent_over_threshold OceanBase 服务器内存使用率超限](https://www.oceanbase.com/docs/common-ocp-1000000000827317) 告警上报，处理方法请参考该告警的解决方法。
 4. 确认是否存在大事务。

   在 OCP 的 **性能诊断** 界面，通过 **TopSQL** 和 **SlowSQL** 页签中的内容查看是否有可疑 SQL，如执行时间过长的 SQL。

   如有，可通过 **诊断结果** 进行分析对 SQL 进行优化，同时结合业务判断是否能将大事务拆成小事务。
 5. 若以上方法都未能解决问题，请参考下述指令联系技术支持人员处理。

   ```sql
   -- 查看所有 Server 信息，用于确定是否存在异常 OBServer 节点
   select * from __all_server;

   -- 查看当前长事务
   SELECT *
   FROM __all_virtual_trans_stat
   WHERE is_exiting !=1 AND part_trans_action <= 2 AND ctx_create_time < DATE_SUB(NOW(), INTERVAL 1200 SECOND)
   LIMIT 100;

   ```

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