SQLSTATE 25001 ERROR Class 25: Invalid Transaction State

active_sql_transaction CREATE DATABASE cannot run inside a transaction block — 25001

PostgreSQL error "CREATE DATABASE cannot run inside a transaction block" (SQLSTATE 25001): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

CREATE DATABASE was issued inside an explicit transaction block. It cannot run transactionally, so PostgreSQL raises SQLSTATE 25001 (active_sql_transaction).

  • CREATE DATABASE issued after BEGIN.
  • Common with tools that wrap statements in transactions.
  • Must run with autocommit on.

What the server log shows

ERROR:  CREATE DATABASE cannot run inside a transaction block

Why PostgreSQL raises this — what the manual says

the CREATE DATABASE reference (Notes):

“CREATE DATABASE cannot be executed inside a transaction block.”

Creating a database copies template files and performs non-transactional filesystem work that cannot be rolled back. Therefore it cannot run inside a transaction, and PostgreSQL rejects it with 25001.

Common causes

  • Running CREATE DATABASE after BEGIN.
  • A migration tool wrapping each statement in a transaction.
  • Autocommit disabled on the connection.

How to fix it

  1. Run it standalone with autocommit on (outside any transaction).
  2. In migration tools, mark this step as non-transactional.
  3. Ensure the connection is in autocommit mode.

Related & next steps

Reference: PostgreSQL 18 — CREATE DATABASE.

Was this helpful?