Aller au contenu
uencoder

Handle base de données deadlocks

Deadlocks occur quand transactions wait sur chaque other's locks. Apprendre detection, prevention, et retry strategies.

  1. 1

    A deadlock: Transaction A locks row 1, wants row 2. Transaction B locks row 2, wants row 1. Both wait forever. The database detects the cycle and aborts one transaction (usually the one that did less work). The aborted transaction gets a deadlock error and must be retried.

  2. 2
    Formateur SQL →

    Formater the SQL statements in the transaction to identify the lock acquisition order. If different transactions acquire locks in different orders, deadlocks are likely. Reformat to document the intended lock order.

  3. 3
    Calculatrice de hash →

    Use a hash of the resource IDs to determine a consistent lock order. Always lock resources in ascending hash order. This prevents the circular wait condition that causes deadlocks. Hash-based ordering works when resources can be identified by a string or number.

Questions fréquentes

How do I prevent deadlocks?
Acquire locks in a consistent order across all transactions. Keep transactions short (less time holding locks). Use appropriate isolation levels (lower levels hold fewer locks). Use lock timeouts (SET lock_timeout) so transactions fail fast instead of waiting. For batch operations, sort by primary key before processing.
Should I retry on deadlock?
Yes, but with limits. Retry 3-5 times with exponential backoff. If the deadlock persists, fail and log for investigation. Track deadlock frequency — a high rate indicates a systemic issue (lock ordering, long transactions) that needs architectural changes, not just retries.

Workflows résolvant cette tâche

Hacher le contenu et coder en Base64
Calculer un hachage de l'entrée et coder le condensat en Base64 pour un transport compact.
PIPELINE
Formater SQL et documenter avec statistiques de mots
Pretty-printer une requête SQL puis analyser la sortie formatée avec des statistiques de mots.
PIPELINE
Hacher le texte et vérifier l'intégrité
Calculer un hachage du texte d'entrée et le comparer à un hachage attendu pour vérifier l'intégrité.
PIPELINE
Hacher le texte et vérifier avec somme CRC32
Calculer à la fois un hachage cryptographique SHA-256 et une somme de contrôle CRC32 pour la vérification d'intégrité des données.
PIPELINE
Hacher MD5 puis coder en Base58
Calculer le hash MD5 puis coder en Base58 pour une représentation compacte.
PIPELINE
Comparaison de vitesse multi-hash
Hacher l'entrée et benchmarker plusieurs algorithmes de hachage pour comparer leur vitesse et sortie.
PIPELINE
Générer un mot de passe et hacher
Générer un mot de passe aléatoire puis le hacher pour un stockage sécurisé.
PIPELINE
Hash SHA3-256 avec somme CRC32
Calculer le hash SHA3-256 puis la somme CRC32 pour une double vérification d'intégrité.
PIPELINE
Hacher SHA-512 puis Hex
Calculer le hash SHA-512 puis coder en Hex pour lisibilité.
PIPELINE
Formater SQL et valider
Formater une requête SQL puis valider la syntaxe.
PIPELINE
Inverser le texte et hacher
Inverser le texte puis calculer le hachage SHA-256 du résultat inversé.
PIPELINE
Brouiller le texte et hacher
Brouiller le texte puis hacher le résultat brouillé.
PIPELINE

Outils associés