SQLSTATE 25001 ERROR Class 25: Invalid Transaction State

active_sql_transaction DROP DATABASE cannot run inside a transaction block — 25001

PostgreSQL error "DROP 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

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

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

What the server log shows

ERROR:  DROP DATABASE cannot run inside a transaction block

Why PostgreSQL raises this — what the manual says

the DROP DATABASE reference (Notes):

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

Dropping a database deletes files irreversibly, which cannot participate in a rollback. PostgreSQL therefore forbids it inside a transaction and reports 25001.

Common causes

  • Running DROP DATABASE after BEGIN.
  • A migration framework wrapping statements in transactions.
  • Autocommit disabled on the connection.

How to fix it

  1. Run it standalone with autocommit on.
  2. Mark the step as non-transactional in migration tools.
  3. Use DROP DATABASE … WITH (FORCE) (PG13+) to disconnect users, still outside a transaction.

Related & next steps

Reference: PostgreSQL 18 — DROP DATABASE.

Was this helpful?