Unit 4 of 4 · B.Sc IT Sem 4

Unit 4: Database protection and distributed databases

Database Management Systems notes · PTU syllabus (BSIT402/BSBC404)

4 min read12 topics10 exam questions
On this page
  1. Unit summary
  2. Recovery
  3. Log-based recovery and checkpoints
  4. Transactions and ACID properties
  5. Concurrency management
  6. Lock-based concurrency control and 2PL
  7. Timestamp ordering
  8. Deadlock handling
  9. Database security
  10. Integrity and control
  11. Disaster management
  12. Distributed databases: structure
  13. Distributed database design
  14. Key terms
  15. Quick revision
  16. Important questions

Unit summary

Databases must survive failures, many simultaneous users and attacks, and may be spread across sites. This unit covers recovery, concurrency management, database security, integrity and control, disaster management, and the structure and design of distributed databases.

After this unit you can

  • Explain failures and recovery techniques
  • Explain concurrency control
  • Explain database security, integrity and disaster management
  • Describe the structure and design of distributed databases

PTU syllabus topics

  • Recovery
  • concurrency management
  • database security
  • integrity and control
  • disaster management
  • structure and design of distributed databases
ClassificationACID properties of a transaction
Transaction
  • Atomicity

    All or nothing

  • Consistency

    Valid state to valid state

  • Isolation

    Transactions don't interfere

  • Durability

    Committed changes survive failures

1

Topic 1

Recovery

Key termsTypes of failure
Transaction failure
Logical error (bad input) or system error (deadlock) aborts one transaction
System crash
Power or software failure loses main memory, disk survives
Disk failure
Head crash destroys stored data
Catastrophe
Fire, flood or earthquake destroys the site
2

Topic 2

Log-based recovery and checkpoints

SQL controls transactions with BEGIN/START TRANSACTION, COMMIT, ROLLBACK and SAVEPOINT, and sets isolation levels: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE. Crash recovery uses a log of all changes (write-ahead logging: log first, then data). After a crash, the system redoes committed transactions and undoes uncommitted ones. Checkpoints limit how much of the log must be scanned. The ARIES algorithm performs analysis, redo and undo phases.

ComparisonDeferred and immediate update
Deferred update
Immediate update

Database written

Only after commit

Before commit, as the transaction runs

Recovery needs

Redo only (no undo)

Undo and redo

Log records

New values

Old and new values

  • Shadow paging: keeps a shadow page table unchanged during a transaction; on commit the new table replaces it, on failure the shadow is restored — no log needed but causes fragmentation.
3

Topic 3

Transactions and ACID properties

A transaction is a sequence of operations performed as a single logical unit of work (for example transferring ₹500 from account A to B).

ClassificationACID properties
Transaction
  • Atomicity

    All operations happen, or none

  • Consistency

    Takes the database from one valid state to another

  • Isolation

    Concurrent transactions don't interfere

  • Durability

    Committed changes survive failures

Transaction states: active → partially committed → committed, or active → failed → aborted.

4

Topic 4

Concurrency management

A schedule is the order in which operations of concurrent transactions are executed. A serial schedule runs transactions one after another; a concurrent schedule interleaves them.

  • A schedule is conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations. Test: draw a precedence graph; if it has no cycle, the schedule is serializable.
  • Two operations conflict if they belong to different transactions, access the same item, and at least one is a write.
  • A recoverable schedule commits a transaction only after every transaction it read from has committed. A cascadeless schedule reads only committed data, avoiding cascading rollbacks.

Problems of uncontrolled concurrency: lost update, dirty read (reading uncommitted data), unrepeatable read and the phantom problem.

5

Topic 5

Lock-based concurrency control and 2PL

  • Shared lock (S): for reading; many transactions can hold it together.
  • Exclusive lock (X): for writing; only one transaction can hold it.

Two-phase locking (2PL) guarantees conflict serializability:

ProcessTwo-phase locking
  1. 1Growing phase

    Acquire locks, release none

  2. 2Lock point

    All locks held

  3. 3Shrinking phase

    Release locks, acquire none

Strict 2PL holds exclusive locks until commit, preventing cascading rollbacks. A lock manager keeps a lock table of granted and waiting requests. Locking has an overhead: more locking reduces concurrency and throughput.

6

Topic 6

Timestamp ordering

  • Each transaction gets a timestamp; conflicting operations must follow timestamp order. If an older transaction tries to read data already written by a younger one, it is rolled back and restarted. Free from deadlock.
7

Topic 7

Deadlock handling

A deadlock occurs when transactions wait for each other's locks in a cycle. Methods:

  • Prevention: wait-die and wound-wait schemes based on timestamps.
  • Detection: build a wait-for graph; a cycle means deadlock; then abort a victim transaction.
  • Timeouts: abort a transaction that waits too long.
8

Topic 8

Database security

Security goals: secrecy (only authorised users read data), integrity (only authorised changes) and availability. Discretionary access control (DAC) lets owners grant and revoke privileges:

sqlGRANT SELECT, INSERT ON student TO clerk;
REVOKE INSERT ON student FROM clerk;
GRANT SELECT ON student TO hod WITH GRANT OPTION;

Mandatory access control (MAC) uses system-wide security labels (top secret, secret …); role-based access control grants privileges to roles rather than individuals.

  • Threats: unauthorised access, SQL injection, privilege abuse, stolen backups, malware. Measures: authentication, encryption at rest and in transit, views to hide data, auditing, least privilege, statistical database controls.
9

Topic 9

Integrity and control

  • Integrity constraints keep data correct and consistent.
Key termsIntegrity constraints
Domain constraint
Values from a valid set: marks between 0 and 100
Entity integrity
Primary key is unique and not null
Referential integrity
Foreign key matches a primary key, with ON DELETE CASCADE or RESTRICT
Key and unique constraints
No duplicate values
Check constraint
Business rule such as fee > 0
Triggers and assertions
Rules enforced automatically on insert, update or delete
sqlCREATE TABLE result (
  roll   INT REFERENCES student(roll) ON DELETE CASCADE,
  code   VARCHAR(10) REFERENCES course(code),
  marks  INT CHECK (marks BETWEEN 0 AND 100),
  PRIMARY KEY (roll, code)
);
  • Control: concurrency control, access control, audit trails and backup policies together keep data controlled.
10

Topic 10

Disaster management

ProcessDatabase disaster recovery plan
  1. 1Risk assessment

    Identify threats such as fire, flood, ransomware

  2. 2Backup strategy

    Full, incremental and differential backups; offsite or cloud copies

  3. 3Replication and standby

    Mirrored or standby databases at another site

  4. 4Recovery objectives

    RPO (data loss allowed) and RTO (downtime allowed)

  5. 5Testing

    Restore drills and plan updates

  • Backup types: full (everything), incremental (changes since the last backup), differential (changes since the last full backup); hot backup while the database runs, cold backup when it is shut down.
11

Topic 11

Distributed databases: structure

  • Distributed database: a single logical database stored across several sites connected by a network, managed by a distributed DBMS that hides the distribution from users (transparency).
ComparisonHomogeneous and heterogeneous
Homogeneous
Heterogeneous

DBMS at sites

Same software everywhere

Different DBMSs or data models

Cooperation

Sites aware of each other

Sites may be unaware; middleware needed

Ease of management

Easier

Harder

  • Advantages: local autonomy, reliability and availability (other sites keep working), faster local access, scalable growth. Disadvantages: complexity, cost, security, harder concurrency and recovery (two-phase commit).
Key termsTransparency
Location transparency
Users need not know where data is stored
Fragmentation transparency
Users need not know how a table is split
Replication transparency
Users need not know about copies
Transaction transparency
Distributed transactions behave like local ones
12

Topic 12

Distributed database design

ClassificationDistributed design
Distribution design
  • Fragmentation

    Horizontal (rows by branch), vertical (columns), mixed

  • Replication

    Full, partial or none

  • Allocation

    Placing fragments at sites near their users

Example

A bank keeps ACCOUNT rows of Ludhiana customers at the Ludhiana site and Delhi customers at Delhi (horizontal fragmentation); the head office keeps a replicated copy for reporting.

  • Two-phase commit (2PC): a coordinator asks all sites to prepare (vote) and then tells all to commit or all to abort, ensuring atomicity across sites.

Key terms

Log
Record of all database changes used for recovery
Checkpoint
Point at which buffers are written and logged to shorten recovery
Serializability
Concurrent schedule equivalent to some serial schedule
Fragmentation
Splitting a relation for storage at different sites
Two-phase commit
Protocol ensuring all sites commit or all abort

Quick revision

  • Failures; log-based recovery, deferred and immediate update, checkpoints, shadow paging.
  • ACID; serializability; 2PL; timestamps; deadlocks.
  • Security: DAC, MAC, RBAC, GRANT and REVOKE.
  • Integrity constraints; disaster recovery, backups, RPO and RTO.
  • Distributed DB: homogeneous vs heterogeneous, transparency, fragmentation, replication, allocation, 2PC.

Important exam questions

Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).

Short-answer questions

  1. Q1.What is a checkpoint?
  2. Q2.Distinguish deferred and immediate update.
  3. Q3.State the ACID properties.
  4. Q4.What is two-phase locking?
  5. Q5.Distinguish horizontal and vertical fragmentation.
  6. Q6.What is location transparency?

Long-answer questions

  1. Q1.Explain log-based recovery techniques.
  2. Q2.Explain concurrency control using locking and timestamps.
  3. Q3.Explain database security and integrity constraints.
  4. Q4.Explain the structure and design of distributed databases.

Stuck on this unit?

Message SBS on WhatsApp for help with Database Management Systems, or to ask about studying B.Sc IT at Synetic.

WhatsApp us