NEW
Also known as: Record Locking, Pessimistic Locking
Mechanisms that restrict access to data to prevent conflicts and ensure consistency during concurrent operations.
DESCRIPTION
Locking is a fundamental concurrency control technique that serializes access to shared resources, such as rows, pages, or tables, to maintain data integrity. Systems use lock modes like shared and exclusive, with varying granularity and duration. Two-phase locking ensures serializability but can increase contention and cause deadlocks. Modern databases combine locking with approaches like MVCC to reduce blocking for readers. Choosing lock strategies impacts throughput, latency, and fairness under high concurrency. Proper monitoring and tuning of locks prevents performance degradation and avoids deadlock cycles.
ALTERNATIVE DEFINITIONS
Wikipedia
In computer science, a lock or mutex is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution.
Emphasizes synchronization and multi-threaded access control.
Oracle
Locks are mechanisms that prevent destructive interaction between transactions accessing the same resource.
Highlights transactions and protection against destructive interactions.
PostgreSQL
Locks are used to control concurrent access to data and ensure data integrity.
Focuses on data integrity under concurrent access.
RELATED TERMS
Transaction Isolation Levels Deadlock Two-Phase Locking ACID Row-Level Locking Isolation (ACID)
COMPETING TERMS
Multiversion Concurrency Control Optimistic Concurrency Control
KNOWLEDGE AREAS
Data Storage & Operations Software Engineering Data Engineering
TARGET AUDIENCE
Software Developer Data Engineer Data Architect IT Manager
EXTERNAL SOURCES
- Wikipedia - Lock (computer science)
- PostgreSQL - Official database locking documentation
- MySQL - MySQL locking mechanisms reference
- Oracle - Oracle consistency and locking concepts
TOP QUESTIONS
Why is Locking important in database systems?
Locking prevents data races and ensures consistency when multiple transactions access the same data. Without proper locks, updates can overwrite changes or read uncommitted data.
Category: Relevancy
What are common Locking modes?
Shared locks allow concurrent reads; exclusive locks block other readers and writers. Additional modes include intent locks and update locks in some systems.
Category: Overview
How does Locking relate to ACID properties?
Locking enforces isolation by controlling concurrent access, supporting atomicity and consistency of transactions. Proper lock management reduces anomalies like dirty reads.
Category: Requirements
What is the risk of overusing Locking?
Excessive locking can cause contention, increased latency, and deadlocks, damaging throughput. Poor granularity choices introduce performance bottlenecks.
Category: Risks
What is a deadlock in the context of Locking?
A deadlock occurs when transactions cyclically wait for each other’s locks, halting progress. Detection and avoidance strategies are essential to recover.
Category: Mistakes
How does MVCC compare to traditional Locking?
MVCC allows readers to access historical snapshots, reducing contention versus exclusive locks. Writers still use locks, but readers avoid blocking.
Category: Alternatives
What is Two-Phase Locking (2PL) and why is it used?
2PL requires locks to be acquired before release, ensuring serializability. It’s widely used but can increase deadlock probability.
Category: Overview
How can Locking be tuned to improve performance?
Adjust lock granularity, isolation levels, and index design. Use shorter transactions, avoid long-held locks, and monitor wait times.
Category: Best practices
What is optimistic concurrency control versus Locking?
Optimistic control assumes low conflict, validating on commit rather than locking upfront. It reduces contention when conflicts are rare.
Category: Alternatives