Data and Database Administration

Preview:

DESCRIPTION

Data and Database Administration. Transaction Management Concurrency Control Database Security. Learning Objectives. Describe the importance of data and database management Describe database transactions are and how they are managed - PowerPoint PPT Presentation

Citation preview

Data and Database Administration

Transaction ManagementConcurrency ControlDatabase Security

Learning Objectives• Describe the importance of data and database management• Describe database transactions are and how they are

managed• Explain concurrency control and locking methods and what

role they have in ensuring database integrity• Describe database backup and recovery and the role they

play in database integrity• Describe the role and responsibilities of a Database

Administrator and tools used to perform required tasks• Apply transaction management principles to solve problems

Traditional Administration Definitions

Data Administration: • High-level function• Policy & Procedure

Planning• DBMS independent• Strategic

Database Administration: • Technical function• Policy &Procedure

Enforcement• DBMS dependent• Tactical

What is a database transaction?

• Logical unit of work in your database• Succeeds / fails as a whole• Works independently of other “units of work”• Doesn’t know about anything else but itself.

• Whether you realize it or not, everything’s a transaction. When you want to change the

Transaction ACID Properties• Atomic

– Transaction cannot be subdivided. Logical unit of work.• Consistent

– Constraints don’t change from before transaction to after transaction

• Isolated– Database changes not revealed to users until after

transaction has completed• Durable

– Database changes are permanent once committed.

Transaction FFCU Demo

Demonstration of the ACID principles.

Concept Example of concept

Transaction Jimmy “do you have a candy bar?” Sally “yes”, then the exchange of $1 for a candy bar between Jimmy and Sally takes place.

Not-Atomic Jimmy gives Sally $1; Sally pockets $1, but keeps the candy bar. Jimmy cries.

Atomic (commit)

The exchange between Jimmy and Sally happens as one unit of work. They exchange money and candy together.

Atomic (rollback)

The exchange between Jimmy and Sally happens as one unit of work. They exchange money and candy at the exact same time, but Jimmy slips Sally a counterfeit $1 bill. Sally demands and receives her candy back, since there was not a valid exchange.

Consistent Before transaction: Jimmy=$1, Sally=Candy Bar, After: Jimmy=Candy Bar, Sally=$1

Not-Consistent Jimmy gives Sally $1, Sally pockets $1 and eats ½ the candy bar in front of Jimmy. Sally grins and laughs, then gives him ½ the candy bar.

Isolated Jimmy and Tommy both ask to buy a candy bar at the same time. Sally tells Tommy “hang on a second; I’ll be right with you.” Sally transacts with Jimmy, and then turns to Tommy and say’s “sorry I just sold out.” Tommy doesn’t know Jimmy got the candy bar.

Not-Isolated Jimmy and Tommy both ask to buy the candy bar at the same time. Sally tells both of them she has a candy bar. She sells it to Jimmy for $1 with Tommy knowing the transaction took place. Tommy knows what Sally did and his feelings are hurt. Tommy cries.

Durable The transaction takes place successfully between Jimmy and Sally. Jimmy decides he no longer wants the candy bar, but Sally says “Sorry, all sales are final!” Jimmy must now try to recoup is $1 with Tommy.

Not-Durable The transaction takes place successfully between Jimmy and Sally. Jimmy no longer wants the candy bar but Sally says “Sorry all sales are final.” Jimmy tells Sally’s Mother and Father and her parents force her to refund the transaction.

Transactions on SQL server• SET IMPLICIT_TRANSACTIONS ON

– DBA responsible for ending the transaction using COMMIT/ ROLLBACK.

– Great way to have an “Undo” feature while working interactively

– Make sure you commit all transactions and check @@TRANCOUNT

• SET IMPLICIT_TRANSACTIONS OFF– Default behavior; used in stored procedures and database

logic– DBA must figure out when to COMMIT / ROLLBACK– @@ROWCOUNT inspection is a common approach

Transaction FFCU Demo

Implicit and explicit transactions, and transaction-safe coding.

Concurrency Control

• Problem–in a multiuser environment, simultaneous access to data can result in interference and data loss

• Solution–Concurrency Control– The process of managing simultaneous

operations against a database so that data integrity is maintained and the operations do not interfere with each other in a multi-user environment

Lost update (no concurrency control in effect)

Simultaneous access causes updates to cancel each otherA similar problem is the inconsistent readinconsistent read problem

Concurrency Control Techniques• Serializability

– Finish one transaction before starting another• Locking Mechanisms

– The most common way of achieving serialization

– Data that is retrieved for the purpose of updating is locked for the updater

– No other user can perform update until unlocked

Updates with locking (concurrency control)

This prevents the lost update problem

Locking Mechanisms• Locking level:

– Database–used during database updates– Table–used for bulk updates– Block or page–very commonly used– Record–only requested row; fairly commonly used– Field–requires significant overhead; impractical

• Types of locks:– Shared lock–Read but no update permitted. Used when

just reading to prevent another user from placing an exclusive lock on the record

– Exclusive lock–No access permitted. Used when preparing to update

Better performance than locking

Versioning - Example

Database Security

• Database Security: Protection of the data against accidental or intentional loss, destruction, or misuse

• Increased difficulty due to Internet access and client/server technologies

• More exposure == Greater Risk!

Possible locations of data security threats

Security Authorization matrix

These are implemented through the external model (views / sp’s) and controlling accessing to database objects with GRANT/REVOKE

From the backup and logs, databases can be restored in case of damage or loss

Database Backup – the audit trail

Basic recovery techniques - Rollback

Like and “Undo” button for the Database

Basic recovery techniques - Rollforward

Point-in-time restore for the Database

Advanced Database Concepts

Questions?

Recommended