Diagnostic Queries
Symptoms
VACUUM was issued inside an explicit transaction block (after BEGIN). VACUUM manages its own transactions and cannot run inside one, so PostgreSQL raises SQLSTATE 25001 (active_sql_transaction).
- Common when a tool wraps every statement in a transaction.
- Same restriction applies to several maintenance commands.
- VACUUM must be sent as its own statement with autocommit on.
What the server log shows
ERROR: VACUUM cannot run inside a transaction block
Why PostgreSQL raises this — what the manual says
the VACUUM reference (Notes):
“VACUUM cannot be executed inside a transaction block.”
VACUUM opens and commits multiple internal transactions and may run concurrently with other work. That is incompatible with executing inside an outer transaction, so PostgreSQL rejects it with 25001.
Common causes
- Running
VACUUMafterBEGIN. - A client/ORM that auto-wraps statements in a transaction.
- A migration tool that disables autocommit globally.
How to fix it
- Run VACUUM with autocommit on, outside any transaction block.
- In psql, ensure you are not inside a
BEGIN; just runVACUUM;. - In code, switch the connection to autocommit before issuing VACUUM.
Related & next steps
Reference: PostgreSQL 18 — VACUUM.
Thanks — noted. This helps keep the database accurate.