Академический Документы
Профессиональный Документы
Культура Документы
Database Administration
Introduction.
The topics covered in these notes provide an overview of different
aspects of database administration.
You need to understand the function of the database administrator.
You will also study some basic concepts about database security,
recovery, transaction control, and concurrency control.
Transaction Integrity.
When several Physical Transactions must process together, such as
saving a Customer Order record to the Orders table and the related
Orderline records to the Orderline table, we term this a Logical
Transaction.
In this situation, either all of the physical transaction must process
or none of them must process.
If one physical transaction fails, we rollback the entire logical
transaction.
If all physical transactions succeed, we commit the changes the
database.
In modern database programming languages, we often implement
processing through the Active-X Data Object model - this is done in
Visual Basic.
The start of a transaction is marked by some command such as BEGIN
TRANSACTION or through use of a pre-defined method such as the
Visual Basic BeginTrans method of the Connection object used to
connect to a database.
If a transaction succeeds, the end of the transaction is marked
through the use of some command such as END TRANSACTION or a
pre-defined method such as the Visual Basic CommitTrans method.
If a transaction fails someplace within the boundaries of the
transaction, then changes to the data source are rolled back (that is
undone). Some command such as ROLLBACK or a pre-defined method
such as the Visual Basic RollbackTrans method of the connection
object is used to rollback the logical transaction.
If the application ends or the database connection falls out of scope
before a transaction commits, all changes are automatically rolled
back.
Usually if a database connection is closed with the Close method
while a transaction is in progress, an error occurs.
Below is given an example of a logical transaction written in Visual
Basic.
Errorhandler:
' Display an error message and check to see if the edit mode is add
' for the recordset and if it is, then cancel the update to throw away
' the blank record. Rollback the transaction that failed.
DisplayerrorMessage
cnAP.RollbackTrans
If rsInvoices.EditMode = adEditAdd Or _
rsInvoices.EditMode = adEditDelete Then
rsInvoices.CancelUpdate
End If
End Sub
Concurrency Control.
Concurrent Access: Two or more users try to access the same data
simultaneously.
Interleaved Transactions (Lost Updates): Work through the example
shown below to understand what happened to the account balance.
Resource Locking: This involves locking data for one user if an
update is planned until the transaction commits. In order to lock
resources the DBMS needs to know two things:
1. Intent to Update on the part of the application program.
2. Transaction Boundaries - as defined by the logical
transaction boundary commands discussed in the previous section.
Lock Levels: There are several levels for locking records. These
include from the individual field up to the entire database.
The figure shown here eliminates the lost transaction update
problem.
Note that User 2 must wait for User 1 to complete the
transaction before acquiring access to the customer account with
the intent to update.
Deadlock: This occurs when two different application programs acquire
resources simultaneously that the other program needs. Both programs
sit and wait on the additional needed resources.
DATABASE RECOVERY.
There are four Basic Recovery Facilities. These include:
1. Backup. Whole Database duplication.
2. Journalizing. Maintains an audit train of transactions and
database changes. A Journal approach usually includes:
Transaction Log: Record of every transaction that processes.
Data Base Change Log: Before and after images of records.
3. Checkpointing. During the time when a Checkpoint record is
written, the DBMS refuses new transactions while those in
progress are processed and the journal files are brought up to
date and synchronized. The DBMS writes a checkpoint record to
the transaction log (this record includes information about non-
completed transactions), then writes main memory contents to
disk.
An alternative approach: Complete all transactions in
progress.
Checkpointing is usually performed automatically.
4. Recovery/Restart Facility. Used to restore DBMS if failure
occurs.
Recovery from Failure:
1. Restore/Rerun. Reprocess a day's transactions against a backup
copy of data base.
2. Rollbackand Rollforward. The figure shown here provides a
diagram of the Rollback and Rollforward process.
End of Notes.