[{"id":"postgresqladvanced-001","courseId":"postgresql-advanced","domain":"concurrency-mvcc","topic":"Read Committed re-check after concurrent update","prompt":"A Read Committed job reads a row, then runs SELECT ... FOR UPDATE on it so a concurrent update cannot slip in before its own UPDATE. What cost does that row lock carry?","hint":"Compare the explicit row lock with the predicate locks that Serializable uses.","explain":"Protecting data from concurrent changes can use explicit locks or the tracking that Serializable uses. The two differ in whether they make other transactions wait and in what they cost the server.","source":"https://www.postgresql.org/docs/current/transaction-iso.html","interaction":{"type":"single"},"options":[{"id":"a","text":"It can block other transactions and cause disk access.","why":"SELECT FOR UPDATE can block other transactions, and it causes disk writes because it marks the selected rows as locked."},{"id":"b","text":"It blocks plain SELECTs but never another UPDATE.","whyNot":"Row-level locks do not affect data querying; they block only writers and lockers of the same row."},{"id":"c","text":"Nothing; it is a predicate lock, which never blocks.","whyNot":"Predicate locks never block, but FOR UPDATE takes an explicit row lock, which can make other transactions wait."},{"id":"d","text":"It takes a table lock that blocks every other transaction.","whyNot":"FOR UPDATE takes a ROW SHARE table lock, which conflicts only with EXCLUSIVE and ACCESS EXCLUSIVE."}],"answer":"a","explanation":"SELECT FOR UPDATE or SELECT FOR SHARE can block other transactions and cause disk access, while Serializable predicate locks cause no blocking.","concept":"SELECT FOR UPDATE or SELECT FOR SHARE can block other transactions and cause disk access, while Serializable predicate locks cause no blocking.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Explicit row locks buy certainty about a row at the price of blocking and disk writes."]},{"id":"postgresqladvanced-002","courseId":"postgresql-advanced","domain":"concurrency-mvcc","topic":"Predicate locks and blocking","prompt":"A Serializable transaction reads a range of rows, and a DBA asks what that read leaves behind in the server. Which TWO statements about PostgreSQL predicate locks are true?","hint":"Think about whether these locks make anyone wait, and where you would see them.","explain":"Predicate locks record what a Serializable read depended on, so the database can flag risky dependencies. They can be merged into coarser locks as a transaction grows.","source":"https://www.postgresql.org/docs/current/transaction-iso.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"They appear in pg_locks with mode SIReadLock.","why":"The manual says predicate locks show up in the pg_locks view with a mode of SIReadLock."},{"id":"b","text":"They never cause blocking, so they cannot take part in a deadlock.","why":"Predicate locks do not cause any blocking, so they cannot play any part in causing a deadlock."},{"id":"c","text":"They block concurrent UPDATEs to the rows the read touched.","whyNot":"Predicate locks only record dependencies; they do not make writers wait."},{"id":"d","text":"They are always released the moment the reading transaction commits.","whyNot":"SIRead locks often must be kept past commit, until overlapping read-write transactions complete."},{"id":"e","text":"They are taken only by SELECT ... FOR UPDATE.","whyNot":"They follow the data a transaction actually accessed, not a locking clause."},{"id":"f","text":"They are never merged, so a range read holds one lock per row.","whyNot":"Finer-grained locks may be combined into coarser page locks to prevent running out of memory."}],"answer":"ab","explanation":"PostgreSQL predicate (SIRead) locks never block, cannot cause deadlocks, show in pg_locks as SIReadLock, and may be combined into coarser locks.","concept":"PostgreSQL predicate (SIRead) locks never block, cannot cause deadlocks, show in pg_locks as SIReadLock, and may be combined into coarser locks.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Predicate locks track dependencies for Serializable; they never make a writer wait."]},{"id":"postgresqladvanced-003","courseId":"postgresql-advanced","domain":"concurrency-mvcc","topic":"Serializable false positives","prompt":"Under Serializable, once a transaction has checked that a key is absent before inserting it, it can never get a unique violation on that key, even if other transactions insert it without checking.","hint":"Think about what one transaction's own check can guarantee about the others.","explain":"Serializable only commits work that some one-at-a-time order would produce. It can still raise errors a serial run would not, and that depends on how every writer of a key behaves.","source":"https://www.postgresql.org/docs/current/transaction-iso.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The check protects only the transaction that makes it; other transactions that insert without checking can still cause the violation."},{"id":"b","text":"False","why":"Unique violations can happen under Serializable even after a check, so every transaction inserting that key must check first."}],"answer":"b","explanation":"Serializable can raise unique violations a serial run would not, even after a key check, unless every transaction inserting that key checks first.","concept":"Serializable can raise unique violations a serial run would not, even after a key check, unless every transaction inserting that key checks first.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Serializable's safety depends on every writer of a conflicting key following the same check-first protocol."]},{"id":"postgresqladvanced-004","courseId":"postgresql-advanced","domain":"concurrency-mvcc","topic":"Deferrable read-only transactions","prompt":"A reporting job starts a SERIALIZABLE READ ONLY DEFERRABLE transaction on a busy server. What happens before the transaction is allowed to read any data?","hint":"Think about when a deferrable transaction is allowed to take its snapshot.","explain":"Serializable reads normally cannot be trusted until the transaction commits, since a later conflict can still roll it back. The deferrable option changes when the transaction may start reading.","source":"https://www.postgresql.org/docs/current/transaction-iso.html","interaction":{"type":"single"},"options":[{"id":"a","text":"It waits until it can take a snapshot guaranteed free of serialization anomalies.","why":"A deferrable read-only transaction waits for such a snapshot before reading any data, so its reads are valid as soon as they happen."},{"id":"b","text":"It starts reading at once and takes ACCESS EXCLUSIVE locks on every table it reads.","whyNot":"Deferral has nothing to do with table locks; it waits for a safe snapshot before reading."},{"id":"c","text":"It reads at once, but its results are untrusted until it commits.","whyNot":"Data read in a deferrable read-only transaction is known to be valid as soon as it is read."},{"id":"d","text":"It runs at once and rolls back with SQLSTATE 40001 if a conflict appears.","whyNot":"The deferrable mode waits for a safe snapshot first, so it does not start and then fail later."}],"answer":"a","explanation":"A SERIALIZABLE READ ONLY DEFERRABLE transaction waits for a snapshot guaranteed free of anomalies before reading, so its data is valid as soon as it is read.","concept":"A SERIALIZABLE READ ONLY DEFERRABLE transaction waits for a snapshot guaranteed free of anomalies before reading, so its data is valid as soon as it is read.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Deferrable read-only transactions trade a startup wait for reads that need no later validity check."]},{"id":"postgresqladvanced-005","courseId":"postgresql-advanced","domain":"concurrency-mvcc","topic":"ALTER TABLE lock levels","prompt":"A maintenance script runs an ALTER TABLE on a busy orders table and holds its lock for a few seconds. Which lock mode, held by that DDL, would also stop a plain SELECT on the table?","hint":"Ask which lock mode conflicts with every other mode, including the one SELECT takes.","explain":"Table-level lock modes each conflict with a specific set of other modes, and some do not conflict with each other at all. Plain reads take a mode that many readers can share, so only the strongest mode affects them.","source":"https://www.postgresql.org/docs/current/explicit-locking.html","interaction":{"type":"single"},"options":[{"id":"a","text":"ACCESS SHARE","whyNot":"SELECT takes ACCESS SHARE itself, and it conflicts only with ACCESS EXCLUSIVE, so holding it does not block a read."},{"id":"b","text":"ROW EXCLUSIVE","whyNot":"UPDATE, DELETE, INSERT and MERGE take it; it conflicts with SHARE and stronger modes, not with plain reads."},{"id":"c","text":"SHARE","whyNot":"SHARE conflicts with ROW EXCLUSIVE and stronger write modes, but it allows the ACCESS SHARE that SELECT needs."},{"id":"d","text":"ACCESS EXCLUSIVE","why":"It conflicts with every lock mode, including ACCESS SHARE, so it blocks even a plain SELECT."}],"answer":"d","explanation":"Only an ACCESS EXCLUSIVE lock blocks a plain SELECT, and many forms of ALTER TABLE acquire it.","concept":"Only an ACCESS EXCLUSIVE lock blocks a plain SELECT, and many forms of ALTER TABLE acquire it.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Many ALTER TABLE forms take ACCESS EXCLUSIVE, which blocks even plain reads until they finish."]}]