An Autonomous Transaction is an independent database transaction that executes within the context of another transaction without being controlled by its commit or rollback.
When an autonomous transaction starts, the main (parent) transaction is suspended. The autonomous transaction can execute SQL statements and independently COMMIT or ROLLBACK its changes. Once it finishes, the parent transaction resumes.
The most important characteristic is that rolling back the parent transaction does not undo changes already committed by the autonomous transaction.
Autonomous transactions are primarily useful when certain database operations must be preserved regardless of the outcome of the main transaction.
Typical use cases include:
Error logging: Preserve error information even when the business transaction fails and rolls back.
Auditing: Record attempts to perform operations independently of their success or failure.
Process monitoring: Save execution status, progress information, and diagnostic events.
Transaction tracking: Generate persistent records of attempted operations.
|
Feature |
Oracle |
SQL Server |
PostgreSQL |
|---|---|---|---|
|
Native autonomous transactions |
Yes |
No |
No |
|
Independent |
Yes |
No native equivalent |
No native equivalent |
|
Parent transaction suspension |
Yes |
No native equivalent |
No native equivalent |
|
Independent rollback |
Yes |
Requires separate transaction context |
Requires separate transaction context |
|
Separate connection required |
No |
Yes |
Yes |
|
Alternative implementation |
Native PL/SQL |
Separate connection |
|
Oracle provides native autonomous transaction support through the PL/SQL directive:
PRAGMA AUTONOMOUS_TRANSACTION
It can be declared inside procedures, functions, triggers, and appropriate PL/SQL blocks.
An autonomous transaction:
Has its own transaction context.
Can commit independently of the parent.
Does not commit or roll back the parent transaction.
Cannot access the parent's uncommitted changes.
Can encounter locking conflicts with the parent transaction.
SQL Server does not support native autonomous transactions.
Although SQL Server allows nested BEGIN TRANSACTION statements, nested transactions are not autonomous. An inner COMMIT does not permanently commit its changes while the outer transaction remains active.
To achieve independent transaction behavior, SQL Server requires a separate database connection or another mechanism that executes outside the parent transaction context.
PostgreSQL also does not provide native autonomous transactions.
Although stored procedures can execute COMMIT and ROLLBACK under specific conditions, these statements control the current transaction rather than creating an independent autonomous transaction.
Similar behavior can be implemented using the dblink extension or a separate database connection.
Oracle provides a native database-level solution, whereas SQL Server and PostgreSQL require additional mechanisms to achieve equivalent transaction independence.
This distinction is particularly important for database-side error logging and auditing, where diagnostic information must survive the rollback of the main transaction.