Some of these are: • Parameter file: used to define the characteristics of an Oracle instance • Archived redo log files: offline copies of the redo log files that may be necessary to rec
Trang 1Connecting to a Database
Apart from the database files, an Oracle server also uses other files Some of
these are:
• Parameter file: used to define the characteristics of an Oracle instance
• Archived redo log files: offline copies of the redo log files that may be
necessary to recover from media failures
The following sections of this lesson explain how a server process uses some
of the components of the Oracle instance and the database to service
requests made by a user process
1-9 Copyright Oracle Corporation, 1998 All rights reserved.
Database
Other Key Physical Structures
Archived log files
Password
file
Parameter
file
Trang 2Running a Query
The following are the main stages in the processing of a query:
1 Parse: In this stage, the user process sends the query to the server process
with a request to parse or compile the query The server process checks
the validity of the command and uses the area in the SGA known as the
shared pool to compile the statement At the end of this phase, the server
process returns the status—that is, success or failure of the parse
phase—to the user process
2 Execute: During this phase in the processing of a query, the server
process prepares to retrieve the data
3 Fetch: The rows that are retrieved by the query are returned by the server
to the user during this phase Depending on the amount of memory used
for the transfer, one or more fetches are required to transfer the results of
a query to the user
Instructor Note
This slide has a build There are three stages
1-10 Copyright Oracle Corporation, 1998 All rights reserved.
User process
Server process
Processing a Query
Parse
Statement
OK Handle
ExecuteOK
Handle
FetchResults
SELECT *
FROM emp
ORDER BY ename;
Trang 3Running a Query
The shared pool is a part of the SGA that is used during the parse phase The
size of the shared pool is specified by the initialization parameter,
SHARED_POOL_SIZE in the parameter file The components of the shared
pool described below are used to parse an SQL statement
Library Cache
The library cache stores the following information about the most recently
used SQL statements:
statement as determined by the optimizer
Since the library cache stores this information, if a query is reexecuted
before its execution plan is aged out by other statements, the server process
does not need to parse the statement Thus the library cache helps improve
the performance of applications
1-11 Copyright Oracle Corporation, 1998 All rights reserved.
The Shared Pool
• Size defined by SHARED_POOL_SIZE
• Library cache contains statement text,
parsed code, and an execution plan
• Data dictionary cache contains table
and column definitions and privileges
Shared pool
Library cache
Data dictionary cache
Trang 4Data Dictionary Cache
The data dictionary cache, also known as the dictionary cache or row cache,
is a part of the shared pool that stores the most recently used data dictionary
information, such as table and column definitions, usernames, passwords,
and privileges
During the parse phase, the server process looks for the information in the
dictionary cache to resolve the object names specified in the SQL statement
and to validate the access privileges If necessary, the server process initiates
the loading of this information from the data files
Trang 5Running a Query
When a query is processed, the server process looks for the blocks needed in
the database buffer cache If the block is not found in the database buffer
cache, the server process reads the block from the data file and places a copy
in the buffer cache Subsequent requests for the same block are likely to find
the block in memory, and may not require physical reads
Function of the Database Buffer Cache
The database buffer cache, or simply the buffer cache, is an area in the SGA
that is used to store the most recently used data blocks The size of each
buffer in the buffer cache is equal to the size of a data block, and it is
specified by the DB_BLOCK_SIZE parameter The number of buffers is
equal to the value of the DB_BLOCK_BUFFERS parameter The Oracle
server uses a least recently used (LRU) algorithm to age out buffers that
have not been accessed recently to make way for new blocks to be
accommodated in the buffer cache
1-12 Copyright Oracle Corporation 1998 All rights reserved
Database Buffer Cache
• Number of buffers defined by
DB_BLOCK_BUFFERS
• Size of a buffer based on DB_BLOCK_SIZE
• Stores the most recently used blocks
Trang 6The Program Global Area (PGA) is a memory region that contains data and
controls information for a single server process or a single background
process In contrast to the SGA, which is shared and written to by several
processes, the PGA, which is also called the process global area, is an area
that is used by only one process When using the dedicated server
configuration, the PGA contains:
are processed or returned to the user
• Cursor state: which indicates the stage in the processing of various
cursors that are currently used by the session
The PGA is allocated when a process is created and deallocated when the
process is terminated
Note
Some of these structures are stored in the SGA when using an MTS
1-13 Copyright Oracle Corporation, 1998 All rights reserved.
Program Global Area (PGA)
• Not shared and not writable
Trang 7What follows are the steps used in executing the update statement:
1 The server process reads the data and rollback blocks from the data files,
if they are not already in the buffer cache
2 Copies of the blocks that are read are placed in the buffer cache
1-14 Copyright Oracle Corporation, 1998 All rights reserved.
Instance SGA Shared pool
Library cache Redo log
buffer
Database buffer cache
Data dictionary cache
Control files
Redo log files Data files
Database
2
3 4 5
Trang 84 The server process records the changes to be made to the rollback
(before-image) and to the data (new value) in the redo log buffer
updates the data block, both in the database buffer cache Both the
changed blocks in the buffer cache are marked as dirty buffers—that is,
buffers that are not the same as the corresponding blocks on the disk
Note
The processing of a DELETE or INSERT command uses similar steps The
before-image for a delete contains the column values in the deleted row,
while inserts just require the row location information to be stored in the
rollback
Instructor Note
• The slide explaining the processing of a DML command has builds
There are five stages
• You may want to ask the students what the DML commands are In the
current context we are referring to only the INSERT, UPDATE, and
DELETE commands
Trang 9Running a DML Statement
Before making a change, the server process saves the old value into a
rollback segment This image is used to:
the DML statement (read consistency)
• Recover the database to a consistent state in case of failures
Rollback segments, like tables and indexes, exist in data files and parts of
them are brought into the database buffer cache when required
1-15 Copyright Oracle Corporation, 1998 All rights reserved.
Rollback Segment
DML statement
Old image
New image Rollback
segment
Table
Trang 10The server process records changes made by an instance in the redo log
buffer, which is a part of the SGA The redo log buffer has the following
characteristics:
• It stores redo records, which record changes—that is, the block that is
changed, the location of the change, and the new value A redo entry
registers a change, but it makes no distinction between the type of block
that is changed So it cannot distinguish, for example, a change to a data
block from a change to an index or a rollback block
transaction may be interleaved with changes made by other transactions
• It is a circular buffer that is reused after it is filled up, but only after all
the old redo entries are recorded in the redo log files
Note
The redo log files are covered in more detail in the lesson “Maintaining
Redo Log Files.”
1-16 Copyright Oracle Corporation, 1998 All rights reserved.
Redo Log Buffer
• Size defined by LOG_BUFFER
• Records changes made through the
instance
• Used sequentially
• Circular buffer
Trang 11Running a DML Statement
The server process records changes to rollback and data blocks in the buffer
cache The database writer (DBWR) writes the dirty buffers from the
database buffer cache to the data files It ensures that sufficient number of
free buffers—buffers that can be overwritten when server processes need to
read in blocks from the data files—are available in the database buffer cache
Database performance is improved because server processes only make
changes in the buffer cache, and the DBWR defers writing to the
data files until one of the following events occur:
buffers and cannot find any
of the database, (Checkpoint is a means of synchronizing the database
buffer cache with the data file.)
Note
Checkpoints are covered in detail in the lesson “Managing Redo Log Files.”
1-17 Copyright Oracle Corporation, 1998 All rights reserved.
Instance SGA Shared pool
DBWR
Database buffer cacheDatabase Writer (DBWR)
Control files
Redo log files Data files
Trang 12The Log Writer (LGWR) is a background process that writes entries from the
redo log buffer into the redo log files The LGWR performs sequential
writes to the redo log file under the following situations:
data files
Instructor Note
You may want to inform the students that although there is a timeout, on a
busy OLTP system, this may never occur because other events may occur
more frequently
1-18 Copyright Oracle Corporation, 1998 All rights reserved.
Instance SGA Shared pool
Redo log buffer
LGWRLog Writer (LGWR)
Control files Redo log files Data files
Trang 13COMMIT Processing
COMMIT Processing
Oracle uses a fast commit mechanism that guarantees that the committed
changes can be recovered in case of failures
System Change Number
Whenever a transaction commits, the Oracle server assigns a commit System
Change Number (SCN) to the transaction, which is monotonically
incremented and is unique within the database The SCN is used by the
Oracle server as an internal “time stamp” to synchronize data and to provide
read consistency when data is retrieved from the data files Using the SCN
allows the Oracle server to perform consistency checks without depending
on the date and time of the operating system
Steps in Processing COMMITs
When a COMMIT is issued, the following steps occur:
redo log buffer
to and including the commit record to the redo log files After this point,
the Oracle server can guarantee that the changes will not be lost even in
case of failures
1-19 Copyright Oracle Corporation, 1998 All rights reserved.
Shared pool
Redo log buffer
LGWR
Control files
Redo log files Data files
SGA Instance
Trang 144 The server process records information to indicate that the transaction is
complete and that resource locks can be released
Flushing of the dirty buffers to the datafile is performed independently by
DBWR, and can take place either before or after the commit
Note
Rolling back a transaction does not trigger LGWR to write to disk The
Oracle server always rolls back uncommitted changes when recovering from
failures If there is a failure after a rollback, before the rollback entries are
recorded on disk, the absence of a commit record is sufficient to ensure that
the changes made by the transaction are rolled back
Advantages of the Fast COMMIT
The use of these steps for processing COMMITs has the following
advantages:
• Sequential writes to the log files are faster than writing to different
blocks in the data file
to the log files, whereas writing to the data files would require whole
blocks of data to be written
transactions requesting to commit at the same time into a single write
• Unless the redo log buffer is particularly full, only one synchronous
write is required per transaction (can be less than one synchronous write
per transaction)
an actual COMMIT operation
Instructor Note
• Even though LGWR may write through the operating system buffer
cache, synchronous writes are used to ensure that confirmation of a
commit is only made after data is written to disk
• The COMMIT processing slide has builds There are four stages
Trang 15Summary
Instructor Note
• Lessons have a summary showing the following:
- A summary slide highlighting the most important objectives for the
lesson
- A Quick Reference listing the initialization parameters, commands,
and packages discussed in the lesson
• You may want to ask the students how users specify the database they
want to connect to, and emphasize the terms instance and database.
1-20 Copyright Oracle Corporation, 1998 All rights reserved.
Instance SGA Shared pool
Database
Control files
Data files Redo log
files
User
process
Server process PGA
Summary
Password file
Archived log files Parameter
file
Trang 16Quick Reference
Server process Background processes:
- DBWR
- LGWR
- Shared pool
- Database buffer cache
- Redo log buffer PGA
Physical structures (files) Database files:
Trang 17
2
Using Administration
Tools
Trang 19Objectives
Instructor Note
The purpose of this lesson is to ensure that participants get acquainted with
the use of the following tools:
• Server Manager Line Mode
• Oracle Enterprise Manager
It is not intended to provide details of all the components of OEM
2-2 Copyright Oracle Corporation, 1998 All rights reserved.
Objectives
• Using the Server Manager Line Mode
• Identifying administration applications
supplied with the Oracle Enterprise
Manager
• Using Oracle Enterprise Manager
components
Trang 20The table lists the common database administration tools and tasks that a
database administrator can perform using the tools
These tools will be covered in this course, but they are only a subset of the
utilities supplied by Oracle The commands for starting up the different tools
depend on the platform
This lesson will introduce the use of the following tools that assist a DBA in
performing administrative tasks:
Note
In addition to these tools, NT-specific utilities like ORADIM80 or Oracle
Database Assistant for creation of an Oracle database will be covered in the
lessons “Managing an Oracle Instance” and “Creating a Database.”
2-3 Copyright Oracle Corporation, 1998 All rights reserved.
Export or Import utility
Password File utility
Description
A line mode utility used for administrative tasks like starting up, shutting down or recovering a database
Graphical user interface to administer, monitor, and tune multiple databases.
Utility for loading data from external files into Oracle tables Utility for exporting/importing data in Oracle format
Utility for creating database password file
Database Administration
Tools: Examples
Trang 21Using the Server Manager
Using the Server Manager
Server Manager line mode is useful for performing unattended operations,
such as running nightly batch jobs or scripts In addition, you can use line
mode when a graphical interface is unavailable
Starting Server Manager in Line Mode
Start Server Manager in line mode by entering the appropriate command at
the operating system prompt For example, on some systems the command
svrmgrl starts up Server Manager in line mode.
You can also start Server Manager in line mode and execute a script
Note
The exact command for starting Server Manager in line mode depends on
your platform For information about starting Server Manager in line mode,
see your operating system–specific Oracle documentation
2-4 Copyright Oracle Corporation, 1998 All rights reserved.
Starting Server Manager in
Line Mode
Starting and executing a script:
svrmgrl command=@credb.sql svrmgrl command=“CONNECT scott/tiger”