Explain the ACID properties in PostgreSQL.

Beginner

Answer

ACID properties ensure database reliability:

  • Atomicity: Transactions are all-or-nothing. If any part fails, the entire transaction rolls back
  • Consistency: Database remains in a valid state before and after transactions
  • Isolation: Concurrent transactions don't interfere with each other
  • Durability: Committed changes persist even after system failures

Example:

BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT; -- Both operations succeed or both fail