Recall & Review
beginner
What is a deadlock in a database system?
A deadlock happens when two or more transactions wait forever for each other to release locks, so none can proceed.
Click to reveal answer
intermediate
How does PostgreSQL detect deadlocks?
PostgreSQL periodically checks for cycles in the waiting transactions graph to find deadlocks and then aborts one transaction to break the cycle.
Click to reveal answer
beginner
Name one common method to prevent deadlocks.
One method is to always acquire locks in a consistent order across transactions to avoid circular waiting.
Click to reveal answer
intermediate
What happens when PostgreSQL detects a deadlock?
PostgreSQL cancels one of the transactions involved in the deadlock and returns an error to that transaction, allowing others to continue.
Click to reveal answer
advanced
Why is deadlock prevention better than detection in some cases?
Prevention avoids deadlocks before they happen, improving performance and user experience by not having to roll back transactions.
Click to reveal answer
What causes a deadlock in PostgreSQL?
✗ Incorrect
Deadlocks occur when transactions wait on each other's locks, creating a cycle with no progress.
How does PostgreSQL resolve a detected deadlock?
✗ Incorrect
PostgreSQL cancels one transaction to break the deadlock cycle.
Which practice helps prevent deadlocks?
✗ Incorrect
Consistent lock order prevents circular waiting and deadlocks.
What is a sign of a deadlock in PostgreSQL logs?
✗ Incorrect
PostgreSQL logs 'ERROR: deadlock detected' when it finds a deadlock.
Why might deadlock prevention be preferred over detection?
✗ Incorrect
Prevention avoids deadlocks and the need to rollback transactions, improving performance.
Explain what a deadlock is and how PostgreSQL detects it.
Think about transactions waiting on each other's locks.
You got /4 concepts.
Describe two ways to prevent deadlocks in database transactions.
Focus on how to avoid circular waiting and long lock holding.
You got /4 concepts.