Docsity

Database Administration - Lecture Notes | CSIS 350, Study notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
CSIS 350 – Lecture 25
Announcements
Welcome back! – we're getting to the end here.
Courses in risk of being cancelled! Register for classes ASAP.
Chapter 9
This chapter is about database administration. This is really important for multi-user
databases.
Responsibility of DBA: facilitate development and use of the DB. Need to balance
conflicting goals:
- protect the database
- maximized its availability and benefit to users
Specific tasks:
- Manage DB structure
- Control concurrent processing
- Manage processing rights and responsibilities
- Develop DB security
- Provide for DB recovery
- Manage the DBMS
- Maintain the data repository
Managing DB structure
DBA’s tasks:
- Participate in database and application development
oAssist in requirements stage and data model creation
oPlay an active role in database design and creation
create DB, allocate disk space, generate tables, triggers, stored
procedures
- Facilitate changes to database structure
oSeek community-wide solutions
oAssess impact on all users
Changes can affect many users/applications
oProvide configuration control forum
How do users request changes?
How are changes approved?
oBe prepared for problems after changes are made
oMaintain documentation
For debugging when problems occur
pf3
pf4
pf5

Partial preview of the text

Download Database Administration - Lecture Notes | CSIS 350 and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

CSIS 350 – Lecture 25

Announcements Welcome back! – we're getting to the end here. Courses in risk of being cancelled! Register for classes ASAP. Chapter 9 This chapter is about database administration. This is really important for multi-user databases. Responsibility of DBA: facilitate development and use of the DB. Need to balance conflicting goals:

  • protect the database
  • maximized its availability and benefit to users Specific tasks:
  • Manage DB structure
  • Control concurrent processing
  • Manage processing rights and responsibilities
  • Develop DB security
  • Provide for DB recovery
  • Manage the DBMS
  • Maintain the data repository Managing DB structure DBA’s tasks:
  • Participate in database and application development o Assist in requirements stage and data model creation o Play an active role in database design and creation  create DB, allocate disk space, generate tables, triggers, stored procedures
  • Facilitate changes to database structure o Seek community-wide solutions o Assess impact on all users  Changes can affect many users/applications o Provide configuration control forum  How do users request changes?  How are changes approved? o Be prepared for problems after changes are made o Maintain documentation  For debugging when problems occur

 For DB restoration  For archived data – what was the database structure when you saved the data? Concurrency Control In most DBs, multiple users are active at the same time. In a large DB, could be 10s of thousands of simultaneous users (Amazon, Orbitz, …). Need to ensure that the user's don’t interfere with each other.

  • This is called concurrency control
  • Each user expects his work to be completed as if he were the only user.
  • There are tradeoffs between levels of concurrency control and performance. Atomic Transactions Often, a DB application needs to modify a set of tables as part of a transaction. For example, assume we have a DB for students to register for classes that includes these tables: Section(CRN, numSeatsLeft, CourseNumber , FacultyID , …) Registration( StudentID , Term, NumUnits, … ) ResistrationCourse( StudentID , Term , RegNum, CRN ) when a student registers for a class, we need to do something like this:
  1. Decrement available seats from Section table for the class
  2. Update the number of units for that student in the Registration Table
  3. Insert a row in the RegistrationCourse table What if step 3 fails for some reason? What do we want to have happen? Either all three changes should occur, or none of them should. We want the three steps to be part of an atomic transaction. (atomic from the idea that an atom is the smallest indivisible physical unit). We need to identify transactions to the database so that it knows what the atomic units are. See slides 1,2, & 3. Three parts: Begin Transaction, Commit Transaction, Rollback transaction Concurrent Transactions In multi-user DBs, multiple users can be performing transactions at the same time. Let's look at an update to a single row in a inventory table: UPDATE Inventory SET ( ItemCount )

A: Lock row A: Read Row from Table A: Subtract 1 B: Lock Row – can’t because it is already locked, so wait A: Write result A: Release Lock B: Place Lock for B B: Read Row from table B: Subtract 1 B: Write result B: Release lock This is an example of a record lock, because it locks a single record (or row) of a table. Different DBMSs have different locking policies:

  • lock a group of records
  • lock an entire table
  • lock the whole database The size of the lock is referred to as the lock granularity. Larger locks are easier to implement and administer, but lead to more conflicts.
  • Large granularity – fewer locks to manage, but more likely to lead to waiting
  • Small granularity – more locks, but better performance because other processes are less likely to be blocked. There are also two types of locks:
  • exclusive: no other process can access the item
  • shared: other processes can read the item, but not modify it.
    Only 1 process can hold an exclusive lock at any time, but multiple processes can hold shared locks simultaneously. Lock granting rules: User 1 Holds User 2 Requests Shared Lock Exclusive Lock Shared Lock Granted User 2 waits Exclusive Lock User 2 waits User 2 waits Serializabile Transactions We want the results of a set of concurrent transactions to be the same as if they had been executed sequentially (in any order). A concurrency control scheme is serializable if it processes the transactions in this way (result is the same as it is in some sequential order). One way to enforce serializability is with two-phase locking:
  1. obtain locks as necessary, but once you release a lock you can't obtain any more (growing phase)
  2. Release the locks (shrinking phase). Many DBMSs hold the locks until the transaction is complete, and then release them all at once, but this is not a requirement of 2-phase locking Deadlock Does this solve all our problems? Yes and no – we've solved problems with interference, but we've introduced a new problem. Look at the following sequence of operations for two processes: Process A Process B Get Exclusive Lock on Table 1 Get Exclusive Lock on Table 2 Do something Release locks Get Exclusive Lock on Table 2 Get Exclusive Lock on Table 1 Do something Release locks What can go wrong? Remember, the steps can be interleaved in any way: A gets Lock on table 1 B gets Lock on table 2 A tries to get lock on table 2, waits for it to be unlocked B tries to get lock on table 1, waits for it to be unlocked Both waiting, but neither will ever get to continue because the locks will never be released. This is called deadlock. Note that this problem is due to the order locks are requested by the applications. Most DBMS products have detection algorithms that look for deadlocks, and aborts one of the transactions that is in a deadlocked state (also rollsback incomplete work). However, lots of deadlocks can be avoided by carefully writing the applications. In this case, if A and B tried to access the tables in the same order, deadlock could never occur. Optimistic and Pessimistic Locking There are two approaches that can be taken by DBMSs regarding locking:
  • Optimistic
  • Pessimistic Optimistic locking assumes that few conflicts will occur:
  • Read data
  • Issue updates
  • Then check for conflict