DBMS
DBMS Part-1
- DBMS Introduction
- DBMS Architecture
- Database Approach vs Traditional File System
- Advantages of DBMS
- Data Models in DBMS
- Schemas in DBMS
- Instances in DBMS
- Data Independence in DBMS
- Database Languages in DBMS
- Interfaces in DBMS
- Structure of DBMS
- Functions of DBA and Designer
- Entities and Attributes in DBMS
- ER Diagram in DBMS
- Generalization, Specialization and Aggregation in DBMS
- Converting ER Diagram to Tables in DBMS
- Difference between Object Oriented, Network and Relational Data Models
DBMS Part-2
- Relational Data Model in DBMS
- Keys in DBMS
- SQL Introduction
- DDL(Data Definition Language)
- DML(Data Manipulation Language)
- Integrity Constraints in DBMS
- Complex SQL Queries
- Joins in DBMS
- Indexing in DBMS
- Triggers in DBMS
- Assertions in DBMS
- Relational Algebra in DBMS
- Tuple Relational Calculus in DBMS
- Domain Relational Calculus in DBMS
DBMS Part-3
- Introduction to Normalization in DBMS
- Normal Forms in DBMS
- Functional Dependency in DBMS
- Decomposition in DBMS
- Dependency Preserving Decomposition in DBMS
- Lossless Join Decomposition in DBMS
- Problems with Null Values and Dangling Tuples
- Multivalued Dependency in DBMS
- Query Optimization in DBMS
- Algorithms for Select, Project and Join Operations in DBMS
- Query Optimization Methods in DBMS
DBMS Part-4
- Transactions in DBMS
- Serializability in DBMS
- Recoverability in DBMS
- Recovery Techniques in DBMS
- Log Based Recovery in DBMS
- Checkpoint in DBMS
- Deadlock in DBMS
- Concurrency Control in DBMS
- Lock Based Protocol in DBMS
- Timestamp Based Protocol in DBMS
- Validation Based Protocol in DBMS
- Multiple Granularity in DBMS
- Multi-Version Concurrency Control(MVCC) in DBMS
- Recovery with Concurrent Transactions in DBMS
DBMS Part-5
Deadlock in DBMS
Deadlock kya hota hai?
DBMS mein deadlock ek aisi situation hoti hai jahan 2 ya zyada transactions ek dusre ka wait karte rehte hain resource release krne ke liye, aur koi bhi aage nahi badh pata.
example:
Imagine:
- Person A ke pas pen hai
- Person B ke pas notebook hai
- A bolta hai “Mai sirf tabhi hi likhunga jab mjhe notebook milegi”
- B bolta hai “Mai tumhe notebook tabhi hi dunga jab mujhe pen milegi”
Koi bhi nahi likh pata na hi A, na hi B .ise hi deadlock kehte hai.
Deadlock ko handle karna kyun zaroori hai?
Agar hum deadlock ko handle nahi karte:
-
Transactions indefinitely wait karte rahenge
-
System hang ya slow ho sakta hai
-
Performance aur data consistency kharaab ho jaati hai
Deadlock ko handle karne ke 4 main tareeke
1. Deadlock Prevention
2. Deadlock Avoidance
3. Deadlock Detection & Recovery
4. Deadlock Ignorance (chhoti systems mein)
1. Deadlock Prevention
Goal: Deadlock hone hi na do. Isme hum 4 Coffman Conditions me se koi ek tod dete hain.
Coffman Conditions:
Condition | Matlab |
---|---|
Mutual Exclusion | Ek resource ek waqt mein sirf ek hi le sakta hai (resource non sharable hai) |
Hold and Wait | Transaction ek resource pakad ke dusra maangta hai |
No Preemption | Resource zabardasti nahi cheen sakte |
Circular Wait | Transactions ek dusre ka wait kar rahe hote hain in cycle |
Kaise rok sakte hain?
a) Hold and Wait todna
Transaction ko bolte hain ki saare resources ek saath maango. Agar mil gaye to chalo, warna wait karo.
Example:
T1 ko A aur B chahiye — dono ek saath maange, nahi to wait kare.
b) Circular Wait todna
Resources ko number de do (e.g. A=1, B=2, C=3). Har transaction ko increasing order mein hi resource maangna hoga.
Example:
T1 ne A (1) le liya — ab sirf B (2) ya C (3) maang sakta hai, A se chhota resource nahi.
2. Deadlock Avoidance
Goal: Deadlock hone se pehle hi check karo ki situation safe hai ya nahi.
Safe State:
Aisi condition jahan har transaction safely complete ho sakta hai.
Unsafe State:
Aisi condition jahan aage jaake deadlock ho sakta hai.
Algorithm: Banker’s Algorithm
Example:
T1 resource A maangta hai → system check karega:
-
Kya sabhi transactions safe tareeke se complete ho sakte hain?
-
Agar haan → resource de do
-
Agar nahi → wait karvao
Iske liye har transaction ka maximum resource requirement pehle se pata hona chahiye
3. Deadlock Detection & Recovery (Pehchaan ke baad sudharna)
Goal: Deadlock hone do, par turant detect karo aur solve karo.
Kaise detect karte hain?
Use karte hain Wait-For Graph (WFG):
-
Har node = ek transaction
-
Edge = T1 is waiting for T2
Cycle in graph = Deadlock
Example Wait-for Graph
T1 → T2 → T3
↑ ↓
└─────────┘
Ye cycle hai ⇒ deadlock hua
Recovery kaise karte hain?
Deadlock detect hone ke baad system kisi ek transaction ko rollback kar deta hai:
Recovery options:
-
Sabse young transaction ko kill karo
-
Sabse purana transaction ko rollback karo
-
Least costly (kam resources) transaction rollback karo
-
Partial rollback bhi kar sakte ho
Example:
T1, T2, T3 deadlock mein hain. T2 ko rollback kar diya, uske resources free ho gaye, aur baaki aage badh gaye.
4. Deadlock Ignorance (Ignore karna)
Kuch DBMS (jaise MySQL) deadlock ko ignore karte hain:
-
Sochte hain deadlock rare hota hai
-
User ko manually transaction retry karna padta hai
Ye approach serious systems ke liye safe nahi hai
Comparison Table
Method | Kab Use Hota Hai | Kaise Kaam Karta Hai | Example |
---|---|---|---|
Prevention | Pehle se | Deadlock ki condition tod deta hai | Saare resources ek saath maangna |
Avoidance | Resource allocation se pehle | Safe/Unsafe state check karta hai | Banker’s Algorithm |
Detection & Recovery | Deadlock hone ke baad | Cycle detect karta hai, rollback karta hai | Wait-for Graph |
Ignore | Small systems mein | Khaali chhod dete hain, user handle kare | Manual retry |
Final Summary
-
Deadlock tab hota hai jab transactions ek dusre ka wait karte hain aur koi bhi aage nahi badh pata
-
Hum deadlock ko prevent, avoid, detect or ignore kar sakte hain
-
Har method ka use depend karta hai system ki complexity, performance aur reliability pe