+ All Categories
Home > Documents > Ch07 CE (Services)(1)

Ch07 CE (Services)(1)

Date post: 05-Apr-2018
Category:
Upload: ttangx
View: 218 times
Download: 0 times
Share this document with a friend

of 62

Transcript
  • 8/2/2019 Ch07 CE (Services)(1)

    1/62

    Concepts of Database ManagementSeventh Edition

    Chapter 7

    DBMS Functions

  • 8/2/2019 Ch07 CE (Services)(1)

    2/62

    Objectives

    Introduce the functions, or services, provided by aDBMS

    Describe how a DBMS handles updating and

    retrieving data Examine the catalog feature of a DBMS

    Illustrate the concurrent update problem anddescribe how a DBMS handles this problem

    Explain the data recovery process in a databaseenvironment

    2

  • 8/2/2019 Ch07 CE (Services)(1)

    3/62

    Objectives (continued)

    Describe the security services provided by a DBMS

    Examine the data integrity features provided by aDBMS

    Discuss the extent to which a DBMS achieves dataindependence

    Define and describe data replication

    Present the utility services provided by a DBMS

    3

  • 8/2/2019 Ch07 CE (Services)(1)

    4/62

    Introduction

    Some services provided by a DBMS

    Data Access: Update and retrieve data

    Support data independence

    Data integrity features Concurrent update

    Catalog

    Security

    Support data replication Data recovery

    Utility services

    4

  • 8/2/2019 Ch07 CE (Services)(1)

    5/62

    Access to Data: Client Server

    User (or application) issues SQL commands to theDB server

    5

    Client /

    Application

    (e.g., ssms or

    C++ app)

    Database

    ServerDatabase

    Storage

  • 8/2/2019 Ch07 CE (Services)(1)

    6/62

  • 8/2/2019 Ch07 CE (Services)(1)

    7/62

    Update and Retrieve Data

    Fundamental capability of a DBMS

    Users or applications dont need to know how data

    is stored or how to manipulate it

    User (or program) makes a request that describeswhat needs to be accomplished

    The DBMS interprets the request and does all thework to retrieve, add, update or delete data

    7

  • 8/2/2019 Ch07 CE (Services)(1)

    8/62

    Making DB Requests

    SQL Access (a non-procedural language)

    QBE - Easy-to-use menu-driven interface

    Access by non-DBMS software (usually

    implemented with procedural languages) Intermixing SQL with procedural statements and

    using a pre-compiler to translate to appropriateprocedure calls

    Using an API (application program interface), usuallyimplemented as an object-oriented set of classesthat provide a procedural access to the database,incorporating SQL statements as strings as required.

    8

  • 8/2/2019 Ch07 CE (Services)(1)

    9/62

    Microsoft Database APIs

    9

    Taken from

    Wikipedia

    MDAC

    Supported

    by many

    platforms

    http://en.wikipedia.org/wiki/File:MDAC_Architecture.svghttp://en.wikipedia.org/wiki/File:MDAC_Architecture.svg
  • 8/2/2019 Ch07 CE (Services)(1)

    10/62

    ADO Example Codehttp://www.timesheetsmts.com/adotutorial.htm

    Private Sub Command1_Click()

    declare ADO objectsDim conConnection As New ADODB.Connection

    Dim cmdCommand As New ADODB.Command

    Dim rstRecordSet As New ADODB.Recordset

    open a connection

    conConnection.ConnectionString = _

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _

    App.Path & "\" & "database.mdb;Mode=Read|Write"

    conConnection.CursorLocation = adUseClientconConnection.Open

    create a command

    With cmdCommand Prepare SQL command

    .ActiveConnection = conConnection

    .CommandText = "SELECT * FROM tabTestTable;"

    .CommandType = adCmdText

    End With

    use command to establish a record set

    With rstRecordSet Use SQL to get cursor

    .CursorType = adOpenStatic

    .CursorLocation = adUseClient

    .LockType = adLockOptimistic

    .Open cmdCommand

    End With

    If rstRecordSet.EOF = False Then Use cursor

    rstRecordSet.MoveFirst

    10

    Do See whats in the tableMsgBox "Record " & rstRecordSet.AbsolutePosition & " " & _

    rstRecordSet.Fields(0).Name & "=" & rstRecordSet.Fields(0) & " " & _

    rstRecordSet.Fields(1).Name & "=" & rstRecordSet.Fields(1)

    rstRecordSet.MoveNext

    Loop Until rstRecordSet.EOF = True

    With rstRecordSet Add a row

    .AddNew

    .Fields(0) = "New"

    .Fields(1) = "Record"

    .Update

    End With

    rstRecordSet.MoveFirst Delete a row

    rstRecordSet.Delete

    rstRecordSet.Update

    rstRecordSet.Close

    Else

    MsgBox "No records were returned using the query " & _

    cmdCommand.CommandText

    End If

    reset objects

    conConnection.Close

    Set conConnection = Nothing

    Set cmdCommand = Nothing

    Set rstRecordSet = Nothing

    End Sub

  • 8/2/2019 Ch07 CE (Services)(1)

    11/62

    Support Data Independence

    Data independence: can change databasestructure without needing to change programs thataccess the database

    Types of changes: Adding a field

    Changing a field property (such as length)

    Creating an index

    Adding or changing a relationship

    11

  • 8/2/2019 Ch07 CE (Services)(1)

    12/62

    Adding a Field

    Only need to change programs that will use thenew field

    Note: SQL SELECT * FROM command will present

    the extra field Solution:

    Many application program interfaces (API) make thistransparent, but for those that do not,

    Instead of using *, list the required fields in any SQLSELECT commandthis is considered a bestpractice

    12

  • 8/2/2019 Ch07 CE (Services)(1)

    13/62

    Changing the Length of a Field

    Generally, dont need to change programs unless a

    portion of a screen or report (or a variable used inthe program) that is set aside for the field is no

    longer large enough to support new, larger datavalues.

    13

  • 8/2/2019 Ch07 CE (Services)(1)

    14/62

    Creating an Index

    To create an index, enter a simple SQL commandor select a few options

    DBMSs use the new index transparently, as

    appropriate, for best performance For some DBMSs, may need to make minor

    changes in already existing programs in order totake advantage of new indexes

    14

  • 8/2/2019 Ch07 CE (Services)(1)

    15/62

    Adding or Changing a Relationship

    May need to modify applications

    A better solution, though, is to provide for this sortof change in advance by creating views

    incorporating tables whose business requirementscan change then, change the view at the sametime you change the relationshipthe change isthen transparent to any programs that use the

    view.

    15

  • 8/2/2019 Ch07 CE (Services)(1)

    16/62

    Provide Data Integrity Features

    Business requirements dictate constraints related todata accuracy and consistency

    Constraints may relate to tables (e.g., a column must beunique, or may contain only certain values), or

    They may relate to relationships (e.g., a tuple in one tablecannot exist without a corresponding tuple in another), or

    They may relate to contents of several tables, possiblynot even in a relationship (e.g., the inventory table mustbe updated whenever an order is generated)

    A good DBMS enforces a wide variety of constraints,but programming may be required for complexconstraints.

    16

  • 8/2/2019 Ch07 CE (Services)(1)

    17/62

    Provide Data Integrity Features(review)

    Constraints enforced by good databases include

    Key integrity Primary key

    Foreign key

    Data integrity Legal values

    Data type

    Domain / Format (Check)

    Null allowed

    Default

    Uniqueness

    17

  • 8/2/2019 Ch07 CE (Services)(1)

    18/62

    Provide Data Integrity Features

    Four ways to handle integrity constraints:

    1. Ignore it

    2. Place responsibility on users

    3. Place responsibility on programmers4. Place responsibility on DBMS

    Number 4 is preferred; number 3 has issues, but is

    better than not enforcing at all (essentially,

    numbers 1 and 2)

    18

  • 8/2/2019 Ch07 CE (Services)(1)

    19/62

    Support Concurrent Update

    Concurrent update:multiple users make updatesto the same database at the same time

    DBMS manages complex update scenarios

    Ensures accuracy when several users updatedatabase at the same time

    19

  • 8/2/2019 Ch07 CE (Services)(1)

    20/62

    The Concurrent Update Problem

    FIGURE 7-4: Scenario 1Ryan and Elenas updates dont overlap (OK)

    - continued on next slide - 20

    Th C U d P bl

  • 8/2/2019 Ch07 CE (Services)(1)

    21/62

    The Concurrent Update Problem(continued)

    FIGURE 7-5: Scenario 1 (continued) no overlapno problems

    21

    Ryan is

    done with

    his update

    Th C t U d t P bl

  • 8/2/2019 Ch07 CE (Services)(1)

    22/62

    The Concurrent Update Problem(continued)

    FIGURE 7-6: Scenario 2Ryans and Elenas updates overlap 22

    Ryan and

    Elena are

    updating

    at the

    same time

    Ryan adds

    100

  • 8/2/2019 Ch07 CE (Services)(1)

    23/62

    The Concurrent Update Problem(continued)

    FIGURE 7-6: Scenario 2 (continued)Ryans and Elenas updates overlap -

    result in a lost update

    23

    Elena

    subtracts

    100

  • 8/2/2019 Ch07 CE (Services)(1)

    24/62

    Avoiding the Lost Update Problem

    Need to assure that updates dont overlap

    inappropriately.

    One approach: Batch processing

    All updates done through a special program runperiodically

    Problem: data becomes stale and may causeincorrect decisions regarding further transactions

    Does not work in situations that require data to becurrent

    24

  • 8/2/2019 Ch07 CE (Services)(1)

    25/62

    Batch Processing

    FIGURE 7-7: Delaying updates to the Premiere Products database to avoid the

    lost update problem

    25

  • 8/2/2019 Ch07 CE (Services)(1)

    26/62

    DB Transaction

    Transaction:set of steps completed by a DBMS toaccomplish a user task

    A sequence of operations (e.g., SQL statements)

    Brings the database from one consistentstate toanother (but partial completion would leave thedatabase in an inconsistent state)

    Must be executed completelyor undone completely

    SQL Server places the statements between BEGINTRANSACTION and {COMMIT | ROLLBACK}TRANSACTION (Oracle has implicit BEGIN onlyspecify COMMIT or ROLLBACK)

    26

  • 8/2/2019 Ch07 CE (Services)(1)

    27/62

    Locking

    Locking:deny other users access to data whileone users updates are being processed

    The DBMS determines what locks are necessary

    Generally at least two levels: read, write a read

    lock allows other read locks (but not write locks), awrite lock allows neither a read nor a write lock.

    Locks have granularity: database, table, block,record, field

    The DBMS choses the lowest appropriate level of lock preferring table, block or record

    If a user holds a number of locks at a given level, theDBMS may choose to promote it (if that doesnt

    conflict with other users locks).

    27

  • 8/2/2019 Ch07 CE (Services)(1)

    28/62

    Locking (continued)

    FIGURE 7-8: The DBMS uses a locking scheme to apply Ryans and Elenas

    updates to the database

    28

  • 8/2/2019 Ch07 CE (Services)(1)

    29/62

    Locking (continued)

    FIGURE 7-8: The DBMS uses a locking scheme to apply Ryans and Elenas

    updates to the database (continued)

    29

  • 8/2/2019 Ch07 CE (Services)(1)

    30/62

    Locking (continued)

    FIGURE 7-8: The DBMS uses a locking scheme to apply Ryans and Elenas

    updates to the database (continued)30

    Ryan now

    cannot

    access the

    record.

  • 8/2/2019 Ch07 CE (Services)(1)

    31/62

    Two-Phase Locking

    Transactions usually require multiple locks

    All the locks need to be held until the end of thetransaction to assure integrity

    The DBMS accomplishes this using two-phaselocking:

    Growing phase: DBMS requests new locks withoutreleasing those already held

    Shrinking phase: DBMS releases locks withoutacquiring any new ones

    31

  • 8/2/2019 Ch07 CE (Services)(1)

    32/62

    Deadlock

    Deadlock or deadly embrace

    Two users hold locks and require a lock on a resource that theother already has neither can procede

    To minimize occurrence, the DBMS could try to lock records in

    a consistent order applicable to all users, but it has no way topredict what data the user will access, let alone the order.

    The DBMS must detect and break deadlocks when theyoccur

    DBMS chooses one user to be the victim DBMS rolls back victims transaction, freeing up its locks for

    other users transactions this usually requires the victimssoftware to detect the failure and reattempt the transaction.

    32

  • 8/2/2019 Ch07 CE (Services)(1)

    33/62

    Deadlock (continued)

    FIGURE 7-9: Two users experiencing deadlockchoose one as the victim

    33

  • 8/2/2019 Ch07 CE (Services)(1)

    34/62

    Locking on PC-Based DBMSs

    Usually more limited than locking facilities onenterprise DBMSs

    Programs can lock an entire table or an individual

    row within a table, but only one or the other Programs can release any or all of the locks they

    currently hold

    Programs can inquire whether a given row or table

    is locked

    34

  • 8/2/2019 Ch07 CE (Services)(1)

    35/62

    Timestamping

    Time stamping is an alternative to locking DBMS assigns each database update a unique time

    (timestamp) when the update started

    Compares the stamp to decide victim

    Advantages Avoids need to lock rows

    Eliminates processing time needed to apply andrelease locks and to detect and resolve deadlocks

    Disadvantages

    Additional disk and memory space

    Extra processing time

    35

  • 8/2/2019 Ch07 CE (Services)(1)

    36/62

    ACID Propertiesto guarantee transaction reliability

    Atomicity Transaction is all or nothing

    Consistency Transaction brings DB from one consistent state to

    another

    Isolation No transaction can interfere with another

    Durability Once committed, it will remain so no matter what

    36

  • 8/2/2019 Ch07 CE (Services)(1)

    37/62

    Catalog Services

    Metadata: data about data

    Catalog stores metadata and makes it accessibleto users

    A data dictionary is a view of the catalog,providing information about database objects.

    37

  • 8/2/2019 Ch07 CE (Services)(1)

    38/62

    Security Services

    Security: prevention of unauthorized access, eitherintentional or accidental, to a database

    Most common security features used by DBMSs:

    Authentication Authorization

    Views

    Encryption

    38

  • 8/2/2019 Ch07 CE (Services)(1)

    39/62

    Authentication

    Authentication:techniques for identifying the personattempting to access the DBMS

    Password:string of characters assigned by DBA to auser that must be entered for access

    Note that more secure options are available; e.g., integration with

    Windows security is preferred for SQL Server.

    Biometrics:identify users by physical characteristicssuch as fingerprints, voiceprints, handwritten signatures,and facial characteristics

    Smart cards:small plastic cards with built-in circuitscontaining processing logic to identify the cardholder

    39

  • 8/2/2019 Ch07 CE (Services)(1)

    40/62

    Authorization

    DBA can use authorization rules to specify whichusers have what type of access to which data

    Workgroups: groups (classes) of users defined to

    simplify the authorization process Permissions:specify what kind of access the user

    has to objects in the databasewe talked aboutthe GRANT command earlier in the course.

    40

  • 8/2/2019 Ch07 CE (Services)(1)

    41/62

    Views

    View: snapshot of certain data in the database at agiven moment in time

    For most users or groups, the DBA grants access

    to views, rather than the underlying tables, in orderto provide appropriate data security.

    41

  • 8/2/2019 Ch07 CE (Services)(1)

    42/62

    Privacy

    Privacy:right of individuals to have certaininformation about them kept confidential

    Laws and regulations dictate some privacy rules

    Companies institute additional privacy rules Privacy is enforced by views.

    42

  • 8/2/2019 Ch07 CE (Services)(1)

    43/62

    Encryption

    Encryption:converts data to a format indecipherable toother programs, and stores it in that form when writingor updating.

    Decryption:reverses the encryption to get clear data.

    DBMS uses encryption in several contexts: Passwords encryption or one-way hash

    Data stored on disk - only DBMS may decrypt

    prevents back-door access

    transparent to legitimate users

    Data transmitted between user and DBMS onlyendpoints see data in the clear

    prevents snoopers from seeing data

    43

  • 8/2/2019 Ch07 CE (Services)(1)

    44/62

    Two Types of EncryptionSymmetric

    Symmetric uses a key

    Key is relatively short (

  • 8/2/2019 Ch07 CE (Services)(1)

    45/62

    Two Types of EncryptionAsymmetric (aka. Public Key)

    Asymmetric uses a key pair Two keys one private another public public key is

    published (e.g., in a certificate) private key must beprotected (often in a separate device that does theactual encryption / decryption)

    To encrypt (and send) data, encrypt with other partys

    public key only that party can read it.

    To sign (and publish) data, encrypt with private key anyone can use public key to decrypt (knowing its

    from you)

    Relatively slow Keys / blocks are large (>= 1KB)

    Generally used to transmit symmetric keys, or digitalsignatures (an encrypted hash of the signed content)

    45

  • 8/2/2019 Ch07 CE (Services)(1)

    46/62

    Two Types of Encryption

    Symmetric and asymmetric are often used incombination

    E.g., when using a https site, the browser chooses asymmetric key, encrypts it using the servers public

    key, and sends it to the server (who is the only onethat can decrypt it); data is encrypted both directionsusing the symmetric key

    Because symmetric keys are easier to break, the twosides may agree to change the symmetric key fromtime to time

    Some secure transmissions require both sides tohave a public key pair smart cards provide onesecure mechanism to support this

    46

  • 8/2/2019 Ch07 CE (Services)(1)

    47/62

    Data Replication

    Replication: providing redundant copies (replicas) of

    data often at different sites

    for performance (at remote sites)

    and/or recovery (of central site)

    Synchronization: DBMS exchanges all updated databetween master database and a replica

    Depending on requirements and cost, synchronization can bebatch or real time (or in between)

    The complexity of synchronization depends on whether data

    can be updated at more than one site.

    This is often done by third-party software.

    47

  • 8/2/2019 Ch07 CE (Services)(1)

    48/62

    Support Data Replication (continued)

    FIGURE 7-18: DBMS synchronizes two databases in a replica set

    48

  • 8/2/2019 Ch07 CE (Services)(1)

    49/62

    Recover Data

    Recovery: returning database to a correct statefrom an incorrect state

    This is usually required after a database failure(e.g., due to power failure, disaster, or malware

    attack)

    49

  • 8/2/2019 Ch07 CE (Services)(1)

    50/62

    Backup / Restore

    Simplest recovery involves using backupsor replicas

    Backup or save: copy of database

    A full backup is often made on the order of once amonth (depending on the size and activity of thedatabase)

    Partial backups are made at least daily theyinclude changes since the last full backup

    Backups are always done, but are used onlyas a last resort since restoration of a largedatabase may take days (or even weeks)

    50

  • 8/2/2019 Ch07 CE (Services)(1)

    51/62

    Recovery

    Recovery: returning database to a correct state froman incorrect state

    This is required after a database failure (e.g., due topower failure, disaster, or malware attack)

    Simplest recovery involves using backups or replicas

    Backups are always done, but recovery from backups is slow.

    Replicas (often at a different site) lag the original, but are nottoo far behindprovides a hot standby for faster resumptionof service

    No matter which is used, there is still a need to do someadjustments to assure integrity and to capture recenttransactions.

    51

  • 8/2/2019 Ch07 CE (Services)(1)

    52/62

    Logging

    Logging (aka Journalling): maintaining a log

    (journal) of all updates to the database

    Logs are usually replicated offsite and availableeven if database is destroyed

    The DBMS writes to the log before writing changesto data.

    The DBA must keep transaction logs goingback to the most recent backup (or at least to

    what is known to be replicated at a hot backupsite)

    52

  • 8/2/2019 Ch07 CE (Services)(1)

    53/62

    Logging

    Information is logged for each transaction:

    Each log entry includes:

    Transaction ID

    Date and time of each update

    Log events include:

    Start of a transaction

    Before image(values of relevant data before a change)

    After image (values of relevant data after a change)

    Successful completion (commit) of a transaction

    Checkpoint (i.e., periodic events where the DBMS stopsall activity and writes all information in cache to thedatabase, bringing the log in sync with the database)

    53

  • 8/2/2019 Ch07 CE (Services)(1)

    54/62

    Logging

    FIGURE 7-10: Four sample transactions

    54

  • 8/2/2019 Ch07 CE (Services)(1)

    55/62

    Using Logs Logs can be used for recovery in two ways:

    1. After a power failure, the DBMS uses the log to rollback transactions that were not committed, usingbefore-images.

    2. After a recovery (from backups or using areplication site), the DBMS uses the log to rollforward transactions that were completed but arenot present in the recovered database (e.g., werenot on the most recent backup or not yet

    replicated), using after-images.3. Recovery often requires a rollback phase followed

    by a recovery phase since a replicated databasemay have partially completed transactions.

    55

  • 8/2/2019 Ch07 CE (Services)(1)

    56/62

    Forward Recovery (continued)

    FIGURE 7-12: Forward recovery

    56

  • 8/2/2019 Ch07 CE (Services)(1)

    57/62

    Backward Recovery (continued)

    FIGURE 7-13: Backward recovery

    57

  • 8/2/2019 Ch07 CE (Services)(1)

    58/62

    Recovery on PC-Based DBMSs

    Sophisticated recovery features not available onPC-based DBMSs

    Regularly make backup copies using DBMS

    Use most recent backup for recovery Systems with large number of updates between

    backups

    Recovery features not supplied by DBMS need to be

    included in application programs

    58

  • 8/2/2019 Ch07 CE (Services)(1)

    59/62

    Utility Services

    Utility services assist in general databasemaintenance

    Change database structure

    Add new indexes and delete indexes Use services available from operating system

    Export and import data

    Support for easy-to-use edit and query capabilities,screen generators, report generators, etc.

    59

  • 8/2/2019 Ch07 CE (Services)(1)

    60/62

    Summary

    DBMS allows users to update and retrieve data in adatabase without needing to know how data isstructured on disk or manipulated

    DBMS must store metadata (data about the data)

    and make this data accessible to users DBMS must support concurrent update

    Locking denies access by other users to data while

    DBMS processes one users updates

    During deadlockand deadly embrace, two or moreusers are waiting for the other user to release alock before they can proceed

    60

  • 8/2/2019 Ch07 CE (Services)(1)

    61/62

    Summary (continued)

    In timestamping, DBMS processes updates to adatabase in timestamp order

    DBMS must provide methods to recover a

    database in the event the database is damaged DBMSs provide facilities for periodically making a

    backup copy of the database

    Enterprise DBMSs maintain a log or journal of all

    database updates since the last backup; log isused in recovery process

    61

  • 8/2/2019 Ch07 CE (Services)(1)

    62/62

    Summary (continued)

    DBMSs provide security features (encryption,authentication, authorizations, and views) toprevent unauthorized access to a database

    DBMS must follow rules or integrity constraints (key

    integrity constraints and data integrity constraints)so that it updates data accurately and consistently

    DBMS must support data independence

    DBMS must have facility to handle data replication DBMS must provide utility services that assist in

    general maintenance of a database


Recommended