Bird
0
0

You want to ensure that a critical section of your application runs only once at a time across all sessions. Which advisory lock type should you use?

hard📝 Application Q8 of 15
PostgreSQL - Transactions and Concurrency
You want to ensure that a critical section of your application runs only once at a time across all sessions. Which advisory lock type should you use?
ASession-level exclusive advisory lock
BTransaction-level shared advisory lock
CSession-level shared advisory lock
DTransaction-level exclusive advisory lock
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement for critical section locking

    The critical section must be locked so only one session can run it at a time, and the lock should release automatically after transaction ends.
  2. Step 2: Choose the appropriate lock type

    Transaction-level exclusive advisory locks ensure mutual exclusion during the transaction and release automatically, preventing deadlocks or stale locks.
  3. Final Answer:

    Transaction-level exclusive advisory lock -> Option D
  4. Quick Check:

    Critical section lock = transaction-level exclusive [OK]
Quick Trick: Use transaction-level exclusive locks for critical sections [OK]
Common Mistakes:
  • Using session-level locks that persist beyond transaction
  • Choosing shared locks which allow concurrent access
  • Confusing session and transaction lock scopes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes