0% found this document useful (0 votes)
3 views

139 Db Notes2

The document outlines the concepts of storage and buffer management in database systems, emphasizing the roles of blocks, buffers, buffer managers, and storage managers. It also details transaction properties, including ACID principles (Atomicity, Consistency, Isolation, Durability), and describes the transaction manager's functions such as logging, concurrency control, and deadlock resolution. Overall, it highlights the importance of efficient data handling and transaction integrity in database management systems.

Uploaded by

soraigds
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

139 Db Notes2

The document outlines the concepts of storage and buffer management in database systems, emphasizing the roles of blocks, buffers, buffer managers, and storage managers. It also details transaction properties, including ACID principles (Atomicity, Consistency, Isolation, Durability), and describes the transaction manager's functions such as logging, concurrency control, and deadlock resolution. Overall, it highlights the importance of efficient data handling and transaction integrity in database management systems.

Uploaded by

soraigds
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Storage and Buffer Management:

In a database system, most data is stored on secondary storage, like hard drives or
SSDs (referred to here as magnetic disks).Why secondary storage? Because it can
hold large amounts of data, unlike main memory (RAM), which is smaller and
temporary.

However:To do any useful operation (e.g., searching or updating data), the data must
first be loaded into main memory (RAM), because the CPU cannot directly work
with data on disk.

Terminologies to Know:
Blocks:

 A block refers to the smallest unit of data that can be read from or written to the
disk. A block corresponds to a fixed-size chunk of data on the storage device
(magnetic disk), typically ranging from 512 bytes to a few kilobytes.

Buffers:

 A buffer is a designated area in main memory (RAM) where data from disk blocks is
temporarily stored before processing.

Buffer Manager:

 The buffer manager is a software component of the DBMS responsible for


allocating and managing buffers in main memory.

Storage Manager:

 It is the job of the storage manager to control the placement of data on disk and its
movement between disk and main memory.

Explanation:
The buffer manager is responsible for dividing the available main memory into
buffers, which are page-sized regions into which disk blocks can be transferred.
Thus, all DBMS components that need information from the disk will interact with
the buffers and the buffer manager, either directly or through the execution
engine. The kinds of information that various components may need include:

1. Data: the contents of the database itself.

2. Metadata: the database schema that describes the structure of, and constraints
on, the database.
3. Log Records: information about recent changes to the database; these support
durability of the database.

4. Statistics: information gathered and stored by the DBMS about data properties
such as the sizes of, and values in. various relations or other components of the
database.

5. Indexes: data structures that support efficient access to the data.

Storage Hierarchy From Diagram:

 Main memory with buffer pools

 Secondary storage (disk) with data blocks

 Data movement between layers

Transaction and its Properties:


A transaction is a group of database operations (like adding, updating, or deleting
data) that should be treated as a single unit of work.Transaction involves
operations like adding ,deleting or updating data. Properly implemented
transactions are commonly said to meet the "ACID test".

The ACID properties include :

Atomicity:

 Definition: A transaction is atomic, meaning it is an all-or-nothing operation.


Either all the changes made during the transaction are committed, or none are. If
any part of the transaction fails, all changes are rolled back.

 How It Works:
o A transaction can involve several operations, such as adding, updating, or
deleting data.

o If an operation fails at any point, the entire transaction is rolled back to its
original state. This ensures the database is never left in an inconsistent or
partial state.

o Example:

 Imagine a bank transaction that involves transferring money from


Account A to Account B. The transaction involves two steps:

1. Deducting $100 from Account A.

2. Adding $100 to Account B.

 If the first operation succeeds (deducting from Account A), but the
second operation fails (adding to Account B), the database will
rollback the entire transaction, and no money will be deducted from
Account A or added to Account B. This ensures the atomicity of the
transaction.

Consistency:

Consistency refers to the property that ensures the database transitions from one
valid state to another after a transaction is executed. In other words, after a
transaction, the database must be in a state that adheres to all defined rules,
constraints, and business logic.

Key points about Consistency:

Transaction Should Not Violate Rules: During the transaction, the changes
made to the database must not violate the rules or constraints of the database
schema. These could include:

o Data type constraints: For example, ensuring that a column that should only
hold integers doesn't get a string.

o Primary key constraints: Ensuring no two rows have the same primary key.

o Business logic: Ensuring that the data remains meaningful. For example,
ensuring an account doesn't go into a negative balance during a transfer.

Eg:

Imagine a banking system where a transaction involves transferring $100 from


Account A to Account B.

 Before Transaction:

o Account A has $500.


o Account B has $300.

 Transaction:

o Debit $100 from Account A.

o Credit $100 to Account B.

 After Transaction:

o Account A should have $400 (after debit).

o Account B should have $400 (after credit).

Now, let’s say that the transaction is supposed to ensure:

 Account A cannot have a negative balance.

 Account B cannot have more money than allowed (let’s say the maximum limit is
$500).

 If the transaction is consistent, after transferring $100, Account A will have


$400 and Account B will have $400. Both accounts are valid and consistent with
the rules.

 If there was a rule violation, for example, if the transaction tried to take out
more money from Account A than it had (e.g., $600 instead of $100), the
transaction would violate consistency, and the DBMS would reject the transaction.

Isolation:

 Definition: Transactions are isolated from each other. One transaction should not
affect the execution of another transaction, even if they occur concurrently.in
DBMS,isolation is implemented through locking.

 How It Works:

o Isolation ensures that intermediate states of a transaction are not visible to


other transactions. Each transaction appears to execute in isolation, even if
multiple transactions are running concurrently.

Without Lock:
Without Isolation (First Diagram):

 Transaction 1 reads balance ($1000)

 Transaction 2 reads balance ($1000) before T1 finishes

 Transaction 1 writes new balance ($800)

 Transaction 2 writes new balance ($700)

 The $200 deduction from T1 is lost!

 Final balance is wrong ($700 instead of $500)

WITH LOCK:
2. With Isolation (Second Diagram):

 Transaction 1 acquires lock and reads balance ($1000)

 Transaction 2 must wait (shown by delayed position)

 Transaction 1 writes new balance ($800) and releases lock

 Transaction 2 can now proceed, reads $800

 Transaction 2 writes final balance ($500)

 Correct final state achieved

DURABILITY:

Durability ensures that once a transaction is committed, its changes are permanent,
even in the face of failures like power outages or crashes.

How It's Achieved:

 Transaction logs record changes before committing them.

 Changes are written to non-volatile storage (e.g., disk or SSD) before the
transaction completes.

Example:

 A transaction deposits $500 into an account. Once committed:

 The database ensures the $500 is stored in durable storage.


 Even if the system crashes immediately after, the $500 will be available
upon recovery

Transaction Processing:
Transaction manager is software component of DBMS.It performs following tasks:

1.Logging:

In order to assure durability, every change in the database is logged separately on disk.
The log manager follows one of several policies designed to assure that no matter when
a system failure or "crash" occurs, a recovery manager will be able to examine the log of
changes and restore the database to some consistent state. The log manager initially
writes the log in buffers and negotiates with the buffer manager to make sure that
buffers are written to disk (where data can survive a crash) at appropriate times.

Why is Logging Necessary for Durability?


If the system crashes or a failure occurs:

1. The database system uses the log to identify what operations were performed.

2. The recovery process uses the log to:

o Redo completed transactions: Ensure their effects are fully applied to the
database.

o Undo incomplete transactions: Rollback changes from transactions that


didn’t finish.

2.Concurrency control:
Transactions must appear to execute in isolation. But in most systems, there will in
truth be many transactions executing simultaneously.So,locks are maintained on
database by scheduler so that there will be no conflict among transactions. The
scheduler affects the execution of queries and other database operations by
forbidding the execution engine from accessing locked parts of the database

3.Deadlock Resolution:

Situations can occur where two transactions have locked resources like transaction
T1 has locked resource R1 and transaction T2 has locked resource R2.Then,T1 also
wants to access R2 which is locked by T2.And at the same time ,T2 while having locked
R2 wants to access R1 which is locked by T1, Both T1 and T2 want each other resources
while don’t want to release the resources they have.This situation is called deadlock
which is solved by the transaction manager which has the responsibility to intervene
and cancel ("rollback" or "abort") one or more transactions to let the others proceed.

You might also like