transactions
PostgreSQL in Production notes about transactions
Manage transactions and concurrency
Where Should an Application Put BEGIN, COMMIT, and ROLLBACK?
Put one transaction around the related SQL changes, inspect the result before committing, and roll back the whole unit when a statement or business check fails.

