You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Aurora PostgreSQL升级后Liquibase部署遇substring参数错误求助

问题描述
  • 环境:启用Babelfish的Aurora PostgreSQL,底层为PostgreSQL,通过T-SQL语法及1433端口访问
  • 操作:将Aurora PostgreSQL引擎从15.6升级至16.4
  • 现象:使用Liquibase部署脚本时触发错误,提示Argument data type char is invalid for argument 1 of substring function,但自身部署脚本中未使用substring函数,且升级前部署正常
  • 验证:本地环境已复现该问题

用到的Docker命令

docker run --rm -v $(pwd):/liquibase/changelog liquibase/liquibase --database-changelog-table-name='databasechangelog' --search-path='/liquibase/changelog' update  --url="jdbc:sqlserver://host:1433;databaseName=master;encrypt=true;trustServerCertificate=true" --changelog-file='Changelog.xml'  --username=******* --password='*******'

Changelog.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
        http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
    <includeAll  path="deploy"/>
</databaseChangeLog>

报错详情

Liquibase Open Source 4.31.1 by Liquibase
ERROR: Exception Details
ERROR: Exception Primary Class:  SQLServerException
ERROR: Exception Primary Reason:  Argument data type char is invalid for argument 1 of substring function.
ERROR: Exception Primary Source:  Microsoft SQL Server 12.00.2000
Unexpected error running Liquibase: Argument data type char is invalid for argument 1 of substring function.
解决方案与排查方向

1. 升级Liquibase版本

你当前使用的Liquibase 4.31.1发布于2023年中,而Aurora PostgreSQL 16.4是较新的版本,Babelfish在PostgreSQL 16上的行为可能有迭代,旧版Liquibase的SQLServer适配逻辑未覆盖这些变化。直接升级到Liquibase最新稳定版(如4.28+及以上版本),新版本通常会修复对新数据库版本的兼容性问题。

2. 排查Babelfish兼容模式变更

PostgreSQL 16升级后,Babelfish的T-SQL兼容层可能对substring函数的参数类型校验更严格。Liquibase在维护自身元数据(读写databasechangelog表)时,可能生成了不符合新规则的SQL:

  • 开启Liquibase调试日志:在Docker命令中添加--log-level=DEBUG,查看底层执行的SQL语句,定位触发错误的具体语句
  • 检查Babelfish的配置参数,确认升级后是否启用了更严格的T-SQL兼容模式,必要时调整相关参数

3. 更新JDBC驱动

你使用SQLServer JDBC驱动连接Babelfish,该驱动对PostgreSQL 16上的Babelfish支持可能不足。尝试更新SQLServer JDBC驱动版本,或改用Babelfish官方推荐的JDBC驱动。如果使用Docker镜像,可以通过自定义镜像打包最新驱动,或挂载驱动文件到容器指定路径。

4. 重置Liquibase元数据表

Liquibase的databasechangelog表在升级后的Babelfish环境中可能存在字段类型不兼容的情况:

  • 先备份当前databasechangelog表数据
  • 删除该表后重新执行Liquibase update,让Liquibase重新创建适配新环境的元数据表
  • 或手动调整表中相关char类型字段为varchar类型,避免substring函数参数类型不匹配

内容的提问来源于stack exchange,提问作者Manjunath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 17:26:06