The server rejected a transaction control command because it was issued in a context where starting, ending, or altering a transaction is not allowed.
invalid_transaction_initiation (SQLSTATE 0B000) means PostgreSQL blocked BEGIN, COMMIT, or ROLLBACK because another transaction block is already active or the command ran inside a function or prepared statement. Remove the nested transaction or switch to SAVEPOINT to resolve the error.
invalid_transaction_initiation
The server raises SQLSTATE 0B000 when a transaction control statement is executed where transactions are already managed for you. Typical examples are issuing BEGIN inside an active transaction block, inside a PL/pgSQL function, or while a cursor is open.
The error protects ACID guarantees by forbidding nested transaction blocks that PostgreSQL cannot safely unwind.
Fixing it involves removing the illegal BEGIN/COMMIT pair or replacing it with SAVEPOINT logic.
Nested transaction blocks trigger the error most often. If psql is already in “” autocommit off mode, an extra BEGIN creates a second-level transaction, which PostgreSQL forbids and returns 0B000.
PL/pgSQL functions and DO blocks always run inside the caller’s transaction.
Any explicit BEGIN or COMMIT inside those procedural blocks violates the rule and throws invalid_transaction_initiation.
Prepared statements and protocol-level extended query mode also reject transaction commands because the surrounding client driver already controls transaction scope.
First, identify where the extra BEGIN, COMMIT, or ROLLBACK is issued. Remove it when a transaction is already open, or move it outside the conflicting scope.
When true nesting is required, switch to SAVEPOINT and RELEASE SAVEPOINT.
These provide sub-transaction semantics supported by PostgreSQL without hitting SQLSTATE 0B000.
If your code needs autonomous work inside a function, call dblink or pg_background to run a separate session instead of a local BEGIN.
psql scripts - Drop the inner BEGIN; psql can manage a single surrounding transaction.
PL/pgSQL function - Replace BEGIN/COMMIT with PERFORM dblink_exec(...) to run autonomous SQL, or redesign logic so the caller controls transactions.
ORM frameworks - Disable autocommit before hand-written BEGIN statements, or let the ORM fully manage the transaction.
Adopt a clear rule: one code layer owns the transaction.
Do not mix manual BEGIN statements with driver-level transaction helpers.
Use SAVEPOINT for partial rollbacks inside long transactions instead of trying to nest BEGIN.
Lint SQL in Galaxy’s editor; it flags BEGIN inside function bodies, preventing the 0B000 error before deployment.
ERROR: cannot begin/end transactions in PL/pgSQL - Same root cause but raised from procedural language checks; remove the commands.
ERROR: current transaction is aborted, commands ignored until end of transaction block - Happens after an error inside a transaction; issue ROLLBACK or COMMIT.
SQLSTATE 25P02 - Similar cleanup error if an earlier statement failed.
Resolve the underlying failure, then restart the transaction.
.
No. PostgreSQL does not support fully nested transactions. Use SAVEPOINT for partial rollbacks instead.
Functions run inside their caller’s transaction. A second BEGIN violates transaction rules and raises SQLSTATE 0B000.
Call external sessions with dblink or pg_background, or move work to the application layer.
Yes. Galaxy’s linter highlights BEGIN/COMMIT inside disallowed contexts and suggests SAVEPOINT, preventing deployment errors.