0% found this document useful (0 votes)
44 views48 pages

Data Base Administration Short Notes

The document provides an overview of Database Administration and Management, focusing on Oracle Database, its installation, and key components such as SQL*Plus and Oracle Enterprise Manager. It details the structure of Oracle databases, including logical and physical storage components, tablespaces, and various types of tables. Additionally, it outlines the importance of database security, backup strategies, and the use of constraints and indexes for data integrity.

Uploaded by

Hina Riaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views48 pages

Data Base Administration Short Notes

The document provides an overview of Database Administration and Management, focusing on Oracle Database, its installation, and key components such as SQL*Plus and Oracle Enterprise Manager. It details the structure of Oracle databases, including logical and physical storage components, tablespaces, and various types of tables. Additionally, it outlines the importance of database security, backup strategies, and the use of constraints and indexes for data integrity.

Uploaded by

Hina Riaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Page 1 of 48 Data Base Administration & Management M.

Waseem
Short Notes.
Data Base Administration & Management.
Chapter 1:
1. Installation; SQL* Plus; Oracle Enterprise Manager; DBA Tools. Oracle Architectural Components: Oracle
Server; Oracle Instance.
Introduction to oracle database
It is a database commonly used for running online transaction processing (OLTP), data warehousing (DW)
and mixed (OLTP & DW) database workloads

The purpose of a database is to store and retrieve related information. A database server is the key to
solving the problems of information management. Oracle Database is the first database designed for
enterprise grid computing, the most flexible and cost-effective way to manage information and applications.

Installation:
The Oracle Database 11g software installation process using the Oracle Universal Installer (OUI), then
creating a database using the Database Creation Assistant (DBCA). You can create a new database using
OUI, running DBCA as a separate step gives you a bit more configuration flexibility
1-Software Installation
• Decide on the local database name and which domain will contain this database.
• Estimate the number of tables and indexes, as well as their size, to plan for disk space estimates
• Plan the locations of the physical data files on the server’s disk to maximize performance and
recoverability. Automatic Storage Management (ASM) instance, making it easier to manage
redundant storage if you don’t have RAID.
• Select the database character set, Character sets can be changed after installation
• Decide on the best default database block size. The default block size defined by
DB_BLOCK_SIZE cannot be changed later without reinstalling the database.
• Make sure that all non-administrative users are assigned a non-SYSTEM tablespace as their
default tablespace.
• Automatic Undo Management is a must to ease the administration of transaction undo
information.
• Plan a backup and recovery strategy. Decide how often the database needs to be backed up;
use more than one method to back up the database

3- OUI to Install the Oracle Software


The Oracle Universal Installer (OUI) is used to install and manage all Oracle components for both the
server-side and client-side components. You can also uninstall any Oracle products from the initial OUI
windows.
During the server installation, you will choose the version of Oracle Database 11g from the list in the
preceding section: Enterprise Edition, Standard Edition, or Standard Edition One.
The Database Configuration Assistant (DBCA) takes over and prompts you for the parameters necessary
to size and configure your database.

SQL* Plus
SQL*Plus is an interactive query tool that is installed with every Oracle Database Server or Client installation.
It has a command-line user interface, a Windows Graphical User Interface (GUI) and the iSQL*Plus
webbased user interface.
It enables you to enter and execute SQL, PL/SQL, SQL*Plus and operating system commands to perform
the following:

• Format, perform calculations on, store, and print from query results
• Examine table and object definitions
• Develop and run batch scripts

https://psc-msc.blogspot.com/
Page 2 of 48 Data Base Administration & Management M. Waseem
• Perform database administration
You can use SQL*Plus to generate reports interactively, and to output the results to text file, to screen, or to
HTML file for browsing on the Internet.
SQL*Plus Installation
SQL*Plus is installed by default when you install the Oracle Database.
SQL*Plus Date Format
The default date format in SQL*Plus is determined by the database NLS_DATE_FORMAT parameter
and may use a date format displaying two digit years. You can use the SQL TO_CHAR function, or the
SQL*Plus COLUMN FORMAT command in your SELECT statements to control the way dates are displayed
in your report Using SQL Plus:
• Run command prompt and type in ―sqlplus‖ then hit enter. OR
• Select the ―SQL Plus‖ shortcut menu from oracle menu option.
• Enter username and password when prompted.
• You can also use ―username as SYSOPER‖ and ―username as SYSDBA‖.
• Shutdown a database instance
• Star a database instance ―startup‖
• View parameters by using SELECT name, value FROM V$PARAMETER:
• To view selected parameter use SHOW PARAMETER parameter_name / SHOW PARAMETER
shared_ pool _size

Which is an SQL * Plus command?


SQL*Plus Command Summary
Command Description
SPOOL Stores query results in an operating system file and, optionally, sends the file to a printer.
START Executes the contents of the specified script. The script can only be called from a url. STARTUP
Starts an Oracle instance and optionally mounts and opens a database.

DBA Tools
Oracle DBA Tools for administrating Database 1-Oracle
Universal installer (OUI):
OUI is a Java-based graphical user interface application that enables you to install Oracle components from
a DVD, multiple DVDs, or the Web.
2-Oracle Database Configuration Assistant (DBCA):
A utility that creates a database from templates, or you can create, configure and drop databases your
own. Database Configuration Assistant (DBCA) is the preferred way to create a database, because it is a
more automated approach, and your database is ready to use when DBCA completes 3-Database
Upgrade Assistant :
Upgrading your database involves using Oracle’s upgrade tool called the Database Upgrade Assistant
(DBUA). you can upgrade of your existing database to a new oracle Database release.
4-Net Configuration Assistant(NETCA):520
A utility that enables you to configure listeners and naming methods, which are critical componenets of the
Oraclae Database Network. This performs the initial network configuration steps after the Oracle software
installation and automatically creates the default, basic configuration files.

Oracle Enterprise Manager


OEM is a valuable set of tools that facilitates the comprehensive management of all components of an
Oracle infrastructure, including Oracle database instances, Oracle application servers, and web servers. The
OEM management repository is stored in a database.
From the Oracle Enterprise Manager's Console, you can:
• Administer, diagnose, and tune multiple databases.
• Distribute software to multiple servers and clients.
• Schedule jobs on multiple nodes at varying time intervals.
• Monitor objects and events throughout the network.
• Customize your display using multiple graphic maps and groups of network objects, such as nodes
and databases.

https://psc-msc.blogspot.com/
Page 3 of 48 Data Base Administration & Management M. Waseem
• Administer Oracle Parallel Servers.
• Integrate participating Oracle or third-party tools

Oracle server:
An Oracle server includes an Oracle Instance and an Oracle database.

1- Oracle database:
A database is a collection of data on disk in one or more files on a database server that collects and
maintains related information. The database consists of various physical and logical structures, the table
being the most important logical structure in the database. A table consists of rows and columns containing
related data. a database provides a level of security to prevent unauthorized access to the data.
• An Oracle database includes several different types of files: datafiles, control files, redo log files
and archive redo log files. The Oracle server also accesses parameter files and password files.
• The database server must manage large amounts of data in a multi-user environment.
• The server must manage concurrent access to the same data.
• The server must deliver high performance. This generally means fast response times.
• Oracle Database provides many mechanisms to facilitate the security necessary to keep
confidential data confidential.
❖ Logical Storage Structure
❖ Logical Database Structure

https://psc-msc.blogspot.com/
Page 4 of 48 Data Base Administration & Management M. Waseem
❖ Physical Database Structure

1.1 Oracle Logical Storage Structures:


The data files in an Oracle database are grouped together into one or more tablespaces. This logical
subdivision of storage allows Oracle to have more efficient control over disk space usage.

Table spaces:
Tablespaces logically organize data that are physically stored in datafiles. A tablespace belongs to only
one database, and has at least one datafile that is used to store data for the associated tablespace. Oracle
11g allows you to create a special kind of tablespace called a bigfile tablespace, which can be as
large as 128TB (terabytes). It can also store many other database objects such as indexes, views,
sequences, etc. The DBA can manage the tablespace as a unit without worrying about the size and
structure of the underlying datafiles.
For an installation of Oracle 11g, a minimum of two tablespaces are created,the SYSTEM
tablespace and the SYSAUX tablespace.
• SYSTEM – a tablespace that is always used to store SYSTEM data that includes data about
tables, indexes, sequences, and other objects – this metadata comprises the data dictionary.
• SYSAUX tablespace stores data for auxiliary applications such as the LogMiner, Workspace
Manager, Oracle Data Mining, Oracle Streams, and many other Oracle tools.

There are three types of tablespaces: (1) permanent, (2) undo, and (3) temporary.
• Permanent – These tablespaces store objects in segments that are permanent – that persist
beyond the duration of a session or transaction.
• Undo – These tablespaces store segments that may be retained beyond a transaction, but are
basically used toProvide the ability to rollback a transaction that fails to commit.
• Temporary – This tablespace stores segments that are transient and only exist for the duration of
a session or a transaction.
Blocks:
Oracle manages the storage space in the datafiles of a database in units called data blocks. A data block is
the smallest unit of data used by a database. The size of a block is a specific number of bytes of storage
within a given tablespace within the database.

Extents:
An extent is a logical unit of database storage space allocation made up of a number of contiguous data
blocks. When you enlarge a database object, the space added to the object is allocated as an extent.

Segments
Each segment is composed of one or more extents that form a database object that Oracle treats as a unit,
such as a table or index. Four types of segments are found in an Oracle database: data segments, index
segments, temporary segments.
• Data Segment: Every table in the database resides in a single data segment, consisting of
one or more extents. Oracle allocates one or more extents to form that table's data segment
• Index Segment: Each index is stored in its own index segment. As with partitioned tables,
each partition of a partitioned index is stored in its own segment.
• Temporary Segment: A temporary segment in a temporary table contains data for multiple
statements of a single transaction or session.Oracle drops the temporary segment at the end of
the transaction or session. As When a user’s SQL statement needs disk space to complete an
operation, such as a sorting operation that cannot fit in memory, Oracle allocates a temporary
segment. Temporary segments exist only for the duration of the SQL statement.
• Rollback Segment: A Rollback Segment is a database object containing before-images of data
written to the database. Rollback segments are used to: Undo changes when a transaction is
rolled back. Rollback segments were also used during database recovery for rolling back
uncommitted transactions that were active when the database instance crashed or terminated
unexpectedly

https://psc-msc.blogspot.com/
Page 5 of 48 Data Base Administration & Management M. Waseem

1.2 Oracle Logical Database Structures

❖ Tables:
A table is the basic unit of storage in an Oracle database. Regardless of the type of table, data in a table is
stored in rows and columns.
• Relational Tables: A relational table is heap organized; you can specify the clause organization heap
to define a heap-organized table Each row of a table contains one or more columns; each column has a
data type and a length.
• Temporary Tables: They are temporary in the sense of the data that is stored in the table, not in the
definition of the table itself. Users have permissions to insert, update, or delete, on a temporary table.
The statement to create a temporary table :
• Index Organized Tables: index Organized Tables (IOT) have their primary key data and non-key
column data stored within the same B*Tree structure. Effectively, the data is stored within the primary
key index. Why Use Index Organized Tables?
o Accessing data via the primary key is quicker as the key and the data reside in the same structure.
There is no need to read an index then read the table data in a separate structure. o Lack of
duplication of the key columns in an index and table mean the total storage requirements are
reduced. the values for the primary key of the table are stored only once in an IOT,
• Object Tables: An object type can represent a student, bank account, computer screen, rational
number, or data structure such as a queue, stack, or list. You can define them interactively in SQL*Plus
using the
SQL statement CREATE TYPE
Object tables can still have both primary and unique keys, just as relational tables do.
• External Tables: External tables allow Oracle to query data that is stored outside the database in flat
files. No DML can be performed on external tables but they can be used for query, join and sort
operations. You cannot create indexes on an external table, and no inserts, updates, or deletes can be
performed on external tables.
• Clustered Tables: A table cluster is a group of tables that share the same data blocks. Clustered
tables reduce the amount of space needed to store the columns the two tables have in common, also
known as a cluster key value. The advantages to clustering a table are reduced if frequent insert,
update, and delete operations occur on the table relative to the number of select statements against the
table.
• Hash Clusters: A hash cluster uses a hashing function to store and retrieve rows in a table. The total
estimated amount of space needed for the table is allocated when the table is created, given the number
of hash keys specified during the creation of the cluster.
• Sorted Hash Clusters: sorted hash clusters allow rows in the table to be stored by one or more
columns of the table in ascending order.
You create sorted hash clusters using the same syntax as regular clustered tables, with the addition
of the SORT positional.
#Partitioned Tables: Partitioning a table helps make a large table more manageable, A table may be
partitioned, or even subpartitioned, into smaller pieces. Queries against the partitioned table using criteria in
the where clause that matches the partitioning scheme. Partitions are one of three types: range partitioned,
hash partitioned, list partitioned;
• A range partition is a partition whose partition key falls within a certain range.
• A list partition is a partition whose partition key falls within groups of distinct values.
• A hash partition assigns a row to a partition based on a hashing function.
• Composite Partitions: a table is partitioned by one data distribution method and then each partition is
further subdivided into sub-partitions using a second data distribution method. All subpartitions for a
given partition represent a logical subset of the data.
• Partitioned Indexes: A partitioned index in Oracle 11g is simply an index broken into multiple pieces.
By breaking an index into multiple physical pieces, you are accessing much smaller pieces (faster), and
you may separate the pieces onto different disk drives (reducing I/O contention). Both b-tree and bitmap
indexes can be partitioned.
https://psc-msc.blogspot.com/
Page 6 of 48 Data Base Administration & Management M. Waseem
❖ Constraints
An Oracle constraint is a rule or rules that you can define on one or more columns in a table to help enforce
a business rule. Six types of data integrity rules can be applied to table columns: null rule, unique column
values, primary key values, referential integrity values, complex in-line integrity, and trigger-based integrity.
▪ Null Rule: The NOT NULL constraint prevents NULL values from being entered.
▪ Unique Column Values: The UNIQUE integrity constraint ensures that a column or
group of columns is unique throughout the table.
▪ Primary Key Values: only one primary key constraint can exist on a table. The
column or columns that comprise the primary key cannot have NULL values.
❖ Integrity o Referential Integrity Values: A foreign key constraint requires values in one table to
match values in another table.
o Complex In-Line Integrity: More complex business rules may be enforced at the
column level by using a CHECK constraint. A check constraint requires a value in
the database to comply with a specified condition.
o Trigger-Based Integrity: A trigger is a named PL/SQL unit that is stored in the
database and executed (fired) in response to a specified event that occurs in the
database.
❖ Indexes
An Oracle index allows faster access to rows in a table when a small subset of the rows will be retrieved
from the table. Indexes are created on a single column or multiple columns. Index entries are stored in a
Btree structure so that traversing the index to find the key value of the row uses very few I/O operations. Use
the CREATE INDEX statement to create an index on: ❖ Users
Use the CREATE USER statement to create and configure a database user, which is an account through
which you can log in to the database, and to establish the means by which Oracle Database permits access
by the user. Access to the database is granted to a database account known as a user. A user may exist in
the database without owning any objects.

❖ Schemas
schema is the set of objects (tables, views, tables, indexes, sequences, views etc.) that belong to that
account. A schema is a collection of database objects owned by a specific user.

❖ Profiles
Profiles are a means to limit resources a user can use. Before profiles can be assigned, they must be created with
create profile. The DBA can add new profiles or change the DEFAULT profile to suit the needs of the enterprise. A
DBA must manage and allocate resources among all database users. Some examples of database resources are CPU
time, concurrent sessions, logical reads, and connect time.

❖ Sequences
A sequence is an object in Oracle that is used to generate a number sequence. This can be useful when you
need to create a unique number to act as a primary key. Sequences can generate numbers up to 38 digits in
length; the series of numbers can be ascending or descending.

❖ Synonyms
A synonym is an alternative name for objects such as tables, views, sequences, stored procedures, and
other database objects.
You generally use synonyms when you are granting access to an object from another schema and you don't
want the users to have to worry about knowing which schema owns the object. Synonyms can be either
public or private. A private synonym is defined in the schema of a user and is available only to the user. A
public synonym is usually created by a DBA and is automatically available for use by any database user.

❖ PL/SQL
Oracle PL/SQL is Oracle’s procedural language extension to SQL. PL/SQL is useful when the standard DML
and select statements cannot produce the desired results in an easy fashion because of the lack of the
procedural elements found in a traditional third-generation language such as C++ and Ada.

❖ Procedures/Function

https://psc-msc.blogspot.com/
Page 7 of 48 Data Base Administration & Management M. Waseem
A procedure is a group of PL/SQL statements treated as a unit for the purposes of execution that you can
call by name. It contains up to three sections: a variable declaration section, an executable section, and an
exception section. Procedures are compiled and stored in the data dictionary once; when more than one
user needs to call the procedure, it is already compiled, and only one copy of the stored procedure exists in
the shared pool.
A function is compiled and executed every time whenever it is called. A function must returns a value and
cannot modify the data received as parameters.

The difference between a procedure and function is that a function will return a single value to a calling
program. A procedure, on the other hand, does not return a value, only a status code.

❖ Packages
PL/SQL packages group together related functions and procedures, along with common variables and
cursors. Packages consist of two parts: a package specification and a package body. In the package
specification, the methods and attributes of the package are exposed; the implementation of the methods
along with any private methods and attributes are hidden in the package body.

❖ Triggers
Triggers are a specialized type of a PL/SQL that is executed, or triggered, when a specified event occurs (
DML statements like Insert,Delete, Update). A trigger is triggered automatically when an associated DML
statement is executed.

https://psc-msc.blogspot.com/
Page 8 of 48 Data Base Administration & Management M. Waseem

Chapter 2.
2. Physical Structure; SGA; Shared Pool; Library Cache; Data Dictionary Cache; Large Pool; User Process; Server
Process; Background Processes.

1.3 Oracle Physical Storage Structures


The Oracle database uses a number of physical storage structures on disk to hold and manage the data from
user transactions. such as the datafiles, redo log files, and archived redo log files, hold actual user data;
other structures, such as control files, maintain the state of the database objects, and text-based alert and
trace files contain logging information for both routine events and error conditions in the database.

❖ Datafiles: A data file is a physical file on disk that was created by Oracle Database and contains data
structures such as tables and indexes. Each datafile in an Oracle database is a member of one and
only one tablespace. An Oracle datafile may automatically expand when it runs out of space, if the
DBA created the datafile with the AUTOEXTEND parameter. The DBA can also limit the amount of
expansion for a given datafile by using the MAXSIZE parameter.

❖ Redo Log Files: The most crucial structure for recovery operations is the redo log, which consists of
two or more pre-allocated files that store all changes made to the database as they occur. Every
instance of an Oracle Database has an associated redo log to protect the database in case of an
instance failure. when a power failure occurs, Oracle instance is restarted, the entries in the redo log
file are applied to the database datafiles in a roll forward operation, to restore the state of the
database up to the point where the failure occurred.

❖ Control Files: A control file is a small binary. The control file is used to keep track of the database's
status and physical structure. Every Oracle Database must have at least one control file. However, it
is recommended to create more than one, up to a maximum of 8. Each copy of a control file should
be stored on a different disk drive. By storing control files in these locations, you minimize the risk that
all control files will be lost in a single disk failure.
The control file contains information like:
▪ Database name
▪ Timestamp of database creation
▪ Names and locations of Data Files
▪ Names and locations of Redo Log files
▪ The current log sequence number
▪ Checkpoint information ▪ Recent RMAN backups taken
▪ Etc.
One of the control files is designated as primary for purposes of retrieving database metadata.

❖ Archived Log Files: An Oracle database can operate in one of two modes: archivelog or
noarchivelog mode.
• ARCHIVELOG mode is a mode that you can put the database in for creating a backup of all
transactions that have occurred in the database so that you can recover to any point in time.
• The database is in noarchivelog mode, the circular reuse of the redo log files means that redo
entries are no longer available in case of a failure to a disk drive or another media-related failure.
In NOARCHIVELOG mode you cannot perform online tablespace backups. NOARCHIVELOG mode
protects a database from instance failure but not from media failure.
❖ Initialization Parameter Files: When a database instance starts, the memory for the Oracle instance
is allocated. The parameters tell the Oracle programs how much memory to allocate, where to put
files related to the database and the location of existing datafiles. A parameter has a name and a
value.
There are two types of initialization parameter files: either a text-based file called
init<SID>.ora/ PFILS and a server parameter file known as an SPFILE.
PFILE/int.ora:

https://psc-msc.blogspot.com/
Page 9 of 48 Data Base Administration & Management M. Waseem
• init.ora or the pfile is a simple text file which can be updated by a standard editor like vi
which contains the various initialization parameters used while starting a database
instance.
• We need to restart the database after editing the init.ora using a text editor so that the
changes can come into effect.
• If we want to start a remote db we need a local pfile.
• RMAN(Recovery manager) which helps in data backup recovery process does not keep
the backup of pfile or init.ora file.

SPFILE:
• The Oracle spfile is a binary representation of the text based init.ora file or pfile which
contains the various initialization parameters used while starting a database instance.
• We do not edit this file using an editor as it is a binary file and may get corrupted and
which may lead to your database instance not starting rather it is altered by using the alter
systemquery.
• We do not need a local copy in case of spfile if we need to start a remote database.
• As this file is maintained by the server the parameters are validated before they are
accepted.
• RMAN keeps the backup of spfile.
• SPFILE permits dynamic changes without requiring you to restart that instance.

INIT.ORA/ PFILEs
PFILEs are also know as INIT.ORA files. Characteristics of a PFILE:
▪ Client side
▪ Text file
▪ Edit with text editor like vi or notepad
SPFILEs
Characteristics of an SPFILE:
▪ Server side
▪ Binary file
▪ Edit by issuing ALTER SYSTEM SET command
❖ Alert and Trace Log Files: When things go wrong, Oracle can and often does write messages to the
alert log . The alert log file is a chronological log of messages and errors written out by an Oracle
Database. Typical messages found in this file is: database startup, shutdown, log switches, space
errors, etc. Oracle will automatically create a new alert log file whenever the old one is deleted.
Oracle will write the alert.log file to the directory as specified by the BACKGROUND_ DUMP_ DEST
parameter.

❖ Trace File are trace (or dump) file that Oracle Database creates to help you diagnose and resolve
operating problems. Each server and background process writes to a trace file. The trace files for the
Oracle instance background processes are also located in BACKGROUND_DUMP_DEST.
❖ Backup Files: Backup and recovery procedures protect your database against data loss and
reconstruct the data, should loss occur. Backup files can originate from a number of sources, such as
operating system copy commands or Oracle Recovery Manager (RMAN). If the DBA performs a
―cold‖ backup the backup files are simply operating system copies of the datafiles, redo log files,
control files, archived redo log files, and so forth. If you lose the original data, then you can
reconstruct it by using a backup.
Recovery Manager (RMAN) is an Oracle utility that can back up, restore, and recover database files.
It is a feature of the Oracle database server and does not require separate installation. RMAN can
generate full and incremental backups of datafiles, control files, archived redo log files, and SPFILEs
that are in a special format, called backupsets, only readable by RMAN. RMAN backupset backups
are generally smaller than the original datafiles because RMAN does not back up unused blocks.
❖ Oracle Managed Files:Oracle Managed Files (OMF) directly manages file creation and deletion at
the operating system level. It has several advantages including:
• Automatic cleanup of the filesystem when database objects are dropped.
• Standardized naming of database files.
• Increased portability since file specifications are not needed.

https://psc-msc.blogspot.com/
Page 10 of 48 Data Base Administration & Management M. Waseem
• Simplified creation of test systems on differing operating systems. No unused files
wasting disk space.
❖ Password Files: An Oracle password file is a file within the Oracle administrative or software
directory structure on disk used to authenticate Oracle system administrators for tasks such as
creating a database or starting up and shutting down the database. The Oracle command-line utility
orapwd creates a password file if one does not exist or is damaged. The privileges granted through
this file are the SYSDBA and SYSOPER privileges.

❖ Multiplexing Database Files: Extra

To minimize the possibility of losing a control file or a redo log file, multiplexing of database files
reduces or eliminates data-loss problems caused by media failures. Multiplexing can be somewhat
automated by using an Automatic Storage Management (ASM) instance. I need some information
regarding the multiplexing of data files and redo log files:

1. Can I keep same datafile on different locations with different sizes?


2. If one datafile at one location is full, will the other datafiles at different locations will be available to
new inserts?
3. If the data is not able to go in the database because of tablespace full error, is that data available in
the redo log file?
❖ Automatic Storage Management: Extra
Using Automatic Storage Management is a multiplexing solution that automates the layout of
datafiles, control files, and redo log files by distributing them across all available disks. When new
disks are added to the ASM cluster, the database files are automatically redistributed across all disk
volumes for optimal performance.

2 Oracle Instances
When a database is started on a database server Oracle allocates a memory area called the System Global
Area (SGA) and starts one or more Oracle processes. This combination of the SGA and the Oracle
processes is called an Oracle instance.
After starting an instance, Oracle associates the instance with the specified database. This is a mounted
database. The database is then ready to be opened, which makes it accessible to authorized users. Only
the database administrator can start up an instance and open the database. The instances that share the
database can be on the same server, most likely the instances will be on separate servers that are
connected by a high-speed interconnect and access a database.

An Oracle Instance consists of two different sets of components: 1-


memory structures 2- background processes

2.1 Oracle Memory Structures: extra

Oracle uses memory to store various information:


program code being executed
• information about a connected session,
• information needed during program execution
• information that is shared and communicated among Oracle processes cached data that is also
permanently stored on peripheral memory SQL statements etc.
The basic memory structures associated with Oracle include:
• System Global Area (SGA)
• Program Global Areas (PGA)
• Software Code Areas
2.1.1 System Global Area (SGA):

A System Global Area (SGA) is a group of shared memory structures that contain data and control
information for one Oracle database instance. If multiple users are concurrently connected to the same
instance, the data in the instance's SGA is "shared" among the users. Most of its parameters have dynamic

https://psc-msc.blogspot.com/
Page 11 of 48 Data Base Administration & Management M. Waseem
size unless the parameter SGA_MAX_SIZE is not specified. SGA is allocated in units of GRANULES. A
GRANULE can either be 4 MB or 16MB.

The SGA contains the following subdivisions:


➢ Buffer Caches:
The database buffer cache is the portion of the SGA that holds copies of data blocks read from datafiles. All
user processes concurrently connected to the instance share access to the database buffer cache. The
initialization parameter DB_BLOCK_BUFFERS specifies the number of buffers in the database buffer cache.
each database buffer in the cache can hold a single data block read from a datafile.

➢ Shared Pool:
The shared pool contains two major sub-caches: the library cache and the data dictionary cache. The
shared pool is sized by the SHARED_POOL_SIZE initialization parameter.
• Library Cache:
The library cache holds information about SQL and PL/SQL statements that are run against the
database. It is shared by all users and also contains execution plan and syntax-tree or SQL
statement to improve execution time without reloading SQL statement each time.
• Data Dictionary Cache:
The data dictionary is a collection of database tables, owned by the SYS and SYSTEM schemas
that contain the metadata about the database, its structures, privileges and roles of database users.
.
➢ Redo Log Buffer:
The redo log buffer holds the most recent changes to the data blocks in the datafiles. When the redo log
buffer is one-third full, or every three seconds, Oracle writes redo log records to the redo log files. A user’s
committed transaction is not considered complete until the redo log entries have been successfully written to
the redo log files.
➢ Large Pool
The large pool is an optional area of the SGA. It is used for transactions that interact with more than one
database, for processes parallel queries, RMAN parallel backup and restore operations. The large pool
makes available large blocks of memory for operations. The initialization parameter LARGE_POOL_SIZE
controls the size of the large pool and is a dynamic parameter.

➢ Java Pool
It used by the Oracle JVM for all Java code and data within a user session. Storing Java code and data in the
Java pool is analogous to SQL and PL/SQL code cached in the shared pool.

➢ Streams Pool
The streams pool is sized by using the initialization parameter STREAMS_POOL_SIZE. The streams pool
holds data and control structures to support the Oracle Streams feature of Oracle Enterprise Edition. Oracle
Streams manages the sharing of data and events in a distributed environment.

2.1.2 Program Global Area

The Program Global Area is an area of memory allocated and private for one process. PGA contains the
data and control information for a server process. It is non-shared memory created by Oracle Database
when a server process is started. Only a server process can access the PGA. Oracle Database reads
and writes information in the PGA on behalf of the server process. The PGA also includes a sort
area.Oracle Database automatically derives the total amount of PGA memory available to active work
areas from the PGA_AGGREGATE_TARGET initialization parameter.

2.1.3 Software Code Area


Software code areas store the Oracle executable files that are running as part of an Oracle instance.
These code areas are static in nature and only change when a new release of the software is installed.
Oracle software code is strictly read-only and can be installed either shared or non-shared.

https://psc-msc.blogspot.com/
Page 12 of 48 Data Base Administration & Management M. Waseem
2.2 Processes
A process is a mechanism in an operating system that can run a series of steps. The mechanism depends
on the operating system. A process normally runs in its own private memory area. Each process in a
database instance performs a specific job.
Multiple-process Oracle (also called multiuser Oracle) uses several processes to run different parts of the
Oracle Database code and additional processes for the users—either one process for each connected user
or one or more processes shared by multiple users.
➢ User Process;
➢ Server Process;
➢ Background Processes.

2.2.1 User Process:


User process commonly works outside the database server itself to run the application that accesses the
database. The user process represents a user’s session in the database. The user process first establish a
connection. It cannot interact directly with oracle server. It is created to execute the program code of an
application program. It also links the user’s connection or client application to the oracle instance.

When a user requests a session with the database, the system starts a dedicated server process for that
user. When the user disconnects from the database, this dedicated server process terminates. Many people
call this dedicated server process a user process as well.

2.2.2 Oracle Process:


It invokes by any other process to perform specific function on behalf of invoking process. Two
types of oracle process are server process and background processes.

❖ Server Process:
Oracle Database creates server processes to handle the requests of user or client processes connected to
the instance. A client process always communicates with a database through a separate server process.
Server processes can be either dedicated or shared.
▪ Dedicated Server Processes: In dedicated server connections, the client connection is associated
with one and only one server process. Each client process communicates directly with its server
process. This server process is dedicated to its client process for the duration of the session.

▪ Shared Server Processes: In shared server connections, client applications connect over a network
to a dispatcher process, not a server process. The dispatcher process receives requests from
connected clients and puts them into a request queue in the large pool. The first available shared
server process takes the request from the queue and processes it. Afterward, the shared server
places the result into the dispatcher response queue. The dispatcher process monitors this queue
and transmits the result to the client.
❖ Background Processes:
When an Oracle instance starts, multiple background processes start. A background process is a block of
executable code designed to perform a specific task. Together, the SGA and the background processes
compose an Oracle instance. Each background process has a separate task, but works with the other
processes. Oracle Database creates background processes automatically when a database instance starts.
This section includes the following topics:
• Mandatory Background Processes
• Optional Background Processes
• Slave Processes Mandatory Background Processes:
These are present in all typical database configurations. These processes run by default in a database
instance
This section describes the following mandatory background processes:
• System Monitor Process (SMON): In the case of a system crash or instance failure, due to a
power outage or CPU failure, the SMON process performs crash recovery by applying the
entries in the online redo log files to the datafiles. It Cleaning up unused temporary segments.

https://psc-msc.blogspot.com/
Page 13 of 48 Data Base Administration & Management M. Waseem
• Process Monitor Process (PMON): The process monitor (PMON) monitors the other
background processes and performs process recovery when a server or dispatcher process
terminates abnormally. PMON perform the following tasks:
• Roll back the transaction that was in progress when the power went out.
• Mark the transaction’s blocks as available in the buffer cache. Remove the locks on
the affected rows in the table.
• Remove the process ID of the disconnected process from the list of active processes.
• Database Writer Process (DBWn): The database writer process (DBWn) writes new or change
the contents of database buffers to data files. The number of DBWn processes is controlled by
the DB_WRITER_PROCESSES parameter.

• Log Writer Process (LGWR): The log writer process (LGWR) manages the redo log buffer. A
transaction is not considered complete until LGWR successfully writes the redo information,
including the commit record, to the redo log files. If the redo log files are grouped, and one of
the multiplexed redo log files in a group is damaged, LGWR writes to the remaining members
of the group and records an error in the alert log file.

• ARCHIVELOG mode ( ARCn) : If the database is in ARCHIVELOG mode, then the archiver
process, or ARCn, copies redo logs to one or more destination directories, devices, or
network locations whenever a redo log fills up and redo information starts to fill the next redo
log in sequence.
• Checkpoint Process (CKPT): The checkpoint process, or CKPT, helps to reduce the amount
of time required for instance recovery. During a checkpoint, CKPT updates the header of the
control file and the datafiles to reflect the last successful SCN (System Change Number). A
checkpoint occurs automatically every time a redo log file switch occurs.

• Recoverer Process (RECO): In a distributed database, the recoverer process (RECO)


automatically resolves failures in distributed transactions. When RECO reestablishes a
connection between the databases, it automatically resolves all in-doubt transactions ,
removing from each database's pending transaction table any rows that correspond to the
resolved transactions.

Optional Background Processes: extra

Most optional background processes are specific to tasks or features.


• Job Queue Processes (CJQ0 and Jnnn): Oracle Database uses job queue processes to
run user jobs, often in batch mode. A job is a user-defined task scheduled to run one or more
times. Oracle Database manages job queue processes dynamically. The database releases
resources used by the new processes when they are idle. The initialization parameter
JOB_QUEUE_PROCESSES represents the maximum number of job queue processes that can
concurrently run on an instance.
• Flashback Data Archiver Process (FBDA): The flashback data archiver process
(FBDA) archives historical rows of tracked tables into Flashback Data Archives. This process stores
the pre-image of the rows into the Flashback Data Archive. FBDA automatically manages the
flashback data archive for space, organization, and retention.
• Space Management Coordinator Process (SMCO): The SMCO process coordinates the
execution of various space management related tasks, such as proactive space allocation and
space reclamation.
Slave Processes: : Extra

Slave processes are background processes that perform work on behalf of other processes.

I/O Slave Processes: I/O slave processes (Innn) simulate asynchronous I/O for systems and devices that do not
support it. In asynchronous I/O, there is no timing requirement for transmission, enabling other processes to start
before the transmission has finished.
Parallel Query Slaves: In parallel execution or parallel processing, multiple processes work together simultaneously
to run a single SQL statement. By dividing the work among multiple processes, Oracle Database can run the statement
more quickly. Parallel execution reduces response time for data-intensive operations on large databases .

https://psc-msc.blogspot.com/
Page 14 of 48 Data Base Administration & Management M. Waseem
Serial Execution :In serial execution, a single server process performs all necessary processing for the sequential
execution of a SQL statement. Parallel Execution In parallel execution, the server process acts as the parallel execution
coordinator responsible for parsing the query, allocating and controlling the slave processes, and sending output to the
user. The number of parallel execution servers assigned to a single operation is the degree of parallelism for an
operation.

Chapter 3:
3. Managing an Oracle Instance: Parameter File; Creating SPFILE; Oracle Managed Files; Startup and Shutdown
Database; Alert Log File; Background Trace File; User Trace File.

Managing an Oracle Instance


An Oracle database system consists of a database and an Oracle instance.
Database—A database consists of a set of disk files that store user data and metadata.
An Oracle instance (database instance) contains the set of Oracle Database background processes that
operate on the stored data and the shared allocated memory that those processes use to do their work. An
instance must be started to read and write information to the database.
It contains the following topics:
• About Initialization Parameters
• About Background Processes
• About Server and Client Processes
• About Instance Memory Structure
• About Instance Startup and Shutdown
❖ Initialization Parameters File:

A parameter file is a file that contains a list of initialization parameters and a value for each parameter. In
order to start an instance and open the database, we must connect as SYSDBA and enter STARTUP
command. The Oracle server will then read the initialization parameter file and prepare the instance
according to the initialization parameters contained within. After being read from a file, initialization
parameters are retained in memory, where the values for many of them can be changed dynamically.
There or two types of parameters:
Explicit: having and entry in the file
Implicit : no entry within the file , but assuming the Oracle default values.
Multiple initialization parameter files can exist. There are two types of files from which these parameters can
be read: a text initialization parameter file and a server parameter file.

➢ Text initialization parameter files (PFILE):


A text initialization parameter file is a text file that can be read by the Oracle instance, but it is not written to
by the instance. The PFILE can be modified using a standard operating system editor.
Creating a Parameter File: Example
CREATE PFILE = 'my_init.ora' FROM SPFILE = 's_params.ora';

➢ Server parameter files (SPFILE):


An SPFILE is a binary file. The file is not meant to be modified manually and must always reside on the
server side. After the file is created it is maintained by the Oracle server.
Creating SPFILE:
The SPFILE cannot be directly edited. An SPFILE is created from a PFILE file using the CREATE SPFILE
command. It must be created prior to its use in the STARTUP command. This command requires the SYSDBA
privilege to execute. This command can be executed before or after instance startup.
CREAT SPFILE [=’SPFILE-NAME’] FROM
PFILE [=’PFILE-NAME’]

https://psc-msc.blogspot.com/
Page 15 of 48 Data Base Administration & Management M. Waseem

❖ Instance Startup and Shutdown


➢ 2-Starting the Oracle Database/ Starting up a database :
When the command STARTUP is used, the spfileSID.ora on the serer side is used to start up the
instance. If the spfileSID.ora is not found, the default SPFILE on the server side is used to start the
instance. If the default SPFILE is not found, the initSID.ora on the server side will be used to start the
instance.

Normally, you start up an instance by mounting and opening the database.


You can start up a database instance with SQL*Plus, Recovery Manager, or Enterprise Manager.
• Starting Up a Database Using SQL*Plus: You can start a SQL*Plus session, connects to Oracle
Database with administrator privileges and then issue the STARTUP command.
• Starting Up a Database Using Recovery Manager: You can also use Recovery Manager (RMAN)
to execute STARTUP and SHUTDOWN commands, You may prefer to do this if you are within the
RMAN environment and do not want to invoke SQL*Plus.
• Starting Up a Database Using Oracle Enterprise Manager : EM combines a GUI console, agents,
common services, and tools to provide an integrated and comprehensive systems management
platform for managing Oracle products.
• Understanding Initialization Parameter Files: To start an instance, the database read instance
configuration parameters from either SPFILE or a text initialization parameter file (PFILE).
When you issue the SQL*Plus STARTUP command, the database attempts to read the initialization
parameters from an SPFILE in a platform-specific default location. If it finds no SPFILE, it searches
for a text initialization parameter file.
• Starting Up with a Non-Default Server Parameter File: you can use the PFILE clause to start an
instance with a non-default server parameter file as follows:
1. Create a one-line text initialization parameter file that contains only the
SPFILE parameter.
2. Start up the instance pointing to this initialization parameter file.
➢ Shutting Down the Oracle Database:
To initiate database shutdown, use the SQL*Plus SHUTDOWN command. Control is not returned to the
session that initiates a database shutdown until shutdown is complete. To Shut down n instance you must
connect a s SYSOPER or SYSDBA.
There are several modes for shutting down a database.
• with the NORMAL Clause :To shut down a database in normal situations, use the SHUTDOWN
command with the NORMAL clause: The NORMAL clause is optional, because this is the default
shutdown method if no clause is provided. SHUTDOWN NORMAL

• with the IMMEDIATE Clause: Use immediate database shutdown only in the following situations:
o To initiate an automated and unattended backup o When a power
shutdown is going to occur soon
o When the database or one of its applications is functioning irregularly
and you cannot contact users to ask them to log off or they are unable
to log off
To shut down a database immediately, use the SHUTDOWN command with the
IMMEDIATE clause: SHUTDOWN IMMEDIATE
• With the TRANSACTIONAL Clause: When you want to perform a planned shutdown of an instance
while allowing active transactions to complete first, use the SHUTDOWN command with the
TRANSACTIONAL clause:
SHUTDOWN TRANSACTIONAL
Transactional database shutdown proceeds with the following conditions:
o No new connections are allowed, nor are new transactions allowed to be started, after the
statement is issued.
o After all transactions have completed, any client still connected to the instance is
disconnected.
o At this point, the instance shuts down just as it would when a SHUTDOWN IMMEDIATE
statement is submitted.

https://psc-msc.blogspot.com/
Page 16 of 48 Data Base Administration & Management M. Waseem

• With the ABORT Clause: If possible, perform this type of shutdown only in the following situations:
The database or one of its applications is functioning irregularly and none of the other types of
shutdown works.
o You need to shut down the database.
o You experience problems when starting a database instance.
When you must do a database shutdown ,issue the SHUTDOWN command with the
ABORT clause:
SHUTDOWN ABORT

Oracle Managed Files:


Oracle Managed Files (OMF) directly manages file creation and deletion at the operating system level.
With Oracle Managed Files, you specify file system directories in which the database automatically
creates, names, and manages files at the database object level. It has several advantages including:
• Automatic cleanup of the filesystem when database objects are dropped.
• Standardized naming of database files.
• Increased portability since file specifications are not needed.
• Simplified creation of test systems on differing operating systems. No unused files wasting disk
space.
The database internally uses standard file system interfaces to create and delete files as needed for the
following database structures:
• Tablespaces
• Redo log files
• Control files
• Archived logs
• Block change tracking files
• Flashback logs
• RMAN backups
Through initialization parameters, you specify the file system directory to be used for a particular type of file.
The database then ensures that a unique file, an Oracle managed file, is created and deleted when no longer
needed.

Who Can Use Oracle Managed Files?


Oracle Managed Files are most useful for the following types of databases:
• Databases that are supported by the following: o A logical volume manager that supports
striping/RAID and dynamically extensible logical volumes o A file system that provides large,
extensible files
• Low end or test databases

The Oracle Managed Files feature provides better integration with operating system functionality for disk
space allocation.

Logical Volume Manager


A logical volume manager (LVM) is a software package available with most operating systems. Sometimes it
is called a logical disk manager (LDM). It allows pieces of multiple physical disks to be combined into a single
contiguous address space that appears as one disk to higher layers of software. File System
A file system is a data structure built inside a contiguous disk address space. A file manager (FM) is a
software package that manipulates file systems, but it is sometimes called the file system. All operating
systems have file managers. The primary task of a file manager is to allocate and deallocate disk space into
files within a file system.

A file system allows the disk space to be allocated to a large number of files. Each file is made to appear as
a contiguous address space to applications such as Oracle Database.

https://psc-msc.blogspot.com/
Page 17 of 48 Data Base Administration & Management M. Waseem

Benefits of Using Oracle Managed Files


Consider the following benefits of using Oracle Managed Files:
• They make the administration of the database easier.
There is no need to invent filenames and define specific storage requirements. A consistent set of
rules is used to name all relevant files. The file system defines the characteristics of the storage and
the pool where it is allocated.
• They reduce corruption caused by administrators specifying the wrong file.
• They reduce wasted disk space consumed by obsolete files.
Oracle Database automatically removes old Oracle Managed Files when they are no longer needed.
• They simplify creation of test and development databases.
• Oracle Managed Files make development of portable third-party tools easier.
Oracle Managed Files eliminate the need to put operating system specific file names in SQL scripts.

Alert Log File


When things go wrong, Oracle can and often does write messages to the alert log . The alert log file is a
chronological log of messages and errors written out by an Oracle Database. Typical messages found in this
file is: database startup, shutdown, log switches, space errors, etc. Oracle will automatically create a new
alert log file whenever the old one is deleted.

Background Trace File


Trace File are trace (or dump) file that Oracle Database creates to help you diagnose and resolve operating
problems. Each server and background process writes to a trace file. The trace files for the Oracle instance
background processes are also located in BACKGROUND_DUMP_DEST.

User Trace File


User trace files contain statistics for traced SQL statements, which are useful for SQL tuning. In
addition, user trace files contain user error messages. Naming convention for user trace file:
Sid_ora_PID.trc(db01_ora_23845/trc).
User trace files can also help the DBA to optimize the performance of SQL statements by producing statistics
for each SQL statement in a user session. The location for user trace files is specified by the system parameter
USER_DUMP_DEST.

https://psc-msc.blogspot.com/
Page 18 of 48 Data Base Administration & Management M. Waseem

Chapter 4:
4. Creating Database and Data dictionary.

Creating Database
1- Considerations Before Creating a Database
Creating a database can also erase information in an existing database and create a new database with the
same name and physical structure. The following topics can help prepare you for database creation.
Planning for Database Creation
• Meeting Creation Prerequisites
• Deciding How to Create an Oracle Database
❖ Planning for Database Creation
• Plan the database tables and indexes and estimate the amount of space they will require.
• Plan the layout of the underlying operating system files that are to comprise your database.
• Using the Oracle Managed Files feature to create and manage the operating system files that
comprise your database storage.
• Select the global database name, which is the name and location of the database within the
network structure.
• Familiarize yourself with the initialization parameters that comprise the initialization parameter file.
• Select the database character set.
• Consider what time zones your database must support.
• Select the standard database block size.
• Use an undo tablespace to manage your undo records, rather than rollback segments.
• Develop a backup and recovery strategy to protect the database from failure.
• Familiarize yourself with the principles and options of starting up and shutting down an instance
and mounting and opening a database.
❖ Deciding How to Create an Oracle Database
You use the CREATE DATABASE statement to perform these operations. You have the following options for
creating your new Oracle database:
• Use the Database Configuration Assistant (DBCA). DBCA can be launched by the Oracle Universal
Installer, depending upon the type of install that you select, and provides a graphical user interface
(GUI) that guides you through the creation of a database.
• Create the database manually from a script. If you already have existing scripts for creating your
database, you can still create your database manually and editing your existing script to take
advantage of new Oracle features.
• Upgrade an existing database. You can upgrade your existing Oracle database and use it with the
new release of the Oracle software.

2- Using the Database Configuration Assistant


DBCA can be launched by the Oracle Universal Installer, depending upon the type of install that you
select, and provides a graphical user interface (GUI) /tools that guides you through the creation of a
database and options for an existing Oracle database, delete an Oracle database, or manage database
templates. DBCA can be run in three modes:
❖ Advantages of Using DBCA
These are a few of the advantages of using DBCA:
• You can use its wizards to guide you through a selection of options providing an easy means of
creating and tailoring your database.
• It builds efficient and effective databases that take advantage of Oracle's new features.
• It uses Optimal Flexible Architecture (OFA), whereby database files and administrative files, including
initialization files, follow standard naming and placement practices.
❖ Creating a Database Using DBCA
DBCA enables you to create a database from predefined templates provided by Oracle or from templates
that you or others have created.

https://psc-msc.blogspot.com/
Page 19 of 48 Data Base Administration & Management M. Waseem
• DBCA displays the templates that are available. You select the appropriate template for the database
that you want to create. Clicking the "Show Details..." button displays specific information about the
database defined by a template.

• When you select a template, you also specify whether the database definition is to include datafiles.
• The next page that DBCA displays enables you provide a global database name and SID.
• Specifying Database Features. The following is a representative list of Oracle features that you can
install in your database.
1. Oracle Spatial
2. Oracle Ultra Search
3. Oracle Label Security
4. Oracle Data Mining
5. Oracle OLAP Services
6. Sample Schemas
• You can also display a list of standard database features. these are optional.
1. Oracle JVM
2. Oracle Text
3. Oracle interMedia
4. XDB Protocol
• You specify mode (dedicated server of shared server), set initialization parameters, and specify
datafile locations.
• After you have completed the specification, you can:
1. Create the database now
2. Save the description as a database template
3. Generate database creation scripts

❖ Configuring Database Options


When you elect to configure database options, this provides you the opportunity to add options and features
that you did not include when you created the database.
❖ Deleting a Database Using DBCA
DBCA enables you to delete a database. When you do so, you delete the database instance and its control file(s), redo
log files, and datafiles. Any server parameter file (SPFILE) or initialization parameter file used by the database is also
deleted.

3- Manually Creating an Oracle Database


This section presents the steps involved when you create a database manually.
1: Specify an Instance Identifier (SID)
Decide on a unique Oracle system identifier (SID) for your instance and set the ORACLE_SID environment
variable accordingly.
% setenv ORACLE_SID mynewdb
2: Establish the Database Administrator Authentication Method
You can use the password file or operating system authentication method.
3: Create the Initialization Parameter File
The instance (System Global Area and background processes) for any Oracle database is started using an
initialization parameter file. For ease of operation, store your initialization parameter file in Oracle's default
location, using the default name.
Default parameter file locations are shown in the following table:
Platform Default Name Default Location

UNIX init$ORACLE_SID.ora $ORACLE_HOME/dbs

Windows init$ORACLE_SID.ora $ORACLE_HOME\database

4: Connect to the Instance


Start SQL*Plus and connect to your Oracle instance AS SYSDBA.
$ SQLPLUS /nolog
CONNECT SYS/password AS SYSDBA
5: Create a Server Parameter File
https://psc-msc.blogspot.com/
Page 20 of 48 Data Base Administration & Management M. Waseem
The server parameter file enables you to change initialization parameters with the ALTER SYSTEM command and
persist the changes across a database shutdown and startup.

Step 6: Start the Instance


Use the STARTUP command with the NOMOUNT option.
STARTUP NOMOUNT
7: Issue the CREATE DATABASE Statement
To create the new database, use the CREATE DATABASE statement. The following statement creates
database mynewdb:
CREATE DATABASE mynewdb
USER SYS IDENTIFIED BY pz6r58
USER SYSTEM IDENTIFIED BY y1tz5p
LOGFILE GROUP 1 ('/vobs/oracle/oradata/mynewdb/redo01.log') SIZE 100M,
GROUP 2 ('/vobs/oracle/oradata/mynewdb/redo02.log') SIZE 100M,
GROUP 3 ('/vobs/oracle/oradata/mynewdb/redo03.log') SIZE 100M
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
MAXINSTANCES 1
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET AL16UTF16
DATAFILE '/vobs/oracle/oradata/mynewdb/system01.dbf' SIZE 325M REUSE
EXTENT MANAGEMENT LOCAL
DEFAULT TEMPORARY TABLESPACE tempts1
DATAFILE '/vobs/oracle/oradata/mynewdb/temp01.dbf'
SIZE 20M REUSE
UNDO TABLESPACE undotbs
DATAFILE '/vobs/oracle/oradata/mynewdb/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
A database is created with the following characteristics:
• The database is named mynewdb.
• Three control files are created as specified by the CONTROL_FILES initialization parameter.
• The password for user SYS is pz6r58 and the password for SYSTEM is y1tz5p.
• The new database has three online redo log files as specified in the LOGFILE clause.
• MAXDATAFILES specifies the maximum number of datafiles that can be open in the database. 8:
Create Additional Tablespaces
To make the database functional, you need to create additional files and tablespaces for users. The following
sample script creates some additional tablespaces:
CONNECT SYS/password AS SYSDBA
-- create a user tablespace to be assigned as the default tablespace for users
CREATE TABLESPACE users LOGGING
DATAFILE '/vobs/oracle/oradata/mynewdb/users01.dbf'
SIZE 25M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
-- create a tablespace for indexes, separate from user tablespace
CREATE TABLESPACE indx LOGGING
DATAFILE '/vobs/oracle/oradata/mynewdb/indx01.dbf'
SIZE 25M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
EXIT
9: Run Scripts to Build Data Dictionary Views
Run the scripts necessary to build views, synonyms, and PL/SQL packages: The
following table contains descriptions of the scripts:
Script Description

https://psc-msc.blogspot.com/
Page 21 of 48 Data Base Administration & Management M. Waseem
CATALOG.SQL Creates the views of the data dictionary tables, the dynamic performance views, and public synonyms
for many of the views. Grants PUBLIC access to the synonyms.

CATPROC.SQL Runs all scripts required for or used with PL/SQL

10: Run Scripts to Install Additional Options (Optional)


Some products require you to create additional data dictionary tables. Usually, command files are provided to
create and load these tables into the database's data dictionary.
11: Create a Server Parameter File (Recommended)
Oracle recommends you create a server parameter file as a dynamic means of maintaining initialization
parameters. The following script creates a server parameter file from the text initialization parameter file and
writes it to the default location.
CONNECT SYS/password AS SYSDBA
-- create the server parameter file
CREATE SPFILE='/vobs/oracle/dbs/spfilemynewdb.ora' FROM
PFILE='/vobs/oracle/admin/mynewdb/scripts/init.ora';
SHUTDOWN
-- this time you will start up using the server parameter file
CONNECT SYS/password AS SYSDBA
STARTUP EXIT
Step 12: Back Up the Database.
You should make a full backup of the database to ensure that you have a complete set of files from which to
recover if a media failure occurs.

Creating Data dictionary


The data dictionary is full of 'Metadata', information about what is going-on inside your database. A data
dictionary contains:
• The definitions of all schema objects in the database (tables, views, indexes, clusters, synonyms,
sequences, procedures, functions, packages, triggers, and so on)
• How much space has been allocated for, and is currently used by, the schema objects Default
values for columns
• Integrity constraint information
• The names of Oracle users
• Privileges and roles each user has been granted
• Auditing information, such as who has accessed or updated various schema objects Other
general database information
The data dictionary is structured in tables and views, All the data dictionary tables and views for a given
database are stored in that database's SYSTEM tablespace. Use SQL statements to access the data
dictionary. you can issue only queries (SELECTstatements) against it's tables and views. ❖ Structure
of the Data Dictionary
➢ Base Tables: The underlying tables that store information about the associated database. Only
Oracle should write to and read these tables. Users rarely access them directly because they are
normalized.

➢ User-Accessible Views: The views that summarize and display the information stored in the base
tables of the data dictionary. These views decode the base table data into useful information, such as
user or table names, using joins and WHERE clauses to simplify the information.

https://psc-msc.blogspot.com/
Page 22 of 48 Data Base Administration & Management M. Waseem

Chapter 5:
5. Managing Control Files and Redo Log Files.

Managing Control Files 1-


What Is a Control File?
Every Oracle database has a control file. A control file is a small binary file that records the physical
structure of the database and includes:
• The database name
• Names and locations of associated datafiles and online redo log files
• The timestamp of the database creation
• The current log sequence number
• Checkpoint information
• Database identifier – recorded when the database is created.
• Tablespace information. This information is updated as tablespaces are added or dropped.
Redo log history – recorded during log switches.

Without the control file, the database cannot be mounted and recovery is difficult. The control file of an
Oracle database is created at the same time as the database. You should create two or more copies of the
control file during database creation. You might also need to create control files later, if you lose control files.
2- Guidelines for Control Files
➢ Provide Filenames for the Control Files
➢ Multiplex Control Files on Different Disks
➢ Place Control Files Appropriately
➢ Back Up Control Files
➢ Manage the Size of Control Files
3- Creating Control Files
➢ Creating Initial Control Files
The initial control files are created when issue the CREATE DATABASE statement. The names of the control
files are specified by the CONTROL_FILES parameter.
CONTROL_FILES =
Creating Additional Copies, Renaming, and Relocating Control Files
You can create an additional control file copy by copying an existing control file to a new location and
adding the file's name to the list of control files. Similarly, you rename an existing control file by copying the
file to its new name or location, and changing the file's name in the control file list.
➢ Creating New Control Files
It is necessary for you to create new control files in the following situations:
• All control files for the database have been permanently damaged and you do not have a control file
backup.
• You want to change one of the permanent database parameter settings originally specified in the
CREATE DATABASEstatement. These settings include the database's name and the following
parameters: MAXLOGFILES, MAXLOGMEMBERS, MAXLOGHISTORY, MAXDATAFILES, and
MAXINSTANCES.
• You can create a new control file for a database using the CREATE CONTROLFILE statement.

4- Troubleshooting After Creating Control Files


➢ Checking for Missing or Extra Files
After creating a new control file and using it to open the database, check the alert file to see if Oracle has
detected inconsistencies between the data dictionary and the control file
5- Backing Up Control Files 6- Recovering a Control File
Use the ALTER DATABASE BACKUP CONTROLFILE statement to back up your control files.
➢ Recovering from Control File Corruption Using a Control File Copy

https://psc-msc.blogspot.com/
Page 23 of 48 Data Base Administration & Management M. Waseem
With the instance shut down, use an operating system command to overwrite the bad control file with a
good copy:
% cp /u01/oracle/prod/control03.ctl /u01/oracle/prod/control02.ctl
Start SQL*Plus and open the database: SQL> STARTUP
7- Dropping Control Files
You can drop control files from the database. Remember that the database must have at least two control
files at all times.
1. Shut down the database.
2. Edit the CONTROL_FILES parameter in the database's initialization parameter file to delete the old
control file's name.
3. Restart the database.

Managing Redo Log Files

1- What Is the Online Redo Log?


The most crucial structure for recovery operations is the online redo log, which consists of two or more
preallocated files that store all changes made to the database as they occur. Every instance of an Oracle
database has an associated online redo log to protect the database in case of an instance failure.

➢ Redo Threads
Each database instance has its own online redo log groups. These online redo log groups, multiplexed or
not, are called an instance's thread of online redo. Only one database instance accesses an Oracle
database, so only one thread is present. ➢ Online Redo Log Contents
• Online redo log files are filled with redo records. A redo record, also called a redo entry.
• These records contain description of a change made to a single block in the database.
• Redo entries record data that you can use to reconstruct all changes made to the database, including
the rollback segments.
• Redo records are buffered in a circular fashion in the redo log buffer of the SGA and are written to
one of the online redo log files by the Oracle background process.
2- Planning the Online Redo Log
➢ Multiplexing Online Redo Log Files
Oracle allows multiplying Redo Log files to protect against failure, meaning that two or more identical copies
can be automatically maintained as groups in separate locations, ideally separate disk drives. ➢
Responding to Online Redo Log Failure
Whenever LGWR connote write to a member of group, the database writes an error message to the LGWR
trace file and to alert log. These errors can be used to resolve issue.
➢ Legal and Illegal Configurations
Multiplexed redo log should have same number of members in each group. However this is not a MUST
HAVE. For example, one group can have only one member, while other groups have two members. This
configuration protects against disk failures that temporarily affect some online redo log members but leave
others intact.
3- Creating Online Redo Log Groups and Members
Plan the online redo log of a database and create all required groups and members of online redo log files
during database creation.
To create new online redo log groups and members, you must have the ALTER DATABASE system privilege. A
database can have up to MAXLOGFILES groups. ➢ Creating Online Redo Log Groups
To create a new group of online redo log files, use the SQL statement ALTER DATABASE with the ADD
LOGFILE clause.

➢ Creating Online Redo Log Members


To create new online redo log members for an existing group, use the SQL statement ALTER DATABASE with
the ADD LOG MEMBER parameter.
The following statement adds a new redo log member to redo log group number 2:
ALTER DATABASE ADD LOGFILE MEMBER '/oracle/dbs/log2b.rdo' TO GROUP 2;

https://psc-msc.blogspot.com/
Page 24 of 48 Data Base Administration & Management M. Waseem
4- Relocating and Renaming Online Redo Log Members
• You can use operating system commands to relocate online redo logs, then use the ALTER DATABASE
statement to make their new names (locations) known to the database.
• It is useful if current disk drive is going to be removed or id some data needs to be moved due to disk
space issues.
• To rename online redo log members, you must have the ALTER DATABASE system privilege.
Additionally, you might also need operating system privileges to copy files to the desired location and
privileges to open and back up the database.( optional or not read)
➢ Steps for Renaming Online Redo Log Members Shut down the
database.
SHUTDOWN
Copy the online redo log files to the new location.
mv /diska/logs/log1a.rdo /diskc/logs/log1c.rdo mv
/diska/logs/log2a.rdo /diskc/logs/log2c.rdo
• Startup the database, mount, but do not open it.
CONNECT / as SYSDBA
STARTUP MOUNT
• Rename the online redo log members.
ALTER DATABASE
RENAME FILE '/diska/logs/log1a.rdo',
'/diska/logs/log2a.rdo'
TO '/diskc/logs/log1c.rdo',
'/diskc/logs/log2c.rdo';
• Open the database for normal operation.
ALTER DATABASE OPEN;

5- Dropping Online Redo Log Groups and Members


You may want to drop an entire group of online redo log members or drop one or more specific online redo
log members.
➢ Dropping Log Groups
• To drop an online redo log group, you must have the ALTER DATABASE system privilege.
• Remember, an instance requires at least two groups of online redo log files.
• You can drop an online redo log group only if it is inactive.
• Make sure an online redo log group is archived (if archiving is enabled) before dropping it.

SELECT GROUP#, ARCHIVED, STATUS FROM V$LOG;


• Drop an online redo log group with the SQL statement ALTER DATABASE with the DROP LOGFILE
clause.
ALTER DATABASE DROP LOGFILE GROUP 3;
• Dropping Online Redo Log Members
• To drop specific inactive online redo log members, use the ALTER DATABASE statement with the
DROP LOGFILE MEMBER clause.
The following statement drops the redo log /oracle/dbs/log3c.rdo: ALTER
DATABASE DROP LOGFILE MEMBER '/oracle/dbs/log3c.rdo';
• Remember, an instance always requires at least two valid groups of online redo log files,
regardless of the number of members in the groups.
• You can drop an online redo log member only if it is not part of an active or current group.
• Make sure the group to which an online redo log member belongs is archived (if archiving is
enabled) before dropping the member.

https://psc-msc.blogspot.com/
Page 25 of 48 Data Base Administration & Management M. Waseem

Chapter 6:
6. Managing Tablespaces, Operations with Tablespaces.

Managing Tablespaces
• Tablespace is a database storage unit that groups related logical structures together.
• Database files are stored in tablespace.
• Multiple table space can be used for flexibility in performance.
• Quotas can be assigned to users for creating tables, views, clusters, indexed and other objects.
• A tablespace belongs to only one database, and has at least one datafile that is used to store data for
the associated tablespace.
❖ Tablespace Types
➢ Permanent – These tablespaces store objects in segments that are permanent – that persist beyond
the duration of a session or transaction. The SYSTEM and SYSAUX tablespaces are two examples of
permanent tablespaces.
• SYSTEM Tablespace o A tablespace that is always used to store SYSTEM data that
includes data about tables, indexes, sequences, and other objects – this metadata
comprises the data dictionary.
• SYSAUX Tablespace
o The SYSAUX tablespace stores data for auxiliary applications such as the
LogMiner, Workspace Manager, Oracle Data Mining, Oracle Streams, and
many other Oracle tools.
.

➢ Undo – These tablespaces store segments that may be retained beyond a transaction, but are
basically used to:
o Provide read consistency for SELECT statements that access tables that have rows that are
in the process of being modified.
o Provide the ability to rollback a transaction that fails to commit.

➢ Temporary – This tablespace stores segments that are transient and only exist for the duration of
a session or a transaction. Mostly, a temporary tablespace stores rows for sort and join operations.

➢ Bigfile: A bigfile tablespace eases database administration because it consists of only one datafile.
The single datafile can be up to 128TB (terabytes) in size if the tablespace block size is 32KB.

1- Guidelines for Managing Tablespaces


➢ Use Multiple Tablespaces:
➢ Specify Tablespace Default Storage Parameters:
➢ Assign Tablespace Quotas to Users
2- Creating Tablespaces
Before you can create a tablespace you must create a database to contain it. The first tablespace in any
database is always the SYSTEM tablespace, and the first datafiles of any database are automatically allocated
in the SYSTEM tablespace during database creation.
To create a new tablespace, use the SQL statement CREATE TABLESPACE or CREATE TEMPORARY
TABLESPACE.

Managing Operations with Tablespaces


Using the action menu, you can perform a variety of tasks with your tablespaces. Select a tablespace and
then action that you want to perform.
❖ Add Datafile: adds a data file to the tablespace, which makes the tablespace larger.
❖ Create Like: To create a new tablespace, use the SQL statement CREATE TABLESPACE or CREATE
TEMPORARY TABLESPACE. You can use the ALTER TABLESPACE or ALTER DATABASEstatements to alter
the tablespace.
❖ Generate DDL: Generates the data definition language (DDL) statement that creates the tablespace.
This can then be copied and pasted into a text file for use as a script or for documentation purposes.
https://psc-msc.blogspot.com/
Page 26 of 48 Data Base Administration & Management M. Waseem
❖ Make locally Managed: Converts the tablespace to locally managed if the tablespace is currently
dictionary managed. This conversion is one-way only:
You cannot convert the tablespace back to dictionary managed.
ALTER TABLESPACE tbsa TEMPORARY;
❖ Make Read only Tablespaces
Making a tablespace read-only prevents write operations on the datafiles in the tablespace. The
primary purpose of read-only tablespaces is to eliminate the need to perform backup and recovery of
large, static portions of a database, Making a tablespace read-only prevents updates on all tables in
the tablespace, regardless of a user's update privilege level.
❖ Make Writable Tablespace: Use the READ WRITE keywords in the ALTER TABLESPACE statement to
change a tablespace to allow write operations. You must have the ALTER TABLESPACE or MANAGE
TABLESPACE system privilege.
ALTER TABLESPACE flights READ WRITE;
❖ Taking Tablespaces Offline
You may want to take a tablespace offline for any of the following reasons:
• To make a portion of the database unavailable while allowing normal access to the remainder of the
database
• To perform an offline tablespace backup.
• To make an application and its group of tables temporarily unavailable while updating or maintaining
the application
❖ Bringing Tablespaces Online
A tablespace is normally online so that the data contained within it is available to database users. The
following statement brings the users tablespace online:
ALTER TABLESPACE users ONLINE;
❖ Altering the Availability of Datafiles or Tempfiles
The ALTER TABLESPACE statement enable you to change the online or offline status of all of the datafiles or
tempfiles within a tablespace.
• ALTER TABLESPACE ... DATAFILE {ONLINE|OFFLINE}
• ALTER TABLESPACE ... TEMPFILE {ONLINE|OFFLINE}
❖ Dropping Tablespaces
• You can drop a tablespace and its contents (the segments contained in the tablespace) from the
database if the tablespace and its contents are no longer required.
• Any tablespace in an Oracle database, except the SYSTEM tablespace, can be dropped. You must
have the DROP TABLESPACE system privilege to drop a tablespace.
• Once a tablespace has been dropped, the tablespace's data is not recoverable. When you drop a
tablespace, the file pointers in the control file of the associated database are removed.
• You cannot drop a tablespace that contains any active segments. For example, if a table in the
tablespace is currently being used or the tablespace contains an active rollback segment, you cannot
drop the tablespace.
• To drop a tablespace, use the DROP TABLESPACE statement.
DROP TABLESPACE users INCLUDING CONTENTS;
• To delete the datafiles associated with a tablespace at the same time that the tablespace is dropped,
use the INCLUDING CONTENTS AND DATAFILES clause.
DROP TABLESPACE users INCLUDING CONTENTS AND DATAFILES;
• The tablespace can be online or offline, but it is best to take the tablespace offline before dropping it.

https://psc-msc.blogspot.com/
Page 27 of 48 Data Base Administration & Management M. Waseem

Chapter 7.
7. Data File Management, Segments, Block.

Managing Datafiles
Data files are the operating system files that store the data within the database. The data is written to these
files in an Oracle proprietary format that cannot be read by other programs. Data files can be broken down
into the following components: 1- Blocks

Oracle manages the storage space in the datafile of a database in units called data blocks. A data block
is the smallest unit of data used by a database. The size of a block is a specific number of bytes of
storage within a given tablespace within the database. The default block size is specified by
DB_BLOCK_SIZE parameter. In oracle 11g Largest block size allowed is 2KB to 32KB. The default block
size is 8KB. Every data block contains:

❖ Header :The header contains general block information, such as the block address and the type of
segment (for example, data, index, or rollback).

❖ Table Directory: This portion of the data block contains information about the tables having
rows in this block.

❖ Row Directory: This portion of the data block contains information about the actual rows in the
block (including addresses for each row piece in the row data area).
Once the space has been allocated in the row directory of a data block's overhead, this space is not
reclaimed when the row is deleted.

❖ Overhead:The data block header, table directory, and row directory are referred to collectively as
overhead. Some block overhead is fixed in size; the fixed and variable portions of data block
overhead total 84 to 107 bytes.
❖ Row Data: This portion of the data block contains table or index data. Rows can span blocks.
❖ Free Space management: Free space is allocated for insertion of new rows and for updates
to rows that require additional space. Two types of statements can increase the free space of one or
more data blocks: DELETE statements, and UPDATE statements that update existing values to
smaller values. The released space from these types of statements is available for subsequent
INSERT statements.
Two space management parameters, PCTFREE and PCTUSED, enable you to control the use of free space
for inserts of and updates to the rows in all the data blocks of a particular segment. You specify these
parameters when creating or altering a table or cluster. PCTFREE and PCTUSED work together to optimize
the utilization of space in the data blocks of the extents within a data segment.

2- Extents
An extent is a logical unit of database storage space allocation made up of a number of contiguous data
blocks. When you enlarge a database object, the space added to the object is allocated as an extent. Oracle
starts with minimum extent size of 64KB. When table is created, initial extent is allocated. When the space in
an extent is full, another extent is allocated.

3- Segments

Each segment is composed of one or more extents that form a database object that Oracle treats as a unit,
such as a table or index. Four types of segments are found in an Oracle database: data segments, index
segments, temporary segments.
https://psc-msc.blogspot.com/
Page 28 of 48 Data Base Administration & Management M. Waseem
❖ Data Segments
A single data segment in an Oracle database holds all of the data for one of the following:
• A table that is not partitioned or clustered
• A partition of a partitioned table
• A cluster of tables
Oracle creates this data segment when you create the table or cluster with the CREATE statement.
❖ Index Segments
Every nonpartitioned index in an Oracle database has a single index segment to hold all of its data. For a
partitioned index, every partition has a single index segment to hold its data. Oracle creates the index
segment for an index or an index partition when you issue the CREATE INDEX statement.
❖ Temporary Segments
When processing queries, Oracle often requires temporary workspace for intermediate stages of SQL
statement parsing and execution. Oracle automatically allocates this disk space called a temporary segment.

https://psc-msc.blogspot.com/
Page 29 of 48 Data Base Administration & Management M. Waseem

Chapter 8:
8. Managing Undo Data, Undo Data Statistics: Managing Tables and Users:

Managing Undo Data, Undo Data Statistics


1- Undo data
• A copy of original, pre-modified data.
• Capture for every transaction that changes data.
• Retained at least until the transaction is ended.
• Read-consistent queries provide results that are consistent with the data as of the time a query
started. Therefore original information must still exist as undo information.
• Undo records are used to:
o Roll back transactions when a ROLLBACK statement is issued o Recover the
database o Provide read consistency o Analyze data as of an earlier point in time by
using Oracle Flashback Query
o Recover from logical corruptions using Oracle Flashback features
During database recovery, undo records are used to undo any uncommitted changes applied from the redo
log to the datafiles.
2- Transactions
Transaction is a collection of SQL data manipulation language (DML) statements treated as a logical unit.
• Failure of any statement results in the transaction being "undone".
• DML is used as INSERT, UPDATE, DELETE and MERGE.
• DML always executes as part of a transaction that can be rollback or commit.
• If all statements process, SQLPlus or the programming application will issue a COMMIT to make
database changes permanent.
• Transactions completed if a user disconnects from Oracle normally.
• Abnormal disconnections result in transaction rollback.
• The command ROLLBACK is used to cancel a transaction that is in progress.
3- Specifying the Mode for Undo Space Management
There are two methods for managing undo data:
(1) Automatic undo management – automatic undo management is preferred.
This is the type of undo management used when you create an UNDO tablespace and specify use
of automatic undo management. it is the default for Oracle 11g for a new database.
UNDO_MANAGEMENT = AUTO

(2) manual undo management – manual undo management is the only method available for Oracle 8i
and earlier versions of Oracle and is the type of management that involves use of rollback
segments.
UNDO_MANAGEMENT = MANUAL
If the UNDO_MANAGEMENT initialization parameter is not specified, the instance starts in manual undo
management mode.

4- Managing Undo Tablespaces


• Undo tablespaces facilitates rollback of logical transactions.
• Undo tablespaces provide instant data recovery by rolling back any crashed transactions that were
not committed time of crash.
• The old data values changed by DML command are recorded in the undo tablespace within a
systemmanaged undo segment or a rollback segment.
• Sufficient undo space must be available in order to rollback a transaction.
• Checkpoints called ―save-points‖ can be created within DML commands to undo the dml statements
since the last savepoint.
https://psc-msc.blogspot.com/
Page 30 of 48 Data Base Administration & Management M. Waseem
5- Flashback Operations
• Data in an undo tablespace is used to support flashback (rewind) operations for table and query.
• Flashback Table will restore a table as of a point of time in the past. Useful to recover a table to a
specific point in time. Example:
FLASHBACK TABLE students TO TIMESTAMP systimestamp-interval’30’ minute;
• Flashback query will let you view a table as of the time in past, Useful to view a version of data as it
existed at some time in past. Example: SLECT* FROM student AS OF TIMESTAMP
systimestamp-interval ‘60’ minute:
• There are a couple of options for activating multiple rollback segments when you start up an
instance:

Managing Tables
About Tables
• Tables are the basic unit of data storage in an Oracle Database.
• Data is stored in rows and columns.
• You define a table with a table name and a set of columns.
• each column a column is given a name, a data type and a width.
• rules can specify for each column of a table. These rules are called integrity constraints. Example
NOT NULL
• Tables can also include virtual columns. column having a derived value.
• After you create a table, you insert rows of data using SQL statements or using an Oracle bulk load
utility.
• The table data con be queried, deleted, updated using SQL.
Guidelines for Managing Tables:
• Design Tables Before Creating Them Specify the type of table to create.
• Specify How Data Block Space Is to Be Used: By specifying the PCTFREE and PCTUSED parameters
during the creation of each table,
• Specify the Location of Each Table
• Consider Parallelizing Table Creation
• Consider Using NOLOGGING When Creating Tables: The NOLOGGING clause causes minimal redo
information to be generated during the table creation
• Estimate Table Size and Set Storage Parameters
• Plan for Large Tables: There are no limits on the physical size of tables and extents. You can specify
the keyword UNLIMITED for MAXEXTENTS.
• You cannot move types and extent tables to a different schema when the original data still exists in
the database.
• You cannot merge an exported table into a preexisting table having the same name in a different
schema.
Tables types
• Relational Tables
• Temporary Tables
• Index organized Tables
• Object Tables
• External Tables
• Clustered Tables
• Partitioned Table

Creating Tables
To create a new table you must have the CREATE TABLE system privilege.
To create a new table in your schema, you must have the CREATE TABLE system privilege. To create a table
in another user's schema, you must have the CREATE ANY TABLE system privilege.

https://psc-msc.blogspot.com/
Page 31 of 48Data Base Administration & Management M. Waseem
➢ Creating a Table you create a table named admin_emp in the hr schema by
CREATE TABLE statement.
CREATE TABLE hr.admin_emp (
empno NUMBER(5) PRIMARY KEY,
ename VARCHAR2(15) NOT NULL,
job VARCHAR2(10), mgr
NUMBER(5), hiredate DATE DEFAULT
(sysdate), sal NUMBER(7,2),
comm NUMBER(7,2), deptno
NUMBER(3) NOT NULL
CONSTRAINT admin_dept_fkey REFERENCES hr.departments
(department_id))
TABLESPACE admin_tbs
STORAGE ( INITIAL 50K
NEXT 50K
MAXEXTENTS 10
PCTINCREASE 25 );

Altering Tables
You alter a table using the ALTER TABLE statement. you must have either the ALTER object privilege for the
table or the ALTER ANY TABLE system privilege. Example:
➢ Moving a Table to a New Segment or Tablespace
The ALTER TABLE ... MOVE statement enables you to relocate data of a nonpartitioned table into a new
segment, and different tablespace.
The following statement moves the hr.admin_emp table to a new segment, specifying new storage
parameters:
ALTER TABLE hr.admin_emp MOVE
STORAGE ( INITIAL 20K
NEXT 40K
MINEXTENTS 2
MAXEXTENTS 20
PCTINCREASE 0 );

➢ Adding Table Columns:


The following statement alters the hr.admin_emp table to add a new column named bonus:
ALTER TABLE hr.admin_emp
ADD (bonus NUMBER (7,2)); ➢
Renaming Table Columns:
Oracle allows you to rename existing columns in a table. Use the RENAME COLUMN clause of the ALTER
TABLE statement to rename a column. The following statement renames the comm column of the
hr.admin_emp table.
ALTER TABLE hr.admin_emp
RENAME COLUMN comm TO commission;

Dropping Tables
• Use DROP TABLE clause to drop a table that is no longer needed in own schema.
• DROP ANY TABLE system privilege is required to drop table from another schema.
o To drop a table: DROP TABLE emp:

https://psc-msc.blogspot.com/
Page 32 of 48 Data Base Administration & Management M. Waseem
o Drop foreign key constraints of child table: DROP TABLE emp CASCADE
CONSTRAINTS; o Drop a table and immediately release associated space: DROP
TABLE emp PURGE;
➢ Drop Columns from Tables
• This statement drops only the sal column:
o ALTER TABLE hr.admin_emp DROP COLUMN sal; o ALTER TABLE
hr.admin_emp DROP UNUSED COLUMNS CHECKPOINT 250;

• The following statement drops both the bonus and comm columns:
ALTER TABLE hr.admin_emp DROP (bonus, commission);

• To mark the hiredate and mgr columns as unused, execute the following statement:
ALTER TABLE hr.admin_emp SET UNUSED (hiredate, mgr); Managing
Users:
Each Oracle database has a list of valid database users. To access a database, a user must run a database
application and connect to the database instance using a valid user name defined in the database.
Creating Users
You create a database user with the CREATE USER statement.To create a user, you must have the CREATE
USER system privilege.
The following example creates a user and specifies that user's password, default tablespace, temporary
tablespace where temporary segments are created, tablespace quotas, and profile.
CREATE USER saad
IDENTIFIED BY wasim
DEFAULT TABLESPACE data_ts
QUOTA 100M ON test_ts
QUOTA 500K ON data_ts
TEMPORARY TABLESPACE temp_ts
PROFILE clerk;
GRANT connect TO saad;

Database User Account


Each database user account has: o A unique username: A user and role cannot
have the same name.
o An authentication method: the connecting user must supply the correct password to the
database to connect successfully:
o A default tablespace: When a user creates a schema object and specifies no tablespace to
contain it, Oracle stores the object in the user's default tablespace. default tablespace is the
SYSTEM tablespace and you can change it with the ALTER USER statement.
o A temporary tablespace: When a user executes a SQL statement that requires a temporary
segment, Oracle stores the segment in the user's temporary tablespace. If a user's temporary
tablespace is not explicitly set, the user is assigned the default temporary tablespace that
was specified at database creation, or by an ALTER DATABASE statement at a later time.
o A user profile: A profile is a set of limits on database resources and password access to the
database. If no profile is specified, the user is assigned a default profile.
o An initial consumer group: o An account status: o
Types of Oracle Database Users
o Database administrator o Security officers o Network Administrators o Application
Developers o Application Administrators o Database Users

https://psc-msc.blogspot.com/
Page 33 of 48 Data Base Administration & Management M. Waseem

Chapter 09:
9. Indexes Management, Maintaining Data Integrity, Constraints. Managing Privileges.

Indexes Management
Indexes are totally optional structures that are intended to speed up the execution of SQL statements against
table data and cluster data. Indexes are used for direct access to a particular row or set of rows in a table.
Type of indexes
Indexes can be categorized in a number of ways. The two primary options are :
Standard (B-tree): A standard, B-tree index contains an entry for each value in the index key along with an
address to the row where the value is stored. A B-tree index is the default in the form of balance tree.
Bitmap: A bitmap index uses strings of bits to encapsulate values and potential row addresses. It is best for
low cordiality columns. It has a bitmap for each index value.

Guidelines for Managing Indexes


• Create Indexes After Inserting Table Data
• Limit the Number of Indexes per Table
• Specify the Table space for Each Index
• Specify Transaction Entry Parameters
• Specify Index Block Space Use
• Parallelize Index Creation
• Consider Creating UNRECOVERABLE Indexes
• Estimate Index Size and Set Storage Parameters Creating Indexes
LONG and LONG RAW columns cannot be indexed.
➢ Creating an Index Explicitly
You can create indexes explicitly (outside of integrity constraints) using the SQL statement CREATE INDEX.
The following statement creates an index named emp_ename for the ename column of the emp table:
CREATE INDEX emp_ename ON emp(ename)
TABLESPACE users
STORAGE (INITIAL 20K
NEXT 20k
PCTINCREASE 75);
➢ Re-creating an Existing Index
You can create an index using an existing index as the data source. Issue
the following statement to re-create an existing index:
ALTER INDEX index name REBUILD;

Altering Indexes
• You can alter an index only to change the transaction entry parameters or to change the storage
parameters; you cannot change its column structure.
The following statement alters the EMP_ENAME index:
ALTER INDEX emp_ename
INITRANS 5
MAXTRANS 10
STORAGE (PCTINCREASE 50);

Dropping Indexes
https://psc-msc.blogspot.com/
Page 34 of 48 Data Base Administration & Management M. Waseem
To drop an index, the index must be contained in your schema, or you must have the DROP ANY INDEX
system privilege.
You might want to drop an index for any of the following reasons:
• The index is no longer required.
• The index is not providing anticipated performance improvements for queries issued against the
associated table. (For example, the table might be very small, or there might be many rows in the
table but very few index entries.)
• Applications do not use the index to query the data.
• The index has become invalid and must be dropped before being rebuilt.
• The index has become too fragmented and must be dropped before being rebuilt.

You cannot drop only the index associated with an enabled UNIQUE key or PRIMARY KEY
constraint. To drop a constraint's associated index, you must disable or drop the constraint itself.
DROP INDEX emp_ename;

Maintaining Data Integrity, Constraints


You can define integrity constraints to enforce business rules on data in your tables. Once an integrity
constraint is enabled, all data in the table must conform to the rule that it specifies. Enforcing rules with
integrity constraints is less costly than enforcing the equivalent rules by issuing SQL statements in your
application.
Then create a referential integrity constraint on the DEPTNO column of the EMP table that references the
primary key of the DEPT table:
ALTER TABLE emp

ADD FOREIGN KEY (deptno) REFERENCES dept(deptno)

INTEGRITY CONSTRAINTS

Integrity Constraints are used to prevent entry of invalid information into tables. There are five Integrity
Constraints Available in Oracle. They are :
• Not Null
• Primary Key
• Unique
• Foreign Key
• Check

➢ Overview of Constraint States


you should first understand the basic purposes of constraints. Some of these purposes are:
• In order to use a constraint for enforcement, the constraint must be in the ENABLE state.
• To use a constraint for validation, the constraint must be in the VALIDATE state.
• In some cases, you will know that the conditions for a given constraint are true, so you do not need to
validate or enforce the constraint.

Enabling and Disabling Integrity Constraints


This section explains the mechanisms and procedures for manually enabling and disabling integrity
constraints.
enabled constraint. When a constraint is enabled, the corresponding rule is enforced on the data values in
the associated columns. The definition of the constraint is stored in the data dictionary.
disabled constraint. When a constraint is disabled, the corresponding rule is not enforced. The definition of
the constraint is still stored in the data dictionary.
(Next states is Optional as for detale)

https://psc-msc.blogspot.com/
Page 35 of 48 Data Base Administration & Management M. Waseem

Managing Privileges
A user privilege is a right to execute a particular type of SQL statement, or a right to access another user's
object. The types of privileges are defined by Oracle.
Roles, on the other hand, are created by users (usually administrators) and are used to group together
privileges or other roles. They are a means of facilitating the granting of multiple privileges or roles to users.
Creating a secure application role: A secure application role enables you to define conditions that control
when a database role can be enabled
This contains the following topics:

• System Privileges
• Object Privileges
• User Roles

System Privileges
There are over 100 distinct system privileges. Each system privilege allows a user to perform a particular
database operation or class of database operations. Because system privileges are so powerful, Oracle
recommends that you configure your database to prevent regular (non-DBA) users exercising ANY system
privileges (such as UPDATE ANY TABLE) on the data dictionary. Object Privileges
Each type of object has different privileges associated with it.

You can specify ALL [PRIVILEGES] to grant or revoke all available object privileges for an object. ALL is not
a privilege; rather, it is a shortcut, or a way of granting or revoking all object privileges with one word in GRANT
and REVOKE statements. User Roles
A role groups several privileges and roles, so that they can be granted to and revoked from users
simultaneously. A role must be enabled for a user before it can be used by the user.

Creating a Role

You can create a role using the CREATE ROLE statement. The following statement creates the clerk role,
which is authorized by the database using the password bicentennial:

CREATE ROLE clerk IDENTIFIED BY bicentennial;

Later, you can set or change the authorization method for a role using the ALTER ROLE statement.
ALTER ROLE clerk IDENTIFIED EXTERNALLY;

Dropping Roles

You can drop a role using the SQL statement DROP ROLE. To drop a role, you must have the DROP ANY
ROLE system privilege or have been granted the role with the ADMIN OPTION.

The following statement drops the role CLERK:

DROP ROLE clerk;

https://psc-msc.blogspot.com/
Page 36 of 48 Data Base Administration & Management M. Waseem

Chapter10:
10. Basic Oracle Net Architecture: Types of Networks, Oracle Net Services, Oracle Shared Server,
Connection Manager, Oracle Net Connections.
Basic Oracle Net Architecture Overview
of Oracle Net:
Oracle Net is a software layer that resides on the client and the Oracle Database server. It is responsible for
establishing and maintaining the connection between the client application and server, as well as
exchanging messages between them, using industry-standard protocols.
• client/server configuration (two-tier architecture): the client, supports the application that initiates
the request from the database. The back-end machine on which the database resides is called the
server. When the client sends a database request to the server, the server receives and executes the
SQL statement that is passed to it. The direct communication takes place between client and server.
The Two-tier architecture is divided into two parts:
1) Client Application (Client Tier)
2) Database (Data Tier)
• Three-tier architecture (thin-client configuration): In it application code is housed and executed
using Java applets on a separate server from the database server. A database request is sent from
the client through the application server to the database server; the database server then receives
and executes the SQL statement that is passed to it. The results of the SQL statement, plus any error
conditions that are returned, are then sent back to the client through the application server.

• server/server configurations: databases on separate servers share data with each other. Each
server supports client applications, but it also has the ability to communicate with other servers in the
network. When one of the servers sends a database request to another server, the sending server
acts like a client. The receiving server executes the SQL statement passed to it and returns the
results plus error conditions to the sender.

Network types
You can model many different types of networks in UIM (Unified Inventory Management), including:
• Personal Area Network (PAN): The smallest and most basic type of network, a PAN is made up of a
wireless modem, a computer or two, tablets, etc.
• Local area network (LAN): LANs are one of the simplest types of networks. LANs connect groups of
computers together across short distances (within a building or two/three) to share information and
resources. Enterprises typically manage and maintain LANs.
• Metropolitan Area Network (MAN): A MAN consists of a computer network across an entire city,
college campus or small region. This type of network can cover an area from several miles to tens of
miles.
• Wide Area Network (WAN): A WAN occupies a very large area, such as an entire country or the
entire world.
• Campus Area Network (CAN): Larger than LANs, but smaller than metropolitan area networks these
types of networks are typically seen in universities or small businesses.
• Storage area network (SAN): As a dedicated high-speed network that connects shared pools
of storage devices to several servers.
• Virtual private network (VPN): A VPN lets its users send and receive data as if their devices were
connected to the private network – even if they’re not.
• Asynchronous transport mode (ATM): ATM is a high-speed networking standard designed to
support voice, video and data communications.
ATM stands for automated teller machine, a machine that bank customers use to make transactions
without a human teller.
• Digital subscriber loop (DSL): DSL is a modem technology that uses existing telephone lines to
transport high-bandwidth data, such as multimedia and video.

https://psc-msc.blogspot.com/
Page 37 of 48 Data Base Administration & Management M. Waseem
Oracle Net Services
Oracle Net Services provides a scalable, secure, and easy-to-use high-availability network infrastructure for
Oracle environment. It eases the complexities of network configuration and management, maximizes
performance, and improves network security and diagnostic capabilities as summarized hereafter.
• Connectivity: Oracle Net Services enables a network session from a client application to an Oracle
database server.
• Manageability: it encompasses location transparency, centralized configuration and management, quick
installation and configuration.
• Performance and Scalability: features such as Database Resident Connection Pool , Shared Server and
scalable event models enable performance and high scalability.
• Network Security: Oracle Net Services enables database access control using features of firewall access
control and protocol access control.
• Diagnose ability: a diagnostic and performance analysis tool, Trace Assistant, provides detailed information
about the source and context of problems as they arise.

Database Server Process Architecture


Configuring Shared Server/ Shared Server Processes:
With shared server architectures, client processes ultimately connect to a dispatcher. A dispatcher can
support multiple client connections concurrently. Each client connection is bound to a virtual circuit. A
virtual circuit is a piece of shared memory used by the dispatcher for client database connection requests
and replies. The dispatcher directs multiple incoming network session requests to a common queue.
Dedicated Server Processes:
With a dedicated server architecture, each client process connects to a dedicated server process. The
server process is not shared by any other client. PMON registers information about dedicated server
processes with the listener. This enables the listener to start up a dedicated server process when a client
request arrives and forward the request to it.

Oracle Connection Manager Architecture


Oracle Connection Manager is a router through which a client connection request may be sent either to
its next hop or directly to the database server. Clients who route connection requests through an Oracle
Connection Manager can take advantage of the connection multiplexing, access control, and protocol
conversion features configured on that Oracle Connection Manager. Oracle Connection Manager consists
of three components:
• listener
• CMGW process
• CMADMIN process
Oracle Net Listener: not its part optional here
Listener: A process that resides on the server whose responsibility is to listen for incoming client connection
requests and manage the traffic to the server.
CMGW process:
The CMGW gateway process receives client connections and evaluates against a set of rules whether to
deny or allow access. If access is allowed, the gateway process forwards the requests to the next hop,
typically the database server.
CMADMIN process:
The CMGW process registers with the CMADMIN administrative process. CMADMIN is a multi-threaded
process that is responsible for all administrative functions of Oracle Connection Manager.
CMCTL: A utility that enables basic management functions for Oracle Control Manager Administration

https://psc-msc.blogspot.com/
Page 38 of 48 Data Base Administration & Management M. Waseem

Chapter 11:
11. Server Side Configuration: The Listener Process; Configuring Listener, Sessions, Creating and Managing
Listener.
Server Side Configuration
Oracle Net Listener is a separate process that runs on the database server computer. It receives incoming
client connection requests and manages the traffic of these requests to the database server.
The Listener Process:
Listener: A process that resides on the server whose responsibility is to listen for incoming client connection
requests and manage the traffic to the server. The Oracle Database Listener listens on a specific network
port (default 1521) and forwards network connections to the Database.
The characters of a listener:
• A listener can listen for more than one database.
• Multiple listeners can listen on behalf of a single database to perform load balancing
• The default name of the listener in Oracle Net is LISTENER
• The listener can listen for multiple protocols
The listener configuration is stored in a configuration file named listener.ora .

Configuring Listener:
Each listener is configured with one or more protocol addresses that specify its listening endpoints. Once a
client request has reached the listener, the listener selects an appropriate service handler to service the
client's request and forwards the client's request to it. It is possible to configure multiple listeners, each with
unique name, in one listener.ora file.

Sessions:
Session events help you debug or coordinate the actions of multiple sessions. This section illustrates how
you customize session events, and discusses:
• Session Event Listeners
• Session Event Manager
• Implementing Events Using Java
➢ Session Event Listeners
One approach to customizing session events is to create session event listeners that detect and respond to
session events. To register objects as listeners for session events, implement ➢ Session Event Manager
The session event manager handles information about session events. Applications register listeners with
the session event manager to receive session event data. ➢ Implementing Events Using Java
You can implement custom events and event handlers in Java code.

Creating and Managing Listener:


The listener.ora file is automatically generated by the Oracle Net Configuration Assistant tool
(netca ). If NETCA runs successfully, the sqlnet.ora, tnsnames.ora and listener.ora files will be created
automatically with default settings.
Perform the following steps to create a listener.
o Select Listener configuration, click Next. o

Select Add, click Next.


o Choose a listener name, click Next.
https://psc-msc.blogspot.com/
Page 39 of 48 Data Base Administration & Management M. Waseem
▪ Default listener name is 'LISTENER'.
o For selected protocols, select TCP, click Next. o Enter in the port used to connect to

the oracle database, click Next. ▪ Default port is 1521.

o Select No to configure another listener, click Next. o Click Next to complete the

listener configuration.

o Click Finish on the Welcome screen.

https://psc-msc.blogspot.com/
Page 40 of 48 Data Base Administration & Management M. Waseem

Chapter 12:
12. Client Side Configuration: Host Naming Method, Local Naming Method, Net Assistant, Configurations.
Usage and Configuration of Oracle Shared Server.
Client Side Configuration
Client machines need to be configured before they can connect to an Oracle database. To configure the
client machine, you must first install Oracle client software, which includes Oracle Net software. Oracle
Net provides four naming methods:
• local naming
• Oracle Names Method
• directory naming
• Easy Connect naming
• external naming
Local Naming Method::
Support all oracle net protocols. With the local naming method, net service names are added to the
TNSNAMES.ORA file. A net service name is mapped to a network address contained in a connect descriptor.
Clients use this net service name when making a connection with an application. It also supports advanced
connection options such as source routing and load balancing.
You can use the Oracle Net Configuration Assistant’s Local Net Service Name configuration options to
manage net service names. Five options are available for the Oracle Net Configuration Assistant’s Local Net
Service Name configuration tool:
Host Naming Method::
Host naming can eliminate the need for service name lookup in the tnsnames.ora files. The host naming
method is available for TCP/IP network environments only.
Clients can connect to a server using host naming if the following conditions are met:
• Oracle Net Services software installed on both the client and database service
• Oracle TCP/IP protocol support on both the client and database service
• An IP address translation mechanism, such as Domain Name System (DNS) or a centrally
maintained TCP/IP hosts file, to resolve names
• No advanced features like Oracle Connection Manager or security are requested or required
No advanced features like connection manager or security options are used.
Net Assistant, Configurations::
Oracle Net Configuration Assistant is a wizard-based tool with a graphical user interface. Its primary uses are
to configure basic Oracle Net network components.This also important for configuring Enterprise User
Security, and also including:

• Listener names and protocol addresses


• Naming methods the client will use to resolve connect identifiers to connect descriptors
• Net service names in a tnsnames.ora file
• Directory server usage

Perform the following steps to configure the listener and naming methods using Oracle Net Configuration
Assistant:
1) Start Oracle Net Configuration Assistant. The Welcome page appears.
2) In the Listener Configuration, Listener Name screen, enter a Listener name or accept the default
value. Click Next.
3) In the Listener Configuration, Select Protocol screen, select one or more protocols from the Available
Protocols list, and move it to the Selected Protocols list. Click Next.
4) In the Listener Configuration, TCP/IP Protocol screen, select the standard port number, or enter a
different port number. Click Next.
5) In the Listener Configuration, More Listeners? screen, select No if you do not want to configure an
additional listener, and click Next.
6) The listener configuration is now complete, click Next to proceed.
7) In the Naming Methods Configuration screen, select Yes to configure naming methods. Click Next.

https://psc-msc.blogspot.com/
Page 41 of 48 Data Base Administration & Management M. Waseem
8) In the Naming Methods Configuration, Select Naming Methods screen, select the naming method you
want from the Available Naming Methods list, and move it to the Selected Naming Methods list. Click
Next.
Typically, Local Naming is sufficient.
9) In the Net Service Name Configuration, Service Name screen, enter Service Name, and click Next.
10) In the Net Service Name Configuration, Select Protocols screen, select the protocol for the database
you want to access, and click Next.
11) In the Net Service Name Configuration, TCP/IP Protocol screen, enter the Host name of the
computer where the Oracle database is installed. Use the standard port number, or specify a different
port number, and click Next.
12) In the Net Service Name Configuration, Test screen, click Yes, perform a test to test the database
connection. Click Next.
13) In the Net Service Name Configuration, Connecting screen, click Next.
14) In the Net Service Name Configuration, Net Service Name screen, enter the name of the Net Service
Name, and click Next.
15) Answer the remaining prompts to complete the configuration.
16) In the Finish screen, click Close, to exit from Oracle Universal Installer.
To start Oracle Net Configuration Assistant in standalone mode, select Programs from the Start menu, and
then select Oracle - HOME_NAME. Next, select Configuration and Migration Tools, and then Oracle Net
Configuration Assistant.

https://psc-msc.blogspot.com/
Page 42 of 48 Data Base Administration & Management M. Waseem

Chapter 13:
13. Backup and Recovery, Instance and Media Recovery, Configuration of Archive log mode, User Managed
Complete Recovery, Loading Data into Database, Tuning Tools, Sizing Shared Pool, Sizing Buffer Cache,
I/O Issues.
Backup and recovery
Backup and recovery is one of the most important aspects of database administration.
BASICS OF BACKUP
A backup is a representative copy of data. This copy can include important parts of a database such as
the control file, redo logs, and datafiles. That can be used to reconstruct that data. Backups can be divided
into
1. physical backups
2. logical backups
Physical backups::
Physical backups are backups of the physical files used in storing and recovering your database, such as
datafiles, control files, and archived redo logs. Physical backup is a copy of files storing database information
to some other location, whether on disk or some offline storage such as tape.
Logical backups::
Contain data that is exported using SQL commands and stored in a binary file. Oracle records both
committed and uncommitted changes in redo log buffers.
KEY DATA STRUCTURES FOR BACKUP AND RECOVERY ::
• Datafiles
• Control Files
• Online Redo Log Files
• Archived Redo Log Files
• Automatic Managed Undo
➢ DATAFILES The data of logical database structures, such as tables and indexes, is physically
located in the blocks of the datafiles allocated for a database.
➢ CONTROL FILES
Every Oracle database has a control file containing the operating system filenames of all other files
that constitute the database. such as the:
➢ ONLINE REDO LOG FILES
Every Oracle database contains a set of two or more online redo log files. Oracle uses the redo log to
record all changes made to the database. LGWR writes to online redo log files in a circular fashion.
➢ ARCHIVED REDO LOG FILES
Archived log files are redo logs that Oracle has filled with redo entries, rendered inactive, and copied
to one or more log archive destinations. Oracle can be run in either of two modes:
• ARCHIVELOG - Oracle archives the filled online redo log files before reusing them in the cycle.
• NOARCHIVELOG - Oracle does not archive the filled online redo log files before reusing them in the
cycle.
➢ Automatic Managed Undo
Every Oracle database must have a method of maintaining information that is used to roll back, or undo,
changes to the database. Oracle has used rollback segments to store undo.
Understanding Basic Backup strategy::
A backup strategy provides a safeguard against data loss:
• What types of failures can occur?
• What information should be backed up?

https://psc-msc.blogspot.com/
Page 43 of 48 Data Base Administration & Management M. Waseem
• Which backup method should be used?
• Should backups be made online or offline?
• How often should backups be made?
• How can dangerous backup techniques be avoided? ❖ WHAT TYPES OF FAILURES CAN
OCCUR?
Data loss can occur for various reasons.
• A statement failure is a logical failure in the handling statement in an Oracle program. A
process failure is a failure in a user process accessing Oracle,
• An instance failure is a problem that prevents an Oracle instance.
• A user or application error is a user mistake that results in the loss of data.
• A media failure is a physical problem that arises when Oracle tries to write or read a file that is
required to operate the database
❖ WHAT INFORMATION SHOULD BE BACKED UP?
When developing backup strategy, DBAs must decide what information they want to copy. The basic backup
types include:
• Online Database Backup
• Offline Database Backup
• Whole Database
• Tablespace
• Datafile
• Control File
• Archived Redo Log
• Configuration Files
In deciding what to back up, the basic principle is to prioritize data depending on its importance and the
degree to which it changes.
❖ WHICH BACKUP METHOD SHOULD BE USED?
Oracle provides users a choice of several basic methods for making backups. The methods include:
➢ Making Recovery Manager Backups
Recovery Manager (RMAN) that allows users to make an RMAN backup or image copy of their data.
You can make backups of archived logs by using the following methods:
• using the RMAN BACKUP command to creates a backup set as output.
• RMAN RESTORE command for recovery operations
• BACKUP AS COPY command is used to create an image copy of a file.
➢ Automatic Disk-Based Backup
The components that create different backup and recovery-related files have no knowledge of each
other or of the size of the file systems where they store their data. With Automatic Disk-Based
Backup and Recovery, you can create a flash recovery area, which automates management of
backuprelated files.
If you do not use a flash recovery area, you must manually manage disk space for your
backuprelated files and balance the use of space among the different types of files.
➢ Oracle Enterprise Manager
The Backup Wizards in Oracle Enterprise Manager is the GUI interface that enables backup and recovery via a
point-and-click method. Oracle Enterprise Manager (EM) supports Backup and Recovery features commonly
used by users.
➢ Using the Data Pump for Supplemental Backup Protection
Physical backups can be supplemented by using the Data Pump utility to make logical backups of
data. Data Pump writes data from a database into Oracle files in a proprietary format, which can then
be imported into a database using the Import utility.
➢ User Managed Backups
Operating system commands can be used such as the UNIX dd or tar command to make backups. Backup
operations can also be automated by writing scripts. The user can make a backup of the whole database at
once or back up individual tablespaces, datafiles, control files, or archived logs.

RECOVERY
Recovery restoring a physical backup and then updating it with the changes made to the database since the
last backup. When preparing a recovery strategy, it is critical to understand the answers to these questions:

https://psc-msc.blogspot.com/
Page 44 of 48 Data Base Administration & Management M. Waseem
• How does recovery work?
• What are the types of recovery?
• Which recovery method should be used?
Recovery refers to the various operations involved in restoring, rolling forward, and rolling back a backup.
WHAT ARE THE TYPES OF RECOVERY?
There are three basic types of recovery: instance recovery, crash recovery, and media recovery.
➢ An instance recovery:
Instance recovery is the process of applying records in the online redo log to data files to reconstruct
changes made after the most recent checkpoint.
A redo thread is a record of all of the changes generated by an instance. Instance recovery consists of two
steps. One is Roll forward, next is Roll backward. ➢ A crash recovery occurs;
• when either a single-instance database crashes or all instances of a multi-instance database
crash.
• In crash recovery, an instance must first open the database and then execute recovery
operations.
• In general, the first instance to open the database after a crash or SHUTDOWN ABORT
automatically performs crash recovery.
The important point is that in both crash and instance recovery Oracle applies the redo automatically: no user
intervention is required to supply redo logs.
➢ media recovery
Datafile Media Recovery
A media recovery is executed on the user's command, usually in response to media failure. In media
recovery, online or archived redo logs can be used to make a restored backup current or to update it to a
specific point in time. Media recovery can restore the whole database, a tablespace or a datafile and recover
them to a specified time.
The following scenarios necessitate media recovery:
• You restore a backup of a datafile.
• You restore a backup control file.
• A datafile is taken offline
• Block Media Recovery
Block media recovery is a technique for restoring and recovering individual data blocks while all database
files remain online and available. The interface to block media recovery is provided by RMAN.
The principal division in media recovery is between complete and incomplete recovery.

WHICH RECOVERY METHOD SHOULD BE USED?


❖ Complete Recovery
Complete recovery involves using redo data or incremental backups, It is called complete because Oracle
applies all of the redo changes contained in the archived and online logs to the backup. Typically, you
perform complete media recovery after a media failure damages datafiles or the control file. If you are
performing complete recovery on the whole database, then whether you are using RMAN or SQL*Plus.
Whichever method you choose, you can recover a database, tablespace, or datafile.
➢ Recovering with Recovery Manager
The basic RMAN commands are RESTORE and RECOVER. RMAN can be used to restore datafiles
from backup sets or image copes, either to their current location or to a new location. Run the
following commands from within RMAN to restore and recover the database to its current time:
SHUTDOWN IMMEDIATE; # shuts down database
STARTUP MOUNT; # starts and mounts database
RESTORE DATABASE; # restores all datafiles
RECOVER DATABASE; # recovers database using all available redo
ALTER DATABASE OPEN; # reopens the database

❖ Incomplete Recovery
You do not apply all of the redo records generated after the most recent backup. You usually perform
incomplete recovery of the whole database in the following situations:
• Media failure destroys some or all of the online redo logs.
• A user error causes data loss.
• You cannot perform complete recovery because an archived redo log is missing.

https://psc-msc.blogspot.com/
Page 45 of 48 Data Base Administration & Management M. Waseem
• You lose your current control file and must use a backup control file to open the database.
➢ Tablespace point-in-time recovery (TSPITR), which enables users to recover one or more
tablespaces to a point-in-time that is different from the rest of the database.
➢ Time-based recovery, recovers the data up to a specified point in time.
➢ Cancel-based recovery, which recovers until the CANCEL command is issued.
➢ Change-based recovery; change-based recovery recovers up to a specified SCN in the redo record.
Conclusion :
Backup and recovery of your Oracle database is important to protecting data from corruptions, hardware
failures, and data failures. While Oracle provides many features to protect your data, nothing can replace a
backup.

Chapter No:14
14. Tuning Rollback Segments, Latches, Rollback Segment Tuning Shared Servers, Types of Locks, Block
Efficiency, Storage hierarchy, Avoiding Dynamic allocation, Statistics, PCTFREE and PCTUSED, Monitoring
Index Usage.

Tuning Rollback Segments::


A rollback segment is Oracle's tool for maintaining read-consistency and for returning incomplete
transactions to their initial state. A Rollback Segment is a database object containing before-images of data
written to the database. The before images will be used to restore the transaction if it fails before completing
all work successfully. Rollback segments are used to:
▪ Undo changes when a transaction is rolled back
▪ Ensure other transactions do not see uncommitted changes made to the database
▪ Recover the database to a consistent state in case of failures
Rollback segment is just like any other table segments and index segments, which consist of extents, also
demand space and they get created in a tablespace.
❖ Guidelines for Managing Rollback Segments:
• Use Multiple Rollback Segments
• Choose Between Public and Private Rollback Segments
• Specify Rollback Segments to Acquire Automatically
• Set Rollback Segment Sizes Appropriately
• Create Rollback Segments with Many Equally Sized Extents
• Set an Optimal Number of Extents for Each Rollback Segment Set the Storage
Location for Rollback Types of Locks::
❖ Locking Mechanism
A lock is a mechanism that prevents destructive interactions between transactions accessing shared data
or same resources. Locks play a crucial row in maintaining database concurrency and consistency. Locks
affect the interaction of readers and writers. A reader is a query of a resource, whereas a writer is a statement
modifying a resource. ❖ Use of Locks
When multiple users are accessing and modifying data, the database must provide a way to prevent
concurrent modification of the same data. Locks achieve the following important database requirements:
Consistency: The data a session is viewing or changing must not be changed by other sessions until the
user is finished.
Integrity: The data and structures must reflect all changes made to them in the correct sequence. Oracle
Database automatically obtains necessary locks when executing SQL statements.
❖ Lock Modes
Oracle Database automatically uses the lowest applicable level of restrictiveness to provide the highest
degree of data concurrency. Oracle Database uses two modes of locking in a multiuser database:
• Exclusive lock mode: This mode prevents the associated resource from being shared. A transaction
obtains an exclusive lock when it modifies data. The first transaction to lock a resource exclusively is
the only transaction that can alter the resource until the exclusive lock is released.
• Share lock mode: This mode allows the associated resource to be shared, depending on the
operations involved. Multiple users reading data can share the data, holding share locks to prevent
concurrent access by a writer who needs an exclusive lock. Several transactions can acquire share
locks on the same resource.
https://psc-msc.blogspot.com/
Page 46 of 48 Data Base Administration & Management M. Waseem
❖ Automatic Locks
Oracle automatically locks a resource on behalf of a transaction to prevent other transactions from doing
something that require exclusive access to the same resource. The database automatically acquires
different types of locks at different levels of restrictiveness depending on the resource and operation
being performed.
❖ Types of lock
• DML Locks
• DDL Locks
• System Locks
➢ DML Locks
A DML lock, also called a data lock, Protect data. For example, table locks lock entire tables, while row locks
lock selected rows.
DML statements automatically acquire the following types of locks:
Row Locks (TX):
A row lock, also called a TX lock, is a lock on a single row of table.
Table Locks (TM):
A table lock, also called a TM lock, is acquired by a transaction when a table is modified by an
INSERT, UPDATE, DELETE, MERGE, SELECT with the FOR UPDATE clause, or LOCK TABLE statement.
➢ DDL Locks
A data dictionary (DDL) lock protects the structure of schema objects—for example, the dictionary definitions
of tables and views.
• Exclusive DDL Locks
An exclusive DDL lock prevents other sessions from obtaining a DDL or DML lock. Most DDL operations
require exclusive DDL locks for a resource to prevent destructive interference with other DDL operations that
might modify or reference the same schema object.
• Share DDL Locks
A share DDL lock for a resource prevents destructive interference with conflicting DDL operations, but
allows data concurrency for similar DDL operations. Breakable Parse Locks
A parse lock is held by a SQL statement or PL/SQL program unit for each schema object that it references.

➢ System Locks
Protect internal database structures and memory structures such as data files. Latches, mutexes, and
internal locks are entirely automatic. o Latches
Latches are simple, low-level system lock that coordinate multi-user access to shared data structures,
objects, and files. Latches protect shared memory resources from corruption when accessed by multiple
processes. Specifically, latches protect data structures from the following situations:
o Concurrent modification by multiple sessions
o Being read by one session while being modified by another session
o De-allocation of memory while being accessed
Typically, a single latch protects multiple objects in the SGA. For example, background processes, shared
pool, library cache. Latch spinning occurs when a process repeatedly requests a latch in a loop, whereas
latch sleeping occurs when a process releases the CPU before renewing the latch request. o
Mutexes
A mutual exclusion object (mutex) is a low-level mechanism that prevents an object in memory
from aging out or from being corrupted when accessed by concurrent processes. A mutex protects
a single object.
Mutexes provide several benefits: o A mutex can reduce the
possibility of contention. o A mutex consumes less
memory than a latch.
o When in shared mode, a mutex permits concurrent reference by multiple sessions.
Internal Locks
Internal locks are higher-level, more complex mechanisms than latches and mutexes and serve
various purposes. The database uses the following types of internal locks:
o Dictionary cache locks
https://psc-msc.blogspot.com/
Page 47 of 48 Data Base Administration & Management M. Waseem
These locks are of very short duration and are held on entries in dictionary caches while the
entries are being modified or used.
o File and log management locks
These locks protect various files. For example, control file . Data files are locked to ensure
that multiple instances mount a database in shared mode or that one instance mounts it in
exclusive mode.
o Tablespace and undo segment locks
These locks protect tablespaces and undo segments. For example, all instances accessing a
database must agree on whether a tablespace is online or offline. Undo segments are locked
so that only one database instance can write to a segment.
❖ Locks and Deadlocks
A deadlock is a situation in which two or more users are waiting for data locked by each other.
Deadlocks prevent some transactions from continuing to work.
Oracle Database automatically detects deadlocks and resolves them by rolling back one statement
involved in the deadlock, releasing one set of the conflicting row locks. The statement rolled back
belongs to the transaction that detects the deadlock. Usually, the signal transaction should be rolled
back explicitly, but it can retry the rolled-back statement after waiting.

Rollback Segment Tuning Shared Servers::


------------------------------------------------------------

Logical Storage Hierarchy

Avoiding Dynamic allocation::


-----------------------------------------------
Statistics::
Optimizer statistics are a collection of data that describe more details about the database and the objects in
the database. These statistics are used by the query optimizer to choose the best execution plan for each
SQL statement. Optimizer statistics include the following:
• Table statistics o Number of rows o
Number of blocks o Average row
length
• Column statistics o Number of
distinct values (NDV) in column o
Number of nulls in column o Data
distribution (histogram)
• Index statistics o Number of leaf blocks
o Levels
o Clustering factor
• System statistics o I/O
performance and utilization
o CPU performance and utilization

PCTFREE and PCTUSED::

https://psc-msc.blogspot.com/
Page 48 of 48 Data Base Administration & Management M. Waseem
• PCTFREE is a block storage parameter
used to specify how much space should
be left in a database block for future
updates. For example, for
PCTFREE=10, Oracle will keep on
adding new rows to a block until it is
90% full. This leaves 10% for future
updates (row expansion).
See the PCTFREE setting for a table:
SQL> SELECT pct_free FROM user_tables WHERE table_name = 'EMP';
PCT_FREE
----------
10
• PCTUSED is a block storage parameter
used to specify when Oracle should
consider a database block to be empty
enough to be added to the free list.
Oracle will only insert new rows in
blocks that is enqueued on the free list.
For example, if PCTUSED=40, Oracle
will not add new rows to the block
unless sufficient rows are deleted from
the block so that it falls below 40% used.
This parameter is ignored for objects
created in locally managed tablespaces
with Segment Space Management
(ASSM) specified as AUTO.

https://psc-msc.blogspot.com/

You might also like