Wallaga University
Department of Computer Science
Advanced Database system
February 08, 2023
2/8/2023 2021 Acadamic Year 1
Transaction Processing Concepts



Chapter 3

Transaction Processing Concepts




What is A Transaction:
A transaction is an action, or a series of actions, carried out
by a single user or an application program, which reads or
updates the contents of a database.
It is a Logical unit of database processing that includes one
or more access operations (read -retrieval, write -insert or
update, delete).
Transaction Processing
Transaction Processing is an application program may
contain several transactions separated by the Begin and End
transaction boundaries.
If the database operations in a transaction do not update
the database, it is called “Read-only transaction”
2/8/2023 2021 Acadamic Year
Transaction User 

o
o
o
o
According to number of user that concurrently connect to the
Transaction system it is divided into :
Single User: only one user use the system in each time
Multi User: many users use the system in the same time
Transaction Concurrency Processing
According to modes of Concurrency processing divided into:
Concurrency Interleaved processing: Concurrent execution of
processes is interleaved in a single CPU
Parallel processing: Processes are concurrently executed in
multiple CPUs.
2/8/2023 2021 Acadamic Year
Transaction properties
•
a.
b.
c.
d.
To ensure integrity of data, the database system requires to
maintain the ACID properties of the transactions:
Atomicity.
Consistency preservation.
Isolation.
Durability or permanency.
2/8/2023 2021 Acadamic Year
Atomicity




Either all operations of the transaction are reflected properly
in the database, or none are
Idea behind ensuring atomicity is following:
The database system keeps track of the old values of
any data on which a transaction performs a write
If the transaction does not complete, the DBMS
restores the old values to make it appear as though
the transaction have never execute.
2/8/2023 2021 Acadamic Year
Consistency


If the database is consistency before an execution of the
transaction, the database remains consistent after the
execution of the transaction.
The consistency requirement here is that the sum of A and
B be unchanged by the execution of the transaction.
2/8/2023 2021 Acadamic Year
Isolation



Even though multiple transactions may execute concurrently,
the system guarantees that, Execution of transaction should
not be interfered with by other transactions
for every pair of transactions TransA and TransB, it appears to
TransA that either TransB finished execution before TransA
started, or TransB started execution after TransA finished.
Thus, each transaction is unaware of each other executing
concurrently in the system.
2/8/2023 2021 Acadamic Year
Durability or permanency



After a transaction completes successfully, the changes it has
made to the database persist, even if there are system failures.
These changes must not be lost because of any failure
ensures that, transaction has been committed, that
transaction’s updates do not get lost, even if there is a system
failure
2/8/2023 2021 Acadamic Year
Example1)
Transfer 50 ETB from account
A to account B
Read(A)
A = A - 50
Write(A)
Read(B)
B = B+50
Write(B)
Atomicity - shouldn’t take
money from A without
giving it to B
Consistency - money isn’t
lost or gained
Isolation - other queries
shouldn’t see A or B
change until completion
Durability - the money
does not go back to A
transaction
2/8/2023 2021 Acadamic Year
Cont…

•
Example2) Let Ti be a transaction that transfer 5000 ETB
from Bona’s account (5000) to Beshatu’s account . The
transaction can be defined as follow :
Ti: read (Bona) (withdraw from Bona)
Bona := Bona – 5000
write (Bona); (update Bona)
____________________________________________
read (Beshatu) (deposit to Beshatu)
Beshatu := Beshatu + 5000
write (Beshatu) (update Beshatu)
2/8/2023 2021 Acadamic Year
Transaction Failure
o
o
o
o
o
o
o
o
DBMS is responsible for making sure that either All
operations in transaction are completed successfully and
the changes is recorded permanently in the database.
Even DBMS assure Transactions should be durable it cannot
prevent all sorts of transaction failures in the middle of
execution
Example of failure:
A computer failure (System crash)
A transaction or system error
Load error or exception conditions detected by the
transaction
Concurrency control enforcement: by concurrency control
method
Disk failure
Physical problems and catastrophes: ex. Power failure, fire,
overwrite disk
2/8/2023 2021 Acadamic Year
The Transaction Manager





The transaction manager enforces the ACID properties
It schedules the operations of transactions
COMMIT and ROLLBACK are used to ensure
atomicity
Locks or timestamps are used to ensure consistency
and isolation for concurrent transactions
A log is kept to ensure durability in the event of system
failure
2/8/2023 2021 Acadamic Year
The Transaction Log











Log is An ordered list of REDO/UNDO actions
The system maintain log by keeping track of all
transactions that effect the database
Keeps information about operations made by
transactions
Log file keep track of the database from start
transaction to complete transaction
Each log record has a unique Log Sequence Number
(LSN).
The transaction log records the details of all
transactions:
Any changes the transaction makes to the database
How to undo these changes
When transactions complete and how
The log is stored on disk, not in memory
If the system crashes it is preserved
2/8/2023 2021 Acadamic Year
State of transaction





For recovery purpose, the system needs to keep track of when
the transaction :
Active, the initial state; the transaction stays in this state while
it is executing.
Partially committed, after the final statement has been
executed
Failed, after the discovery that normal execution can no longer
proceed.
Aborted, after the transaction has been rolled backed and the
database has been restored to its state prior to the start of
transaction.
Committed, after successful completion
2/8/2023 2021 Acadamic Year
Cont…






The recovery manager keep track of the followings in
Transaction Process :
Begin_transaction: mark the beginning of transaction
execute
Read or write: specified operations on the database item
that executes as part of transaction
End_transaction: specifies that operations have ended
and marks the end of execution
Commit_Transaction: successful end
Rollback: unsuccessful end (undone)
2/8/2023 2021 Acadamic Year
Transaction Concurrent Executions





Transaction processing permit
Multiple transactions to run concurrently.
Multiple transactions to update data concurrently
Why concurrency is allowed ?
Improved throughput of transactions and system resource
utilization
Reduced waiting time of transactions
2/8/2023 2021 Acadamic Year
Scheduling Transactions





Schedule is A series of operation order from one transaction
to another transaction
Serial schedule
Schedule that does not interleave the actions of different
transactions.
one transaction is executed completely before starting
another transaction.
Non-serial Schedule
If interleaving of operations is allowed, then there will be non-
serial schedule.
It contains many possible orders in which the system can
execute the individual operations of the transactions.
2/8/2023 2021 Acadamic Year
Serial Schedule
2/8/2023 2021 Acadamic Year
Non-serial schedule
2/8/2023 2021 Acadamic Year
Class Activities



Describe role of DBMS Transaction Processing
How concurrent Execution managed in Transaction
Processing
Explain the different between Serial and non-Serial
schedule
2/8/2023 2021 Acadamic Year
CHAPTER FOUR
Concurrency Control Techniques



Concurrency Control in DBMS is a procedure of managing
simultaneous operations without conflicting with each
other.
Concurrency Control is the management procedure that is
required for controlling concurrent execution of the
operations that take place on a database
In concurrent Processing there are chances of a conflict to
occur which can leave database to an inconsistent state.
2/8/2023 2021 Acadamic Year
Cont…
•
◘
Conflict Example:
You and your brother have a joint bank account, from which
you both can withdraw money. Now let’s say you both go to
different branches of the same bank at the same time and try
to withdraw 8000 ETB, your joint account has only 9000
balance. Now if we don’t have concurrency control in place
you both can get 8000 ETB at the same time but once both the
transactions finish the account balance would be -7000 which
is not possible and leaves the database in inconsistent state
To handle these conflicts we need concurrency control in
DBMS, which allows transactions to run simultaneously but
handles them in such a way so that the integrity of data
remains intact.
2/8/2023 2021 Acadamic Year
Concurrency control protocols types

a)
b)
c)
The concurrency control protocols ensure the ACID
properties of the concurrent execution of the database
transactions.
Concurrency control protocols can be categorized as :
Lock Based Concurrency Control Protocol
Time Stamp Concurrency Control Protocol
Validation Based Concurrency Control Protocol
2/8/2023 2021 Acadamic Year
Lock-based Protocols



a)
b)


Locking prevents multiple applications from obtaining copies
o f the same resource when the resource is about to be
changed
The main techniques used to control concurrent execution of
transactions are based on the concept of locking data items
L o c k s are used as a means of synchronizing the access by
concurrent transactions to the database items.
Locks are of two kinds
B i n a r y Locks − A lock on a data item can be in two states
locked or unlocked.
S h a r e d / e x c l u s i v e − This type of locking mechanism
differentiates the locks based on their uses.
Allowing more than one transaction to write on the same data
item would lead the database into an inconsistent state.
R e a d locks are shared because no data value is being
changed
2/8/2023 2021 Acadamic Year
Binary Locks
a)
b)




A binary lock can have two states or values:
locked(1) and
unlocked (0)
A distinct lock is associated with each database item X.
If the value of the lock on X is 1, item X cannot be accessed
by a database operation that requests the item.
I f the value of the lock on X is 0, the item can be accessed
when requested, and the lock value is changed to 1.
T h e Two operations, lock_item and unlock_item, are used
with binary locking
2/8/2023 2021 Acadamic Year
Cont…





A transaction requests access to an item X by first issuing a
lock_item(X) operation.
If LOCK(X) = 1, the transaction is forced to wait.
If LOCK(X) = 0, it is set to 1 and the transaction is allowed to
access item X.
W h e n the transaction is through using the item, it issues an
unlock_item(X) operation, which sets LOCK(X) back to 0 so
that X may be accessed by other transactions.
He nc e , a binary lock enforces mutual exclusion on the data
item.
2/8/2023 2021 Acadamic Year
Shared lock vs Exclusive
Shared lock




Read-only lock
the data item can only read
by the transaction.
allows other users to read
the locked resource, but
they cannot update it
It can be shared between
the transactions because
when the transaction holds
a lock, then it can't update
the data on the data item.
Exclusive lock



the data item can be both
reads as well as written by
the transaction.
prohibits other users from
reading the locked resource
This lock is exclusive, and,
multiple transactions do not
modify the same data
simultaneously.
2/8/2023 2021 Acadamic Year
Chapter 5
Database Recovery Techniques



Recovery process restores database to most recent
consistent state before time of failure
Purpose of Database Recovery
To bring the database into the last consistent state, which
existed prior to the failure.
To preserve transaction properties (Atomicity,
Consistency, Isolation and Durability).
Note: Main goal of recovery is Ensure atomicity property of a
transaction
2/8/2023 2021 Acadamic Year
Recovery Concepts






Undo and redo operations required to be idempotent
Executing operations multiple times equivalent to
executing just once
Entire recovery process should be idempotent
Typical recovery strategies
Restore backed-up copy of database
Identify any changes that may cause inconsistency
2/8/2023 2021 Acadamic Year
Update Techniques





Deferred update techniques
Do not physically update the database until after
transaction commits
Redo-type log entries are needed
Undo-type log entries not necessary
Can only be used for short transactions and transactions
that change few items
2/8/2023 2021 Acadamic Year
Immediate Update techniques





Immediate update Database may be updated by some
operations of a transaction before it reaches commit point
UNDO-type log entries must be stored
It allows database updates of an uncommitted transaction to
be made as the writes are issued
The update logs must have both old value and new value
Update log record must be written before database item is
written
2/8/2023 2021 Acadamic Year
Cont…
o
o
o
o
o
In-place updating techniques
Writes the buffer to the same original disk location
Overwrites old values of any changed data items
Shadow Paging Techniques
Writes an updated buffer at a different disk
location, to maintain multiple versions of data
items
Shadow paging considers disk to be made of n
fixed-size disk pages
No log required in a single-user environment, but in
multiuser
2/8/2023 2021 Acadamic Year
The ARIES Algorithm


o
o
o




ARIES stands for “Algorithm for Recovery and Isolation
Exploiting Semantics”
ARIES main principles are listed below
Write-ahead logging
Repeating history during redo
Logging Changes During Undo
Write-ahead logging
Ensure the before-image (BFIM) is recorded
Necessary for UNDO operation if needed
any change to DB element is first recorded in log
2/8/2023 2021 Acadamic Year
Cont…






Repeating history during redo
Retrace all database system actions prior to crash to
reconstruct database state when crash occurred
On restart following crash, retrace all actions of DBMS
before crash
Logging changes during undo
Prevents ARIES from repeating completed undo
operations if failure occurs during recovery
Changes to DB while undoing a transaction are logged to
ensure such an action is not repeated in the event of
repeated restarts
2/8/2023 2021 Acadamic Year
Cont…







After a crash, the recovery manager is invoked and Proceed in
three phases:
Analysis:
identify dirty pages in buffer pool (i.e., changes not yet written
to disk), and identify active transactions at time of crash.
Scan down from most recent begin checkpoint to last record.
Determines appropriate start point in the log for the REDO
operation
Redo:
repeats all actions, starting from proper point in log, thus
restoring the DB state to its original status
Start at smallest recLSN in dirty page table at end of Analysis.
Redo all changes to any page that might have been dirty at
crash
Only necessary REDO operations are applied
35
ADBMS_Notes
Cont…



UNDO
undo actions of transactions that didn’t commit -- DB
reflects only committed transactions.
Starting at end of log, in reverse order, undo changes of all
transactions at time of crash.
Every log record has associated log sequence number (LSN)
2/8/2023 2021 Acadamic Year
Chapter 6

Database System Security






Multi-user database systems include security to control how
the database is accessed and used .
Those security Mechanisms are :
Prevent unauthorized database access
Prevent unauthorized access to schema objects
Control disk usage and Audit user actions
Database System Security can be considered as :
System security
Data security
37
ADBMS_Notes
Cont…
o




System Security
The access and use of the database at the system level
Example:
username and password
disk space allocated to users, and the system operations
that users can perform
Data security
The access and use of the database objects and
the actions that those users can have on the objects
Example : retrieving a data value from table
38
ADBMS_Notes
AAA security model




Authentication: verifying the identity of someone who
wants to access data ,resources ,or applications.
Authorization: Access limits for authenticated users
user must be able to access only the information and
resources that he/she has allowed
Accounting: auditing
39
ADBMS_Notes
User Accounts



The default administrative user accounts are
automatically created when you install Oracle/SQL
/MySQL Server Database are:
SYS: granted by DBA role, owns Data Dictionary
SYSTEM: granted the DBA role and perform all
administrative functions
40
ADBMS_Notes
Data Type Differences
SQL Server Oracle
INTEGER NUMBER(10)
SMALLINT NUMBER(6)
TINYINT NUMBER(3)
REAL FLOAT
FLOAT FLOAT
BIT NUMBER(1)
VARCHAR(n) VARCHAR2(n)
TEXT CLOB
IMAGE BLOB
BINARY(n) RAW(n) or BLOB
41
ADBMS_Notes
Cont…
SQL Server Oracle
VARBINARY RAW(n) or BLOB
DATETIME DATE
SMALL-DATETIME DATE
MONEY NUMBER(19,4)
NCHAR(n) CHAR(n*2)
NVARCHAR(n) VARCHAR(n*2)
SMALLMONEY NUMBER(10,4)
TIMESTAMP NUMBER
SYSNAME VARCHAR2(30),
VARCHAR2(128)
42
ADBMS_Notes
Privileges

•







Privileges are the right to execute particular SQL statements.
The database administrator (DBA) is a high-level user with
the ability to grant users access to the database and its
objects
Example:
The ability to connect to the database
The ability to create a user
The ability CREATE SESSION
The ability CREATE TABLE
The ability CREATE SEQUENCE
The ability CREATE VIEW
The ability CREATE PROCEDURE

43
ADBMS_Notes
Cont…
a)
b)


•
•
System privileges: Gaining access to the database
Object privileges: Manipulating the content of the
database objects
System privileges can be given to a user by another user
who has administrator privileges
Example:

– Creating new users
– Removing users
– Removing tables
– Backing up tables
Special Administrative privileges: required for an
administrator to perform basic database operations are
granted through two special system privileges
SYSDBA privilege: can do anything
SYSOPER privilege: sub-admin access, can perform
Backup, recover, startup, shutdown
44
ADBMS_Notes
Cont…


To grant privileges on an object, the object must be in your
own schema, or granted privileges WITH GRANT OPTION .

• An object owner can grant any object privilege on the
object to any other user or role of the database.
• The owner of an object automatically acquires all object
privileges on that object.
GRANT privilege TO user [WITH ADMIN OPTION] ;
WITH ADMIN OPTION: it means give grantee right to grant
the same privilegesto other users
45
ADBMS_Notes
Operations Authorized 
 System Privilege
Grantee can create other Oracle users (a
privilege required 
for a DBA role). 
CREATE USER
Grantee can drop another user. DROP USER
Grantee can drop a table in any schema. DROP ANY TABLE
Grantee can back up any table in any schema
with the export utility
BACKUP ANY TABLE
Grantee can create tables in any schema.  CREATE ANY TABLE
Grantee can query tables, views, or snapshots
in any schema
SELECT ANY TABLE
46
ADBMS_Notes
Creating Users

• The syntax for creating a user is:
CREATE USER username
IDENTIFIED BY password
Example:
CREATE USER Scott
IDENTIFIED BY tiger


47
ADBMS_Notes
48
GRANT SELECT
INSERT
DELETE
UPDATE
(column-name)
,
,
ALL PRIVILEGES
ON base relation
view relation
TO user-name
PUBLIC

WITH
GRANT
OPTION
GRANT-Statement
GRANT privileges ON object TO users [WITH GRANT OPTION]
ADBMS_Notes
49
REVOKE Statement
ADBMS_Notes
50
GRANT and REVOKE of Privileges






GRANT INSERT, SELECT ON Employees TO Chala
Chala can query Employees or insert tuples into it
GRANT DELETE ON Employees TO Beka WITH GRANT
OPTION
Beka can delete tuples, and also authorize others to do so.
GRANT UPDATE Salary ON Employees TO Dawit
Dawit can update (only) the salary field of Employees
tuples.
ADBMS_Notes
Granting Object Privileges
• Grant query privileges on the EMPLOYEES table.
GRANT select

ON employees

TO Norah, Sarah;

• Grant privileges to update specific columns to users and
roles. 

GRANT update (department name, location_id)

ON departments

TO Scott, manager;


51
ADBMS_Notes
Cont…


• Syntax to Revoke Object Privileges :
REVOKE privilege ,ALL ON object FROM user/role/PUBLIC;
Example
REVOKE select, insert
ON departments
FROM Scott;

52
ADBMS_Notes
What Is a Role?


–
–
–
A role is a named group of related privileges that can be
granted to the user.
Pre-defined roles:
DBA: it has all system privileges
RESOURCE: Enables a user to create certain types of
objects in his own schema
CONNECT: Enables a user to connect to the database.
Grant this role to any user or application that needs
database access.
53
ADBMS_Notes
Creating and Assigning a Role





First, the DBA must create the role. Then the DBA can
assign privileges to the role and users to the role.
Syntax

CREATE ROLE rolename;
Creating and Granting Privileges to a Role
Create a role
CREATE ROLE manager;
Grant system privileges to a role
GRANT create table, create view 

TO manager;
Grant a role to users
GRANT manager TO Maha, Nora;

54
ADBMS_Notes
Changing Your Password





The DBA creates your user account and initializes your
password.
You can change your password by using the 
ALTER USER statement.
Syntax

ALTER USER user IDENTIFIED BY newpassword;
EXAMPLE:
ALTER USER Scott 

IDENTIFIED BY lion;


55
ADBMS_Notes
WITH GRANT OPTION and PUBLIC Keywords

• Give a user authority to pass along privileges.
GRANT select, insert
ON departments
TO Scott
WITH GRANT OPTION;
• Allow all users on the system to query data from Alice’s
DEPARTMENTS table.
GRANT select
ON Alice. Departments
TO PUBLIC;
 56
ADBMS_Notes
DBMS LANGUAGES
STATEMENT
57
ADBMS_Notes
DDL (Data Definition Language)




DDL statements are used to alter/modify a database or table
structure and schema.
CREATE – create a new Table, database, schema
ALTER – alter existing table, column description
DROP – delete existing objects from database
Creating a New Table with an Encrypted Column
CREATE TABLE employee ( first_name VARCHAR2(128),
last_name VARCHAR2(128), empID NUMBER, salary
NUMBER(6) ENCRYPT );
Encrypting Unencrypted Columns
ALTER TABLE employee MODIFY (first_name ENCRYPT);
Disabling Encryption on a Column
ALTER TABLE employee MODIFY (first_name DECRYPT);
58
ADBMS_Notes
DML (Data Manipulation
Language)
 DML operations performed on data such as selecting a few
records from a table, inserting new records, deleting
unnecessary records, and updating/modifying existing records.
Example :
SELECT – select records from a table
INSERT – insert new records
UPDATE – update/Modify existing records
DELETE – delete existing records
59
ADBMS_Notes
DCL (Data Control Language)




DCL statements control the level of access that
users have on database objects.
GRANT – allows users to read/write on certain
database objects
REVOKE – keeps users from read/write permission
on database objects
TCL (Transaction Control Language)
TCL statements allow you to control and manage
transactions to maintain the integrity of data within
SQL statements.
BEGIN Transaction – opens a transaction
COMMIT Transaction – commits a transaction
ROLLBACK Transaction – ROLLBACK a transaction
in case of any error
60
ADBMS_Notes
ThankYou
Emerging Technology

presentationprintTemp presentationorint.pdf

  • 1.
    Wallaga University Department ofComputer Science Advanced Database system February 08, 2023 2/8/2023 2021 Acadamic Year 1
  • 2.
    Transaction Processing Concepts Chapter3 Transaction Processing Concepts     What is A Transaction: A transaction is an action, or a series of actions, carried out by a single user or an application program, which reads or updates the contents of a database. It is a Logical unit of database processing that includes one or more access operations (read -retrieval, write -insert or update, delete). Transaction Processing Transaction Processing is an application program may contain several transactions separated by the Begin and End transaction boundaries. If the database operations in a transaction do not update the database, it is called “Read-only transaction” 2/8/2023 2021 Acadamic Year
  • 3.
    Transaction User  o o o o Accordingto number of user that concurrently connect to the Transaction system it is divided into : Single User: only one user use the system in each time Multi User: many users use the system in the same time Transaction Concurrency Processing According to modes of Concurrency processing divided into: Concurrency Interleaved processing: Concurrent execution of processes is interleaved in a single CPU Parallel processing: Processes are concurrently executed in multiple CPUs. 2/8/2023 2021 Acadamic Year
  • 4.
    Transaction properties • a. b. c. d. To ensureintegrity of data, the database system requires to maintain the ACID properties of the transactions: Atomicity. Consistency preservation. Isolation. Durability or permanency. 2/8/2023 2021 Acadamic Year
  • 5.
    Atomicity     Either all operationsof the transaction are reflected properly in the database, or none are Idea behind ensuring atomicity is following: The database system keeps track of the old values of any data on which a transaction performs a write If the transaction does not complete, the DBMS restores the old values to make it appear as though the transaction have never execute. 2/8/2023 2021 Acadamic Year
  • 6.
    Consistency   If the databaseis consistency before an execution of the transaction, the database remains consistent after the execution of the transaction. The consistency requirement here is that the sum of A and B be unchanged by the execution of the transaction. 2/8/2023 2021 Acadamic Year
  • 7.
    Isolation    Even though multipletransactions may execute concurrently, the system guarantees that, Execution of transaction should not be interfered with by other transactions for every pair of transactions TransA and TransB, it appears to TransA that either TransB finished execution before TransA started, or TransB started execution after TransA finished. Thus, each transaction is unaware of each other executing concurrently in the system. 2/8/2023 2021 Acadamic Year
  • 8.
    Durability or permanency    Aftera transaction completes successfully, the changes it has made to the database persist, even if there are system failures. These changes must not be lost because of any failure ensures that, transaction has been committed, that transaction’s updates do not get lost, even if there is a system failure 2/8/2023 2021 Acadamic Year
  • 9.
    Example1) Transfer 50 ETBfrom account A to account B Read(A) A = A - 50 Write(A) Read(B) B = B+50 Write(B) Atomicity - shouldn’t take money from A without giving it to B Consistency - money isn’t lost or gained Isolation - other queries shouldn’t see A or B change until completion Durability - the money does not go back to A transaction 2/8/2023 2021 Acadamic Year
  • 10.
    Cont…  • Example2) Let Tibe a transaction that transfer 5000 ETB from Bona’s account (5000) to Beshatu’s account . The transaction can be defined as follow : Ti: read (Bona) (withdraw from Bona) Bona := Bona – 5000 write (Bona); (update Bona) ____________________________________________ read (Beshatu) (deposit to Beshatu) Beshatu := Beshatu + 5000 write (Beshatu) (update Beshatu) 2/8/2023 2021 Acadamic Year
  • 11.
    Transaction Failure o o o o o o o o DBMS isresponsible for making sure that either All operations in transaction are completed successfully and the changes is recorded permanently in the database. Even DBMS assure Transactions should be durable it cannot prevent all sorts of transaction failures in the middle of execution Example of failure: A computer failure (System crash) A transaction or system error Load error or exception conditions detected by the transaction Concurrency control enforcement: by concurrency control method Disk failure Physical problems and catastrophes: ex. Power failure, fire, overwrite disk 2/8/2023 2021 Acadamic Year
  • 12.
    The Transaction Manager      Thetransaction manager enforces the ACID properties It schedules the operations of transactions COMMIT and ROLLBACK are used to ensure atomicity Locks or timestamps are used to ensure consistency and isolation for concurrent transactions A log is kept to ensure durability in the event of system failure 2/8/2023 2021 Acadamic Year
  • 13.
    The Transaction Log            Logis An ordered list of REDO/UNDO actions The system maintain log by keeping track of all transactions that effect the database Keeps information about operations made by transactions Log file keep track of the database from start transaction to complete transaction Each log record has a unique Log Sequence Number (LSN). The transaction log records the details of all transactions: Any changes the transaction makes to the database How to undo these changes When transactions complete and how The log is stored on disk, not in memory If the system crashes it is preserved 2/8/2023 2021 Acadamic Year
  • 14.
    State of transaction      Forrecovery purpose, the system needs to keep track of when the transaction : Active, the initial state; the transaction stays in this state while it is executing. Partially committed, after the final statement has been executed Failed, after the discovery that normal execution can no longer proceed. Aborted, after the transaction has been rolled backed and the database has been restored to its state prior to the start of transaction. Committed, after successful completion 2/8/2023 2021 Acadamic Year
  • 15.
    Cont…       The recovery managerkeep track of the followings in Transaction Process : Begin_transaction: mark the beginning of transaction execute Read or write: specified operations on the database item that executes as part of transaction End_transaction: specifies that operations have ended and marks the end of execution Commit_Transaction: successful end Rollback: unsuccessful end (undone) 2/8/2023 2021 Acadamic Year
  • 16.
    Transaction Concurrent Executions      Transactionprocessing permit Multiple transactions to run concurrently. Multiple transactions to update data concurrently Why concurrency is allowed ? Improved throughput of transactions and system resource utilization Reduced waiting time of transactions 2/8/2023 2021 Acadamic Year
  • 17.
    Scheduling Transactions      Schedule isA series of operation order from one transaction to another transaction Serial schedule Schedule that does not interleave the actions of different transactions. one transaction is executed completely before starting another transaction. Non-serial Schedule If interleaving of operations is allowed, then there will be non- serial schedule. It contains many possible orders in which the system can execute the individual operations of the transactions. 2/8/2023 2021 Acadamic Year
  • 18.
  • 19.
  • 20.
    Class Activities    Describe roleof DBMS Transaction Processing How concurrent Execution managed in Transaction Processing Explain the different between Serial and non-Serial schedule 2/8/2023 2021 Acadamic Year
  • 21.
    CHAPTER FOUR Concurrency ControlTechniques    Concurrency Control in DBMS is a procedure of managing simultaneous operations without conflicting with each other. Concurrency Control is the management procedure that is required for controlling concurrent execution of the operations that take place on a database In concurrent Processing there are chances of a conflict to occur which can leave database to an inconsistent state. 2/8/2023 2021 Acadamic Year
  • 22.
    Cont… • ◘ Conflict Example: You andyour brother have a joint bank account, from which you both can withdraw money. Now let’s say you both go to different branches of the same bank at the same time and try to withdraw 8000 ETB, your joint account has only 9000 balance. Now if we don’t have concurrency control in place you both can get 8000 ETB at the same time but once both the transactions finish the account balance would be -7000 which is not possible and leaves the database in inconsistent state To handle these conflicts we need concurrency control in DBMS, which allows transactions to run simultaneously but handles them in such a way so that the integrity of data remains intact. 2/8/2023 2021 Acadamic Year
  • 23.
    Concurrency control protocolstypes  a) b) c) The concurrency control protocols ensure the ACID properties of the concurrent execution of the database transactions. Concurrency control protocols can be categorized as : Lock Based Concurrency Control Protocol Time Stamp Concurrency Control Protocol Validation Based Concurrency Control Protocol 2/8/2023 2021 Acadamic Year
  • 24.
    Lock-based Protocols    a) b)   Locking preventsmultiple applications from obtaining copies o f the same resource when the resource is about to be changed The main techniques used to control concurrent execution of transactions are based on the concept of locking data items L o c k s are used as a means of synchronizing the access by concurrent transactions to the database items. Locks are of two kinds B i n a r y Locks − A lock on a data item can be in two states locked or unlocked. S h a r e d / e x c l u s i v e − This type of locking mechanism differentiates the locks based on their uses. Allowing more than one transaction to write on the same data item would lead the database into an inconsistent state. R e a d locks are shared because no data value is being changed 2/8/2023 2021 Acadamic Year
  • 25.
    Binary Locks a) b)     A binarylock can have two states or values: locked(1) and unlocked (0) A distinct lock is associated with each database item X. If the value of the lock on X is 1, item X cannot be accessed by a database operation that requests the item. I f the value of the lock on X is 0, the item can be accessed when requested, and the lock value is changed to 1. T h e Two operations, lock_item and unlock_item, are used with binary locking 2/8/2023 2021 Acadamic Year
  • 26.
    Cont…      A transaction requestsaccess to an item X by first issuing a lock_item(X) operation. If LOCK(X) = 1, the transaction is forced to wait. If LOCK(X) = 0, it is set to 1 and the transaction is allowed to access item X. W h e n the transaction is through using the item, it issues an unlock_item(X) operation, which sets LOCK(X) back to 0 so that X may be accessed by other transactions. He nc e , a binary lock enforces mutual exclusion on the data item. 2/8/2023 2021 Acadamic Year
  • 27.
    Shared lock vsExclusive Shared lock     Read-only lock the data item can only read by the transaction. allows other users to read the locked resource, but they cannot update it It can be shared between the transactions because when the transaction holds a lock, then it can't update the data on the data item. Exclusive lock    the data item can be both reads as well as written by the transaction. prohibits other users from reading the locked resource This lock is exclusive, and, multiple transactions do not modify the same data simultaneously. 2/8/2023 2021 Acadamic Year
  • 28.
    Chapter 5 Database RecoveryTechniques    Recovery process restores database to most recent consistent state before time of failure Purpose of Database Recovery To bring the database into the last consistent state, which existed prior to the failure. To preserve transaction properties (Atomicity, Consistency, Isolation and Durability). Note: Main goal of recovery is Ensure atomicity property of a transaction 2/8/2023 2021 Acadamic Year
  • 29.
    Recovery Concepts       Undo andredo operations required to be idempotent Executing operations multiple times equivalent to executing just once Entire recovery process should be idempotent Typical recovery strategies Restore backed-up copy of database Identify any changes that may cause inconsistency 2/8/2023 2021 Acadamic Year
  • 30.
    Update Techniques      Deferred updatetechniques Do not physically update the database until after transaction commits Redo-type log entries are needed Undo-type log entries not necessary Can only be used for short transactions and transactions that change few items 2/8/2023 2021 Acadamic Year
  • 31.
    Immediate Update techniques      Immediateupdate Database may be updated by some operations of a transaction before it reaches commit point UNDO-type log entries must be stored It allows database updates of an uncommitted transaction to be made as the writes are issued The update logs must have both old value and new value Update log record must be written before database item is written 2/8/2023 2021 Acadamic Year
  • 32.
    Cont… o o o o o In-place updating techniques Writesthe buffer to the same original disk location Overwrites old values of any changed data items Shadow Paging Techniques Writes an updated buffer at a different disk location, to maintain multiple versions of data items Shadow paging considers disk to be made of n fixed-size disk pages No log required in a single-user environment, but in multiuser 2/8/2023 2021 Acadamic Year
  • 33.
    The ARIES Algorithm   o o o     ARIESstands for “Algorithm for Recovery and Isolation Exploiting Semantics” ARIES main principles are listed below Write-ahead logging Repeating history during redo Logging Changes During Undo Write-ahead logging Ensure the before-image (BFIM) is recorded Necessary for UNDO operation if needed any change to DB element is first recorded in log 2/8/2023 2021 Acadamic Year
  • 34.
    Cont…       Repeating history duringredo Retrace all database system actions prior to crash to reconstruct database state when crash occurred On restart following crash, retrace all actions of DBMS before crash Logging changes during undo Prevents ARIES from repeating completed undo operations if failure occurs during recovery Changes to DB while undoing a transaction are logged to ensure such an action is not repeated in the event of repeated restarts 2/8/2023 2021 Acadamic Year
  • 35.
    Cont…        After a crash,the recovery manager is invoked and Proceed in three phases: Analysis: identify dirty pages in buffer pool (i.e., changes not yet written to disk), and identify active transactions at time of crash. Scan down from most recent begin checkpoint to last record. Determines appropriate start point in the log for the REDO operation Redo: repeats all actions, starting from proper point in log, thus restoring the DB state to its original status Start at smallest recLSN in dirty page table at end of Analysis. Redo all changes to any page that might have been dirty at crash Only necessary REDO operations are applied 35 ADBMS_Notes
  • 36.
    Cont…    UNDO undo actions oftransactions that didn’t commit -- DB reflects only committed transactions. Starting at end of log, in reverse order, undo changes of all transactions at time of crash. Every log record has associated log sequence number (LSN) 2/8/2023 2021 Acadamic Year
  • 37.
    Chapter 6 Database SystemSecurity       Multi-user database systems include security to control how the database is accessed and used . Those security Mechanisms are : Prevent unauthorized database access Prevent unauthorized access to schema objects Control disk usage and Audit user actions Database System Security can be considered as : System security Data security 37 ADBMS_Notes
  • 38.
    Cont… o     System Security The accessand use of the database at the system level Example: username and password disk space allocated to users, and the system operations that users can perform Data security The access and use of the database objects and the actions that those users can have on the objects Example : retrieving a data value from table 38 ADBMS_Notes
  • 39.
    AAA security model     Authentication:verifying the identity of someone who wants to access data ,resources ,or applications. Authorization: Access limits for authenticated users user must be able to access only the information and resources that he/she has allowed Accounting: auditing 39 ADBMS_Notes
  • 40.
    User Accounts    The defaultadministrative user accounts are automatically created when you install Oracle/SQL /MySQL Server Database are: SYS: granted by DBA role, owns Data Dictionary SYSTEM: granted the DBA role and perform all administrative functions 40 ADBMS_Notes
  • 41.
    Data Type Differences SQLServer Oracle INTEGER NUMBER(10) SMALLINT NUMBER(6) TINYINT NUMBER(3) REAL FLOAT FLOAT FLOAT BIT NUMBER(1) VARCHAR(n) VARCHAR2(n) TEXT CLOB IMAGE BLOB BINARY(n) RAW(n) or BLOB 41 ADBMS_Notes
  • 42.
    Cont… SQL Server Oracle VARBINARYRAW(n) or BLOB DATETIME DATE SMALL-DATETIME DATE MONEY NUMBER(19,4) NCHAR(n) CHAR(n*2) NVARCHAR(n) VARCHAR(n*2) SMALLMONEY NUMBER(10,4) TIMESTAMP NUMBER SYSNAME VARCHAR2(30), VARCHAR2(128) 42 ADBMS_Notes
  • 43.
    Privileges •        Privileges are theright to execute particular SQL statements. The database administrator (DBA) is a high-level user with the ability to grant users access to the database and its objects Example: The ability to connect to the database The ability to create a user The ability CREATE SESSION The ability CREATE TABLE The ability CREATE SEQUENCE The ability CREATE VIEW The ability CREATE PROCEDURE 43 ADBMS_Notes
  • 44.
    Cont… a) b)   • • System privileges: Gainingaccess to the database Object privileges: Manipulating the content of the database objects System privileges can be given to a user by another user who has administrator privileges Example: – Creating new users – Removing users – Removing tables – Backing up tables Special Administrative privileges: required for an administrator to perform basic database operations are granted through two special system privileges SYSDBA privilege: can do anything SYSOPER privilege: sub-admin access, can perform Backup, recover, startup, shutdown 44 ADBMS_Notes
  • 45.
    Cont…   To grant privilegeson an object, the object must be in your own schema, or granted privileges WITH GRANT OPTION . • An object owner can grant any object privilege on the object to any other user or role of the database. • The owner of an object automatically acquires all object privileges on that object. GRANT privilege TO user [WITH ADMIN OPTION] ; WITH ADMIN OPTION: it means give grantee right to grant the same privilegesto other users 45 ADBMS_Notes
  • 46.
    Operations Authorized System Privilege Grantee can create other Oracle users (a privilege required for a DBA role). CREATE USER Grantee can drop another user. DROP USER Grantee can drop a table in any schema. DROP ANY TABLE Grantee can back up any table in any schema with the export utility BACKUP ANY TABLE Grantee can create tables in any schema. CREATE ANY TABLE Grantee can query tables, views, or snapshots in any schema SELECT ANY TABLE 46 ADBMS_Notes
  • 47.
    Creating Users • Thesyntax for creating a user is: CREATE USER username IDENTIFIED BY password Example: CREATE USER Scott IDENTIFIED BY tiger 47 ADBMS_Notes
  • 48.
    48 GRANT SELECT INSERT DELETE UPDATE (column-name) , , ALL PRIVILEGES ONbase relation view relation TO user-name PUBLIC  WITH GRANT OPTION GRANT-Statement GRANT privileges ON object TO users [WITH GRANT OPTION] ADBMS_Notes
  • 49.
  • 50.
    50 GRANT and REVOKEof Privileges       GRANT INSERT, SELECT ON Employees TO Chala Chala can query Employees or insert tuples into it GRANT DELETE ON Employees TO Beka WITH GRANT OPTION Beka can delete tuples, and also authorize others to do so. GRANT UPDATE Salary ON Employees TO Dawit Dawit can update (only) the salary field of Employees tuples. ADBMS_Notes
  • 51.
    Granting Object Privileges •Grant query privileges on the EMPLOYEES table. GRANT select ON employees TO Norah, Sarah; • Grant privileges to update specific columns to users and roles. GRANT update (department name, location_id) ON departments TO Scott, manager; 51 ADBMS_Notes
  • 52.
    Cont… • Syntax toRevoke Object Privileges : REVOKE privilege ,ALL ON object FROM user/role/PUBLIC; Example REVOKE select, insert ON departments FROM Scott; 52 ADBMS_Notes
  • 53.
    What Is aRole?   – – – A role is a named group of related privileges that can be granted to the user. Pre-defined roles: DBA: it has all system privileges RESOURCE: Enables a user to create certain types of objects in his own schema CONNECT: Enables a user to connect to the database. Grant this role to any user or application that needs database access. 53 ADBMS_Notes
  • 54.
    Creating and Assigninga Role      First, the DBA must create the role. Then the DBA can assign privileges to the role and users to the role. Syntax CREATE ROLE rolename; Creating and Granting Privileges to a Role Create a role CREATE ROLE manager; Grant system privileges to a role GRANT create table, create view TO manager; Grant a role to users GRANT manager TO Maha, Nora; 54 ADBMS_Notes
  • 55.
    Changing Your Password     TheDBA creates your user account and initializes your password. You can change your password by using the ALTER USER statement. Syntax ALTER USER user IDENTIFIED BY newpassword; EXAMPLE: ALTER USER Scott IDENTIFIED BY lion; 55 ADBMS_Notes
  • 56.
    WITH GRANT OPTIONand PUBLIC Keywords • Give a user authority to pass along privileges. GRANT select, insert ON departments TO Scott WITH GRANT OPTION; • Allow all users on the system to query data from Alice’s DEPARTMENTS table. GRANT select ON Alice. Departments TO PUBLIC; 56 ADBMS_Notes
  • 57.
  • 58.
    DDL (Data DefinitionLanguage)     DDL statements are used to alter/modify a database or table structure and schema. CREATE – create a new Table, database, schema ALTER – alter existing table, column description DROP – delete existing objects from database Creating a New Table with an Encrypted Column CREATE TABLE employee ( first_name VARCHAR2(128), last_name VARCHAR2(128), empID NUMBER, salary NUMBER(6) ENCRYPT ); Encrypting Unencrypted Columns ALTER TABLE employee MODIFY (first_name ENCRYPT); Disabling Encryption on a Column ALTER TABLE employee MODIFY (first_name DECRYPT); 58 ADBMS_Notes
  • 59.
    DML (Data Manipulation Language) DML operations performed on data such as selecting a few records from a table, inserting new records, deleting unnecessary records, and updating/modifying existing records. Example : SELECT – select records from a table INSERT – insert new records UPDATE – update/Modify existing records DELETE – delete existing records 59 ADBMS_Notes
  • 60.
    DCL (Data ControlLanguage)     DCL statements control the level of access that users have on database objects. GRANT – allows users to read/write on certain database objects REVOKE – keeps users from read/write permission on database objects TCL (Transaction Control Language) TCL statements allow you to control and manage transactions to maintain the integrity of data within SQL statements. BEGIN Transaction – opens a transaction COMMIT Transaction – commits a transaction ROLLBACK Transaction – ROLLBACK a transaction in case of any error 60 ADBMS_Notes
  • 61.