25002
PostgreSQLERRORNotableInvalid Transaction StateHIGH confidence
active SQL transaction
What this means
SQLSTATE 25002 is raised when a command that requires no active transaction is issued while a transaction is in progress. Certain DDL commands and session-level settings cannot be executed inside a transaction block.
Why it happens
- 1Running VACUUM, CLUSTER, or certain CREATE DATABASE commands inside a BEGIN...COMMIT block
- 2Issuing a command that requires autocommit context inside an explicit transaction
How to reproduce
VACUUM inside a transaction block.
trigger — this will error
trigger — this will error
BEGIN; VACUUM ANALYZE employees; -- not allowed inside transaction
expected output
ERROR: VACUUM cannot run inside a transaction block
Fix
Execute the command outside a transaction block
WHEN When a command requiring no active transaction is needed.
Execute the command outside a transaction block
-- Do not wrap in BEGIN...COMMIT: VACUUM ANALYZE employees;
Why this works
VACUUM and similar commands must be executed as standalone statements in autocommit mode, not inside explicit transaction blocks.
Sources
Official documentation ↗
Class 25 — Invalid Transaction State
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev