Professional Documents
Culture Documents
Instructor's Notes
(If applicable)
Lesson 18: Managing Control Files
This hands-on lesson will teach you how to protect, add, backup and recreate
control files.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
In this course, the control file was introduced in the lessons on database
architecture. Let's spend a minute to review the major concepts
The control file is a relatively small file typically a few megabytes which
contains control information for the database. This information includes the
name of the database, the name and location of the database files, the names of
the online and archived redo log files and information required for database
recovery.
The control file is read at startup time (specifically, when the database is
mounted). Reading the control file gives the instance the names and locations of
the datafiles and redo log files. If the control file is not available then the
instance will not mount (i.e start). The control file is also updated during normal
database operations:
o
Other Text:
(Examples or comments displayed on slide, if any).
SQL> select name
2 from v$controlfile;
NAME
-----------------------------------C:\ORACLE\ORADATA\DAVE\CONTROL01.CTL
C:\ORACLE\ORADATA\DAVE\CONTROL02.CTL
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
As we will learn in this lesson, it is easy for the database administrator to keep
more than one copy of the control file. These copies should obviously be on
separate disk drives to guard against loss of the entire disk. Query the
V$CONTROLFILE view to determine the name and location of current in-use
control files.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Refer to the lesson on Backup and Recovery for detailed instructions on backing
up the control file with RMAN.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
The administrator will be responsible for restoring the control file if all copies
are lost. This should not happen! Remember, you will have a minimum of two,
preferably three or four copies of the control file on separate disk devices.
However, if you do lose all copies, you can restore from backups or recreate
with the CREATE CONTROLFILE command. (We will study the CREATE
CONTROLFILE command in this lesson.)
Another reason to use the CREATE CONTROLFILE command is to recreate
the control file to change the "fixed" parameter values specified on the CREATE
DATABASE command. A little background information on CREATE
DATABASE command (which is covered in detail in the Creating a New
Database lesson): The control file is created by the CREATE DATABASE
command. The parameters specified on CREATE DATABASE cause Oracle to
reserve records (also known as "slots") in the control file. For example,
"MAXLOGFILES 5" will reserve 5 slots for recording the names of redo logs.
If, over time, you determine that the database will perform better with 10 log
files, you will need to recreate the control file which a larger
MAXLOGFILES value to add more slots.
Yet another reason to situation that would require control file to be recreated
would be when moving a database to a new server where the directory structure
does not match the original server.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
We have established that it is critical to maintain more than one at least two
copies of the control file, on separate disk devices. Follow the steps summarized
here and demonstrated in the next few pages if your database does not have
enough control files or you would like to move a control file to a new disk
device.
Other Text:
(Examples or comments displayed on slide, if any).
See the following page for an example
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Start by determining the current in-use control files. This can be accomplished
with a query on the V$PARAMETER2 view as shown above.
V$PARAMETER2 is a new view available with Oracle9i. It is similar to the
V$PARAMETER view in that it shows the current, in-use initialization
parameter values. The difference is that for parameters such as
CONTROL_FILES that contain multiple values it contains one row per value.
The ORDINAL column allows you to extract the parameter values in the order
specified in the parameter file.
2 from v$controlfile;
NAME
--------------------------------------
C:\ORACLE\ORADATA\DAVE\CONTROL01.CTL
C:\ORACLE\ORADATA\DAVE\CONTROL02.CTL
Other Text:
(Examples or comments displayed on slide, if any).
SQL> select value
2 from v$parameter2
3 where name = 'control_files'
4 order by ordinal;
VALUE
------------------------------------C:\oracle\oradata\dave\CONTROL01.CTL
C:\oracle\oradata\dave\CONTROL02.CTL
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
The next step is to cleanly shutdown the database. Use SHUTDOWN,
SHUTDOWN IMMEDIATE or SHUTDOWN TRANSACTIONAL. This is
required to get a consistent copy of the control file. Do not use SHUTDOWN
ABORT because that would cause the control files to be out of sync with the
datafiles .
Next, use the operating system to copy an existing control file to the new
location.
Other Text:
(Examples or comments displayed on slide, if any).
SQL> shutdown transactional
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> $copy C:\ORACLE\ORADATA\DAVE\CONTROL01.CTL
D:\ORACLE\ORADATA\DAVE\CONTROL03.CTL
1 file(s) copied.
Create a new copy of the control file.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
I recommend that you backup the server parameter file (SPFILE) before
you update it. Why? Because I discovered (the hard way) that the
ALTER SYSTEM command will let you put invalid file names in the
CONTROL_FILES parameter and thus cause a failure when you attempt
to restart the database. It is easy to backup the SPFILE; use the CREATE
PFILE FROM SPFILE command as shown above (yes, this command
works with the database shut down). The text parameter file is created in
the default directory, $ORACLE_HOME\database on a Windows server.
Other Text:
(Examples or comments displayed on slide, if any).
Backup SPFILE before changing
SQL> create pfile from spfile;
File created.
Start DB to change SPFILE. Use NOMOUNT so control file is not opened
Update SPFILE SQL> startup nomount
SQL> alter system
2 set control_files = 'C:\oracle\oradata\dave\CONTROL01.CTL' ,
3 'C:\oracle\oradata\dave\CONTROL02.CTL' ,
4 'D:\oracle\oradata\dave\CONTROL03.CTL'
5 scope = spfile
6/
Shutdown the database and restart
System altered.
SQL> shutdown
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Update the SPFILE
The database must be in NOMOUNT mode for this next step. We do not want to
MOUNT the database at this time because the control file would then be opened
and updated and we have not yet told Oracle about our additional new control
file. The ALTER SYSTEM command, as shown above, will update the
CONTROL_FILES parameter in the SPFILE.
CAUTION: Next, shutdown and restart the database. This is a critical step
because when we restart the database the updated parameter file is read and the
instance recognizes the existence of the new control file. Do not do an ALTER
DATABASE MOUNT and ALTER DATABASE OPEN because the new
control file is not recognized. If you do this, the database will open without the
new control file in effect. Therefore the new control file will not be kept in sync
with the existing control files. The next time you shutdown and startup, the new
control file will be opened, but Oracle will give a ORA-00214: control file xxx
version vvv inconsistent with file yyy version www. You can recover from this
error my doing a shutdown and recopying one of the original control files to the
new control file .
If you experience errors when you try to restart the database, shutdown
the database (you will probably be in nomount stage), restore the
original copy of the server parameter file, then restart the database. Use
the CREATE SPFILE command to restore the server parameter file:
o
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Instructor's Notes
(If applicable)
In addition to protecting the control file, backing up the control file is also a
primary responsibility of the DBA. This can be accomplished:
o With user-managed backups.
o
The example shown above uses the "TO TRACE" option to create a script to
recreate the control file. The script is written to the USER_DUMP_DEST
directory. Unfortunately, the name of the script is not intuitive or obvious. It will
typically follow the format "SID_ora_SPID.trc", where SID is the database
system id and SPID is the session process id of the session that executed the
ALTER DATABASE command. The easiest method of determining which file
in the USER_DUMP_DEST directory is the script file is by the date/time stamp.
However, we can get more precise. The SID can be found with this query:
INSTANCE_NAME
---------------
dave
Other Text:
(Examples or comments displayed on slide, if any).
SQL> alter database backup controlfile to trace;
Database altered.
SQL> show parameter user_dump_dest
NAME VALUE
---------------------------------- -------------------------user_dump_dest C:\oracle\admin\class\udump
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
The SPID can be found unless you are connected as SYSDBA - by executing
this query:
SQL> select a.spid
SPID
------------
1752
If the session that ran the ALTER DATABASE command was connected as
SYSDBA, the SPID's of all sessions are returned. In this case, you are back to
searching using the file date/time stamp.
The following pages in this lesson will describe the process of using this script
to recreate a control file.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
A new control file can be created with the CREATE CONTROLFILE
command. This can be useful when you have lost all copies of the current
control file, you are moving the database to a server with different mount points
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
Procedure continues
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
vsnsql=12 vsnxtr=3
# LOG_ARCHIVE_DEST=''
# LOG_ARCHIVE_DUPLEX_DEST=''
# LOG_ARCHIVE_FORMAT=ARC%S.%T
# REMOTE_ARCHIVE_ENABLE=TRUE
# LOG_ARCHIVE_START=TRUE
# LOG_ARCHIVE_MAX_PROCESSES=2
# STANDBY_FILE_MANAGEMENT=MANUAL
# STANDBY_ARCHIVE_DEST=%ORACLE_HOME%\RDBMS
# FAL_CLIENT=''
# FAL_SERVER=''
# LOG_ARCHIVE_DEST_1='LOCATION=c:\oracle\oradata\dave\archive\'
# LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE
NODEPENDENCY'
# LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE
NOQUOTA_USED'
# LOG_ARCHIVE_DEST_STATE_1=ENABLE
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
# Below are two sets of SQL statements, each of which creates a new
# control file and uses it to open the database. The first set opens
# the database with the NORESETLOGS option and should be used only if
# the current versions of all online logs are available. The second
# set opens the database with the RESETLOGS option and should be used
# The appropriate set of statements can be copied from the trace into
# The following commands will create a new control file and use it
# Data used by the recovery manager will be lost. Additional logs may
# be required for media recovery of offline data files. Use this
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXDATAFILES 1000
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
-- STANDBY LOGFILE
'C:\ORACLE\ORADATA\DAVE\SYSTEM01.DBF',
'C:\ORACLE\ORADATA\DAVE\UNDOTBS01.DBF',
'C:\ORACLE\ORADATA\DAVE\CWMLITE01.DBF',
'C:\ORACLE\ORADATA\DAVE\DRSYS01.DBF',
'C:\ORACLE\ORADATA\DAVE\EXAMPLE01.DBF',
'C:\ORACLE\ORADATA\DAVE\INDX01.DBF',
'C:\ORACLE\ORADATA\DAVE\ODM01.DBF',
'C:\ORACLE\ORADATA\DAVE\TOOLS01.DBF',
DATAFILE
'C:\ORACLE\ORADATA\DAVE\XDB01.DBF',
'C:\ORACLE\ORADATA\DAVE\O1_MF_USERS_ZMNKR400_.DBF'
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Next, use SQL*Plus to login with SYSDBA privileges and execute the
script. Check for errors. If everything is OK, shutdown the database and
perform a full cold backup.
Note that since the database parameter file contains the location of the control
files, the script above will create all control file copies.
Other Text:
(Examples or comments displayed on slide, if any).
SQL> connect system/dave as sysdba
Connected.
SQL> shutdown
SQL> @create_controlfile
ORACLE instance started.
Total System Global Area 126950220 bytes
Fixed Size 453452 bytes
Variable Size 96468992 bytes
Database Buffers 29360128 bytes
Redo Buffers 667648 bytes
Control file created.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Lesson 17: Managing Redo Logs
In this lesson we will cover redo log concepts and a DBAs responsibilities to
redo logs, including archiving online logs, multiplexing online and archive logs
and avoiding log switch waits.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
We learned about REDO, online logs and archived logs in the lessons on
database architecture. Let's take a moment to review the basics
The online redo log files are used to record changes made to the database files.
As an update is applied to the database, Oracle automatically creates a "redo"
record. The redo contains the after-image of the change and is used in the event
the change needs to be reapplied, e.g. a recovery operation.
This redo record is written to the redo buffer. When a commit is issued, the redo
is flushed to the redo log file by the log writer background process (LGWR).
The logs are used in cyclical rotation. When one redo log file fills a log switch
occurs and Oracle begins writing redo to the next log file. At least two log files
must exist. Specifically, when a log fills:
o
A checkpoint is initiated for that log (i.e. the blocks changed by the
operations recorded in the log are flushed to disk by the DBWR
background process).
A log switch occurs - Oracle starts writing to the next log in the
rotation.
Other Text:
(Examples or comments displayed on slide, if any).
Online Logs
Redo Buffer
Redo Buffer
LGWR
SGA
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
The dynamic performance view V$LOGFILE contains a row for each online log
defined to the database.
The V$LOG view contains, for each log group, the size of the logs in the group.
A group can contain more than one log file. Log files in a single group are
mirror images of each other. This multiplexing concept protects against the loss
of a disk device containing an online log. See the section on Multiplexing in this
lesson for more information.
Supplemental Notes
There is no advantage to having different size log files. In fact, there is a
disadvantage - tuning is near impossible. The decision of how many and
how big your log files are is a tuning issue.
Other Text:
(Examples or comments displayed on slide, if any).
SQL> select member
2 from v$logfile;
MEMBER
----------------------------------C:\ORACLE\ORADATA\DAVE\REDO01.LOG
C:\ORACLE\ORADATA\DAVE\REDO02.LOG
C:\ORACLE\ORADATA\DAVE\REDO03.LOG
Active online logs
SQL> select group#, bytes
2 from v$log;
GROUP# BYTES
---------- ---------1 104857600
2 104857600
3 104857600
Group number and size
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
If the archive background process is running and the database is in
ARCHIVELOG mode, the ARCH background process will write a filled log file
to an archive location so that the changes will not be lost when the log file is
needed again (and its contents are overwritten). Oracle9i supports multiplexing
the archive logs, i.e. writing the archive logs to multiple locations (up to 10).
If the archive process is not active you cannot recover your database after a
MEDIA (disk) failure!
Other Text:
(Examples or comments displayed on slide, if any).
LGWR
SGA
Redo Buffer
Online Logs
Archive Logs
Instructor's Notes
(If applicable)
Some of the primary responsibilities of the DBA regarding redo logs are to
insure the recoverability of the database by:
o Insuring that the redo logs are archived (thus preserving the contents)
o
Multiplexing the online logs (thus protecting against the loss of redo
though loss of a disk device)
Additionally, having enough online logs will prevent the database from waiting
for a log as it cycles through the available logs. Adding more log files can fix
this problem.
In this lesson we will focus our study on learning the techniques necessary to
fulfill the responsibilities stated here. Let's get started
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> show parameter log_archive_start
NAME TYPE VALUE
--------------------- ------------ ----log_archive_start boolean TRUE
SQL> select log_mode from v$database;
LOG_MODE
-----------ARCHIVELOG
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Yet another way to check on the archive status of your database is to use the
SQL*Plus command ARCHIVE LOG LIST. This command displays the log
mode, whether the automatic archive (ARCH) process is active, the archive log
file destination and the current log sequence number.
The two main points we can determine from the output of the ARCHIVE LOG
LIST command are:
o
Database Log Mode When in "Archive Mode", the database will not
overwrite an online redo log until it has been archived. This is the
desired mode.
Other Text:
(Examples or comments displayed on slide, if any).
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination C:\Oracle\oradata\dave\archive
Oldest online log sequence 111
Next log sequence to archive 113
Current log sequence 113
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
You will want to insure that you are archiving to protect the redo generated by
database operations. There are two steps:
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
###########################################
# Archive
###########################################
log_archive_dest_1='LOCATION=C:\Oracle\oradata\dave\archive'
log_archive_format=%S.arc
log_archive_start=true
Database parameter file contains
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
First, insure that the archive background process starts when the database is
started. This is done by setting initialization parameter
LOG_ARCHIVE_START = TRUE.
If using a text INIT.ORA file (the only option in pre-9i databases), simply edit
the text file and restart the database as shown on the previous page.
If you are using a Server Parameter file (SPFILE), execute the ALTER
SYSTEM command as shown in the example above. Since
LOG_ARCHIVE_START is not a dynamic parameter (it is a static parameter),
we need to alter the SPFILE then restart the database (as the example
demonstrates).
Next, we will put the database in ARCHIVELOG mode. Turn to the next page
for an example.
Other Text:
(Examples or comments displayed on slide, if any).
SQL> alter system
2 set log_archive_start = true
3 comment = 'dga, 6/6/03'
4 scope = spfile;
System altered.
SQL> shutdown immediate
...
SQL> startup
ORACLE instance started.
...
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
Shutdown the database cleanly, then mount
SQL> shutdown
SQL> startup mount
ORACLE instance started.
...
SQL> alter database archivelog;
Statement processed.
SQL> alter database open;
Statement processed.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Archiving Workshop
1. Check the ARCHIVELOG mode of your database.
Instructor's Notes
(If applicable)
We have learned that protecting archived redo is one of our main responsibilities
because without archived redo we cannot recover the database from a disk
failure. To meet this responsibility we should "multiplex" the archived redo
logs. When we multiplex the archive logs, the archive background process
simultaneously writes the logs to all locations up to 10 that we specify in the
initialization parameters LOG_ARCHIVE_DEST_n. These logs are mirror
images of each other.
By default many databases use the old LOG_ARCHIVE_DEST and
LOG_ARCHIVE_DUPLEX_DEST parameters. These parameters have been
deprecated with Oracle9i and replaced by LOG_ARCHIVE_DEST_n, where
"n" is 1 to 10. (Note that Standard Edition does not support 10 locations, just
two; therefore, LOG_ARCHIVE_DEST and
LOG_ARCHIVE_DUPLEX_DEST have not been deprecated with Standard
Edition.)
The example above demonstrates how to multiplex the archive logs on a system
that currently used the LOG_ARCHIVE_DEST parameter to specify just one
archive destination. Here's a description of the steps:
First, I alter the database to remove the current setting of
LOG_ARCHIVE_DEST parameter. This is required because the
LOG_ARCHIVE_DEST parameter is mutually exclusive with the
LOG_ARCHIVE_DEST_n parameters.
o
Other Text:
(Examples or comments displayed on slide, if any).
SQL> alter system
2 set log_archive_dest = ''
3 scope = both;
System altered.
SQL> alter system
2 set log_archive_dest_1 = "location=c:\archive\ mandatory"
3 scope = both;
System altered.
SQL> alter system
2 set log_archive_dest_2 = "location=d:\archive2\ mandatory"
3 scope = both;
System altered.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Notes continued from the previous page:
o Next, I set LOG_ARCHIVE_DEST_1 and LOG_ARCHIVE_DEST_2
parameters to the desired locations. This causes Oracle to create two
mirror-image archive logs for each online redo log file. Note that I have
specified "mandatory" for both locations. This means that Oracle will
not overwrite the online redo log until it have been copied to both
locations. You can also specify "optional". At least one location must be
specified as mandatory.
CAUTION
Instructor's Notes
(If applicable)
The V$ARCHIVE_STATUS view contains the current status of the archive log
destinations.
In this example we see that - as a result of the commands executed in the
previous example - destinations 1 and 2 are active and mandatory. We can also
see the destination directories.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
Multiplex Archive Logs Workshop
1. Determine the current status of your databases archive logs, with respect
to location and multiplexing.
2. If your database is not multiplexing the archive redo log, multiplex the
log. Specify two mandatory locations for the log. If the computer you
are using for these workshops has two disks available, place the archive
logs on separate disks. (If your database is already multiplexing the
online logs, try adding another multiplexed location.)
3. Query the V$ARCHIVE_DEST view to insure the configuration
multiplexes the archive log.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
If the DBWR background process has not finished checkpoint operation for a
log (remember that a log switch causes a checkpoint), and that log is needed by
LGWR (i.e. it is the next log in the cycle), the database will suspend all
operations until the checkpoint is complete.
You can detect this problem by searching your alert log for the "checkpoint not
complete, cannot allocate new log" messages.
Possible solutions to this problem include adding more log files, speeding up
checkpoints and decreasing the log file size to increase the number of
checkpoints taken.
Note that this is a Tuning issue and covered in more detail in SkillBuilders'
Database Performance and Tuning course.
Other Text:
(Examples or comments displayed on slide, if any).
Tuning course covers in more detail
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
If you determine that additional logs are necessary, they can easily be added
with the ALTER DATABASE ADD LOGFILE command, as shown in the
example above. Refer to the next page for an example of adding OMF-managed
logs.
Because we are modifying the structure of the database, the instance must be
started in a MOUNT mode. Remember that having the instance in a mounted
state means that the control file is open - the names of the new redo log file can
be recorded in the control file(s).
Other Text:
(Examples or comments displayed on slide, if any).
ALTER DATABASE ADD LOGFILE
'C:\Oracle\oradata\dave\redo03.log' SIZE 100m;
See next page for more info!
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Oracle Managed Files (OMF) gives the database the ability to manage database
files, including datafiles, online redo log files, and control files. Oracle will
create, name, and locate physical files for you and will delete them from the
operating system automatically when you drop objects the file is associated
with.
OMF is an optional feature and, even when configured, is not mandatory.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
This example demonstrates the use of the Oracle9i feature Oracle Managed
Files (OMF) to add OMF-managed redo logs.
First, insure the DB_CREATE_ONLINE_DEST_n parameters are set correctly.
DB_CREATE_ONLINE_DEST_n specifies the location of the online logs. Up
to 5 can be specified so that, like the archive logs, you can multiplex the online
logs.
Be sure that all the online logs are the same size. Tuning is made more difficult
(impossible?) is the logs are different sizes. Add the SIZE parameter to the
ALTER SYSTEM command if the database does not use 100Mb log files:
Turn to the next page for more information on multiplexing the online logs.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
As illustrated above, the online redo log files can be easily multiplexed (also
known as "mirrored logs"). Thus, each group can have any number of members,
where each member in the group is a mirror-image of another member. Ideally
the members would be placed on separate disk devices. This technique greatly
reduces the chance of losing a log file and being unable to recover the database.
Supplemental Notes
Note that multiplexing generally results in faster commits, not slower!
This is because Oracle signals the completion of a commit as soon as
any one of the mirrored log files has been written.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Multiplexing the online logs when using OMF is easy. Just set the
DB_CREATE_ONLINE_LOG_DEST_n parameters (where "n" is 1, 2, 3, 4 or
5). This was demonstrated in the previous example. Then simply execute the
ALTER DATABASE ADD LOGFILE command. Oracle takes care of the rest.
To manually add new members to existing groups, we will need to know what
groups and members currently exist. Querying V$LOGFILE will reveal what
log files currently exist and what group they belong to.
Supplemental Notes
Note that you cannot drop a logfile group or a member of a group if the
group is the active group. You must first force a log file switch:
o
You may have to force a checkpoint too so the the redo in the log is not
needed for crash recovery:
o
Other Text:
(Examples or comments displayed on slide, if any).
SQL> alter database add logfile;
Database altered.
OMF does automatically
Find existing groups & members
1 SELECT group#, member
2* FROM v$logfile
SQL> /
GROUP# MEMBER
---------- --------------------------------1 C:\ORACLE\ORADATA\DAVE\REDO01.LOG
2 C:\ORACLE\ORADATA\DAVE\REDO02.LOG
3 C:\ORACLE\ORADATA\DAVE\REDO03.LOG
Manually add new members; OMF not used
ALTER DATABASE ADD LOGFILE MEMBER 'C:\Oracle\oradata\multi\redo01b.log' TO
GROUP 1;
ALTER DATABASE ADD LOGFILE MEMBER 'C:\Oracle\oradata\multi\redo02b.log' TO
GROUP 2;
ALTER DATABASE ADD LOGFILE MEMBER 'C:\Oracle\oradata\multi\redo03b.log' TO
GROUP 3;
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Redo Log Workshop
1. Use V$LOG and V$LOGFILE to determine the number and size of the
existing log files.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Lesson 16: Managing Undo
We will start by defining the term undo and introducing the two methods of
managing: manual and automatic. We will then learn the new method,
Automatic Undo Management (AUM) in detail. Automatic Undo Management
(AUM) is a new Oracle9i feature that deprecates the configuration and use of
Rollback Segments.
Learn about the concepts and architecture of AUM. This will also
uncover the benefits of AUM.
o
o
Look at the new data dictionary views available for monitoring and
sizing the AUM tablespace.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
* Quote from Oracle8 DBA Handbook, Kevin Loney, Oracle Press ISBN 0-07882406
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Undo records need disk space. With Oracle9i, there are two methods of
acquiring and managing the disk space, automatic and manual.
In Automatic Undo Management mode, we will create an undo tablespace and
let the database create undo segments within the tablespace. In manual mode,
we are responsible for creating and managing the rollback segments within the
rollback tablespace.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Rollback segments have always been a thorn in the side of Oracle DBAs.
Planning for, creation, monitoring, and maintenance of rollback segments can
sometimes be an onerous task even for experienced DBAs. Until precise
statistics are available, configuring rollback segments is, at best, educated
guesses based on anticipated number and size of transactions your database will
support. The considerations involve:
o how big to make the tablespace(s) that will contain the rollback
segments
o
o
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
And lets not forget about the dreaded snapshot too old errors. These typically
occur when a long running query is accessing data that is being changed by
another transaction; the before image of the data is overwritten in the rollback
segment before the query gets to it.
In summary, tuning rollback segments is an ongoing task and a hassle. So, lets
move on to AUM!
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
OK, now that we know what AUM is, why we want to use it, let's get started
with implementation. If creating a new database with the Oracle9i Database
Configuration Assistant, it is easy; the DBCA automatically creates the database
in AUM mode. Implementing AUM on an existing database involves the
following steps:
1. Planning Check for applications that depend on rollback segments.
Code that includes the SET TRANSACTION USE ROLLBACK
SEGMENT statement will fail unless errors are suppressed. See
initialization parameters later in this lesson to see how to suppress
errors.
2. Create the undo tablespace. We will need to guesstimate the initial size
of our undo tablespace. A starting point can be calculated by multiplying
UNDO per second (transaction rate - see V$UNDOSTAT) * blocksize *
your desired retention period. See chapter 13 of the Oracle9i
Administrators Guide for a complete description of this calculation and
Managing UNDO in general.
3. Adjust the initialization parameters.
4. Bounce the database.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
1 select tablespace_name, status
2 from dba_tablespaces
3* where contents = 'UNDO'
SQL> /
TABLESPACE_NAME STATUS
------------------------------ --------UNDOTBS1 ONLINE
UNDO_DATA_TS ONLINE
Only one will be in use
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
The undo tablespaces cannot be used for anything but undo segments,
else an ORA-30022 error is returned.
Our example omits the EXTENT MANAGEMENT clause; therefore the
default ALLOCATION TYPE of AUTOALLOCATE is used.
Other Text:
(Examples or comments displayed on slide, if any).
Instructor's Notes
(If applicable)
LOGFILE
(c:\oradata\redo\log01a.log',
GROUP 3
(c:\oradata\redo\log03a.log',
GROUP 2
(c:\oradata\redo\log02a.log',
GROUP 1
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Instructor's Notes
(If applicable)
The four AUM-related parameters are described here:
UNDO_MANAGEMENT - Set equal to MANUAL or AUTO. This
parameter is not dynamic. If AUTO is specified, Oracle will use an
UNDO tablespace if available (details on the following slides).
However, if an UNDO tablespace is not available, Oracle will use the
SYSTEM rollback segment which is really NOT a good idea. In fact,
Oracle gets so upset about having to use the SYSTEM rollback segment
that it complains loudly by writing warnings to the alert log.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
o
Flashback Query, but will cause Oracle to keep more undo, requiring a
larger undo tablespace. If an out-of-space condition occurs in the
tablespace, Oracle will start using unexpired undo, which can cause
snapshot too old errors to occur. This is a dynamic parameter.
UNDO_SUPPRESS_ERRORS - (TRUE|FALSE) Provides support for
applications written using manual UNDO commands such as SET
TRANSACTION USE ROLLBACK SEGMENT. Suppresses errors
such as ORA-30019. This parameter can be set at the system level (in
the database parameter file or ALTER SYSTEM) or at the session level
with ALTER SESSION.
After adding these parameters to your database parameter file, shutdown and restart your database to implement AUM.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Assume that UNDO_TABLESPACE = SKILLBUILDERS_OTHER_UNDO
has been specified and we would like to change the UNDO tablespace. To do so,
we would issue the commands shown in this example.
Oracle places the old undo tablespace in PENDING OFFLINE mode which
means that existing transactions continue but the tablespace will not accept new
transaction undo. When all active transactions have committed, the tablespace is
placed in OFFLINE mode.
Other Text:
(Examples or comments displayed on slide, if any).
ALTER TABLESPACE skillbuilders_undo ONLINE;
ALTER SYSTEM
SET UNDO_TABLESPACE = skillbuilders_undo
COMMENT = 'changed on 5-1-2003'
SCOPE = BOTH;
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
An UNDO tablespace may also be dropped provided that it is not in use by any
instance and does not contain information about incomplete transactions.
Additionally, the UNDO_RETENTION parameter is ignored during DROP.
Oracle does not care that you may have specified a six month retention period.
When the DROP is processed, the tablespace is history! It will, however, wait
for active transactions to complete.
Other Text:
(Examples or comments displayed on slide, if any).
DROP TABLESPACE skillbuilders_undo ;
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
The whole point of AUM is the little maintenance required, especially compared
to rollback segments. However, certain columns in the V$UNDOSTAT dynamic
view will help the DBA keep abreast, or better yet ahead, of any potential
problems due to lack of space in the undo tablespace.
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
A description of helpful columns in V$UNDOSTAT:
UNDOBLKS this column contains the total number of undo blocks
generated during period of statistical collection. If this number is far
larger then the UNDO tablespaces size, then the size of the undo
tablespace needs to be increased.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
o
more and more users start to use the system, generating increasing
numbers of undo blocks. The Oracle DBA can increase the value of
parameter UNDO_RETENTION_TIME to get rid of such errors.
Sometimes raising this value is not enough to get rid of all snapshot too
old errors, and the DBA has to additionally add more space to the undo
tablespace.
o MAXQUERYLEN this column contains the value, in seconds, of the
longest-running transaction in the past 24 hours. The undo management
parameter UNDO_RETENTION should be set to a value larger than the
value in MAXQUERYLEN.
NOSPACERRCNT This column keep track of the number of any
space unavailable errors generated when Oracle writes undo transaction
blocks to an undo tablespace. If this value is not zero, increase the size
of the undo tablespace.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
There is also some useful transaction-related information in
V$TRANSACTION and V$ROLLSTAT. V$TRANSACTION contains
information on active transactions. V$ROLLSTAT contains information about
undo segments if operating in AUM mode; rollback segment information if
running in manual mode.
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
If you determine that the undo tablespace is not large enough, adding space can
be accomplished by adding a datafile to the tablespace as shown in this
example.
Other Text:
(Examples or comments displayed on slide, if any).
ALTER TABLESPACE skillbuilders_undo
ADD DATAFILE
'c:\oracle9i\oradata\test\sb_undo02.dbf'
SIZE 10M AUTOEXTEND ON;
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SkillBuilders Advertisement
Instructor's Notes
(If applicable)
AUM Workshop
1. What are the current values of the four AUM parameters for your
database?