Bird
0
0

This query returns false unexpectedly:

medium📝 Debug Q7 of 15
PostgreSQL - Transactions and Concurrency
This query returns false unexpectedly:

SELECT pg_try_advisory_lock_shared(555);

What could be the reason?
AThe key 555 is invalid for shared locks
BAn exclusive lock on key 555 is already held by another session
Cpg_try_advisory_lock_shared only works with transaction-level locks
DThe function requires two keys, not one
Step-by-Step Solution
Solution:
  1. Step 1: Understand shared advisory locks behavior

    Shared locks cannot be acquired if an exclusive lock on the same key is held by another session.
  2. Step 2: Analyze why pg_try_advisory_lock_shared returns false

    If an exclusive lock on key 555 exists, the shared lock attempt fails and returns false immediately.
  3. Final Answer:

    An exclusive lock on key 555 is already held by another session -> Option B
  4. Quick Check:

    Shared lock fails if exclusive lock held [OK]
Quick Trick: Shared locks fail if exclusive lock exists on key [OK]
Common Mistakes:
  • Assuming key invalid for shared locks
  • Confusing session and transaction locks
  • Thinking function needs two keys always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes