College of Computer and Information Sciences Information Systems Department IS337 - Database Lab
College of Computer and Information Sciences Information Systems Department IS337 - Database Lab
Page | 1
Course reference book:
OCA Oracle Database 11g Administration I
ISBN 978-0-07-159104-1
Published by Oracle Press
Title Page No
Page | 2
Metadata Views
An Oracle 10g database contains two types of meta data views.
1. Data dictionary views: Oracle 10g contains over 1,300 dictionary views. Their names
begin with dba_, all_, and user_.
2. Dynamic performance views: Oracle 10g contains over 350 dynamic performance views.
Most of these views have names that begin with v$.
Views usually have plural names. Views generally have singular names.
Available only when database is OPEN. Some are available when database is
NOT OPEN.
Data is static, not change when db is shutdown. Data lost when database shutdown.
Page | 3
Some Useful Views
dba_clu_columns v$dbfile
dba_clusters v$dblink
dba_constraints v$instance
dba_data_files v$librarycache
dba_db_links v$log
dba_extents v$log_history
dba_free_space v$logfile
dba_ind_columns v$parameter
dba_ind_partitions v$rollname
dba_ind_subpartitions v$rollstat
dba_locks v$session
dba_objects v$session_wait
dba_outstanding_alerts v$sga
dba_part_key_columns v$sgastat
dba_part_tables v$sort_segment
dba_password_limits v$sql
dba_profiles v$sqlarea
dba_resourse_limits v$sqltext
dba_role_privs v$sysstat
dba_roles v$system_parameter
dba_rollback_segs v$tempfile
dba_segments v$transaction
dba_subpart_columns v$recovery_file_dest
dba_sys_privs v$flash_recovery_area_usage
dba_tab_partitions
dba_tab_privs rc_archived_log
dba_tab_subpartitions rc_backup_controlfile
dba_tables rc_backup_piece
dba_tablespaces rc_backup_redolog
dba_temp_files rc_backup_set
dba_ts_quotas rc_controlfile_copy
dba_users rc_database
v$archive rc_database_block_corruption
v$archive_dest rc_datafile
v$archived_log rc_datafile_copy
v$backup_datafile rc_rman_configuration
v$backup_device rc_rman_status
v$backup_piece rc_stored_script
v$backup_redolog rc_stored_script_line
v$backup_set rc_tablespace
v$controlfile rc_unusable_backupfile_detail
v$controlfile_record_section
v$database role_role_privs
v$datafile role_tab_privs
v$datafile_header role_sys_privs
v$db_object_cache
Page | 4
CH 2: Exploring the Oracle Database Architecture
Topic Page No
1. Oracle Architecture 6
2. Memory Structures 7
3. Background Threads of an Instance 8
4. Least Recently Used (LRU) algorithm 17
5. Calculating size of SGA and it’s Components 18
6. Oracle Physical structures 21
a. Initialization file 22
b. Control file 24
c. Data files 24
d. Redo Log files 26
e. Alert Log files 27
f. Trace files 28
g. Password files 31
7. User Session 32
8. Checkpoint 33
9. Connection Request Failure reasons 34
10. SQL Statement Execution Steps 35
11. Instance recovery at instance startup (SMON) 35
Page | 5
Oracle Architecture
To work as a DBA, you need to completely understand Oracle’s underlying architecture and
its mechanism. Understand the relationship between Oracle’s memory structures,
background process, and I/O activities on physical structure. Oracle server architecture can
be broken into two main categories
Following are Oracle structures and together we call them Oracle Database Server.
Oracle Instance
1. Memory structures
2. Processes
Physical structures / Oracle database (group of 3 type of physical structures)
Oracle Server instance is a collection of server side processed and memory areas that
Oracle used for managing access to database. Oracle Server instance main memory
structure called System Global Area (SGA), and Oracle background processes. The SGA, at
a minimum, is made up of four components: The Shared Pool, The Database Buffer Cache,
The java Pool, and Redo Log Buffer. Other components of the SGA, like Large Pool may also
exist on the Oracle system depending on which optional features you chose to use.
The Oracle background processes are System Monitor (SMON), Process Monitor (PMON),
Database Writer (DBW0), Log Writer (LGWR), and Checkpoint (CKPT). Several other Oracle
processes may also be running on the system, depending on which optional features you
have decided to implement.
The SGA and the required background processes acquire space in the server’s memory
immediately upon startup of the Oracle server. Four initialization parameters are the primary
determinant of the SGA memory requirements.
The Oracle database is made up of a set of physical files that reside on the host server disk
drives. These files are called control files, data files, and redo logs. Additional physical files
that are associated with the Oracle database, but are not technically part of the database, are
password file, the PFILE/SPFILE and archived redo log files.
Page | 6
Memory Structures
Shared Pool Caches the most recently used SQL statements that have been issued by
database users.
Library Cache (mandatory): Used for storing parsed SQL statement text and statement
execution plan for reuse.
Dictionary cache / Row cache (mandatory): Used for storing recently accessed
information (table, column definition, user name, PWD and privileges)
Redo Log Buffer temporarily stores in memory the redo log information generated by DML in
user sessions until Oracle writes information to disk. Redo log is small amount of information
produced and saved to redo changes made to database by insert, update, alter, drop
statements.
Large Pool buffers Caches data for large I/O operations such as RMAN backup and restore
activities and shared server components.
Java Pool Caches the most recently used Java objects and application code when Oracle
JVM option is used.
Streams Pool Caches the data associated with queued message requests when
Oracle Advance Queuing (OAQ) option is used.
Page | 7
Background Threads of an Instance.
At the user level two processes allow a user to interact with instance and, ultimately with the
database. They are User process and Server process. The user process exists either on the
user’s own pc or on the middle-tier application server. Once the connection is made, the user
establishes a session in the instance. After establishing a session, each user then starts a
Server process on the host server. It is the server process that is responsible for performing
the tasks that actually allow the user to interact with the database.
In a Dedicated Server configuration each end user has his/her own Server Process. When
Shared Server option is used, several end-users share one or more Server Processes.
Server process management is an important aspect of overall database performance.
Data base Writer (DBWn): Writes modified data block from data buffer cache back to data
files on disk. At least one DBWn may have more DBW0, DBW1, DBW3 ….DBW9
DBWR writes dirty data blocks from buffer cache to disk.
1. Writes when need room in buffer cache.
2. When DBWr is told to write data to disk by LGWR at checkpoint.
Log Writer (LGWR): Write Redo Log entries from redo log buffer to online redo log files on
disk.
Process Monitor (PMON) Cleans up messes left by dedicated server with no user session
attached to it. Roll back changes and kills the dedicated server memory and CPU usage.
Page | 8
Optional Oracle Background Processes
Archive (ARCn) automatically back ups transactions log files. After LGWR fills them with redo
log entries.
Dispatcher (Dnnn): Assigns user’s request to request queue in Oracle Shared Server mode.
Shared Server (Snnn): Server processes that are shared among several users when Oracle
Shared Server feature is used.
Job Queue Monitor (CJQn): Assigns jobs to Job Queue processes when using oracle job
scheduling feature.
Job Queue (Jnnn): Executes database jobs that have been schedules using Oracle Job
scheduling feature.
Queue Monitor (QMNn): Monitors the messages in the message queue when Oracle
Advanced Queuing feature is used.
Parallel Query Slave (Qnnn): Used to carry out portions of a large overall query when Oracle
Parallel Query feature is used.
Memory Manager (MMAN): Manages the size of each individual SGA component when
Oracle Automatic Shared Memory Management feature is used.
Memory Monitor (MMON): Gathers and analyzes statistic used by the Automatic Workload
Repository featured.
Memory Monitor Light (MMNL): Gathers and analyzes statistic used by the Automatic
Workload Repository featured.
Recovery Writer (RVWR): Writes recovery information to disk when Oracle Flashback
Database Recovery feature is used.
Change Tracking Writer (CTWR): keeps track of which database blocks have changed when
Oracle Incremental Recovery Manager feature is used.
Page | 9
User and Server Processes relationship
Page | 10
The basic Oracle Architecture Components
Oracle Instance
Physical
Structures
Memory Structures
SGA PGA
Processes
Page | 11
Some Important Memory Areas and Processes
Page | 12
Page | 13
Subdivision of SGA Areas
Page | 14
Some of Oracle memory areas and processes description
Page | 15
Oracle SGA, background processes and some physical structures
Page | 16
Least Recently Used (LRU) algorithm
Oracle used a Least Recently Used (LRU) algorithm to manage the contents of the Shared
Pool and Database Buffer Cache. Oracle keeps frequently accessed SQL statements and
database buffers in memory longer, improving the overall performance of the server by
minimizing parsing and physical I/O.
The size of the SGA can be managed by manually or automatically. In automatic mode, the
instance itself will monitor the utilization of each SGA component and adjust their size
accordingly, relative to a predefined maximum allowable aggregate SGA size. Oracle
allocates SGA memory into chunks called granules. These granules of memory are
dynamically allocated or de-allocated from the buffer cache, shared pool, large pool, and
java pool as needed according to the demand placed on these areas by application users.
SGA granules can be 4mb, 8mb, or 16mb in size, depending on the server OS and size of
SGA.
Cache STATUS
Cache Hit/Cache Get:
Cache hit happens when an application request data that is already in memory cache.
Cache Miss:
Cache miss happens when an application request data that is not in the cache, so a disk read
is necessary.
Cache reload:
Cache reload happens when application request data that was in the cache, but aged from
cache (written back to disk), so data must be read from disk into memory. A memory cache is
a fixed chunk of memory that does not grow or shrink. Most Recently Used (MRU)/Least
Recently Used (LRU) caching algorithm is used to keep the most frequently used data blocks
in memory and minimize number of cache miss or reload.
Cache hit ratio is calculated to find out the performance of different memory areas of Oracle
server running Modes.
Page | 17
Calculating size of SGA and it’s Components
SGA_MB
164
Total size of SGA is 164 mb.
Variable space (144964076) is composed of shared pool, large pool, and java pool,
database buffer cache is 25165824, the redo log 1048576 and additional space (787988) that
stores information used by the instance background processes.
COMPONENT CURR_SIZE_MB
shared pool 80
large pool 8
java pool 48
DEFAULT buffer cache 24
Page | 18
> select name, value
from v$parameter
where name in ('java_pool_size', 'sga_max_size', 'large_pool_size',
'log_buffer', 'shared_pool_size', 'sort_area_size');
NAME VALUE
sga_max_size 171966464
shared_pool_size 83886080
large_pool_size 8388608
java_pool_size 50331648
log_buffer 1048576
sort_area_size 65536
POOL size
shared pool 83886080
NAME SIZE_MB
buffer_cache 24.00
log_buffer 1.00
sql area 8.56
library cache 10.65
Page | 19
> select pool Name, sum(bytes)/(1024*1024) Size_MB
from v$sgastat
where pool in ('java pool','large pool','shared pool') group by pool
union
select name, value/(1024*1024) size_MB
from v$sga where name in ('Database Buffers','Redo Buffers');
NAME SIZE_MB
Database Buffers 24
Redo Buffers 1
java pool 48
large pool 8
shared pool 80
NAME SIZE_MB
shared_pool_size 80
large_pool_size 8
java_pool_size 48
db_cache_size 24
log_buffer 1
Page | 20
Oracle Physical Structures
The physical files are made up of control files, datafiles, and redo log files. Additional files
that are associated with the Oracle database are initialization file, trace file, alert log files,
password file and any archived log files.
Initialization Listing of configuration parameters for the instance and the database.
Control Location of other physical files, database name, database block size,
database character set, and optionally recovery information
Datafile Data blocks from all database segments. (data and metadata)
Redo Log Record of all changes made to the database and used for recovery.
Oracle Database
An instance is a temporary structure, but the Oracle database is made up of a set of physical
files that reside on the host server’s disk drives. These files are called:
1. control file
2. data files
3. redo logs
Additional physical files that are associated with the Oracle database, but are not technically
part of the database are pfile/spfile, any archive log files and password file.
Page | 21
Initialization file (pfile / spfile)
When we start server, PFILE.ORA file is read and initializes parameters and the
memory areas. This is a text file and can be read in any standard text editor. This file
is known as PFILE. There are 280+ different documented parameters in Oracle.
Oracle recommends that you set only about 30 basic initialization parameters
manually.
From Oracle9 version, Oracle introduces Server Parameter (SP) files also known as
SPFile (server parameter file) located in same directory as pfile.
SPFile can not be edited by standard text editor. It is created from standard PFILE
and modified by ALTER SYSTEM command. Command can change the value of a
parameter for the life of instance, or across a shutdown and start or both. The SP files
are named like spfile_SID.ora. The SP file will automatically incorporate any changes
made dynamically via ALTER SYSTEM commands.
A pfile.ora file will not reflect any dynamic system changes unless they are manually
added to the file. Unless the instance is specially started using the STARTUP PFILE
option with an existing pfile.ora, the values contained in the spfile.ora , not the pfile.ora
will be used to determine the instance parameters. Basic information in initialization
file is:
Sort the attribute cename to Arabic format if default is other than Arabic.
> select cno, cname, cename
from customers order by nlssort(cename,”NLS_SORT=ARABIC”);
Change the max dump file size to 20000 bytes and will take effect when we restart the Oracle
Server after shutting down.
> alter system set max_dump_file_size=20000 scope=spfile
scope clause are:
memory = effect is life of current instance
spfile = new value takes effect when instance shutdown and start
both [DEFAULT] = for current instance across shutdown and restart
Page | 23
Control Files
Control files are critical components of the database because they store important
information.
The name of database
The name, location, and sizes of the data files and redo log files.
Information to recover the database in the case of a failure.
Latest SCN (System Change Number)
Last LSN (log switch number)
The controlfiles are created when the database is created in the locations specified in the
control_files parameter in the parameter file. Oracle used CKPT process to automatically
update each of these files as needed, keeping the contents of all copies of the controlfile
synchronized. You can use the view v$controlfile to display the names and locations of all the
controlfiles.
Controlfile is used to mount the database. Minimun one controlfile is needed but for safety
oracle create three controlfile. We can create more if we want.Minimum one controlfile is
needed but default value is three.
Following command will display how many control files the database has.
> select name from v$controlfile;
> show parameter control_files;
Datafiles
Data files are the physical files that actually store the data that has been inserted into each
table in the database. Datafiles are the physical structure behind another database storage
area called tablespace. A tablespace is a logical storage unit within the database. By default
Oracle 10g must have at least three tablespaces. You can use v$tablespace and v$datafile
views to display their information.
Required Tablespaces
Tablespace Name Description
SYSTEM Stores the data dictionary tables and PL/SQL code.
SYSAUX Stores segments used for databasae options such as the Automatic
Workload Repository, Online Analytical Processing (OLAP), and Spatial.
TEMP used for performing large sort operations.
Common Tablespaces
Tablespace Name Description
TOOLS Used to store segments for nonapplication management tools.
USERS Used as default tablespace for database users.
UNDOTBS1 used to store information for read consistency and recovery purposes.
Page | 24
Beyond the six mentioned tablespaces listed above, production databases often have many
more tablespaces for storing application segments. For each of the tablespace, there must be
at least one datafile. Some tablespaces may be composed of several datafiles for
management or performance reasons.
Following command displays the datafiles and the corresponding tablespace they belong.
> select tablespace_name, file_name from dba_data_file order by tablespace_name;
When a user performs a SQL operation on a table, the users server process copies the
affected data from the datafile into the database buffer cache in the SGA. If the user has
performed a committed transaction that modified that data, the DBWn ultimately writes the
modified data blocks to the datafiles.
Page | 25
Redo Log Files
When a user performs a transaction in the database, the information needed to reproduce
this transaction in the event of a database failure is automatically recorded in the redo log
buffer. The contents of the redo log buffer are ultimately written to the redo log files by the
LGWR process. Redo logs are usually multiplexed or copied. Collectively, these sets of redo
logs are referred to as redo log groups. Each multiplexed file with in the group is called a
redo log member. Oracle writes to all members of redo log group to keep the files in sync.
Each redo log group must be composed of one or more members. Each database must have
a minimum of two redo log groups because redo logs are used in a circular fashion.
When a user performs a DML activity on the database, the recovery information for the
transaction is written to the redo log buffer by user server process. LGWR eventually writes
this recovery information to the active redo log group until that group is filled. Once the
CURRENT log fills with transaction information, LGWR switches to the next redo log until that
group fills with transaction information and so on. When the last redo log is used, LGWR
wraps around and starts using the first redo log again.
When LGWR wraps around from the last redo log back to the first redo log, any recovery
information previously stored in the first redo log group is overwritten and therefore no longer
available for recovery purpose. However, if the database is running in archive log mode, the
contents of these previously used logs are copied to a secondary location before the log is
reused. It is the job of the ARCn process to copy the contents of the redo log to the archive
location. These copies of the old redo log entries are called archive logs.
In the figure, the first redo log group has been filled, and LGWR has moved/switch to on to
redo log group 2 from redo log group 1. As soon as LGWR switches from redo log group 1 to
redo log group 2, the ARCn process starts copying the contents of the redo log group 1 to the
archive log file location as mentioned in the parameter file. Once the first redo log group is
safely archived, LGWR is free to wrap around and reuse the first redo log group once redo
log group 3 is filled.
Page | 26
The Alert Log
The Oracle alert log records information and error messages for a variety of activities that
have occurred against the database during its operation. The alert log is constantly appended
to while the database is in operation. If left unmanaged, it can grow very large. Oracle
automatically creates a new alert log if the prior was deleted or renamed. The information
helps in tuning the database.
Page | 27
The Trace Files
Oracle trace files contain session information for the process that created them. Trace files
can be created by the oracle background process, through the use of pfile.ora trace events or
by tracing user Server Processes.
Event Tracing
The database event is a specific action or activity that occurs in the database. Oracle has
special option that you can configure to enable the collection of detailed tracing information
for particular database event. By default, most database events do not cause the creation of
trace files. However, some database events can be forced to create a trace file of their
activities you wish to trace.
Tracing of these events is usually done at the instance level by adding new lines to pfile.ora.
Generally you may be asked to do event tracing by the Oracle Worldwide Support (OWS) as
part of trouble shooting.
The background process and EVENT trace files are found in the directory specified by
BACKGROUND_DUMP_DEST parameter. Systems those follow OFA model this directory
will be %oracle_base%\admin\SID\bdump on windows 2000.
Tracing of these events is usually done at the instance level by adding new lines to the
pfile.ora. If several events are being added to the pfile.ora, they should be grouped together
and commented appropriately. The spfile.ora looks like this:
>alter system set event = "10046 trace name context forever, level 12"
OWS personnel will provide you with these numeric values when the need for using trace
events arises.
Page | 28
User Trace files
User Process Trace files incorporate by OS process identifier in the trace file. An example
can be ora00776.trc. Query against the V$PROCESS and V$SESSION views can be
performed to identify which user generated a particular trace file.
USERNAME SPID
Scott 2922
Najm 3088
The User trace files are found in the directory specified by USER_DUMP_DEST parameter.
Page | 29
Activating Instance-Level Tracing (background processes tracing)
By setting SQL_TRACE=TRUE in pfile.ora, all processes against the instance will create their
own trace files. It creates a great deal of overhead against the system, so care must be
taken. The default value for the parameter is FALSE.
Page | 30
Password file
The physical file used by Oracle to authenticate database users who are connecting with
SYSDBA or SYSOPER privileges.
Entries in the file cannot be modified. To change the entries we must delete and recreate the
password file.
Page | 31
User Session
A user session is stared when database connection is made. Session is available as long as
user is connected to the database. An ID is assigned to each session. Session identifier (SID)
and serial# uniquely identifies each session. The serial# guarantees that commands are
applied to the correct session object, if the session end and another session begins with the
same SID.
When you kill a session, Oracle terminates the session to prevent any more SQL execution.
Statement is terminates when session is terminated and all changes are rolled back. Session
lock and other resources are released.
If inactive session is killed, Oracle terminates the session and mark the status as killed
Subsequently when user tries to use session, error is returned to user and session
information is removed from v$session
If active session is killed with IMMEDIATE option, ongoing transaction is rolled back and
release session locks.
Page | 32
Checkpoint
Periodically Oracle perform checkpoint. DBWn writes all modified data blocks in the instance
buffer cache back to Data Files that contains those blocks. Checkpoint indicates how much of
transaction log entries oracle must apply if simple server crash occurs.
Log_checkpoint_interval =
[(log file size /db_block_size)*(db_block_size/os block size)] / # of desired checkpoints b/w log switch
Commit
1. Releases the Locks
2. Rollback segment is freed
3. Trans move from log buffer to log file.
Rollback
1. Move old / rolled back information from rollback segment back to memory
2. Releases the Locks
3. Rollback segment is freed
Page | 33
Connection Request Failure reasons
A connection request may fail for many reasons. Here are a few of most common reasons for
connection failure.
ERROR:
ORA-12154: TNS:could not resolve service name
ERROR:
ORA-12545: Connect failed because target host or object does not exist
ERROR:
ORA-12541: TNS:no listener
ERROR:
ORA-12514 TNS:listener could not resolve SERVICE_NAME given in correct descriptor
ERROR:
ORA-01034: ORACLE not available
ERROR:
ORA-01017: invalid username/password; logon denied
Page | 34
SQL Statement Execution Steps
When a statement is send to Oracle database server, Oracle server process
- First converts the characters in the SQL statement to ASCII equivalent numeric codes.
- Next, this string of ASCII code is passed through hashing algorithm, which in turn
produces a single hashed value.
- The User Server process then checks to see if that hashed value already exists in the
SQL Area of the Shared Pool.
- If it does, the User’s Server Process uses the cached version of the statement to execute
the statement.
- If the hashed value does not exist in the Shared Pool, The User’s Server Process goes
about the process of parsing the statement, and then executes it.
1. At Checkpoint DBWr writes dirty blocks of committed transactions from data buffer to data
files.
2. Checkpoint process CKPT, updates the header of all the data files with the last
Transaction number SCN whose data is moved from data buffer to data files.
3. At the server startup SMON compares the SCN in the Control files with the SCN of all the
data files. If any transaction is missing, SMON will run that transaction and will
synchronize the SCN of Data files with that of Control files and the database reached to
consistent state.
Page | 35