首页 > 解决方案 > 对 Oracle 数据库运行 Liquibase GenerateChangeLog 命令导致空闲,在特定点之后日志文件/控制台中没有输出

问题描述

我正在尝试DatabaseChangeLog.xml针对具有特定模式的现有 Oracle 数据库创建新的 Liqubase 文件,以从中获取数据库结构。目标是用 changeSet 格式替换现有的 sql 脚本,并使 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

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

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.jar在同一个目录中liquibase.properties

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

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

提前致谢。

编辑:实际上它在工作 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

但是模式中有数据/表。

标签: xmloraclecommand-line-interfaceliquibaseojdbc

解决方案


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

确保复制从下面提到的位置下载的 liquibase-zipojdbc8-19.3.0.0.jarlib文件夹中。我已经从这里下载了 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 文件中替换了这样的属性,它工作正常。注意之间没有空格

键=值

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

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

推荐阅读