ROLLBACK aborts the current and all of its , discarding all transactional updates made by statements included in the transaction.
There are two ways to use ROLLBACK:
-
The
ROLLBACKstatement rolls back the entire transaction. -
The
ROLLBACK TO SAVEPOINTstatement rolls back and restarts the nested transaction started at the correspondingSAVEPOINTstatement, for working with . This is in addition to the existing support for working with . For examples of each usage, see: - Rollback a nested transaction
- Retry a transaction
Rollbacks to savepoints over DDL statements are only supported if you’re rolling back to a savepoint created at the beginning of the transaction.
Synopsis
Required privileges
No are required to rollback a transaction. However, privileges are required for each statement within a transaction.Parameters
| Parameter | Description |
|---|---|
TO SAVEPOINT cockroach_restart | If using , retry the transaction. You should execute this statement when a transaction returns a 40001 / retry transaction error. |
TO SAVEPOINT <name> | If using , roll back and restart the started at the corresponding SAVEPOINT statement. |
Savepoints and row locks
CockroachDB supports exclusive row locks.- In PostgreSQL, row locks are released/cancelled upon
ROLLBACK TO SAVEPOINT. - In CockroachDB, row locks are preserved upon
ROLLBACK TO SAVEPOINT.
ROLLBACK TO SAVEPOINT to release row locks and allow a concurrent transaction touching the same rows to proceed, this behavior will not work with CockroachDB.
Savepoints and high priority transactions
(for either regular savepoints or “restart savepoints” defined withcockroach_restart) causes a “feature not supported” error after a DDL statement in a , in order to avoid a transaction deadlock.
Examples
Rollback a transaction
Typically, an application conditionally executes rollbacks, but we can see their behavior by usingROLLBACK instead of COMMIT directly through SQL:
Rollback a nested transaction
TheROLLBACK TO SAVEPOINT statement rolls back and restarts the started at the corresponding SAVEPOINT statement.
For examples showing how to use ROLLBACK TO SAVEPOINT to rollback a nested transaction, see .
Retry a transaction
When using , useROLLBACK TO SAVEPOINT to handle a transaction that needs to be retried (identified via the 40001 error code or restart transaction string in the error message), and then re-execute the statements you want the transaction to contain.

