The PostgreSQL administration field guideField notes · Runbooks · Free certification

Section 2 of 3 · 7 minutes

Keep the change reversible until it is checked

Your goal

What you will be able to do

Use an explicit transaction to change, inspect, and either commit or roll back work.

Why this matters at work

The practical reason

A transaction gives you a clear point where an unverified change can still be discarded.

Learn

The idea in plain English

`BEGIN` starts a transaction. Statements after it stay uncommitted until `COMMIT`. Your session can inspect its own changes before deciding.

Use `ROLLBACK` when the result is wrong or uncertain. Keep the transaction short because open transactions can hold locks and prevent vacuum from cleaning old row versions.

Remember these points

  • BEGIN, verify, then COMMIT or ROLLBACK.
  • Uncommitted changes are not a substitute for a backup.
  • Do not leave an operational transaction open while waiting for approval.

See it in SQL

Correct rows and verify before commit

Show the complete safe sequence for a small data repair.

BEGIN;

UPDATE training_accounts
SET account_status = 'paused'
WHERE account_status = 'pause';

SELECT account_id, account_status
FROM training_accounts
WHERE account_status = 'pause'
   OR account_status = 'paused'
ORDER BY account_id;

ROLLBACK;

This example deliberately rolls back after verification. In a real approved repair, use COMMIT only when the reviewed result matches the change request.

The verification query checks both the old and new values. That makes unexpected remaining rows visible.

What you should see

The session temporarily shows corrected rows, then ROLLBACK restores the original data.

Useful words

Important terms

Transaction
A group of statements that commit or roll back as one unit.

Quick check · Not graded

Check your understanding

What should you do when verification inside a transaction is uncertain?

Choose one answer

Your progress is saved to your signed-in account.