Consider two concurrent transactions in PostgreSQL using REPEATABLE READ isolation level. Transaction A reads a row, then Transaction B updates that row and commits. Transaction A reads the same row again.
What will Transaction A see on the second read?
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; SELECT balance FROM accounts WHERE id = 1; -- returns 100 -- Concurrently, another transaction updates balance to 200 and commits SELECT balance FROM accounts WHERE id = 1; -- What is the output here?
Think about how REPEATABLE READ isolation keeps a consistent snapshot for the duration of the transaction.
In REPEATABLE READ, the transaction sees a consistent snapshot of the database as of the start of the transaction. Even if another transaction commits changes, the first transaction will not see those changes until it ends and starts a new transaction.
Which of the following statements about phantom reads under REPEATABLE READ isolation level in PostgreSQL is true?
Consider how PostgreSQL's MVCC handles visibility of new rows in REPEATABLE READ.
PostgreSQL's REPEATABLE READ uses MVCC to provide a snapshot that includes all rows visible at the start of the transaction, so phantom reads do not occur. New rows inserted after the transaction starts are not visible.
Which of the following SQL commands correctly sets the transaction isolation level to REPEATABLE READ in PostgreSQL for the current transaction?
Focus on the command that sets isolation level for the current transaction before it starts.
In PostgreSQL, BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; (or START TRANSACTION ISOLATION LEVEL REPEATABLE READ;) sets the isolation level when starting the transaction. SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; must follow an explicit BEGIN;.
In PostgreSQL, under REPEATABLE READ isolation, serialization failures can occur due to concurrent updates. Which approach best reduces serialization failures while keeping repeatable read guarantees?
Think about how locking can prevent concurrent conflicting updates.
Explicit row-level locking with SELECT ... FOR UPDATE ensures that concurrent transactions serialize access to rows, reducing serialization failures while maintaining repeatable read guarantees.
Two concurrent transactions under REPEATABLE READ isolation update the same row and commit. One transaction gets a serialization failure error. What is the most likely cause?
Consider how PostgreSQL detects conflicts under REPEATABLE READ.
PostgreSQL detects serialization conflicts when concurrent transactions update the same data under REPEATABLE READ. One transaction must abort with a serialization failure to maintain consistency.