Transaction Lifecycle
A database transaction is a unit of work that groups one or more SQL statements into an atomic operation — either all statements succeed and are persisted, or none of them take effect.
A database transaction is a unit of work that groups one or more SQL statements into an atomic operation — either all statements succeed and are persisted, or none of them take effect.
This sequence diagram traces the complete lifecycle of a single transaction from the client's BEGIN through to the final COMMIT (or ROLLBACK). The client issues BEGIN, which opens a transaction context in the database engine. The engine allocates a transaction ID and establishes the transaction's visibility snapshot — the set of committed rows the transaction is allowed to see, determined by the isolation level.
Within the transaction, the client executes one or more statements. For each write (UPDATE, INSERT, DELETE), the engine locks the affected rows (in pessimistic concurrency mode) or creates new row versions (in MVCC — see MVCC Workflow). The changes are written to the write-ahead log before being applied to the heap, so they survive a crash even before COMMIT.
At COMMIT, the engine writes a commit record to the WAL, flushing it to durable storage. Only after the WAL is fsynced does the engine release row locks and make the changes visible to other transactions. If a ROLLBACK is issued instead — because of an application error or an explicit decision — the engine uses the WAL or undo log to reverse all changes made during the transaction, as if it never started.
Understanding this lifecycle is the foundation for reasoning about ACID Properties. Atomicity is enforced by the all-or-nothing commit/rollback decision. Durability is guaranteed by the WAL fsync before commit returns. Isolation is controlled by lock acquisition and snapshot management during the active phase. When multiple databases participate in a single logical transaction, the Two Phase Commit protocol extends this lifecycle across nodes.