unit 5 dbms
unit 5 dbms
Creating a user:
-Creating a user in a DBMS involves defining the username and password,
and assigning the user specific roles or permissions.
-Geneally,this task is performed by the database administrator.
-The CREATE USER statement is used to create new user accounts for
database access. It enables database administrators to define which users
can connect to the database server and specify their login credentials.
Syntax:
CREATE USER username IDENTIFIED BY password;
username: It is the name that the user wants to give to the database account.
password:It is the password used to assign to the username.The password is
specified in the IDENTIFIED BY clause.
Altering a user:
-ALTER USER command to change the settings, such as the password, for
the specified user
Syntax:
ALTER USER username IDENTIFIED BY new_password;
Deleting a User:
- To remove a user from the database,you would use the DROP USER
command.
Syntax:
Drop user username;
Assign Privileges to users-
Database privileges:
- privileges is a term which determine the level of access and actions a user can
perform on a database.
- Privileges can be categorized into system privileges and object privileges
based on the type of actions allowed on the database system and its objects.
1. System Privileges
- System privileges refer to the rights granted to a user to perform certain administrative
tasks or actions that affect the entire database system.
2. Object Privileges
- Object privileges refer to the rights granted to a user to perform actions on specific
Database objects(e.g.,tables,views,procedures,etc.).
- They are more granular and control access at the level of specific objects within the
database.
1. GRANT Command
- The privileges can include actions like SELECT, INSERT, UPDATE, DELETE, and
more.
Syntax:
GRANT privileges
ON object_name
TO user_name
[WITHGRANTOPTION];
1. Granting SELECT privilege on a table: If you want to grant a user1 the ability
to read data from a table employees:
-After a privilege is revoked,the user can no longer has access to the specified object unless
the privilege is granted again.
Syntax:
REVOKE privilege
ON object_name
FROM user_name;
1. Revoking a single privilege: If you want to revoke the SELECT privilege from
user1 on the employees table:
This removes the SELECT privilege from user1, so they can no longer query the
employees table.
Types of failure:
In a Database Management System(DBMS), failures can occur for various reasons,
ranging from hardware issues to software bugs or human errors. These failures can result
in data loss, inconsistency, or system unavailability. Understanding the types of failures
is crucial for designing systems that ensure data reliability and recovery.
1. Transaction Failure
Common Causes:
Logic or application errors: Errors in the application code or business logic that
cause the transaction to violate constraints (e.g. foreign key violations, division by
zero, etc.).
Resource unavailability: Lack of necessary resources, such as memory, CPU, or
disk space, causing the transaction to fail.
Deadlocks: When two or more transactions are stuck, each waiting for the other to
release resources, leading to a deadlock.
Timeouts: A transaction may fail if it does not complete within a predefined time
limit.
2. System Crash
A system crash occurs when the DBMS or the underlying system (e.g., the operating
system or hardware) experiences a failure, causing the database to become inaccessible.
Common Causes:
A media failure refers to a problem with the physical storage medium (e.g., hard drive,
SSD) where the database is stored. It happens when the hardware storing the data
becomes corrupt or unavailable.
Common Causes:
Disk corruption: Physical damage to the storage medium that corrupts data.
Hardware malfunction: A malfunctioning storage device can lead to data loss.
File system corruption: If the file system becomes corrupted, the database files
may be inaccessible.
Dataloss: If a disk fails and there are no adequate backups, data may be
permanently lost.
4. Logical Failure
A logical failure occurs when the database is logically inconsistent or incorrect, even if
the system and hardware are functioning correctly. These failures typically result from
human errors or software bugs that violate the logical integrity of the database.
Causes of failure:
- Database failure can occur due to a wide variety of reasons, which can be categorized
into hardware, software, human error, and environmental factors.
1. Hardware Failures
Disk Failures: Hard drives or storage devices can fail, resulting in data loss or
corruption.
Power Failures: Sudden power outages can disrupt database operations and lead
to inconsistencies or corruption.
Memory Failures:Issues with RAM or system memory can cause database
operations to malfunction, leading to crashes or data corruption.
Network Failures: Disruptions in network connectivity can prevent access to the
database or cause timeouts in distributed databases.
Server Failures: Server crashes or hardware malfunctions can cause the database
service to become unavailable.
2. Software Failures
3. Human Errors
Data Corruptionor Loss: Mistakes made during data entry, data migrations, or
updates can lead to corruption or loss of data.
Improper Configuration: Misconfigurations of the DBMS, such as incorrect
indexing, security settings, can cause poor performance or failure.
Accidental Deletion: Admins or users accidentally deleting tables, records, or
configurations can cause irreparable damage to a database.
Poor Backup and Recovery Practices: Failure to implement a proper backup
strategy or neglecting to test recovery procedures can lead to permanent data loss
in the event of a failure.
4. Environmental Factors
8. Concurrency Issues
Deadlocks: If two or more transactions are waiting for each other to release locks,
a deadlock can occur, causing the database to hang or crash.
Resource Exhaustion: Databases may fail if they run out of critical resources like
disk space, memory, or CPU, especially under high load or unexpected spikes in
traffic.
Scaling Problems: If the database is not scaled properly to handle increased loads
it may experience performance degradation or complete failure.
Database backup ensures that data can be recovered in the event of failure, corruption, or
accidental loss.
A database backup is a copy of storage that is stored on a server. Backup is used to
prevent unexpected data loss. If original data gets lost, then with the help of a backup, it
is easy to gain access to the data again.
A robust backup strategy typically involves a combination of different backup types and
methods, tailored to the specific needs of the organization.
There are two types of database backup.
Physical backup
Logical backup
Physical Backup:
Physical database backups are backups of physical files that are used to store and recover
databases.
These include different data files, control files, archived redo logs, and many more.
Typically, physical backup data is kept in the cloud, offline storage, magnetic tape, or on
a disc.
1. Full Physical Backup: A backup of all the database's physical files. It provides a
complete snapshot of the database at the time of backup.
2. Incremental Physical Backup: A backup of only the changes made to the
physical files since the last backup(full or incremental). These are often combined
with transaction log backups for point-in-time recovery.
3. Differential Physical Backup: A backup of all changes made since the last full
backup, but unlike incremental backups, it does not reset after each backup.
This type of backup is useful when the user needs to restore the complete database in a
short period.
It is considered the foundation of the recovery mechanism. This form of backup has the
drawback of slowing down database operations.
Advantages:
Faster Restoration: Since it includes the actual data files, restoring a physical backup is
typically faster, especially for large databases.
Consistency: Can be made consistent with minimal impact on database performance if
transaction logs are also included (ensuring no data is missed).
Database State: Provides an exact copy of the database's files, meaning the entire database
(data, schema and indexes) can be restored without the need for additional steps
Disadvantage:
Size: Backup files tend to be large, as they involve copying entire database files, which
can be resource-intensive, especially for large databases.
Complexity: Requires more careful management of the physical files (e.g., ensuring that
all files are included for a complete backup and restoring them in the correct order).
Large Databases: When backing up large or complex databases with many objects, physical
backups are more efficient in terms of both time and space.
Full Restores: For systems where the entire database needs to be restored quickly, such as in
disaster recovery scenarios.
Logical Backup:
A logical backup focuses on the logical structure of the database, such as the schema,
tables, views, indexes, and data contained in the tables themselves. Instead of backing up
physical database files, a logical backup creates a high-level representation of the
database objects in a readable or portable format such as CSV files.
It contains logical data which is retrieved from the database. This is useful when users
want to restore or transfer a copy of the database to a different location. Logical backups
are not as secure as physical backups in preventing data loss. It only provides structural
details.
Advantages:
Portability: Logical backups can be more portable since they are stored in widely-used
formats(e.g.,SQL, CSV)that can easily be transferred or imported into different systems
or DBMSs.
Database Version Independence: Logical backups can often be restored on a different
database version or platform, which is useful when upgrading or migrating databases.
Smaller Size: Logical backups can be smaller than physical backups because they don’t
contain all the low-level system files (e.g., transaction logs, undo segments).
Disadvantages:
Slower Restoration: Restoring from a logical backup can be slower than restoring a
physical backup, especially for large databases, because the DBMS needs to recreate the
schema, indexes, and data.
Lack of Full Database State: Logical backups do not typically capture certain database-
specific configurations, transaction logs, or system files that may be needed to fully
restore the database to its exact state (e.g., to ensure point-in-time recovery).
Consistency Issues: Ensuring consistency during the backup process can be difficult,
especially for databases with high transaction volumes.
Database Migration: Logical backups are ideal for migrating a database from one server to
another or even to a different DBMS (e.g., moving from MySQL to PostgreSQL).
Selective Backup: When you only need to back up specific tables, views, or schemas rather than
the entire database.