Pra*_*esh 7 postgresql liquibase liquibase-sql
我正在尝试使用 liquibase 在 PostgreSQL 上创建一个数据库。这是我的 dbchangelog 文件
<?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"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="testuser" id="3">
<sql dbms="postgresql"
endDelimiter=";">
CREATE DATABASE testdb;
</sql>
</changeSet>
</databaseChangeLog
Run Code Online (Sandbox Code Playgroud)
当我尝试从我的项目目录运行时,liquibase update我得到
Unexpected error running Liquibase: ERROR: CREATE DATABASE cannot run inside a transaction block [Failed SQL: (0) CREATE DATABASE testdb]
Run Code Online (Sandbox Code Playgroud)
我看到在 PostgreSQL 中设置 AUTOCOMMIT = ON 可以解决这个问题。但此方法仅适用于 PostgreSQL 9.4 及以下版本。但我正在使用 AWS RDS PostgreSQL 9.6.8
小智 11
简短:添加runInTransaction="false"到您的changeSet.
解释:
Liquibase 打开一个事务块是为了保证某个changeSet事务被完全执行或根本不被执行。
PostgreSQL 文档说:(CREATE DATABASE cannot be executed inside a transaction block.请参阅有关创建数据库的 PostgreSQL 文档!)
因此,显然存在冲突行为,只能通过不使用事务块来避免。
请注意,使用多个命令停用事务行为可能会导致更改集仅部分执行的问题。
| 归档时间: |
|
| 查看次数: |
2665 次 |
| 最近记录: |