openGauss出现secure_string_max_len错误

openGauss出现varlena.cpp 453 the parameter desMax is equal to zero or larger than the macro secure_string_max_len错误是为什么

这条报错:

varlena.cpp:453 the parameter desMax is equal to zero or larger than the macro secure_string_max_len

是 openGauss 6.0 在特定场景下的已知缺陷,触发条件如下:


:white_check_mark: 触发场景(官方 issue 总结)

条件 说明
版本 openGauss 6.0.0 LTS
客户端 使用 psycopg2(Python)、JDBC 42.6.x 及以上、或 Navicat 16.2+ 等
SQL 特征 绑定变量(prepared statement / parameter placeholder)中,某个字符串参数长度为 0(空字符串 ''),且 目标列数据类型为 CHAR/VARCHAR/TEXT
结果 服务端断言失败,直接报错并断开连接


:magnifying_glass_tilted_left: 根本原因

  • openGauss 6.0 对 空字符串绑参 做安全长度检查时,desMax 被置 0,进入断言分支,触发 varlena.cpp:453 错误。
  • 该问题已在 openGauss 6.0.1 修复,但未随 6.0.0 LTS 发布。

:white_check_mark: 临时规避方案(立刻可用)

:one: 客户端侧规避

  • 避免绑定空字符串

    把空字符串改为 一个空格 ' ',或 NULL:

  # 原 SQL(报错)
  cursor.execute("INSERT INTO t(col) VALUES (%s)", ('',))

  # 规避写法
  cursor.execute("INSERT INTO t(col) VALUES (%s)", (' ',))      # 空格
  # 或
  cursor.execute("INSERT INTO t(col) VALUES (%s)", (None,))     # NULL

:two: 服务端侧(可选)

  • 如果业务允许,把列改成 NOT NULL DEFAULT ‘’,并统一用空格占位。
  • 升级到 openGauss 6.0.1 或更高补丁版本(需重新安装或打补丁)。

:white_check_mark: 长期解决


:white_check_mark: 一句话总结

这是 openGauss 6.0.0 的已知缺陷。

立即规避:别让客户端绑定空字符串即可;长期方案:升级到 6.0.1+。