0
0
PostgreSQLquery~5 mins

Deadlock detection and prevention in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ATwo transactions waiting on each other's locks
BA transaction running too long
CA missing index
DA syntax error in SQL
How does PostgreSQL resolve a detected deadlock?
AIt cancels one transaction involved in the deadlock
BIt restarts the database server
CIt ignores the deadlock and waits
DIt locks all tables
Which practice helps prevent deadlocks?
AAcquiring locks in random order
BAcquiring locks in a consistent order
CUsing only read locks
DDisabling transactions
What is a sign of a deadlock in PostgreSQL logs?
ANOTICE: query completed
BWARNING: slow query
CERROR: deadlock detected
DINFO: connection established
Why might deadlock prevention be preferred over detection?
AIt uses more CPU
BIt disables locking
CIt allows deadlocks to happen
DIt avoids transaction rollbacks
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.