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
- Run it standalone with autocommit on (outside any transaction).
- In migration tools, mark this step as non-transactional.
- Ensure the connection is in autocommit mode.
Related & next steps
Reference: PostgreSQL 18 — CREATE DATABASE.
Thanks — noted. This helps keep the database accurate.