300104

Database Design and Development
Spring 2010 Parramatta Campus
11

Today’s Topics
Locking continued Deadlock Recovery facilities Detailed roles of DA and DBA Maintenance of DBMS, utilities and applications

2

Transactions and Database Administration

Two-Phase Locking (2PL)
Transaction follows 2PL protocol if all locking operations precede the first unlock operation in the transaction. Two phases for transaction:
Growing Phase - acquires all locks but cannot release any locks. Shrinking Phase - releases locks but cannot acquire any new locks.
4

5 .. Loss of T2’s update avoided by preventing T1 from reading balx until after update.Lost Update Problem .

the write lock request in T1 can not be immediately granted and T1 has to wait until T2 releases the lock on balx. T2 will release the lock only after all aspects of the transaction have been completed. 6 .Prevent Lost Update Problem using 2PL T1 is essentially after T2 Because T2 already has an exclusive lock on balx.

Problem avoided by preventing T3 from reading balx until after T4 commits or aborts 7 .Uncommitted Dependency Problem ..

8 .Prevent Uncommitted Dependency using 2PL T3 is essentially after T4 T3 has to wait until the lock is released by T4. This happens only after the entire rollback of T4 is finished.

Prevent Inconsistent Analysis Problem using 2PL T6 is essentially after T5 T6 can’t read any of the values being updated by T5 because of the T5 exclusive lock 9 .

problems can occur with interpretation of when locks can be released – see example on the next slide 10 . schedule is serializable.Cascading Rollback . However. If every transaction in a schedule follows 2PL.

. 11 .Cascading Rollback .

T14 aborts. These transactions conform to 2PL. it too must be rolled back. To prevent this with 2PL. This is called cascading rollback. leave release of all locks until end of transaction. 12 .Cascading Rollback . T15 must also be rolled back. Since T15 is dependent on T14. Since T16 is dependent on T15...

e.Variants of 2PL Rigorous 2PL – 2PL that leaves the release of all locks until the end of the transaction (i. either committed or aborted) This solve the cascading rollback problem in the previous example Strict 2PL – 2PL that holds only exclusive locks until the end of the transaction Most database systems implement one of these two variants of 2PL 13 .

14 . An impasse that may result when two (or more) transactions are each waiting for locks held by the other to be released.Deadlock .

Only one way to break deadlock: abort one or more of the transactions.Deadlock . 15 .. Deadlock prevention. Deadlock detection and recovery. Deadlock should be transparent to user so DBMS should automatically restart any transaction aborted to resolve deadlock. Three general techniques for handling deadlock: Timeouts.

even though it may not be. 16 . lock request times out. DBMS assumes transaction may be deadlocked.Timeout Transaction that requests lock will only wait for a system-defined period of time. and it aborts and automatically restarts the transaction. In this case. If lock has not been granted within this period.

17 . DBMS looks ahead to see if transaction would cause deadlock and never allows deadlock to occur.only an older transaction can wait for younger one. otherwise transaction is aborted (dies) and restarted with same timestamp.Deadlock Prevention . Could order transactions using transaction timestamps: Wait-Die .

Deadlock Prevention . If older transaction requests lock held by younger one.only a younger transaction can wait for an older one.. … and restarts with the original timestamp 18 . Wound-Wait . younger one is aborted (wounded).

Deadlock Detection and Recovery DBMS allows deadlock to occur but recognizes it and breaks it. Deadlock exists if and only if WFG contains cycle. if Ti waiting to lock item locked by Tj. WFG is created at regular intervals. Create edge Ti -> Tj. 19 . Usually handled by construction of wait-for graph (WFG) showing transaction dependencies: Create a node for each transaction.

Wait-For-Graph (WFG) T17 is waiting for T18 and also T18 is waiting for T17 … this is a deadlock situation y x 20 .Example .

Transactions ordered globally so that older transactions. get priority in the event of conflict. Conflict is resolved by rolling back and restarting transaction. No locks so no deadlock. transactions with smaller timestamps. 21 .Timestamping .

Timestamp A unique identifier created by DBMS that indicates relative starting time of a transaction. or by incrementing a logical counter every time a new transaction starts.Timestamping . 22 .. Can be generated by using system clock at time transaction started.

Volatile storage does not survive system crashes. Stable storage represents information that has been replicated in several nonvolatile storage media with independent failure modes.Database Recovery Process of restoring database to a correct state in the event of a failure. 23 . Need for Recovery Control Two types of storage: volatile (main memory) and nonvolatile.

Media failures. resulting in loss of main memory.Types of Failure System crashes. resulting in loss of parts of secondary storage. Sabotage. Application software errors. 24 . Carelessness or unintentional destruction of data or facilities. Natural physical disasters.

Recovery manager responsible for atomicity and durability. recovery manager has to redo (roll forward) transaction’s updates. Transactions represent basic unit of recovery. 25 .Transactions and Recovery. to ensure durability. If failure occurs between commit and database buffers being flushed to secondary storage then.

Transactions and Recovery. recovery manager has to undo (rollback) any effects of that transaction for atomicity. 26 .. Global undo . If transaction had not committed at failure time.only one transaction has to be undone. Partial undo .all transactions have to be undone.

recovery manager has to redo T2.Example DBMS starts at time t0. T4. Assume data for transactions T2 and T3 have been written to secondary storage. but fails at time tf. In absence of any other information. and T5. T3. T1 and T6 have to be undone. 27 .

Recovery Facilities DBMS should provide following facilities to assist with recovery: Backup mechanism. Recovery manager. which makes periodic backup copies of database. Checkpoint facility. Logging facilities. which keep track of current state of transactions and database changes. 28 . which allows DBMS to restore database to consistent state following a failure. which enables updates to database in progress to be made permanent.

auditing). Often used for other purposes (for example. Contains information about all updates to database: Transaction records. 29 . Checkpoint records.Log File .

delete. commit). Type of log record. 30 . delete. (transaction start. insert. Identifier of data item affected by database action (insert. Log management information. Transaction records contain: Transaction identifier. update. abort.. Before-image of data item. After-image of data item.Log File . and update operations).

Sample Log File 31 .

Checkpointing . Checkpoint record is created containing identifiers of all active transactions. Checkpoint Point of synchronization between database and log file. All buffers are force-written to secondary storage. 32 . When failure occurs. redo all transactions that committed since the checkpoint and undo all transactions active at time of crash.

22. if tc denotes the checkpoint. then changes made by T2 and T3 have been written to secondary storage. undo transactions T1 and T6. 33 .. Thus: only redo T4 and T5.24).Checkpointing . untouched In previous example (fig.

If database is only inconsistent: Need to undo changes that caused inconsistency. Do not need backup.Recovery Techniques If database has been damaged: Need to restore last backup copy of database and reapply updates of committed transactions using log file. May also need to redo some transactions to ensure updates reach secondary storage. but can restore database using before.and after-images in the log file. 34 .

Data and Database Administration .

The Data Administrator (DA) and Database Administrator (DBA) are responsible for managing and controlling the corporate data and corporate database. development and maintenance of standards. database planning.Data Administrator and Database Administrator . 36 . respectively.g. e. policies and procedures. and conceptual and logical database design. DA is more concerned with early stages of database system development lifecycle.

. backup and recovery selecting appropriate software 37 . DBA is more concerned with later stages. and reorganizing the database. setting security and integrity controls. e.g.Data Administrator and Database Administrator . Management of physical realization of a database system including: physical database design and implementation. monitoring system performance.

..Database planning System definition DA Demarcation not as clear as it seems . Requirements collection & analysis Database Design Application Design Conceptual DB Design DBMS selection (optional) Logical DB Design Physical DB Design DBA Prototyping (Optional) Implementation / Data conversion and loading / Testing / Operational maintenance 38 .

constraints. procedures. backup. recovery. automated CASE tools used in organization) 39 . IT Specialist) Resolving data conflict (ownership) (Procedures for conflict resolution. needs. use of external data sources. mediate and enforce) Internal marketing of DA concepts ( reduces resistance to change and data ownership problems) (training) Managing the data repository ( data definitions. business rules. Data policies. training) Planning (organization’s information architecture. standards (PW.Traditional DA Functions Database is a shared resource. effective administration.

testing. upgrading. natural disasters. 3rd party S/W. rebuilding of DB for new user requirements. security.Traditional DBA Functions Database administration is responsible for logical and physical database design and dealing with security. non-repudiation) Data backup and recovery ( due to H/W. and availability of database. compacting) Improving query processing performance (dealing with large tables. performance benchmarks. privacy. Selection of hardware and software (vendors. processing time. indexing. concurrent processes) Managing data security. distributing data. testing implementing and training staff to deal with data loss) 40 . backup/recovery.…) Mac / IBM? Unix/ windows? Single/multi core? Installing/upgrading DBMS (versions. integrity. creating user accounts) Tuning database performance (query run time. encryption. partitioning. and integrity (privacy. (SDLC) Must know the schema of data to be administered. device drivers. S/W failure. performance.

implementation. eDBA – managing Internet-enabled database applications. …) 41 . analysis. (ad hoc queries. Data warehouse administration (DWA).Evolving DBA Roles Blend data and database administration into one role Fast-track development – reduction in development time (planning. similar roles to DA and DWA. stored procedures and persistent modules. maintenance-SDLC) Procedural DBAs – managing quality of triggers. design. with DWH. 24x7x356 PDA DBA – data synchronization and personal database management.

Database vendors provide the software tools and utilities for DBA eg. Maintenance activities are dedicated to the preservation of the DBMS environment.Maintenance of the DBMS. Utilities and Applications . the Oracle Enterprise Manager Interface 42 .

. Utilities and Applications . Management of the physical or secondary storage devices. providing more space for new data. (e. (Non fragmented) Re-organisation process may also free space allocated to deleted data. (marked for deletion) Creation and expansion of database storage 43 structures . Horizontal/vertical partitioning) To improve performance DBA may allocate contiguous disk-page locations to the DBMS.g. Commonly need to re-organize the physical location of data in the database.Maintenance of the DBMS.

.Maintenance of the DBMS. 44 . Utilities and Applications . DBA may create an additional DBMS gateway to allow access to a host DBMS running on a different host computer – particularly important in distributed DBMS applications running in client/server environment.. DBA may need to install a new version of the DBMS software or an Internet front-end tool. Upgrading DBMS and utility software.

Utilities and Applications . procedures etc.. Customisation of database initialisation parameters. indexes. 45 .Maintenance of the DBMS.. Migration and conversion services. triggers. Focus on data exchange with data in dissimilar or incompatible formats. Management of database objects such as tables..

20 (20.Reading Read Chapter 22 (22. Chapter 13 46 . Prescott M B and Topi H. read Hoffer J A.3-22. 9th edition. Modern Database Management.5).6) If possible.