Bird
0
0

You want to implement a lock that multiple sessions can hold simultaneously but prevents exclusive locks. Which function should you use?

hard📝 Application Q9 of 15
PostgreSQL - Transactions and Concurrency
You want to implement a lock that multiple sessions can hold simultaneously but prevents exclusive locks. Which function should you use?
Apg_advisory_lock_shared(key bigint)
Bpg_advisory_lock(key bigint)
Cpg_advisory_xact_lock(key bigint)
Dpg_advisory_unlock(key bigint)
Step-by-Step Solution
Solution:
  1. Step 1: Understand shared vs exclusive advisory locks

    Shared locks allow multiple holders simultaneously but block exclusive locks until all shared locks are released.
  2. Step 2: Identify the function for acquiring shared locks

    pg_advisory_lock_shared acquires a session-level shared advisory lock allowing concurrent holders.
  3. Final Answer:

    pg_advisory_lock_shared(key bigint) -> Option A
  4. Quick Check:

    Multiple holders = shared lock function [OK]
Quick Trick: Use pg_advisory_lock_shared for concurrent shared locks [OK]
Common Mistakes:
  • Using exclusive lock functions for shared locks
  • Confusing unlock functions with lock acquisition
  • Assuming transaction-level locks for shared concurrency

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes