Chapter6 Database Architecture
Chapter6 Database Architecture
Managing Sessions
Two-Minute Drill
Chapter Questions
In this chapter, you will learn about and demonstrate knowledge in the
following areas:
To be a successful Oracle DBA and to pass OCP Exam 2, you must understand
the Oracle database architecture. About 16 percent of OCP Exam 2 is on this
area. An Oracle database in action consists of several elements, including
memory structures, special processes that make things run faster, and
recovery mechanisms that allow the DBA to restore systems after seemingly
unrecoverable problems. Whatever the Oracle feature, it’s all here. Review
this chapter carefully, as these concepts form the foundation for material
covered in the rest of unit and book, the OCP exam, and your work as a
DBA.
Focus first on the memory components of the Oracle instance. There are
two basic memory structures in Oracle. The first and most important is the
System Global Area, or SGA. When DBAs talk about most things related to
memory, they usually mean the SGA. The SGA consists of several different
items: the buffer cache, shared pool, and redo log buffer, as well as a few
other items that will be discussed later in the unit. The following subtopics
explain the primary components of the Oracle SGA.
Buffer Cache
This memory structure consists of buffers the size of database blocks that
store data needed by SQL statements issued in user processes. A database
block is the most granular unit of information storage in Oracle, in which
Oracle can place several rows of table data. The buffer cache has two
purposes: to improve performance for subsequent
repeated select statements on the same data, and to allow Oracle users to
make data changes quickly in memory. Oracle writes those data changes to
disk later.
Shared Pool
There are two mandatory structures and one optional structure in the Oracle
shared pool. The first required component is the library cache, used for
storing parsed SQL statement text and the statement’s execution plan for
reuse. The second is the dictionary cache, sometimes also referred to as
the row cache, which is used for storing recently accessed information from
the Oracle data dictionary, such as table and column definitions, usernames,
passwords, and privileges. (If you don’t know what the data dictionary is,
you’ll find more out about it later in this chapter.) These two components
are designed to improve overall Oracle performance in multiuser
environments. The optional shared pool structure contains session
information about user processes connected to Oracle. When will Oracle
include this optional component in the SGA? You’ll find out shortly.
The other memory structure in the Oracle instance is called the Program
Global Area, or PGA. The PGA helps user processes execute by storing
information like bind variable values, sort areas, and other aspects of cursor
handling. Why do users need their own area to execute? Even though the
parse information for SQL or PL/SQL may already be available in the library
cache of the shared pool, the values upon which the user wants to execute
the select or update statement cannot be shared. The PGA is used to
store real values in place of bind variables for executing SQL statements.
TIP: Think of the Oracle server process as a genie—the magical being from
the story of Aladdin—because your wish for Oracle data is the server
process’s command!
In this setup, every single user connecting to Oracle will have a personal
genie handling data retrieval from disk into the buffer cache. If there are
150 users connected to Oracle, there will also be 150 genies out there
grabbing data from disk and putting it in the buffer cache for those users.
The architectural setup means that every user gets their data retrieval
requests acted upon immediately. It also means there will be additional
memory and CPU overhead on the machine running the Oracle database, and
that each dedicated server process will, depending on the workload and the
access method, sit idle most of the time. Still, this is the setup chosen by
many DBAs for overall performance reasons when hardware resources are
readily available.
In this setup, there is a small pool of server processes running in Oracle that
support data retrieval requests for a large number of users. Several users
are served by one server process. Oracle manages this utilization by means
of a network process called the dispatcher. User processes are assigned to a
dispatcher, and the dispatcher puts the user requests for data into one
queue, and the shared server process fulfills all the requests, one at a time.
This configuration can reduce memory and CPU burden on the machine that
hosts Oracle, as well as limiting server process idle time, but during periods
of high database use, the user processes may have to wait for attention
from the genie with many masters.
Let’s return to the point raised earlier about the optional component of the
shared pool, where user session information is stored in Oracle. Oracle will
store session information in the shared pool only if the DBA configures
Oracle to use shared servers to handle user data retrieval requests. This
option is known as the multithreaded server, or MTS, architecture.
Otherwise, if dedicated servers are used, user session information is housed
in the PGA.
Before answering this final question, let’s spend just another quick moment
covering a few other important Oracle network processes. The first is called
the listener process. The Oracle listener process does just that—it listens for
users trying to connect to the Oracle database via the network. When a user
connects to the machine hosting the Oracle database, the listener process
will do one of two things. If dedicated server processes are being used, the
listener tells Oracle to generate a new dedicated server and then assigns the
user process to that dedicated server. If MTS is being used, the listener
sends the user process to another process called the dispatcher process,
which has already been mentioned.
Exercises
1. What is the name of the main memory structure in Oracle, and what are
its components? What is the function of the PGA?
When complete, both the statement execution plan and the data in blocks
retrieved from disk stick around in the library cache and buffer cache,
respectively, for a variable length of time, just in case that user or another
one wants to execute the same select statement. In multiuser application
environments, a performance gain is achieved every time user processes
execute the same select statement because the RDBMS spends less time
parsing the statement, and the server process spends less time retrieving
data.
Exercises
1. Does SQL allow the user to define procedures or desired data for
information retrieval? Explain.
With this in mind, return to the processing of DML statements. There are
several differences between how Oracle processes select statements and
how it processes DML statements such as update, insert, and delete.
Though the operations involved in executing DML statements fall into the
same general pattern as those for selectstatements shown in Figure 6-2,
the specific flow of operation in processing DML statements is as follows:
3. Generate redo informationRecall from the prior lesson that the redo
log buffer stores redo or data change information produced as the result
of DML operations running in user sessions. After issuing DML statements,
the user process must write a redo entry to the redo log buffer. In this
way, Oracle can recover a data change if damage is later done to the disk
files containing Oracle data.
TIP: Acquiring a lock is how one Oracle user says to the other users “Hey!
Hands off this data! I’m changing it now, so that means you can’t have it
until I let go of my lock!” Locks can be acquired at the row level implicitly
as part of update or delete statements, or at the table level through
explicit methods described later in the book.
Moving Data Changes from Memory to Disk
Once the DML statement has been executed, there is no further need to
fetch values, as there was for select statements. However, as
with select statements, the execution plan for the DML statement sticks
around in the library cache for a variable period of time in case another user
tries to execute the same statement. The changed blocks in the buffer
cache are now considered “dirty” because the version in the buffer cache
and on disk are no longer identical. Those dirty buffers stick around in the
buffer cache as well, but they will need to be copied to disk eventually in
order for Oracle not to lose the data change made. Also, new information
appears in the redo log buffer as the result of the data changes made by the
DML statement. By having all the data changes happening in memory, Oracle
is in a position to relieve user processes from having to wait for the data
changes to be written to disk. Oracle does this by running two other
background processes called DBWR and LGWR that write the data changes
from buffer cache and redo log buffer to disk; these processes are
asynchronous, meaning that they occur sometime after the user actually
made the change. The following subtopics explain the role of each
background process.
Role of DBWR
Called the database writer process, the DBWR background process writes
dirty data blocks from buffer cache to disk. The writes are done when the
server process needs to make room in the buffer cache to read more data in
for user processes, when DBWR is told to write data to disk by the LGWR
process, or every three seconds due to a timeout. The event that causes
LGWR to tell DBWR to write to disk is called a checkpoint. You will learn
more about checkpoints in Chapter 7. Because Oracle8 allows multiple
database writers to run on the host machine, the DBWR process is
sometimes referred to as DBW0, where 0 can be any digit between 0 and 9,
representing one of several DBWR processes running in Oracle.
Role of LGWR
Called the log writer process, the LGWR background process writes redo log
entries from the redo log buffer to online redo log files on disk. LGWR has
some other specialized functions related to the management of redo
information that you will learn about in Chapter 7. LGWR also tells DBWR to
write dirty buffers to disk at checkpoints, as mentioned earlier.
Exercises
2. What are rollback segments? What are locks? How are these objects
involved in DML processing?
Before proceeding any further, make sure you understand the following
important point—issuing commit has no effect on when Oracle copies that
data change in the buffer cache to disk. Thus, a commit statement does not
somehow trigger DBWR activity. Only a checkpoint, a timeout, or a need for
room in the buffer cache for blocks requested by users will make DBWR
write dirty blocks to disk. With that fact in mind, what exactly does
processing a commit statement consist of? The following list tells all:
Note that Oracle takes no special action related to redo information as the
result of that commit, other than to indicate that the transaction has been
committed. How does Oracle know which DML statement redo entries to
associate with each transaction? The answer is the system change
numbers (SCNs). An SCN is an ID that Oracle generates for each and every
transaction that a user process engages. Every redo entry for every data
change lists the change made and the SCN the change is associated with.
The redo entry for the commit also identifies the SCN and simply notes that
this SCN has been committed. Thus, Oracle can keep easy track of the status
of every transaction via the SCN.
Exercises
2. What does a redo entry for commit statements consist of? What is an
SCN?
In the past few years, there has been an explosion in the use of
administrative tools for Oracle databases. These tools are designed to
simplify many aspects of Oracle database administration, including
tablespace, instance, storage, object, and backup and recovery
management. However, OCP certification on Oracle7 did not focus on using
administrative tools. Instead, it focused on the importance of understanding
server internals, such as V$ views and issuing commands from the command
line. Though the importance of these Oracle components can hardly be
diminished, administrative tools such as Oracle Enterprise Manager matured
and expanded their functionality, and these areas have risen to take similar
levels of importance in the repertoire of every DBA. Plus, they make your
job a heck of a lot easier.
Server Manager is usually started from the command line on the machine
hosting the Oracle database. In UNIX, the executable is called svrmgrl.
You can access the host machine command line either via Telnet or an X
terminal. You can execute Server Manager from any place in your file system
if the $ORACLE_HOME/bin directory is part of your path environment
setting. If this directory is not part of your path, you should add it. The
following code block demonstrates the execution of Server Manager in line
mode from the UNIX command line.
Exercises
Exercises
2. What are some other administrative tools that OEM might use, and
where/how might the DBA get them?
TIP: Instance Manager will not prompt you for login information if you run it
from OEM. It will instead use the login info you provided when you started
OEM.
After login, you will see the Instance Manager interface. The left-hand
window is the navigator window. On it, there are several nodes you can drill
down into to find information. You drill into each node by clicking on the
plus sign (+) to the left of the node. The names of each node are self-
explanatory. For example, if you drill into the Sessions node as shown in
Figure 6-6, you will see all the sessions currently happening in Oracle listed
below the node. On the right side is the work interface. If you click on the
name of the node or the file folder icon to the left of that name, the
relevant information will be displayed in the work window. As another
example, if you click on the name of one of the connected sessions in the
navigator window, you will see some additional information about that
session appearing in the work window.
Along the top of the interface is a set of several menus. From left to right,
they are File, View, Database, Sessions, Transactions, Configuration, and
Help. The options under the File menu allow you to change database
connection, enable roles, or exit the application. The options under the
View menu allow you to modify the tools available in Instance Manager and
expand or collapse nodes in the left window. The Database menu permits
startup and shutdown operations, archiving, and other things. The Sessions
menu permits management of sessions, including the ability to disconnect a
session, restrict access to the database to only those users
with restricted session privileges, or allow all users to access the
database. The Transactions menu allows the DBA to
force commit and rollback operations to happen in the database. The
Configuration menu allows you to change or remove database configurations
from the database to the desktop. Finally, the Help menu gives you access
to online help.
After using Instance Manager, as well as some of the other manager tools,
you should be able to see some general patters of use. All the manager tools
have both a navigator window with several nodes allowing you to access
various things, and a work window where you will actually execute the tasks
that the manager tool allows you to do. For each, you can login with
Normal, sysdba, or sysoper privileges. Though the actual menus and
options for each manager tool are different, they all basically mirror the
functionality you have through the navigator and work windows. Finally,
each of these tools can be run alone or as part of OEM.
Exercises
1. Describe the functionality and general use of the Instance Manager tool.
What three connect options do you have when logging into Oracle via the
tool?
2. What general use guidelines can you extract from using Instance Manager
that apply to using all of the manager tools?
Managing sessions
Monitoring ALERT and trace files
After installing the Oracle software, the DBA should master the management
of an Oracle instance. There are several important things that should be
done to manage the Oracle instance before even thinking about setting up
the Oracle database. Important questions about authentication must be
answered, and the parameter file must be developed and managed. This
parameter file is generically referred to as initsid.ora by many DBAs.
Starting up and shutting down the instance, and opening and closing the
database are key areas both before and after the database is created.
Finally, the management of sessions and places to look for information
about the Oracle instance in action are covered in this section.
Another round of introductions is in order. SYS and SYSTEM are two users
Oracle creates when you install your database. Each has their own default
password. The default password for SYS is CHANGE_ON_INSTALL, and for
SYSTEM it is MANAGER. Be careful to protect the passwords for both these
users by changing them after installing Oracle. These two privileged users
have the power to administer most any feature of the Oracle database. SYS
is more important than SYSTEM because SYS will wind up owning all Oracle
system tables from which the data dictionary is derived.
The Oracle data dictionary is the system resource you will turn to in order to
find out just about anything about your database, from which users own
what objects, to the initialization parameter settings, to performance
monitoring, and more. There are two basic categories for Oracle database
views: those that show information about database objects and those that
show dynamic performance. The views showing information about objects
are the data dictionary views. The views showing information about
performance are dynamic performance views.
Using OS Authentication
Or,
Oracle creates some other OS roles as part of its UNIX installation that must
be granted to the DBA, such as osoper and osdba. These OS roles are given
to the Oracle software owner, and must be granted to other OS users who
would be DBAs via operating system commands. These roles cannot be
revoked or granted from within Oracle. However, there are two equivalent
Oracle privileges used when you authenticate with a password file—
sysoper and sysdba, respectively.
There are some small differences between the osoper and sysoper,
and osdba and sysdba, which you may use to your advantage for breaking
out DBA roles and responsibilities. The osoper role and sysoper privilege
allow you to start and stop the instance, mount or open the database, back
up the database, initiate archiving redo logs, initiate database recovery, and
change database access to restricted session mode.
The sysoper and sysdba roles offer the same privileges
as osoperand sysoper, and add the ability to execute and administer all
Oracle system privileges, the create database privilege, and all privileges
required for time-based incomplete database recovery.
Obviously, osoper or sysoper is given to the DBA ultimately responsible
for the operation of the database.
Oracle’s other method of authenticating DBAs is the password file. The DBA
creates the password file, and passwords for all others permitted to
administer Oracle are stored in the file. The password file is created with
the ORAPWD utility. The name of this executable varies by operating
system. For example, it is orapwd on UNIX, but orapwd80 on Windows.
D:\orant\bin\>orapwd80 FILE=D:\orant\dbs\orapworgdb01.pwd
PASSWORD=jason ENTRIES=5
/home/oracle80> orapwd \
FILE=app/oracle/product/8.0.5/dbs/orapwdorgdb01.pwd \
PASSWORD=jason ENTRIES=5
After creating the password file, you must do a few other things to allow
administrative access to the database while simultaneously preventing use
of internal. First, set the value for
the REMOTE_LOGIN_PASSWORDFILE parameter in
the initsid.ora parameter file. This parameter accepts none, shared,
and exclusive as its values. The none setting means the database won’t
allow privileged sessions over unsecured connections. When OS
authentication is used, the REMOTE_LOGIN_PASSWORDFILE is set
to none to disallow remote database administration.
Setting REMOTE_LOGIN_PASSWORDFILE to shared means that only SYS
and internal can log into Oracle to perform administrative functions
remotely. Finally,
setting REMOTE_LOGIN_PASSWORDFILE to exclusive means that a
password file exists and any user/password combination in the password file
can log in to Oracle remotely and administer that instance. If this setting is
used, the DBA should use the create user command in Oracle to create
the users that are added to the password file, and
grant sysoper and/or sysdba system privileges to those users. After that,
users can log into the database as themselves with all administrator
privileges.
After creating the password file with the ORAPWD utility and setting
the REMOTE_LOGIN_PASSWORDFILE parameter to exclusive in order to
administer a database remotely, the DBA can then connect to the database
as a user with sysdba privileges as shown here:
TIP: Remember two important points about password files. First, to find out
which users are in the database password file, use the V$PWFILE_USERS
dynamic performance view. (More on the data dictionary will be presented
in Chapter 7.) Second, any object created by anyone logging in
as sysdba or sysoper will be owned by SYS.
Exercises
3. What are the two Oracle roles granted to DBAs in order to perform
database administration?
You can create your parameter file from scratch, but why bother when
Oracle creates one for you? The parameter file Oracle creates for you will
contain several different options for the most essential initialization
parameters you need to include when creating a new database. However,
Oracle has literally hundreds of initialization parameters, documented and
undocumented. The following code block shows a sample parameter file in
use on a small Oracle database running under Windows. The pound sign (#)
is used to denote comments in the parameter file.
db_name = ORGDB01
db_files = 1020
control_files = (D:\orant\DATABASE\ctl1orgdb01.ora,
D:\orant\DATABASE\ctl2orgdb01.ora)
db_file_multiblock_read_count = 16
db_block_buffers = 1000
shared_pool_size = 1048576
log_checkpoint_interval = 8000
processes = 100
dml_locks = 200
log_buffer = 32768
sequence_cache_entries = 30
sequence_cache_hash_buckets = 23
#audit_trail = true
#timed_statistics = true
background_dump_dest = D:\orant\RDBMS80\trace
user_dump_dest = D:\orant\RDBMS80\trace
core_dump_dest = D:\orant\RDBMS80\trace
db_block_size =2048
sort_area_size = 65536
log_checkpoint_timeout = 0
remote_login_passwordfile = shared
max_dump_file_size = 10240
rollback_segments = (RB0_ORGDB01, RB1_ORGDB02)
global_names=false
open_cursors=400
In general, when working with parameter files, it is best not to start from
scratch. Use the Oracle default, or borrow one from another DBA. But be
sure that you alter the parameters in the file to reflect your own database,
including DB_NAME, DB_BLOCK_SIZE, CONTROL_FILES, and others. You
should remember where you store your parameter file on the machine
hosting the Oracle database. Do not leave multiple copies in different
directories. This could lead you to make a change to one but not the other.
Then if you start your instance with the old parameter file later, you could
have problems. However, it can be useful to have a few different copies of a
parameter file for various administrative purposes, such as one for
production environments, and one for running the database is restricted
mode for DBA maintenance operations.
Exercises
1. What is the typical name for the parameter file in Oracle? By what name
do most DBAs refer to their parameter file?
With that distinction made, let’s consider starting the Oracle instance. You
must do this before creating a new database, or before allowing access to
an existing database. To start the instance, follow these steps:
1. From the command line on the host machine, start Server Manager and
log in either as sysdba or internal:
You can also start a database with OEM Instance Manager. All the options
discussed for Server Manager are available via Instance Manager, except
through a graphical user interface. You may also want to note that starting
Oracle databases in Windows is not necessarily handled with Server Manager
or even OEM, but instead may be handled as a service. A service in Windows
is similar to a daemon in UNIX. Both of these operating system functions
allow Oracle to start automatically when the machine boots. (We’re getting
a little off the topic here, but if you’re interested in more information,
consult the Oracle8 Installation Guide for Windows NT, which comes with
that distribution of Oracle.) There are several different options for starting
Oracle instances, with or without opening the database.
STARTUP NOMOUNT
This option starts the instance without mounting the database. That means
all the memory structures and background processes are in place, but no
database is attached to the instance. You will use this option later, for
creating the Oracle database. You can specify this option with or without
specifying an initsid.ora file for the PFILEparameter. If you do not
specify PFILE, Oracle uses its own built-in default settings for initialization
parameters specific to each operating system.
STARTUP MOUNT
This option starts the instance and attaches the database, but does not open
it. You can’t mount a database you haven’t created yet. This option is
useful in situations where you have to move physical database files around
on the machine hosting Oracle, or when database recovery is required. You
should specify an initsid.ora file for the PFILE parameter when using
this option; otherwise, Oracle will not use values you may have specified in
your initsid.ora file. If the instance is already started but the database
is not mounted, use alter database mount instead.
STARTUP OPEN
This option starts your instance, attaches the database, and opens it. This is
the default option for starting Oracle. It is used when you want to make
your database available to users. You can’t open a database you haven’t
created yet. The file you specify for the PFILE parameter must be
an initsid.ora file. If the instance is started and the database is
mounted, use alter database open instead.
STARTUP FORCE
This option forces the instance to start and the database to open. It is used
in situations where other startup options are met with errors from Oracle,
and no shutdownoptions seem to work either. This is an option of last
resort, and there is no reason to use it generally unless you cannot start the
database with any other option.
TIP: Two other cases for database startup include startup recover for
handling database recovery, and startup restrict to open the database
while simultaneously preventing all users but the DBA from accessing
database objects. You’ll learn about using startup restrict when we
talk about the EXPORT utility in Chapters 10 and 15, and about database
recovery in Unit III.
Exercises
1. What tools can be used for starting Oracle instances and databases? What
connection must be used for the task?
1. From the command line on the host machine, start Server Manager, and
log in either as sysdba or internal:
There are four priorities that can be specified by the DBA for shutting down
the database. They
include shutdown normal, shutdown immediate, shutdown abort,
and shutdown transactional. The next four subtopics will explain each
of these options and give cases where their use might be appropriate.
SHUTDOWN NORMAL
SHUTDOWN IMMEDIATE
SHUTDOWN ABORT
This is the highest priority database shutdown command. In all cases where
this priority is used, the database will shut down immediately. All users are
immediately disconnected, no transactions are rolled back, and media
recovery will be required when the database starts up again. You will use
this option only when media or disk failure has taken place on the machine
hosting Oracle.
SHUTDOWN TRANSACTIONAL
Exercises
Setting parameters is done in one of two ways. By far, the most effective
way to set a database parameter is to add the name of the parameter and
the value to the initsid.ora file for your instance. After that, shut down
and start up your instance using the initsid.ora file. Unfortunately, in
the world of multiuser database environments, DBAs do not always have the
luxury of bouncing the database whenever they want. You can always try to
schedule this sort of thing, or if the need is not critical, wait until the
weekend. Another method for setting parameters is with
the alter system command. However, this is not an effective method for
changing parameters, because not all initialization parameters can be
changed using this command. The ones that can be changed
include RESOURCE_LIMIT, GLOBAL_NAMES,AUDIT_TRAIL, TIMED_STATI
STICS, some of the MTS parameters, and some of the licensing parameters.
Exercises
1. Identify some ways you can obtain instance parameters. Which of these
ways is least effective? Which are most effective?
2. What methods are available for changing instance parameters before the
instance is started? What about after the instance is started?
Managing Sessions
Each user process that connects to Oracle maintains a session with the
Oracle database. The user has the ability to do whatever they have been
granted privileges to do within their session. User sessions are managed with
the alter session statement. Several things can be changed about a user
session, including national language settings
like NLS_LANGUAGE, NLS_DATE_FORMAT, and so on, in the form alter
session set NLS_DATE_FORMAT = 'date_format'. In addition, if the
user wants to enable tracing on the session to determine performance
statistics for the SQL they execute, the alter session set
SQL_TRACE = TRUE command can be used.
In order to connect to the database, the user must be granted
the create session privilege. Note that this privilege only allows the user
to connect to Oracle—that user must be granted further privileges to
actually see anything once connected! Although privileges will be covered in
more detail in Chapter 10, this privilege is mentioned because it is useful in
managing sessions to know how to continue and discontinue a user’s ability
to create sessions with Oracle.
There are a few basic ways the DBA can manage sessions. One is to
disconnect a session, another is to restrict access to an open database to
only those users with a special privilege called restricted session. You
have already seen how to open the database from Server Manager in
restricted mode with the startup restrict command. (You also already
know that there is more information about startup restrict in Chapter
10.) You can restrict database access with
the alter system enablerestricted session command after the
database is open. To disconnect a session, you must issue
the alter system kill session 'sid, serial#' command. The
values for sid and serial# come from the V$SESSION data dictionary view
columns of the same name.
TIP: The V$SESSION dictionary view contains information about every session
currently connected to Oracle. It forms the basis of information displayed in
the Instance Manager tool.
Exercises
1. What command is used to manage a user session? What tasks can actually
be accomplished with that command?
There are other times in Oracle execution when the ALERT log is written to,
as well. The ALERT log can grow quite large, so it makes sense to clear it
out once in a while and allow Oracle to start generating a new one,
particularly if nothing eventful has happened on your database in a long
time. Sometimes, when the ALERT log is written, the message must be
addressed. As such, it is important for you as the DBA to check the ALERT
log regularly for things like internal errors or other anomalies in database
behavior. If you have some kind of problem with your Oracle software and
need to open a trouble ticket with Oracle Support, you may be requested to
supply them with a copy of your ALERT log, as well.
The location of your ALERT log and background trace files depends on the
directory specified for the BACKGROUND_DUMP_DEST parameter for your
instance. Both the background process trace files and the ALERT log will be
found in this directory. If you are unsure of the location of your ALERT log,
simply use the methods defined for getting parameter values, and look up
the value for BACKGROUND_DUMP_DEST.
TIP: If you start getting really weird errors in your database, and your ALERT
log contains ORA-00600 errors, you should call Oracle Support ASAP!
Exercises
1. What is the ALERT log? What is a trace file? What is the difference
between the two?
Once the DBA has set up some necessary preliminary items for running the
Oracle instance, such as password authentication, the DBA can then create
the database that users will soon utilize for data management. Creating a
database involves three activities that will be discussed in this section. The
first activity for creating a database is mapping a logical entity-relationship
diagram that details a model for a process to the data model upon which the
creation of database objects like indexes and tables will be based. Second
the DBA will create physical data storage resources in the Oracle
architecture, such as datafiles and redo log files. The final (and perhaps the
most important) aspect of creating a database is creating the structures that
comprise the Oracle data dictionary. Each element in the database creation
process will be discussed in detail.
Exercise
What are some items you may need to tend to at the OS level before
creating your database?
DB_NAME
The local name of the database on the machine hosting Oracle, and one
component of a database’s unique name within the network. If the value for
this parameter is the same as another Oracle database running on the host,
permanent damage may result in the event that a database is created. Try
to limit this name to approximately eight characters. Do not leave the name
as DEFAULT. There is a name for the database and a name for the instance,
and they should be the same. DB_NAME is required for the creation of the
database, and it should be unique among all Oracle databases running in
your organization.
DB_DOMAIN
The size in bytes of data blocks within the system. Data blocks are unit
components of datafiles into which Oracle places the row data from indexes
and tables. This parameter cannot be changed for the life of the database.
CONTROL_FILES
A name or list of names for the control files of the database. The control
files document the location of all disk files used by the Oracle. If the
name(s) specified for this parameter do not match filenames that exist
currently, then Oracle will create a new control file for the database at
startup only when you create a new database. Otherwise, Oracle simply tells
you it won’t start because it can’t find the control files it needs to open
your existing database. Only during creation of a new database will Oracle
overwrite the contents of a file of the same name as the control file you
specified in initsid.ora with the physical layout of the database being
created. Beware of this feature, as it can cause a control file on an existing
database to be overwritten if you are creating a second database to run on
the same machine.
DB_BLOCK_BUFFERS
The maximum number of data blocks that will be stored in the database
buffer cache of the Oracle SGA. The size of the buffer cache in bytes is a
derived value of DB_BLOCK_SIZE multiplied by DB_BLOCK_BUFFERS.
LOG_BUFFER
The size of the redo log buffer in bytes. As stated earlier, the redo log
buffer stores redo log entries in memory until LGWR can write the entries to
online redo logs on disk. There will be more about this in Chapter 7.
ROLLBACK_SEGMENTS
A list of named rollback segments that the Oracle instance will have to
acquire at database startup. If there are particular segments the DBA wants
Oracle to acquire, these can be named here.
PROCESSES
The number of processes that can connect to Oracle at any given time. This
value includes background processes (of which there are at least five) and
server processes. This value should be set high in order to avoid errors that
prevent users from connecting.
LICENSE_MAX_SESSIONS
LICENSE_MAX_WARNING
LICENSE_MAX_USERS
Exercises
2. What happens if you have two databases on one machine, you borrow
the parameter file from one database to create the other, and then
forget to change the value set for CONTROL_FILES?
1. Back up the existing databases on the machine hosting the new database
you want to create.
2. Create or edit the initsid.ora parameter file for your new instance.
3. Verify the instance name in any database creation script you have, as
well as in the initsid.ora file.
9. Open your new database again to make the database available to the
users.
CONNECT INTERNAL;
EXIT;
Redo logs are created with the logfile clause. Redo logs are entries for
data changes made to the database. You must create at least two redo log
groups for your new database, each with at least one member. In the
database created with the preceding code block, redo log group 1 consists
of two members, called log1a.dbf and log1b.dbf, respectively. If any
file specified in the create database statement currently exists on the
system, and the reuse keyword is used, Oracle will overwrite the file. Be
careful when reusing files to prevent accidentally overwriting the files in
your existing database on the host machine. You will learn more about redo
logs in Chapter 7, also.
Exercises
3. What is a parameter file? What are some of the parameters a DBA must
set uniquely for any database via the parameter file?
Chapter Summary
This chapter introduced you to Oracle database administration. It covered
several topics, including an overview of the Oracle architecture, using
administrative tools such as Server Manager and OEM, managing the Oracle
instance, starting and stopping the instance, and creating an Oracle
database. The material in this chapter comprises about 16 percent of the
questions asked on OCP Exam 2.
The first area of discussion in this chapter was an overview of the various
components of the Oracle database. Figure 6-1 gave an idea of the
background processes, memory structures, and disk resources that comprise
the Oracle instance, and how they act together to allow users to access
information. Several memory structures exist on the Oracle database to
improve performance on various areas of the database. They include the
System Global Area (SGA) and the Program Global Area (PGA). The SGA, in
turn, consists of several components: the buffer cache, the shared pool, and
the redo log buffer. Behind the scenes, there are several memory processes
that move data between disk and memory or handle activities on Oracle’s
behalf. The core background processes covered in this chapter were the
database writer (DBWR or DBW0) for writing blocks to disk, the log writer
(LGWR) for writing redo entries to disk, and the server for reading data from
disk into the buffer cache for users.
The next section covered using administrative tools. The Server Manager
application was demonstrated in its line mode operation for various
environments. You also learned about the administrative tools that are part
of Oracle Enterprise Manager, or OEM for short. The tools described were
the Instance Manager, Data Manager, Schema Manager, Backup Manager,
Software Manager, Storage Manager, as well as many others. A
demonstration of using some of these tools was presented, as well, so that
you could better grasp how Oracle allows you to perform the same functions
in a graphical user interface that it allows you to execute using line mode
commands in Server Manager.
The next area covered was managing the Oracle instance. Setting up
operating system authentication for management of Oracle from the
command line of the machine that hosts the database was demonstrated.
The use of password file administrative authentication and the value of
setting this up was also demonstrated. If you want to use OEM for things like
starting up and shutting down your database from the client desktop, you
must set up a password file. This is handled with the ORAPWD utility. An
explanation of the various ways to connect to Oracle administratively, such
as connect internal, connect as sysdba, and the differences
between sysdba and osdbaand sysoper and osoper were all covered, as
well.
Creating a parameter file, also known as the initsid.ora file, was also
covered. Oracle provides a generic parameter file with every software
release, so it is easiest to reuse an initialization parameter file rather than
creating one from scratch yourself. The various parameters that can be set
were explained in some detail, along with how to find out what the current
parameter values are using the V$PARAMETER dynamic performance view,
the show parameter command in Server Manager, and from within the OEM
Instance Manager. The requirement for changing parameter values by
modifying the initsid.ora file and stopping and restarting the instance in
most cases, as well as the special cases for changing parameter values with
the alter system command, were shown in this discussion, too.
The final area covered in this chapter was creating a database. The steps
required for preparing the OS were described, such as making sure the
hardware capacity, such as CPU, memory, and disk space, were up to the
task of managing the Oracle database you want to run. The required
changes to be made to the parameter file were also described. The
importance of
changing DB_NAME, DB_DOMAIN, DB_BLOCK_SIZE, DB_BLOCK_BUFFERS, P
ROCESSES, ROLLBACK_SEGMENTS, LICENSE_MAX_SESSIONS,LICENSE_M
AX_WARNING, and the LICENSE_MAX_USERS parameters to reflect the
uniqueness of this database from others on the host machine or on the
network in your organization was addressed.
Finally, the steps of database creation were also discussed. First, the DBA
should back up existing databases associated with the instance, if any, in
order to prevent data loss or accidental deletion of a disk file resource. The
next thing that should happen is that the DBA should create a parameter file
that is unique to the database being created. Several initialization
parameters were identified as needing to be set to create a database. After
the parameter file is created, the DBA can execute
the createdatabase command, which creates disk files for a special
resource called the SYSTEM tablespace, and other disk files for online redo
logs. Oracle also uses the settings in the initsid.ora file to make
appropriate changes to control files, database block size, and other things.
The SYSTEM tablespace will contain at least one system rollback segment,
which must be allocated in order for Oracle to start, and all the tables and
views that comprise the Oracle data dictionary. After creating the database,
the DBA should back up the new database to avoid needing to create it from
scratch in the event of a problem later.
Two-Minute Drill
Several structures are used to connect users to an Oracle server. They
include memory structures like the System Global Area (SGA) and
Program Global Area (PGA), network processes like listeners and
dispatchers, shared or dedicated server processes, and background
processes like DBW0 and LGWR.
The SGA consists of the buffer cache for storing recently accessed data
blocks, the redo log buffer for storing redo entries until they can be
written to disk, and the shared pool for storing parsed information about
recently executed SQL for code sharing.
DBW0 writes data to disk in three cases. They are every 3 seconds (when
a timeout occurs), when LGWR tells it to (during a checkpoint), and when
the buffer cache is full and a server process needs to make room for
buffers required by user processes.
Server processes are like genies from the story of Aladdin because they
retrieve data from disk into the buffer cache according to the user’s
command.
There are two configurations for server processes: shared servers and
dedicated servers. In dedicated servers, a listener process listens for
users connecting to Oracle. When a listener hears a user, the listener
tells Oracle to spawn a dedicated server. Each user process has its own
server process available for retrieving data from disk.
The commit statement may trigger Oracle to write changed data in the
buffer cache to disk, but not necessarily. It only makes a redo log buffer
entry that says all data changes associated with a particular transaction
are now committed.
There are two privileges DBAs require to perform their function on the
database. In Oracle authentication environments, they are
called sysdba and sysoper.
To use Oracle authentication, the DBA must create a password file using
the ORAPWD utility.
The tool used to start and stop the database is called Server Manager.
This tool is usually run in line mode.
Another tool for managing database administration activity is Oracle
Enterprise Manager (OEM). OEM has many administrative tools available,
including Backup Manager, Data Manager, Daemon Manager, Instance
Manager, Replication Manager, Schema Manager, Security Manager, SQL
Worksheet, Storage Manager, Net8 Assistant, Software Manager.
startup mountStarts the instance and mounts but does not open the
database.
When a database is open, any user with a username and password and
the create session privilege can log into the Oracle database.
You can obtain values for initialization parameters from several sources:
Trace files and ALERT logs are found in the directory identified by
the BACKGROUND_DUMP_DEST parameter in the initsid.ora file.
Are there enough individual disk resources to run Oracle without I/O
bottlenecks?
Is there enough CPU, memory, and disk space for Oracle processing?
Are disk resources for different Oracle databases on the same host in
separate directories?
Chapter Questions
1. The user is trying to execute a select statement. Which of the
following background processes will obtain data from disk for the
user?
A. DBW0
B. LGWR
C. SERVER
D. USER
E. DISPATCHER
A. sysdba or sysoper
B. CONNECT or RESOURCE
A. Buffer cache
B. Private SQL area
D. Library cache
E. Row cache
A. Each user gets their own server process for data retrieval
A. DB_BLOCK_BUFFERS
B. BUFFER_SIZE
C. DB_BLOCK_SIZE
D. ROLLBACK_SEGMENTS
A. SYSTEM tablespace
B. initsid.ora file
D. ALERT log
B. RPT_BATCH
C. CONNECT
D. internal
E. audit
A. CHANGE_ON_INSTALL
B. NO_PASSWORD
C. MANAGER
D. ORACLE
E. NULL
A. ORAPWD
D. A password file
A. shutdown normal
B. shutdown immediate
C. shutdown abort
D. shutdown force
E. shutdown recover
A. Schema Manager
B. Instance Manager
C. Security Manager
D. Data Manager
E. Software Manager
12. Which two of the following items are required for killing a user
session?
A. Username
B. SID
C. Serial number
D. Password
ExplanationThe server process handles data access and retrieval from disk
for all user processes connected to Oracle. Choice A, DBW0, moves data
blocks between disk and the buffer cache, and therefore is not correct.
Choice B, LGWR, copies redo entries from the redo log buffer to online redo
logs on disk, and therefore is not correct. Choice D, USER, is the process for
which the server process acts in support of. Choice E, DISPATCHER, i s used
in Oracle MTS architecture and routes user processes to a server, but does
not handle reading data from disk on behalf of the user process.
2. A.sysdba or sysoper
ExplanationChoices B and C are incorrect. Each privilege listed has some
bearing on access, but none of them give any administrative ability. Refer to
the discussion of choosing an authentication method.
3. Library cache D.
4. Each user gets their own server process for data retrieval A.
5. C.DB_BLOCK_SIZE
ExplanationSince each buffer in the buffer cache is designed to fit one data
block, the size of buffers in the database block buffer cache will be the
same size as the blocks they store. The size of blocks in the database is
determined by DB_BLOCK_BUFFERS. Refer to the discussion of
initialization parameters to be changed during database creation.
6. SYSTEM tablespace A.
7. D.internal
8. CHANGE_ON_INSTALL A.