You are on page 1of 8

Describe Oracle architecture in brief.

Answer
The Oracle database has:
- Logical layer: The components of the logical layer map the data to these physical components
- Physical layer: The physical layer consists of the files that reside on the disk
Tablespaces and Datafiles
The database is divided into one or more logical pieces known as tablespaces. A tablespace is used to logically
group data together
The Database Schema: A collection of logical-structure objects, known as schema objects.
These schema objects consist of structures such as:
- tables,
- clusters,
- indexes,
- views,
- stored procedures,
- database triggers, and
- sequences.
Segments, Extents, and Data Blocks
Within Oracle, the space used to store data is controlled by the use of logical structures. These structures consist of
the following:
 Data blocks--A block is the smallest unit of storage in an Oracle database. (contains header information
concerning the block itself as well as the data)
 Extents--Extents consist of data blocks.
 Segments--A segment is a set of extents used to store a particular type of data.
The Oracle Instance has:
 User processes
 Oracle background processes
 The shared memory
The Oracle Memory Structure contains:
 The System Global Area (SGA)
 The Data-Dictionary Cache
 The Program Global Area (PGA)
What is the function of SMON?
Answer
The SMON background process performs all system monitoring functions on the oracle database.
Each time oracle is re-started, SMON performs a warm start and makes sure that the transactions that were left
incomplete at the last shut down are recovered.
SMON performs periodic cleanup of temporary segments that are no longer needed.

Oracle architecture - August 28, 2008 at 17:00 PM by Amit Satpute


Explain different types of segment. Data segment, Index segment, Rollback segment and
temporary segment.
Answer
There are four types of segments used in Oracle databases:
- data segments
- index segments
- rollback segments
- temporary segments
Data Segments:
There is a single data segment to hold all the data of every non clustered table in an oracle database. This data
segment is created when you create an object with the CREATE TABLE/SNAPSHOT/SNAPSHOT LOG command.
Also, a data segment is created for a cluster when a CREATE CLUSTER command is issued.
The storage parameters control the way that its data segment's extents are allocated. These affect the efficiency of
data retrieval and storage for the data segment associated with the object.
Index Segments:
Every index in an Oracle database has a single index segment to hold all of its data. Oracle creates the index
segment for the index when you issue the CREATE INDEX command. Setting the storage parameters directly affects
the efficiency of data retrieval and storage.
Rollback Segments
Rollbacks are required when the transactions that affect the database need to be undone. Rollbacks are also needed
during the time of system failures. The way the roll-backed data is saved in rollback segment, the data can also be
redone which is held in redo segment.
A rollback segment is a portion of the database that records the actions of transactions if the transaction should be
rolled back. Each database contains one or more rollback segments. Rollback segments are used to provide read
consistency, to rollback transactions, and to recover the database.
Types of rollbacks:
- statement level rollback
- rollback to a savepoint
- rollback of a transaction due to user request
- rollback of a transaction due to abnormal process termination
- rollback of all outstanding transactions when an instance terminates abnormally
- rollback of incomplete transactions during recovery.
Temporary Segments:
The SELECT statements need a temporary storage. When queries are fired, oracle needs area to do sorting and
other operation due to which temporary storages are useful.
The commands that may use temporary storage when used with SELECT are:
GROUP BY, UNION, DISTINCT, etc.
Explain SGA memory structures: Shared Pool, Database buffer Cache, Redo log Cache,
Large Pool Java Pool.
Answer
SGA (System Global Area) is a dynamic memory area of an Oracle Server. In SGA,the allocation is done in granuels.
The size of the SGA is dependent on SGA_MAX_SIZE parameter.
The memory structures contained by SGA are:-
Shared Pool -
this memory structure is divided into two sub-structures which are Library Cache and Data Dictionary Cache for
storing recently used PL/SQL statements and the recent data definitions. The maximum size of the Shared Pool
depends on the SHARED_POOL_SIZE parameter.
Database Buffer Cache –
This memory structure improves the performance while fetching or updating the recently used data as it stores the
recently used datafiles. The size of this block is decided by DB_BLOCK_SIZE.
Redo Log Buffer –
This memory structure is used to store all the changes made to the database and it's primarily used for the data
recovery purposes. The size of this block is decided by LOG_BUFFER.
Java Pool –
This memory structure is used when Java is installed on the Oracle server. Size that can be used is stored in
parameter named JAVA_POOL_SIZE.
Large Pool –
This memory structure is used to reduce the burden of the Shared Pool, as the Session memory for the Shared
Server, as the temporary storage for the I/O and for the backup and restore operations or RMAN. Parameter that
stores the maximum size is LARGE_POOL_SIZE.
What is SQL Loader? Explain the files used by SQL Loader to load file. i.e Loader control file,
Input datafile, Log File, Bad File, Discard file.
Answer
SQL*Loader is a bulk loader utility used for moving data from external files into the Oracle database. SQL*Loader
supports various load formats, selective loading, and multi-table loads.
When a control file is fed to an SQL*Loader, it writes messages to the log file, bad rows to the bad file and discarded
rows to the discard file.
Control file
The SQL*Loader control file contains information that describes how the data will be loaded. It contains the table
name, column datatypes, field delimiters, etc.
controlfile.sql should be used to generate an accurate control file for a given table.
Log File
The log file contains information about the SQL*loader execution. It should be viewed after each SQL*Loader job is
complete.
Explain the methods provided by SQL Loader.
Answer
Conventional Path Load
Direct Path Load

What is the physical and logical structure of oracle?


Answer
Logical Database structures
Logical structures include tablespaces, schema objects, data blocks, extents and segments.

Tablespaces
Database is logically divided into one or more tablespaces. Each tablespace creates one or more datafiles to
physically store data.

Schema objects
Schema objects are the structure that represents database's data. Schema objects include structures such as tables,
views, sequences, stored procedures, indexes, synonyms, clusters and database links.

Data Blocks
Data block represents specific number of bytes of physical database space on disk.

Extents
An extent represents continuous data blocks that are used to store specific data information.

Segments
A segment is a set of extents allocated for a certain logical structure.

Physical database structure


The physical database structure comprises of datafiles, redo log files and control files
Datafiles
Datafiles contain database's data. The data of logical data structures such as tables and indexes is stored in datafiles
of the database. One or more datafiles form a logical unit of database storage called a tablespace.

Redo log files


The purpose of these files is to record all changes made to data. These files protect database against failures.

Control files
Control files contain entries such as database name, name and location of datafiles and redo log files and time stamp
of database creation.
Explain the categories of oracle processes i.e. user, data writing processes, logging
processes and monitoring processes.
 User process – User process is used in invocation of application software.
 Data writing process - A database writer process is used to write buffer content into a datafile. They are
specifically used to write “dirty block” to data files from the buffer.
 Logging processes - Log writer is used to write the redo log buffer from system global area to online redo
log file. Only those redo entries are written hat have been copied into the buffer since the last time it wrote.
 Monitoring process - this can be either a system monitor process or a process monitor process. System
monitor process is mainly used for crash recovery and cleaning up of temporary segments. Process monitor
is used to clean all resources acquired by a failed process.
What are the Back ground processes in Oracle?
There are a number of background processes running. Each process is used for a specific job.
 SMON – system monitor process is used to clean temporary segments and crash recovery of a crashed
instance.
 PMON – process monitor is used to clean all resources acquired by a failed process.
 DBWR- Database writer is used to write “dirty block” to data files from the buffer.
 LGWR - Log writer is used to write the redo log buffer from system global area to online redo log file.
 MMAN – Memory manager process is used to manage the memory.
 ARCn - Archiver 0-9 is used for writing the online redo log files to the mentioned archive log destination after
a log switch has occurred.
 CKPT – checkpoint process using the checkpoints information signals the synchronization of all database
files. Used for database consistency and faster database recovery.
 LCK0 -9 – LOCK process is used to lock shared resources for manages the global enqueue requests and
the cross-instance broadcast
Explain the areas of memory used by oracle, i.e. Software code area, system global area
(SGA), program global area(PGA), sort area.
Software area code: - It is a protected location that is used to store oracle code that is supposed to be run. The
location is different from users' programs. The software area code is read only and can be shared or nonshared.
System global area: - SGA is used to store data and control information of an Oracles database instance when
started. Each instance has its own SGA. SGA is read write. It comprises data structures like Redo buffer, Java pool,
Streams pool etc.
Program global area:- PGA contains information about server process. It is a non shared memory when a server
process is started. Each process has an exclusive PGA.
Sort area: - SQL work area is typically used for complex queries by memory-intensive operators such as Sort area. A
sort operator is used to perform the in-memory sort of a set of rows
Explain the types of data files used by the oracle RDBMS.
Online redo log files
A control file contains information such as location of redo log files, backup data and redo log information.
The control file is updated to reflect the structure changes every time a datafile or a redo log file is added or dropped
from the database. These records are necessary to identify datafiles and redo log files during startup and recovery.
Archive log files
Archived log files are redo logs that Oracle fills with redo entries that are rendered inactive and copied to one or more
log archives.
Running the database in ARCHIVELOG mode has the following benefits:
 Complete recovery of database from instance and media failure.
 Performing online backups.
 Transmitting and applying archived redo logs to the standby database.
 Multiplexed archive logs to avoid single point of failure on the archive logs.
 More recovery options (tablespace-point-in-time recovery)
Initialization files
Initialization parameter file is a text file in ASCII which contains information needed to initialize a database and
instance.
Control files
Control Files contain:
 The physical structure of a database
 Database name,
 Names and locations of associated databases and online redo log files, Timestamp of database creation,
 Current log sequence number
 Checkpoint information.
SGA definition files
System Global Area
The System Global Area (SGA) is a shared memory region that contains data and control information for one Oracle
instance. When an instance starts, the SGA is allocated by Oracle and is deallocated when the instance shuts down.
Every instance has an own SGA.
Online Users share the data in the SGA.
The information stored in the SGA is divided into memory structures like:
 The database buffers
 Redo log buffer
 The shared pool.
Explain in brief oracle database objects.
1. Tables
Oracle stores information in the form of tables. For eg you can have a table named as climate in which you can store
information about the climate of a place in the form of columns which could be the temperature, name of the place,
date, humidity, etc.
In the terms of a relational database, one can call a table as an entity and the columns as it attributes.
2. Indexes
Indexing is a concept of listing of keywords accompanied by the location of information of the subject. Indexes are
used to speed up the processing, especially searching.
3. Views
A view is a way of hiding the logic that created the joined table just displayed. For example:
create view AB
select A.x, B.y from A, B where A.x = B.y;
You can query it as select x, y from AB.
Note: AB is the view name, A, B are the Table names with x and y as their column names respectively.
For views, you don’t need to specify the tables as the logic is hidden inside the views.
4. Synonyms
A synonym is a name assigned to a table or view that may be used refer to it thereafter. If you have an access to
another users table, you may create a synonym for it and refer to it by the synonym alone, without entering the users
name as a qualifier.
Using synonyms is a good way to implement location transparency.
5. Sequences
Tables usually have a primary key which uniquely identifies a row in a table. A sequence is a unique number
generator which can be assigned to the primary keys of the tables.
Eg create sequence xyz
increment by 1
start with 1;
6. Partitions
Partitioning provides tremendous advantages to applications by improving manageability, performance, and
availability.
Partitioning allows a table, index or index-organized table to be subdivided into smaller pieces.
Each piece of database object is called a partition.
Techniques for partitioning tables:
Range Partitioning
List Partitioning
Hash Partitioning
Composite Range-Hash Partitioning
Composite Range-List Partitioning
7. Clusters
A cluster is a schema object that contains data from one or more tables, all of which have one or more columns in
common.
All the rows from all the tables that share the same cluster key are stored.
After you create a cluster, you add tables to it. A cluster can contain a maximum of 32 tables.
8. Stored procedures and packages
A procedure is a PL/SQL block alike the functions of the 3rd generation languages. You just have to compile them so
as to use them later.
When a procedure is created, it is compiled and stored in the database in the compiled form.
Parameters can be passed to a procedure.
A procedure call is a PL/SQL statement by itself. A procedure is a PL/SQL block with a declarative section, an
executable section and an exception handling section.
Package:
Packages are PL/SQL constructs that allow related objects to be stored together. A package has two separate parts.
Each of them is stored separately in the data dictionary.
A package can include procedures, functions, cursors, types, and variables.
Eg create or replace package XYZ as
procedure p1 (p_id IN tablename.id % type, …………, ……..)
end XYZ;
9. User-defined data types
User defined data types are PL/SQl types that are based on the existing types. Subtypes are used to gives an
alternate name to for a type.
Eg:
declare
subtype counter is number;
counter a;
10. Table spaces
A table space is an area on disk which comprises of one or more disk files. A tablespace can contain many tables,
clusters or indexes.
One or more tablespaces together make a database.
Each table has a single area of diskspace called a segment set aside for it in the table space.
Each segment has an initial area on disk space set aside for it in the table space called the initial extent.
Once it has been used up, another extent is set aside for it.
11. Constraint
Constraints help understand how the tables and columns are related to each other.
The constraint information is accessible under the USER_constraint view.
The constraints include the following columns
Owner - - - of constraint
Constraint_name
Constraint_type
Table_name
Search_condition
R_Owner - - owner of the foreign key referenced table.
R_constraint_name
Delete_rule
Status
What is composite data type?
Answer
Collections are usually referred to as Composite Data types. Composite type is one that has components in it. A
variable of a composite type contains one or more scalar types.
Explain the types of composite data type.
Answer
Following are the types of composite data types:
RECORD – PL/SQL records are similar to C structures. A record provides with a way to deal with separate but
related variables as a unit.
TABLE – They are similar to arrays in C. However, they are implemented differently.
In order to declare a PL/SQL table, you need to first define a table type, then you declare a variable of this type.
Explain the constraints that can be applied to Oracle tables.
Answer
The syntax of writing a table is
create table tablename ( columnname type, columnname type ..., primary key(keycolumn);
The keycolumn is associates with the key constraint.
You can even add the foreign key constraint by adding the references to the table for that foreign key in the following
way:
foreign key(column) references foreigntable

Explain various types of constraints in Oracle.


Answer
Oracle "Check" Constraint:
It validates incoming columns at row insert time.
Not Null Constraint:
It is used to specify that a column may never contain a NULL value.
Primary Key Constraint:
It is used to identify the primary key for a table. This operation requires that the primary columns are unique, and it
creates a unique index on the target primary key.
References Constraint:
This is the foreign key constraint and is only applied during INSERT and DELETE.
Unique Constraint:
It is used to ensure that all column values within a table never contain a duplicate entry.
What is an integrity constraint?
Answer - Integrity constraints define a business rule for a column of the table. They are defined with a table and are
stored as part of a table’s definition.

Types of integrity constraints supported by oracle are


NOT NULL integrity constraint
Unique Key integrity constraint
Primary Key integrity constraint
Foreign key integrity constraint
Check integrity constraint