Bird
0
0

What will be the result of this query if the advisory lock with key 999 is already held by another session?

medium📝 query result Q13 of 15
PostgreSQL - Transactions and Concurrency
What will be the result of this query if the advisory lock with key 999 is already held by another session?
SELECT pg_try_advisory_lock(999);
Atrue
Bfalse
Cnull
Derror
Step-by-Step Solution
Solution:
  1. Step 1: Understand pg_try_advisory_lock behavior

    This function tries to acquire the lock immediately and returns true if successful, false if the lock is held by someone else.
  2. Step 2: Analyze the scenario

    Since the lock with key 999 is already held, the function returns false without waiting.
  3. Final Answer:

    false -> Option B
  4. Quick Check:

    pg_try_advisory_lock returns false if lock busy [OK]
Quick Trick: pg_try_advisory_lock returns false if lock busy [OK]
Common Mistakes:
  • Expecting true even if lock is held
  • Thinking it returns null or error
  • Confusing pg_try_advisory_lock with pg_advisory_lock

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes