---
title: 开启 SPM 功能影响 DDL 执行或导致 schema 内存占用大或影响 OBServer 重启-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于 开启 SPM 功能影响 DDL 执行或导致 schema 内存占用大或影响 OBServer 重启相关的常见问题和使用技巧，帮助您快速解决 开启 SPM 功能影响 DDL 执行或导致 schema 内存占用大或影响 OBServer 重启的难题。
---
切换语言

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

划线反馈

# 开启 SPM 功能影响 DDL 执行或导致 schema 内存占用大或影响 OBServer 重启

更新时间：2024-01-22 01:56

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

## 问题现象

租户系统变量 `optimizer_use_sql_plan_baselines` 为 `true` 时会开启 SPM 功能，会通过内部表持久化 plan。在 V4.0 之前的版本，SPM 会由 SQL 自动生成 `plan_baseline schema` 对象并通过 schema 的机制同步给整个集群。

该方式有以下几个问题。

1. 持久化 `plan_baseline schema` 对象需要走 DDL，由于 DDL 是集群内串行执行，由 SQL 自动触发的大量 DDL 可能会影响到业务正常的 DDL。
 2. `plan_baseline schema` 对象缺乏自动清理的机制，随着 SQL 的执行，`plan_baseline schema` 对象会越来越多，只增不减。这伴随两个问题。

   a. `plan_baseline schema` 对象过多导致 schema 内存占用大。

   b. `plan_baseline schema` 对象过多导致 OBServer 重启需要全量刷新schema，耗时长或者会超时。

SPM 功能开启引发问题举例如下。

- OBServer 出现 `plan_baseline schema` 内存占用大，以下 SQL 结果集大。

     - 获取 `plan_baseline` 对象数量信息，执行如下语句。

      ```shell
      obclient > SELECT tenant_id,count(*) FROM __all_virtual_tenant_plan_baseline_history GROUP BY tentant_id;

      ```

      输出结果如下。

      ```shell
      +-----------+----------+
      | tenant_id | count(*) |
      +----------------+-----+
      | xxxx      |   1681866|
      | xxxx      |     39161|
      +-----------+----------+

      ```
 - OBServer 刷新 schema 失败或 OBServer 重启失败。

      ```

      输出结果如下。

      ```shell
      +-----------+----------+
      | tenant_id | count(*) |
      +-----------+----------+
      | xxxx      |   1682091|
      | xxxx      |     58667|
      +-----------+----------+

      ```
     - 错误日志信息。

      ```shell
      WARN  [SQL.EXE] get_next_row (ob_execute_result.cpp:141) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=8] [dc=0] get next row from operator failed(ret=-4012)
      WARN  [SQL.SESSION] get_next_row (ob_result_set.cpp:570) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=5] [dc=0] get next row from exec result failed(ret=-4012)
      WARN  [SERVER] next (ob_inner_sql_result.cpp:197) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=9] [dc=0] get next row failed(ret=-4012)
      WARN  [SHARE.SCHEMA] fetch_plan_baselines (ob_schema_service_sql_impl.cpp:5079) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=6] [dc=1] failed to retrieve plan baseline schema(ret=-4012)
      WARN  [SERVER] inner_close (ob_inner_sql_result.cpp:170) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=7] [dc=0] result set close failed(ret=-4012, need_retry=false)
      WARN  [SERVER] close (ob_inner_sql_result.cpp:142) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=6] [dc=0] result set close failed(ret=-4012)
      WARN  [SHARE.SCHEMA] get_all_plan_baselines (ob_schema_service_sql_impl.cpp:1354) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=5] [dc=0] fetch plan_baselines failed(ret=-4012, schema_status={tenant_id:xxxxx, snapshot_timestamp:-1, readable_schema_version:-1}, schema_version=xxxxxx, tenant_id=xxxxx)
      WARN  [SHARE.SCHEMA] refresh_tenant_full_normal_schema (ob_server_schema_service.cpp:6374) [71151][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=11] [dc=0] get all plan_baseline schema failed(ret=-4012, schema_version=xxxxx, tenant_id=xxxxx)

      ```

## 问题原因

SPM 功能在 OceanBase V4.0 版本之前存在缺陷。

## 问题的风险及影响

- `plan_baseline schema` 对象过多影响正常业务 DDL 执行。
 - `plan_baseline schema` 内存占用大, 重启无法有效释放。
 - OBServer 重启超时。

## 影响的版本

OceanBase 数据库企业版 V4.x 之前所有版本。

## 解决方法及规避方式

### 解决方法

升级至问题已修复版本。目前已修复的版本包括 OceanBase 数据库企业版 V4.x 及其之后版本。

### 规避方式

- 租户关闭 SPM 功能。

  ```
  ```shell
  set @@global.optimimzer_use_sql_plan_baselines = '0';
  ```

  ```

  #### 注意

  OceanBase 数据库企业版 V4.0 之前的版本禁止使用 SPM 功能。
 - OBServer 重启时 `observer.log` 日志持续报 -4012，可尝试调大集群级配置项。

  ```
  ```shell
  ALTER SYSTEM SET internal_sql_execute_time = '10m';
  ```

  ```

  恢复正常之后还原缺省值。

  ```shell
   ALTER SYSTEM SET internal_sql_execute_time = '30s';

  ```

上一篇

[并行 DML(PDML) 性能不及预期的问题](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000225642)

下一篇

[OceanBase 数据库 MySQL 模式手工收集统计信息的方法](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000217860) ![有帮助](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) 咨询热线
