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
- Run it standalone with autocommit on.
- Mark the step as non-transactional in migration tools.
- Use
DROP DATABASE … WITH (FORCE)(PG13+) to disconnect users, still outside a transaction.
Related & next steps
Reference: PostgreSQL 18 — DROP DATABASE.
Thanks — noted. This helps keep the database accurate.