针对Oracle数据库运行Liquibase GenerateChangeLog命令导致空闲,并且在特定点之后日志文件/控制台中没有输出

问题描述

我试图针对具有特定模式的现有Oracle数据库创建新的Liqubase DatabaseChangeLog.xml文件,以从中获取db结构。目标是将现有的sql脚本替换为changeSet格式,并使Liquibase迁移可同时在PostgreSQL和Oracle数据库上进行。

我将liquibase.properties文件指定为:

changeLogFile: DatabaseChangelog.xml
schemas: schema1,schema2,schema3
driver: oracle.jdbc.OracleDriver
classpath: ojdbc8.jar
url: jdbc:oracle:thin:@host:port:SID
username: User
password: PASSWORD
logLevel: debug
logFile: log.txt

当我在cli中执行liquibase generateChangeLog时,我得到以下输出:

Liquibase Community 4.0.0 by Datical
Starting Liquibase at 12:44:52 (version 4.0.0 #19 built at 2020-07-13 19:45+0000)

,并在一段时间后输出错误:

Unexpected error running Liquibase: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to jdbc:oracle:thin:@host:port:SID with driver oracle.jdbc.OracleDriver.  Possibly the wrong driver for the given database URL
For more information,please use the --logLevel flag

log.txt的输出不包含任何错误消息,并且看来liquibase已很好地连接到数据库,但是日志意外结束。 这是一条日志:

[2020-09-14 12:44:52] FINE [liquibase.database] Properties:
[2020-09-14 12:44:52] FINE [liquibase.database] Key:'password' Value:'**********'
[2020-09-14 12:44:52] FINE [liquibase.database] Key:'user' Value:'USER'
[2020-09-14 12:44:52] FINE [liquibase.database] Connecting to the URL:'jdbc:oracle:thin:@host:port:SID' using driver:'oracle.jdbc.OracleDriver'
[2020-09-14 12:44:52] FINE [liquibase.servicelocator] Loaded liquibase.database.DatabaseConnection instance liquibase.database.jvm.JdbcConnection
[2020-09-14 12:44:52] FINE [liquibase.servicelocator] Loaded liquibase.database.DatabaseConnection instance com.datical.liquibase.ext.database.jvm.ProJdbcConnection
[2020-09-14 12:44:59] FINE [liquibase.database] Connection has been created
[2020-09-14 12:45:00] FINE [liquibase.database] Connected to USER@jdbc:oracle:thin:@host:port:SID
[2020-09-14 12:45:00] FINE [liquibase.database] Setting auto commit to false from true
...
[2020-09-14 12:45:40] FINE [liquibase.executor] Executing with the 'jdbc' executor

最后一行是日志文件中的最后一行。

Liquibase版本为Community 4.0.0,oracle驱动程序为ojdbc8.jar

我的ojdbc8.jarliquibase.properties位于同一目录。

数据库和用户凭据正确,并且我可以使用DBForge(具有相同地址和用户凭据的tnsnames.ora格式)连接到数据库。

有人试图从现有的oracle数据库创建新的DatabaseChangeLog.xml时遇到同样的问题吗?我很高兴看到任何建议。

谢谢。

已编辑: 实际上,经过1个小时的工作,它给了我一个输出:

Unexpected error running Liquibase: liquibase.exception.DatabaseException: java.sql.SQLRecoverableException: No data to read from socket
For more information,please use the --logLevel flag

但是架构中有数据/表。

解决方法

您可以使用命令行工具从现有架构中生成变更日志。 使用以下命令,并注意多余的空间,因为liquibase会抱怨这一点。

请确保将ojdbc8-19.3.0.0.jar复制到从下面提到的位置下载的liquibase-zip的 lib 文件夹中。 我从这里下载了liquibase.zip,并使用了以下命令 liquibase_zip

liquibase.bat --driver=oracle.jdbc.driver.OracleDriver --url="jdbc:oracle:thin:@localhost:1521/orcl" --username=TEST_A --password=test --changeLogFile=db.test.xml generateChangeLog

您可以使用相同的方法。我已经在liquibase.properties文件中替换了类似的属性,并且可以正常工作。请注意,之间没有空格

key = value

changeLogFile=DatabaseChangelog.xml
schemas=TEST
driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@localhost:1521/service_name
username=TEST_A
password=password
logLevel=debug
logFile=log.txt

对于SID,请替换这样的网址

url=jdbc:oracle:thin:@localhost:1521:sid

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...