2

I am trying to create a new PostgreSQL database using Liquibase. I am using this syntax:

<?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.0.xsd">

<changeSet id="23" author="pre_actions">
    <sqlFile dbms="postgresql" path="src\main\resources\liquibase\createDB.sql" />
</changeSet>

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.6.3:update (default-cli) on project cre_roles_schemas: Error setting up or running Liquibase: Migration failed for change set src/main/resources/liquibase/createDB.xml::23::pre_actions: [ERROR]
Reason: liquibase.exception.DatabaseException: ERROR: CREATE DATABASE cannot run inside a transaction block [Failed SQL: --Create DB octopusdb [ERROR] create database octopusdb owner octopus]

--The create database statement works fine directly from psql

Tamar
  • 145
  • 4
  • 15
  • You could try to run `SET AUTOCOMMIT = ON` in your PostgreSQL-client (i.E. psql) – iLuvLogix Jun 24 '19 at 11:04
  • 1
    I'm not sure what the switch runInTransaction="false" on Tag changeSet exactly does, but give it a shot. But as stated in https://stackoverflow.com/questions/34283630/create-databases-with-liquibase-on-empty-mysql-instance, Liquibase is not the right tool to create a DB. – teclis Jun 24 '19 at 11:09
  • Adding the attribute runInTransaction="false" to changeSet indeed allowed the database to be created. Thanks teclis! – Tamar Jun 25 '19 at 08:29

0 Answers0