使用Liquibase生成AWS Redshift变更日志遇information_schema.sequences不存在错误
解决Liquibase生成AWS Redshift变更日志时的"relation 'information_schema.sequences'不存在"错误
问题概述
使用Liquibase 4.20.0跟踪现有AWS Redshift数据库,执行generate-changelog命令时触发错误,核心报错为relation "information_schema.sequences" does not exist,导致事务中止,根源是Liquibase未正确适配Redshift的元数据存储结构。
错误执行日志
❯ liquibase generate-changelog --changeLogFile="gen.sql" #################################################### ## _ _ _ _ ## ## | | (_) (_) | ## ## | | _ __ _ _ _ _| |__ __ _ ___ ___ ## ## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ ## ## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ ## ## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| ## ## | | ## ## |_| ## ## ## ## Get documentation at docs.liquibase.com ## ## Get certified courses at learn.liquibase.com ## ## Free schema change activity reports at ## ## https://hub.liquibase.com ## ## ## #################################################### Starting Liquibase at 20:27:03 (version 4.20.0 #7837 built at 2023-03-07 16:25+0000) Liquibase Version: 4.20.0 Liquibase Open Source 4.20.0 by Liquibase Unexpected error running Liquibase: ERROR: current transaction is aborted, commands ignored until end of transaction block - Caused by: ERROR: relation "information_schema.sequences" does not exist
Liquibase配置文件(liquibase.properties)
changeLogFile:report.changelog-root.xml url: jdbc:redshift://localhost:1234/project_name username: <<UserGoesHere>> password: <<Passy-McPasswordFace>> driver: com.amazon.redshift.jdbc42.Driver classpath: lib/liquibase-redshift-4.20.0.jar
解决方案
Redshift不支持information_schema.sequences视图(序列元数据存储在pg_catalog.pg_sequences中),需通过以下步骤确保Liquibase使用Redshift专属适配逻辑:
显式指定Redshift数据库类:在liquibase.properties中添加配置,强制Liquibase加载Redshift适配,避免通用JDBC适配查询错误的元数据表:
databaseClass: liquibase.database.core.RedshiftDatabase修正JDBC URL配置:若使用非默认schema,在URL中添加
currentSchema参数,确保Liquibase访问正确的schema:url: jdbc:redshift://localhost:1234/project_name?currentSchema=你的schema名称验证扩展加载路径:检查
liquibase-redshift-4.20.0.jar是否被正确加载,可改为绝对路径配置classpath:classpath: "C:/Program Files/liquibase/lib/liquibase-redshift-4.20.0.jar"升级Liquibase版本:若上述方法无效,升级到4.24.0及以上版本,新版本修复了Redshift元数据查询的适配问题。
内容的提问来源于stack exchange,提问作者AdamSane
相关产品推荐
相关产品推荐

