🐘 PostgreSQL
Beginner
What is a transaction in PostgreSQL?
Answer
A transaction is a sequence of operations treated as a single atomic unit — either all succeed or none do. PostgreSQL is fully ACID-compliant. Start a transaction: BEGIN;. Commit (make permanent): COMMIT;. Rollback (undo all changes): ROLLBACK;. Every individual SQL statement in PostgreSQL runs in an implicit single-statement transaction if not wrapped in an explicit BEGIN...COMMIT. Savepoints allow partial rollbacks within a transaction: SAVEPOINT sp1; then ROLLBACK TO sp1;. PostgreSQL never has dirty reads — even uncommitted transactions don't see each other's changes by default (READ COMMITTED isolation). Transactions are essential for maintaining data consistency across multiple related operations.