Understanding Oracle Database Architecture
Understanding Oracle Database Architecture
The client application attempts to establish a connection to the server using the
proper Net8 driver.
When the oracle server detects the connection request from the client it’s check
client authentication, if authentication pass the oracle server creates a (dedicated)
server process on behalf of the user process. When the user executes a SQL
statement and commits the transaction. For example, the user changes a name in a
row of a table. The server process receives the statement and checks the shared
pool for any shared SQL area that contains an identical SQL statement. If a shared
SQL area is found, the server process checks the user's access privileges to the
requested data and the previously existing shared SQL area is used to process the
statement; if not, a new shared SQL area is allocated for the statement so that it can
be parsed and processed. The server process retrieves any necessary data values
from the actual datafile or those stored in the system global area. The server process
modifies data block in the system global area. The DBWn process writes modified
blocks permanently to disk when doing so is efficient. Because the transaction
committed, the LGWR process immediately records the transaction in the online redo
log file. If the transaction is successful, the server process sends a message across
the network to the application. If it is not successful, an appropriate error message is
transmitted. Throughout this entire procedure, the other background processes run,
watching for conditions that require intervention.
Basically, there are two main components of Oracle database –– instance and
database itself. An instance consists of some memory structures (SGA) and the
background processes.
1
Figure 1. Two main components of Oracle database
Instance
2
Figure 2. The instance components
SGA is the primary memory structures. This area is broken into a few of part
memory –– Buffer Cache, Shared Pool, Redo Log Buffer, Large Pool, and Java Pool.
Buffer Cache
Buffer cache is used to stores the copies of data block that retrieved from datafiles.
That is, when user retrieves data from database, the data will be stored in buffer
cache. Its size can be manipulated via DB_CACHE_SIZE parameter in [Link]
initialization parameter file.
Shared Pool
Shared pool is broken into two small part memories –– Library Cache and Dictionary
Cache. The library cache is used to stores information about the commonly used SQL
and PL/SQL statements; and is managed by a Least Recently Used (LRU) algorithm.
It is also enables the sharing those statements among users. In the other hand,
dictionary cache is used to stores information about object definitions in the
database, such as columns, tables, indexes, users, privileges, etc.
The shared pool size can be set via SHARED_POOL_SIZE parameter in [Link]
initialization parameter file.
Each DML statement (insert, update, and delete) executed by users will generates
the redo entry. What is a redo entry? It is an information about all data changes
made by users. That redo entry is stored in redo log buffer before it is written into
the redo log files. To manipulate the size of redo log buffer, you can use the
LOG_BUFFER parameter in [Link] initialization parameter file.
Large Pool
Large pool is an optional area of memory in the SGA. It is used to relieves the
burden place on the shared pool. It is also used for I/O processes. The large pool
size can be set by LARGE_POOL_SIZE parameter in [Link] initialization parameter
file.
Java Pool
As its name, Java pool is used to services parsing of the Java commands. Its size can
be set by JAVA_POOL_SIZE parameter in [Link] initialization parameter file.
Oracle background processes is the processes behind the scene that work together
with the memories.
DBWn
3
Database writer (DBWn) process is used to write data from buffer cache into the
datafiles. Historically, the database writer is named DBWR. But since some of Oracle
version allows us to have more than one database writer, the name is changed to
DBWn, where n value is a number 0 to 9.
LGWR
Log writer (LGWR) process is similar to DBWn. It writes the redo entries from redo
log buffer into the redo log files.
CKPT
Checkpoint (CKPT) is a process to give a signal to DBWn to writes data in the buffer
cache into datafiles. It will also updates datafiles and control files header when log
file switch occurs.
SMON
System Monitor (SMON) process is used to recover the system crach or instance
failure by applying the entries in the redo log files to the datafiles.
PMON
Process Monitor (PMON) process is used to clean up work after failed processes by
rolling back the transactions and releasing other resources.
Database
We can broken up database into two main structures –– Logical structures and
Physical structures.
Logical Structures
The logical units are tablespace, segment, extent, and data block.
4
Figure 3. The relationships between the Oracle logical structures
Tablespace
Segment
A Tablespace is further broken into segments. A segment is used to stores same type
of objects. That is, every table in the database will store into a specific segment
(named Data Segment) and every index in the database will also store in its own
segment (named Index Segment). The other segment types are Temporary Segment
and Rollback Segment.
Extent
A segment is further broken into extents. An extent consists of one or more data
block. When the database object is enlarged, an extent will be allocated. Unlike a
5
tablespace or a segment, an extent cannot be named.
Data Block
A data block is the smallest unit of storage in the Oracle database. The data block
size is a specific number of bytes within tablespace and it has the same number of
bytes.
Physical Structures
The physical structures are structures of an Oracle database (in this case the disk
files) that are not directly manipulated by users. The physical structure consists of
datafiles, redo log files, and control files.
Datafiles
A datafile is a file that correspondens with a tablespace. One datafile can be used by
one tablespace, but one tablespace can has more than one datafiles.
Redo log files are the files that store the redo entries generated by DML statements.
It can be used for recovery processes.
Control Files
Control files are used to store information about physical structure of database, such
as datafiles size and location, redo log files location, etc.
Starting up a database
This article explains the procedures involved in starting an Oracle instance and
database.
When Oracle starts an instance, it reads the initialization parameter file to determine
the values of initialization parameters. Then, it allocates an SGA, which is a shared
area of memory used for database information, and creates background processes.
At this point, no database is associated with these memory structures and processes.
To mount the database, the instance finds the database control files and opens
them. Control files are specified in the CONTROL_FILES initialization parameter in
the parameter file used to start the instance. Oracle then reads the control files to
get the names of the database's datafiles and redo log files.
At this point, the database is still closed and is accessible only to the database
administrator. The database administrator can keep the database closed while
completing specific maintenance operations. However, the database is not yet
available for normal operations.
6
Final Stage: Database open for normal operation
You can open any database in read-only mode to prevent its data from being
modified by user transactions. Read-only mode restricts database access to read-
only transactions, which cannot write to the datafiles or to the redo log files.
Disk writes to other files, such as control files, operating system audit trails, trace
files, and alert files, can continue in read-only mode. Temporary tablespaces for sort
operations are not affected by the database being open in read-only mode. However,
you cannot take permanent tablespaces offline while a database is open in read-only
mode. Also, job queues are not available in read-only mode.
Read-only mode does not restrict database recovery or operations that change the
database's state without generating redo data. For example, in read-only mode:
Datafiles can be taken offline and online
Offline datafiles and tablespaces can be recovered
The control file remains available for updates about the state of the database
One useful application of read-only mode is that standby databases can function as
temporary reporting databases.
Database Shutdown
The three steps to shutting down a database and its associated instance are:
Close the database.
Unmount the database.
Shut down the instance.
Close a Database
When you close a database, Oracle writes all database data and recovery data in the
SGA to the datafiles and redo log files, respectively. Next, Oracle closes all online
datafiles and online redo log files. At this point, the database is closed and
inaccessible for normal operations. The control files remain open after a database is
closed but still mounted.
7
In rare emergency situations, you can terminate the instance of an open database to
close and completely shut down the database instantaneously. This process is fast,
because the operation of writing all data in the buffers of the SGA to the datafiles
and redo log files is skipped. The subsequent reopening of the database requires
recovery, which Oracle performs automatically.
Un mount a Database
After the database is closed, Oracle un mounts the database to disassociate it from
the instance. At this point, the instance remains in the memory of your computer.
After a database is un mounted, Oracle closes the control files of the database.
The final step in database shutdown is shutting down the instance. When you shut
down an instance, the SGA is removed from memory and the background processes
are terminated.
Before work user must connect to an Instance. When user LOG on Oracle Server
Oracle Engine create a process called Server processes. Server process
communicate with oracle instance on the behalf of user process.
Each background process is useful for a specific purpose and its role is well defined.
8
This process writes the dirty buffers for the database buffer cache to data files. One
database writer process is sufficient for most systems; more can be configured if
essential. The initialisation parameter, DB_WRITER_PROCESSES, specifies the
number of database writer processes to start.
The DBWn process writes dirty buffer to disk under the following conditions:
When a checkpoint is issued.
When a server process cannot find a clean reusable buffer after
scanning a threshold number of buffers.
Every 3 seconds.
When we place a normal or temporary table space offline and read only
mode
When we drop and truncate table.
When we put a table space in backup mode;
Log Writer(LGWR)
The log writer process writes data from the redo log buffers to the redo log files on
disk.
Log writer will write synchronously to the redo log groups in a circular fashion. If any
damage is identified with a redo log file, the log writer will log an error in the LGWR
trace file and the system Alert Log. Sometimes, when additional redo log buffer
space is required, the LGWR will even write uncommitted redo log entries to release
the held buffers. LGWR can also use group commits (multiple committed
transaction's redo entries taken together) to write to redo logs when a database is
undergoing heavy write operations.
System Monitor
9
This process is responsible for instance recovery, if necessary, at instance startup.
SMON also cleans up temporary segments that are no longer in use. SMON wakes up
about every 5 minutes to perform housekeeping activities. SMON must always be
running for an instance.
Process Monitor
This process is responsible for performing recovery if a user process fails. It will
rollback uncommitted transactions. PMON is also responsible for cleaning up the
database buffer cache and freeing resources that were allocated to a process. PMON
also registers information about the instance and dispatcher processes with network
listener.
PMON wakes up every 3 seconds to perform housekeeping activities. PMON must
always be running for an instance.
Checkpoint Process
Checkpoint process signals the synchronization of all database files with the
checkpoint information. It ensures data consistency and faster database recovery in
case of a crash.
CKPT ensures that all database changes present in the buffer cache at that point are
written to the data files, the actual writing is done by the Database Writer process.
The datafile headers and the control files are updated with the latest SCN (when the
checkpoint occurred), this is done by the log writer process.
The CKPT process is invoked under the following conditions:
10
Incremental Checkpoints initiate the writing of recovery information to datafile
headers and controlfiles. Database writer is not signaled to perform buffer cache
flushing activity here.
Archiver
The ARCn process is responsible for writing the online redo log files to the mentioned
archive log destination after a log switch has occurred. ARCn is present only if the
database is running in archivelog mode and automatic archiving is enabled. The log
writer process is responsible for starting multiple ARCn processes when the workload
increases. Unless ARCn completes the copying of a redo log file, it is not released to
log writer for overwriting.
The number of Archiver processes that can be invoked initially is specified by the
initialization parameter LOG_ARCHIVE_MAX_PROCESSES. The actual number of
Archiver processes in use may vary based on the workload.
Lock Monitor
Meant for Parallel server setups, Lock Monitor manages global locks and resources. It
handles the redistribution of instance locks whenever instances are started or
shutdown. Lock Monitor also recovers instance lock information prior to the instance
recovery process. Lock Monitor co-ordinates with the Process Monitor to recover
dead processes that hold instance locks.
Lock processes
Meant for Parallel server setups, the instance locks that are used to share resources
between instances are held by the lock processes.
Meant for Parallel server setups, Block server Processes have to do with providing a
consistent read image of a buffer that is requested by a process of another instance,
in certain circumstances.
Queue Monitor
11
This is the advanced Queuing Time manager process. QMNn monitors the message
queues. Failure of QMNn process will not cause the instance to fail.
Event Monitor
This process is also related to Advanced Queuing, and is meant for allowing a
publish/subscribe style of messaging between applications.
Recoverer
Intended for distributed recovery. All in-doubt transactions are recovered by this
process in the distributed database setup. RECO will connect to the remote database
to resolve pending transactions.
Job queue processes carry out batch processing. All scheduled jobs are executed by
these processes. The initialization parameter JOB_QUEUE_PROCESSES specifies the
maximum job processes that can be run concurrently. If a job fails with some Oracle
error, it is recorded in the alert file and a process trace file is generated. Failure of
the Job queue process will not cause the instance to fail.
Dispatcher
Intended for Shared server setups (MTS). Dispatcher processes listen to and receive
requests from connected sessions and places them in the request queue for further
processing. Dispatcher processes also pickup outgoing responses from the result
queue and transmit them back to the clients. Dnnn are mediators between the client
processes and the shared server processes. The maximum number of Dispatcher
process can be specified using the initialization parameter MAX_DISPATCHERS.
Intended for Shared server setups (MTS). These processes pickup requests from the
call request queue, process them and then return the results to a result queue. The
12
number of shared server processes to be created at instance startup can be specified
using the initialization parameter SHARED_SERVERS.
These processes are used for parallel processing. It can be used for parallel
execution of SQL statements or recovery. The Maximum number of parallel
processes that can be invoked is specified by the initialization parameter
PARALLEL_MAX_SERVERS.
Trace Writer
Trace writer writes trace files from an Oracle internal tracing facility.
Input/Output Slaves
These processes are used to simulate asynchronous I/O on platforms that do not
support it. The initialization parameter DBWR_IO_SLAVES is set for this purpose.
This process was available in older versions of Oracle to alarm other processes that
are suspended while waiting for an event to occur. This process is obsolete and has
been removed.
Conclusion
With every release of Oracle, new background processes have been added and some
existing ones modified. These processes are the key to the proper working of the
database. Any issues related to background processes should be monitored and
analyzed from the trace files generated and the alert log.
Managing Tablespace
A tablespace is a logical storage unit. Why we are say logical because a tablespace is
not visible in the file system. Oracle store data physically is datafiles. A tablespace
consist of one or more datafile.
13
Type of tablespace:
System Tablespace:
Example:
The extents are managed with in the tablespace via bitmaps. In locally managed
tablespace, all tablespace information store in datafile header and don’t use data
dictionary table for store information. Advantage of locally managed tablespace is
that no DML generate and reduce contention on data dictionary tables and no undo
generated when space allocation or deallocation occurs.
14
Extent Management [Local | Dictionary]
The following statement creates a locally managed tablespace named USERS, where
AUTOALLOCATE causes Oracle to automatically manage extent size.
Alternatively, this tablespace could be created specifying the UNIFORM clause. In this
example, a 512K extent size is specified. Each 512K extent (which is equivalent to
64 Oracle blocks of 8K) is represented by a bit in the bitmap for this file.
15
INITIAL 64K
NEXT 64K
MINEXTENTS 2
MAXEXTENTS 121
PCTINCREASE 0);
Manual: This is default option. This option use free lists for managing free
space within segments. What are free lists: Free lists are lists of data blocks
that have space available for inserting new rows.
Auto: This option use bitmaps for managing free space within segments.
This is typically called automatic segment-space management
Example:
16
TABLESPACE INITIAL_EXT NEXT_EXT MIN_EXT MAX_EXT PCT_INCREASE
---------- ----------- -------- ------- ------- ------------
RBS 1048576 1048576 2 40 0
SYSTEM 106496 106496 1 99 1
TEMP 106496 106496 1 99 0
TESTTBS 57344 16384 2 10 1
USERS 57344 57344 1 99 1
Managing Datafiles
17
What is datafile?
Datafiles are physical files of the OS that store the data of all logical structures in the
database. Datafile must be created for each tablespace.
At least one datafile is required for the SYSTEM tablespace. We can create separate
datafile for other tablespace. When we create DATABASE , MAXDATAFILES may be
or not specify in create database statement clause. Oracle assassin db_files default
value to 200. We can also specify the number of datafiles in init file.
When we start the oracle instance , the DB_FILES initialization parameter reserve
for datafile information and the maximum number of datafile in SGA. We can change
the value of DB_FILES (by changing the initialization parameter setting), but the new
value does not take effect until you shut down and restart the instance.
Important:
If the value of DB_FILES is too low, you cannot add datafiles beyond the
DB_FILES limit. Example : if init parameter db_files set to 2 then you can not
add more then 2 in your database.
If the value of DB_FILES is too high, memory is unnecessarily consumed.
When you issue CREATE DATABASE or CREATE CONTROLFILE statements, the
MAXDATAFILES parameter specifies an initial size. However, if you attempt to
add a new file whose number is greater than MAXDATAFILES, but less than or
equal to DB_FILES, the control file will expand automatically so that the
datafiles section can accommodate more files.
Note:
If you add new datafiles to a tablespace and do not fully specify the filenames, the
database creates the datafiles in the default database directory . Oracle recommends
you always specify a fully qualified name for a datafile. Unless you want to reuse
existing files, make sure the new filenames do not conflict with other files. Old files
that have been previously dropped will be overwritten.
18
How to rename the datafile in a single tablespace?
Step:1 Take the tablespace that contains the datafiles offline. The database must be
open.
Step:3 Use the ALTER TABLESPACE statement with the RENAME DATAFILE clause to
change the filenames within the database.
Step 4: Back up the database. After making any structural changes to a database,
always perform an immediate and complete backup.
Step:1 Use following query to know the specifiec file name or size.
Step:3 Copy the datafiles to their new locations and rename them using the
operating system.
Step:5 Back up the database. After making any structural changes to a database,
always perform an immediate and complete backup.
Step:2 Copy the datafiles to be renamed to their new locations and new names,
using the operating system.
Step:3 Use ALTER DATABASE to rename the file pointers in the database control file.
19
ALTER DATABASE RENAME FILE
'/u02/oracle/rbdb1/[Link]','/u02/oracle/rbdb1/[Link]'
TO '/u02/oracle/rbdb1/[Link]','/u02/oracle/rbdb1/[Link];
Step:4 Back up the database. After making any structural changes to a database,
always perform an immediate and complete backup.
Important : Oracle does not provide an interface for dropping datafiles in the same
way you would drop a schema object such as a table or a user.
Important : Once the DBA creates a datafile for a tablespace, the datafile cannot be
removed. If you want to do any critical operation like dropping datafiles, ensure you
have a full backup of the database.
To determine how many and which datafiles make up a tablespace, you can use the
following query:
Case 1:
If you have only one datafile in the tablespace and you want to remove it. You can
simply drop the entire tablespace using the following:
The above command will remove the tablespace, the datafile, and the tablespace's
contents from the data dictionary.
Important : Oracle will not drop the physical datafile after the DROP TABLESPACE
command. This action needs to be performed at the operating system.
Case 2:
20
If you have more than one datafile in the tablespace, and you want to remove all
datafiles and also no need the information contained in that tablespace, then use the
same command as above:
Case 3:
If you have more than one datafile in the tablespace and you want to remove only
one or two ( not all) datafile in the tablesapce or you want to keep the objects that
reside in the other datafile(s) which are part of this tablespace, then you must export
all the objects inside the tablespace.
Step: 1 Gather information on the current datafiles within the tablespace by running
the following query in SQL*Plus:
Step: 2 You now need to identify which objects are inside the tablespace for the
purpose of running an export. To do this, run the following query:
Step : 3 Now, export all the objects that you wish to keep.
Step : 5 Delete the datafiles belonging to this tablespace using the operating
system.
Step : 6 Recreate the tablespace with the datafile(s) desired, then import the
objects into that tablespace.
Case : 4
If you do not want to follow any of these procedures, there are other things that can
be done besides dropping the tablespace.
If the reason you wanted to drop the file is because you mistakenly created
the file of the wrong size, then consider using the RESIZE command.
If you really added the datafile by mistake, and Oracle has not yet allocated
any space within this datafile, then you can use ALTER DATABASE DATAFILE
<filename> RESIZE; command to make the file smaller than 5 Oracle blocks.
If the datafile is resized to smaller than 5 oracle blocks, then it will
never be considered for extent allocation. At some later date, the
tablespace can be rebuilt to exclude the incorrect datafile.
21
Important : The ALTER DATABASE DATAFILE <datafile name> OFFLINE DROP
command is not meant to allow you to remove a datafile. What the command really
means is that you are offlining the datafile with the intention of dropping the
tablespace.
Important : If you are running in archivelog mode, you can also use: ALTER
DATABASE DATAFILE <datafile name> OFFLINE; instead of OFFLINE DROP. Once
the datafile is offline, Oracle no longer attempts to access it, but it is still considered
part of that tablespace. This datafile is marked only as offline in the controlfile and
there is no SCN comparison done between the controlfile and the datafile during
startup (This also allows you to startup a database with a non-critical datafile
missing). The entry for that datafile is not deleted from the controlfile to give us the
opportunity to recover that datafile.
22
23
24
UNDO TABLESPACE
UNDO_MANAGEMENT:
The default value for this parameter is MANUAL. If you want to set the database in
an automated mode, set this value to AUTO. (UNDO_MANAGEMENT = AUTO)
UNDO_TABLESPACE:
25
UNDO_TABLESPACE defines the tablespaces that are to be used as Undo
Tablespaces. If no value is specified, Oracle will use the system rollback segment to
startup. This value is dynamic and can be changed online (UNDO_TABLESPACE =
<Tablespace_Name>)
UNDO_RETENTION:
The default value for this parameter is 900 Secs. This value specifies the amount of
time, Undo is kept in the tablespace. This applies to both committed and
uncommitted transactions since the introduction of FlashBack Query feature in Oracle
needs this information to create a read consistent copy of the data in the past.
UNDO_SUPRESS_ERRORS:
Default values is FALSE. Set this to true to suppress the errors generated when
manual management SQL operations are issued in an automated management
mode.
UNDO tablespaces can be created during the database creation time or can be added
to an existing database using the create UNDO Tablespace command
26
You cannot drop Active undo tablespace. Means, undo tablespace can only be
dropped if it is not currently used by any instance. Use the DROP TABLESPACE
statement to drop an undo tablespace and all contents of the undo tablespace are
removed.
Example:
We can switch form one undo tablespace to another undo tablespace. Because the
UNDO_TABLESPACE initialization parameter is a dynamic parameter, the ALTER
SYSTEM SET statement can be used to assign a new undo tablespace.
IMPORTANT:
The database is online while the switch operation is performed, and user transactions
can be executed while this command is being executed. When the switch operation
completes successfully, all transactions started after the switch operation began are
assigned to transaction tables in the new undo tablespace.
The switch operation does not wait for transactions in the old undo tablespace to
commit. If there is any pending transactions in the old undo tablespace, the old undo
tablespace enters into a PENDING OFFLINE mode (status). In this mode, existing
transactions can continue to execute, but undo records for new user transactions
cannot be stored in this undo tablespace.
An undo tablespace can exist in this PENDING OFFLINE mode, even after the switch
operation completes successfully. A PENDING OFFLINE undo tablespace cannot used
by another instance, nor can it be dropped. Eventually, after all active transactions
have committed, the undo tablespace automatically goes from the PENDING OFFLINE
mode to the OFFLINE mode. From then on, the undo tablespace is available for other
instances (in an Oracle Real Application Cluster environment).
If the parameter value for UNDO TABLESPACE is set to '' (two single quotes), the
current undo tablespace will be switched out without switching in any other undo
27
tablespace. This can be used, for example, to unassign an undo tablespace in the
event that you want to revert to manual undo management mode.
The V$UNDOSTAT view is useful for monitoring the effects of transaction execution
on undo space in the current instance. Statistics are available for undo space
consumption, transaction concurrency, and length of queries in the instance.
The following example shows the results of a query on the V$UNDOSTAT view.
28
DATABASE statement. The names of the control files are specified by the
CONTROL_FILES parameter in the initialization parameter file used during database
creation.
How to Create Additional Copies, Renaming, and Relocating Control Files
Step:1 Shut down the database.
Step:2 Copy an existing control file to a different location, using operating system
commands.
Step:3 Edit the CONTROL_FILES parameter in the database's initialization parameter
file to add the new control file's name, or to change the existing control filename.
Step:4 Restart the database.
When you Create New Control Files?
All control files for the database have been permanently damaged and you do
not have a control file backup.
You want to change one of the permanent database parameter settings
originally specified in the CREATE DATABASE statement. These settings
include the database's name and the following parameters: MAXLOGFILES,
MAXLOGMEMBERS, MAXLOGHISTORY, MAXDATAFILES, and MAXINSTANCES.
Steps for Creating New Control Files
Step:1 Make a list of all datafiles and online redo log files of the database.
SELECT MEMBER FROM V$LOGFILE;
SELECT NAME FROM V$DATAFILE;
SELECT VALUE FROM V$PARAMETER WHERE NAME = 'CONTROL_FILES';
Step:3 Back up all datafiles and online redo log files of the database.
Step:4 Start up a new instance, but do not mount or open the database:
STARTUP NOMOUNT
Step:5 Create a new control file for the database using the CREATE CONTROLFILE
statement.
Example:
CREATE CONTROLFILE REUSE DATABASE "<DB_NAME" NORESETLOGS
NOARCHIVELOG
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 '<DISK>:\Directory\[Link]' SIZE 5024K,
GROUP 2 '<DISK>:\Directory\[Link]' SIZE 5024K,
GROUP 3 '<DISK>:\Directory\[Link]' SIZE 5024K
# STANDBY LOGFILE
DATAFILE
'<DISK>:\Directory\[Link]',
'<DISK>:\Directory\[Link]'
29
CHARACTER SET WE8MSWIN1252
;
Step:6 Open the database using one of the following methods:
If you specify NORESETLOGS when creation the control file, use following
commands: ALTER DATABASE OPEN;
If you specified RESETLOGS when creating the control file, use the ALTER
DATABASE statement, indicating RESETLOGS.
TIPS:
When creating a new control file, select the RESETLOGS option if you have lost any
online redo log groups in addition to control files. In this case, you will need to
recover from the loss of the redo logs . You must also specify the RESETLOGS option
if you have renamed the database. Otherwise, select the NORESETLOGS option.
Backing Up Control Files
Method 1:
Back up the control file to a binary file (duplicate of existing control file) using the
following statement:
Redo logs consists of two or more pre allocated files that store all changes made to
the database. Every instance of an Oracle database has an associated online redo log
to protect the database in case of an instance failure.
30
Set the archive destination to separate disk other than redo log members to
avoid contention between LGWR and Arch.
With mirrored groups of online redo logs , all members of the same group
must be the same size.
MAXLOGFILES
MAXLOGMEMEBERS
Interpretation:
Here you will observe that status is UNUSED means that this redo log file is not
being used by oracle as yet. ARC is the archived column in v$log , it is by default
YES when you create a redo log file. It will returns to NO if the system is not in
archive log mode and this file is used by oracle. Sequence# 0 also indicate that it is
not being used as yet.
Step:3 Copy the desired redo log files to new location . You can change the name of
redo log file in the new location.
31
Step:4 Alter database rename file ‘<DISK>:\Directory\<LOG_FILE_NAME>.log’ to
‘<new path><DISK>:\Directory\<LOG_FILE_NAME>.log’,
Important:
Syntax:
32
User-Managed Backup Terminology
(Operating system command are used to make backups when database is closed or
open in this terminology)
Whole database backup refer to a backup of all data file, control file and log file of
the database. whole database backup can be perform when database open or closed.
The backup takes when database is closed called consistent backup. (Because
database file header are consistent with the control file and when restore completely
the database can be opened without any recovery.)
The backup takes when database is opened and operational called inconsistent
backup. (Because database file header are not consistent with the control file.)
Use the v$tablespace and v$datafile data dictonery view to obtain a list of all
datafiles and there respective tablespace.
33
Making a Backup of an Online teblespace or Data file
(Note:This prevent the sequence number in the datafile header from changing.)
Use an operating system backup utility to copy all database in the tablespace
to backup storage.
After the datafile of the tablespace have been backed up, set them into mode
by issuing the following command:
When a datafile is placed in backup mode, more redo log entries may be generated
because the log writer writes block image of changes block of the datafile in backup
mode to the redo log instead of just the row information
select * from v$backup; (view to determine which file are in backup mode, when
alter tablespace begin backup command is issued the status change to ACTIVE.)
34
CREATE PFILE ='C:\BACKUP\[Link]' FRoM SPFILE;
>dbv file='path of file location' start=1 logfile='enter path for log file generation'
Tablespace, table, index may be use to set to NOLOGGING mode for Faster load of
data when using direct load operation like SQL LOADER.( Because the redo logs do
not contain the values that were inserted when the table was in NOLOGGING mode.
If your database is running in archive log mode and you take cold backup means
consistent backup (all data file, control file and redo log file) in every Sunday and
Monday to Saturday you take only backup of archive log file.
Case 1:
You have Sunday cold backup and you have also Monday to Wednesday archive log
file backup. Suppose any data file corrupt or missed on Thursday, how will you
recover database up to Wednesday.
SQL> startup
ORACLE instance started.
Read DBWR trace file or alert log file and find details of missing data files.
Restore missing files from backup storage area by using OS Copy command
and try to open database by using alter database open command.
35
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: 'C:\O\ORADATA\[Link]'
(Error means data file 1 needs media recovery)
AUTO
Log applied.
Open databae:
SQL> startup
36
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1:
'D:\ORACLE_DATA\LOGS\ORCL\[Link]'
SQL>
To fix this we simply copy [Link] from its multiplexed location on E: to the
above location on D:.
Database altered.
SQL>
If a redo log is missing, it should be restored from a Cold backup (if redo log backup
available in Sunday Cold Backup) if possible. Here's an example, where I attempt to
startup from SQLPlus when a redo log is missing:
SQL> startup
ORACLE instance started.
SQL>
Database altered.
SQL>
37
Case 3: All redo log file or any one redo log file missing and we have no
cbackup copy of redo log file or no multiplexing redo log file.
If all or some redo log is missing. Here's an example, where I attempt to startup
from SQLPlus when a redo log is missing:
SQL> startup
ORACLE instance started.
Database altered.
[Link]-requisites:
The following are the pre-requisites to fully recover an Oracle database server in the
event a disaster occurs:
A FULL Oracle database backup (all data file, control file and redo log file) using copy
command. When making this backup, make sure the Oracle database is shut down.
This backup set will contain a FULL CLOSED Oracle Database backup. A FULL Oracle
database backup should be performed every time any changes are made to the
physical and/or logical structure of the Oracle database and forms the base for
recovering the database server to a fully working order.
Scenario
38
if your database is running in archive log mode and every Sunday you take full/cold
backup of database (all data file , control file and redolog file ) and every day
Monday to Saturday you take only archive log file backup. If a situation in which
your database server has been destroyed at Saturday , how will u recover data up to
Saturday
Steps
You need a server to host the database, so the first step is to acquire or build the
new machine. This is not strictly a DBA task, so we won't delve into details here. The
main point to keep in mind is that the replacement server should, as far as possible,
be identical to the old one. In particular, pay attention to the following areas:
Disk layout and capacity: Ideally the server should have the same number of disks
as the original. This avoids messy renaming of files during recovery. Obviously, the
new disks should also have enough space to hold all software and data that was on
the original server.
Operating system, service pack and patches: The operating system environment
should be the same as the original, right up to service pack and patch level.
Memory: The new server must have enough memory to cater to Oracle and
operating system / other software requirements. Oracle memory structures (Shared
pool, db buffer caches etc) will be sized identically to the original database instance.
Use of the backup server parameter file will ensure this.
Now we get to the meat of the database recovery process. The next step is to install
Oracle software on the machine. The following points should be kept in mind when
installing the software:
Install the same version of Oracle as was on the destroyed server. The version
number should match right down to the patch level, so this may be a multi-step
process involving installation followed by the application of one or more patchsets
and patches.
Create a listener using the Network Configuration Assistant. Ensure that it has the
same name and listening ports as the original listener. Relevant listener
configuration information can be found in the backed up [Link] file.
After software installation is completed, create all directories required for datafiles,
(online and archived) logs, control files and backups. All directory paths should
match those on the original server. This, though not mandatory, saves additional
steps associated with renaming files during recovery.
39
Don't worry if you do not know where the database files should be located. You can
obtain the required information from the backup spfile and control file at a later
stage. Continue reading - we'll come back to this later.
An Oracle service must be exist before a database is created. The service is created
using the oradim utility, which must be run from the command line. The following
commands show how to create and modify a service (comments in italics, typed
commands in bold):
Unfortunately oradim does not give any feedback, but you can check that the service
exists via the Services administrative panel. The service has been configured to start
automatically when the computer is powered up. Note that oradim offers options to
delete, startup and shutdown a service. See the documentation for details.
If an Oracle database server experienced a disaster such as a hard disk failure, use
this procedure to recover the server and the Oracle databases:
Shutdown database
Restore all data file, log file from cold backup and restore all archive log file from
Cold backup to disaster.
When the restore operation completes, move to the Oracle database server
Start server manager, connect as Internal and start the database but only mount it
by typing:
40
Note :Oracle will respond to this command by returning the following message,
suggesting a log sequence to apply.
ORA-00289: Suggestion :
\Oracle_Home\Oradata\<SID>\%SID%[Link]
AUTO
This will automatically apply all archived log sequences required to recover the
database (assuming all archived redo logs are available in the location specified
in the [Link] parameter and that the format corresponds to the format
specified).
'E:\ORACLE\ORADATA\KIMSTAD\ARCHIVE\[Link]
'
To finish the recovery, stay in server manager with the database mounted, and type:
41
CANCEL
11. To open the database and to synchronize the log sequence, type:
The Oracle database server is now restored to full working order up to the time
of the latest full online Oracle backup.
1. Backup all data file and Control file by using following commands on
every Sunday.
(BACKUP SCRIPTS)
3. Suppose You have Sunday hot backup and you have also Monday to
42
Wednesday archive log file backup. Suppose any data file corrupt or missed
on Thursday, how will you recover database up to Wednesday.
SQL> startup
ORACLE instance started.
5. Check backup status and messing file (Required recovery) and current log
sicquence of all data file.
43
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: 'E:\LOCAL\ORADATA\[Link]'
44
SQL> recover datafile 1;
ORA-00279: change 334936 generated at 10/14/2006 [Link] needed for thread 1
ORA-00289: suggestion : C:\ORACLE\RDBMS\ARC00208.001
ORA-00280: change 334936 for thread 1 is in sequence #208
Connected to:
Oracle9i Enterprise Edition Release [Link].1 - Production
With the Partitioning option
JServer Release [Link].1 - Production
no rows selected
45
3 NOT ACTIVE 251388 12-OCT-06
4 NOT ACTIVE 251396 12-OCT-06
SQL> /
SQL> /
SQL> /
SQL> /
SQL> /
46
2 NOT ACTIVE 314014 13-OCT-06
3 ACTIVE 314021 13-OCT-06
4 NOT ACTIVE 251396 12-OCT-06
SQL> /
SQL> /
SQL> /
SQL> /
SQL> /
47
SQL> startup
ORACLE instance started.
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
48
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
49
SQL> /
System altered.
50
16 603754401 1 16 314130 13-OCT-06 314131
17 603754406 1 17 314131 13-OCT-06 314132
18 603754406 1 18 314132 13-OCT-06 314133
19 603754411 1 19 314133 13-OCT-06 314134
20 603754412 1 20 314134 13-OCT-06 314135
21 603754417 1 21 314135 13-OCT-06 314136
22 603754417 1 22 314136 13-OCT-06 314137
25 rows selected.
51
3 603754369 1 3 314116 13-OCT-06 314118
4 603754369 1 4 314118 13-OCT-06 314119
5 603754374 1 5 314119 13-OCT-06 314120
6 603754374 1 6 314120 13-OCT-06 314121
7 603754379 1 7 314121 13-OCT-06 314122
8 603754379 1 8 314122 13-OCT-06 314123
9 603754385 1 9 314123 13-OCT-06 314124
10 603754385 1 10 314124 13-OCT-06 314125
11 603754390 1 11 314125 13-OCT-06 314126
25 rows selected.
8
----------
8
8
8
8
52
4 6774 06-OCT-06 3 4 ONLINE READ WRITE 314150 13-OCT-06 0 314150 13-OCT-
06
SQL> ed
Wrote file [Link]
53
17 603670733 C:\ORACLE\RDBMS\ARC00008.001
18 603670733 C:\ORACLE\RDBMS\ARC00009.001
19 603670737 C:\ORACLE\RDBMS\ARC00010.001
20 603670737 C:\ORACLE\RDBMS\ARC00011.001
21 603670742 C:\ORACLE\RDBMS\ARC00012.001
22 603670743 C:\ORACLE\RDBMS\ARC00013.001
54
---------- ---------- -------------------------------------------------------------------------
---------------------------------------------------------------------
56 603737244 C:\ORACLE\RDBMS\ARC00047.001
57 603737246 C:\ORACLE\RDBMS\ARC00048.001
58 603737251 C:\ORACLE\RDBMS\ARC00049.001
59 603737252 C:\ORACLE\RDBMS\ARC00050.001
60 603737253 C:\ORACLE\RDBMS\ARC00051.001
61 603737255 C:\ORACLE\RDBMS\ARC00052.001
62 603738258 C:\ORACLE\RDBMS\ARC00053.001
63 603738298 C:\ORACLE\RDBMS\ARC00054.001
64 603738303 C:\ORACLE\RDBMS\ARC00055.001
65 603738303 C:\ORACLE\RDBMS\ARC00056.001
66 603738303 C:\ORACLE\RDBMS\ARC00057.001
55
95 603749809 C:\ORACLE\RDBMS\ARC00021.001
96 603749810 C:\ORACLE\RDBMS\ARC00022.001
97 603751702 C:\ORACLE\RDBMS\ARC00023.001
98 603751703 C:\ORACLE\RDBMS\ARC00024.001
99 603751707 C:\ORACLE\RDBMS\ARC00025.001
56
---------------------------------------------------------------------
133 603754412 C:\ORACLE\RDBMS\ARC00020.001
134 603754417 C:\ORACLE\RDBMS\ARC00021.001
135 603754417 C:\ORACLE\RDBMS\ARC00022.001
136 603754422 C:\ORACLE\RDBMS\ARC00023.001
137 603754422 C:\ORACLE\RDBMS\ARC00024.001
138 603754445 C:\ORACLE\RDBMS\ARC00025.001
Oracle provide a tool for Database backup and restore operation is called RMAN.
BACKUP DATABASE;
RMAN reduces the complexity of backup and recovery. RMAN can determine what
needs to be backed up or restored.
57
Understanding the RMAN Architecture
An oracle RMAN comprises of RMAN EXECUTABLE This could be present and fired
even through client side, TARGET DATABASE (This is the database which needs to be
backed up) and RECOVERY CATALOG (Recovery catalog is optional otherwise backup
details are stored in target database controlfile .)
The RMAN repository is a set of metadata that RMAN uses to store information about
the target database and its backup and recovery operations. RMAN stores
information about:
Target database
RMAN connects you to the target database with the SYSDBA privilege. If you do not
have this privilege, then the connection fails.
Recovery catalog database
This database is optional: you can also use RMAN with the default NOCATALOG
option.
Auxiliary database
You can connect to a standby database, duplicate database, or auxiliary instance
(standby instance or tablespace point-in-time recovery instance
Note: That a SYSDBA privilege is not required when connecting to the recovery
catalog. The only requirement is that the RECOVERY_CATALOG_OWNER role be
granted to the schema owner.
After you have learned how to connect to a target database, you can immediately
begin performing backup and recovery operations. Use the examples in this section
to go through a basic backup and restore scenario using a test database. These
examples assume the following:
58
Connecting to the Target Database
rman TARGET /
If the database is already mounted or open, then RMAN displays output similar to
the following:
Recovery Manager: Release [Link].0
In this example, you generate a report describing the target datafiles. Run the report
schema command as follows:
RMAN> REPORT SCHEMA; (RMAN displays the datafiles currently in the target
database.)
In this task, you back up the database to the default disk location. Because you do
not specify the format parameter in this example, RMAN assigns the backup a unique
filename.
You can make two basic types of backups: full and incremental.
Run the backup command at the RMAN prompt as follows to make a full backup of
the datafiles, control file, and current server parameter file (if the instance is started
with a server parameter file) to the default device type:
RMAN> BACKUP DATABASE;
Incremental backups are a convenient way to conserve storage space because they
back up only database blocks that have changed. RMAN compares the current
datafiles to a base backup, also called a level 0 backup, to determine which blocks to
back up.
59
To list the backup sets and image copies that you have created, run the list
command as follows:
Check that you are able to restore the backups that you created without actually
restoring them. Run the RESTORE ... VALIDATE command as follows:
Full Backups
A full backup reads the entire file and copies all blocks into the backup set, only
skipping datafile blocks that have never been used.
Rman create backup only changed block since a previous backup. You can use RMAN
to create incremental backups of datafiles, tablespaces, or the whole database.
Each data block in a datafile contains a system change number (SCN), which is the
SCN at which the most recent change was made to the block. During an incremental
backup, RMAN reads the SCN of each data block in the input file and compares it to
the checkpoint SCN of the parent incremental backup. RMAN reads the entire file
every time whether or not the blocks have been used.
The parent backup is the backup that RMAN uses for comparing the SCNs. If the
current incremental is a differential backup at level n, then the parent is the most
recent incremental of level n or less. If the current incremental is a cumulative
backup at level n, then the parent is the most recent incremental of level n-1 or less.
If the SCN in the input data block is greater than or equal to the checkpoint SCN of
the parent, then RMAN copies the block.
RMAN can create multilevel incremental backups. Each incremental level is denoted
by an integer, for example, 0, 1, 2, and so forth. A level 0 incremental backup, which
is the base for subsequent incremental backups, copies all blocks containing data.
60
The only difference between a level 0 backup and a full backup is that a full
backup is never included in an incremental strategy.
If no level 0 backup exists when you run a level 1 or higher backup, RMAN makes a
level 0 backup automatically to serve as the base.
The benefit of performing multilevel incremental backups is that RMAN does not back
up all blocks all of the time.
In a differential level n incremental backup, RMAN backs up all blocks that have
changed since the most recent backup at level n or lower.
Backup Example ( You can view your incremental Backup Details by using
following Query)
61
select incremental_level, incremental_change#, checkpoint_change#, blocks from
v$backup_datafile;
0 0 271365 59595
3 271365 271369 2
3 271369 271371 1
3 271371 271374 2
2 271365 271378 2
3 271378 271380 1
3 271380 271383 2
For example, in cumulative level 2 backups, RMAN determines which level 1 backup
occurred most recently and copies all blocks changed since that backup. If no level 1
backups is available, RMAN copies all blocks changed since the base level 0 backup.
Cumulative incremental backups reduce the work needed for a restore by ensuring
that you only need one incremental backup from any particular level. Cumulative
backups require more space and time than differential backups, however, because
they duplicate the work done by previous backups at the same level.
62
Use Command for Cumulative Level Backup
You can implement a three-level backup scheme so that a full or level 0 backup is
taken monthly, a cumulative level 1 backup is taken weekly, and a cumulative level
2 is taken daily. In this scheme, you never have to apply more than a day's worth of
redo for complete recovery. When deciding how often to take full or level 0 backups,
a good rule of thumb is to take a new level 0 whenever 50% or more of the data has
changed. If the rate of change to your database is predictable, then you can observe
the size of your incremental backups to determine when a new level 0 is appropriate.
The following query displays the number of blocks written to a backup set for each
datafile with at least 50% of its blocks backed up:
63
ORDER BY COMPLETION_TIME;
Use the RMAN RESTORE command to restore the following types of files from
copies on disk or backups on other media:
RMAN automates the procedure for restoring files. When you issue a RESTORE
command, RMAN restore the correct backups and copies to either:
· The default location, overwriting the old files with the same name
· A new location, which you can specify with the SET NEWNAME command
For example:
If you restore datafile 'C:_DATA.DBF’ to its default location, then RMAN restores the
file C:_DTAA.DBF’ and overwrites any file that it finds with the same filename.
if you run a SET NEWNAME command before you restore a file, then RMAN creates
a datafile copy with the name that you specify. For example, assume that you run
the following commands:
Run
64
'C:_DATA.DBF’ to 'C:_DATA.DBF’ in the control file, run a SWITCH command so
that RMAN considers the restored file as the current database file.
If possible, make the recovery catalog available to perform the media recovery. If it
is not available, then RMAN uses metadata from the target database control file.
Assuming that you have backups of the datafiles and at least one autobackup of the
control file.
The generic steps for media recovery using RMAN are as follows:
· Place the database in the appropriate state: mounted or open. For example, mount
the database when performing whole database recovery, or open the database when
performing online tablespace recovery.
RESTORE DATABASE;
RECOVER DATABASE;
The RMAN recovery catalog obtains its metadata from the target database control
file. RMAN decides which backup sets to restore, and which incremental backups and
archived logs to use for recovery. A server session on the target database instance
performs the actual work of restore and recovery.
RMAN does not need to apply incremental backups to a restored level 0 incremental
backup: it can also apply archived logs. RMAN simply restores the datafiles that it
needs from available backups and copies, and then applies incremental backups to
the datafiles if it can and if not applies logs.
If RMAN cannot find an incremental backup, then it looks in the repository for the
names of archived redo logs to use for recovery. Oracle records an archived log in
the control file whenever one of the following occurs:
65
· RMAN restores an archived log
RMAN propagates archived log data into the recovery catalog during
resynchronization, classifying archived logs as image copies. You can view the log
information through:
During recovery, RMAN looks for the needed logs using the filenames specified in the
V$ARCHIVED_LOG view. If the logs were created in multiple destinations or were
generated by the COPY, CATALOG, or RESTORE commands, then multiple, identical
copies of each log sequence number exist on disk.
If the RMAN repository indicates that a log has been deleted or uncataloged, then
RMAN ceases to consider it as available for recovery. For example, assume that the
database archives log 100 to directories /dest1 and /dest2. The RMAN repository
indicates that /dest1/[Link] and /dest2/[Link] exist. If you delete
/dest1/[Link] with the DELETE command, then the repository indicates that only
/dest2/[Link] is available for recovery.
If the RMAN repository indicates that no copies of a needed log sequence number
exist on disk, then RMAN looks in backups and restores archived redo logs as needed
to perform the media recovery. By default, RMAN restores the archived redo logs to
the first local archiving destination specified in the initialization parameter file. You
can run the SET ARCHIVELOG DESTINATION command to specify a different restore
location. If you specify the DELETE ARCHIVELOG option on RECOVER, then RMAN
deletes the archived logs after restoring and applying them. If you also specify
MAXSIZE integer on the RECOVER command, then RMAN staggers the restores so
that they consume no more than integer amount of disk space at a time.
Incomplete Recovery
RMAN can perform either complete or incomplete recovery. You can specify a time,
SCN, or log sequence number as a limit for incomplete recovery with the SET UNTIL
command or with an UNTIL clause specified directory on the RESTORE and RECOVER
commands. After performing incomplete recovery, you must open the database with
the RESETLOGS option.
Assume that you lose both the target database and the recovery catalog. All that you
have remaining is a tape with RMAN backups of the target database and archived
redo logs. Can you still recover the database? Yes, assuming that you enabled the
66
control file autobackup feature. In a disaster recovery situation, RMAN can determine
the name of a control file autobackup even without a repository available. You can
then restore this control file, mount the database, and perform media recovery.
You can also use the RMAN BLOCKRECOVER command to perform block media
recovery. Block media recovery recovers an individual corrupt datablock or set of
datablocks within a datafile. In cases when a small number of blocks require media
recovery, you can selectively restore and recover damaged blocks rather than whole
datafiles.
You can only perform block media recovery with Recovery Manager. No
SQL*Plus recovery interface is available.
You can only perform complete recovery of individual blocks. In other words,
you cannot stop recovery before all redo has been applied to the block.
You can only recover blocks marked media corrupt. The
V$DATABASE_BLOCK_CORRUPTION view indicates which blocks in a file were
marked corrupt since the most recent BACKUP, BACKUP ... VALIDATE, or
COPY command was run against the file.
You must have a full RMAN backup. Incremental backups are not allowed.
Blocks that are marked media corrupt are not accessible to users until
recovery is complete. Any attempt to use a block undergoing media recovery
results in an error message indicating that the block is media corrupt.
For example, you may discover the following messages in a user trace file:
You can then specify the corrupt blocks in the BLOCKRECOVER command as follows:
Like datafile media recovery, block media recovery cannot survive a missing or
inaccessible archived log. Where is datafile recovery requires an unbroken series of
redo changes from the beginning of recovery to the end, block media recovery only
requires an unbroken set of redo changes for the blocks being recovered.
When RMAN first detects missing or corrupt redo records during block media
recovery, it does not immediately signal an error because the block undergoing
recovery may become a newed block later in the redo stream. When a block is
newed all previous redo for that block becomes irrelevant because the redo applies
67
to an old incarnation of the block. For example, Oracle can new a block when users
delete all the rows recorded in the block or drop a table.
When you use a recovery catalog, RMAN can perform a wider variety of automated
backup and recovery functions than when you use the control file in the target
database as the sole repository of metadata.
You can store metadata about multiple target databases in a single catalog.
You can store metadata about multiple incarnations of a single target
database in the catalog. Hence, you can restore backups from any
incarnation.
Resynchronizing the recovery catalog at intervals less than the
CONTROL_FILE_RECORD_KEEP_TIME setting, you can keep historical
metadata.
You can report the target database schema at a noncurrent time.
You can store RMAN scripts in the recovery catalog.
When restoring and recovering to a time when the database files that exist in
the database are different from the files recorded in the mounted control file,
the recovery catalog specifies which files that are needed. Without a catalog,
you must first restore a control file backup that lists the correct set of
database files.
If the control file is lost and must be restored from backup, and if persistent
configurations have been made to automate the tape channel allocation,
these configurations are still available when the database is not mounted.
The main cost of using a catalog is the maintenance overhead required for this
additional database.
For example, you have to:Find a database other than the target database to store
the recovery catalog (otherwise, the benefits of maintaining the catalog are lost), or
create a new database Create enough space on the database for the RMAN
metadata.
68
Upgrade the recovery catalog when necessary
Database, which includes all datafiles as well as the current control file and current
server parameter
file:
RMAN can invoked from the command line on the database host machine like so:
69
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT 'e:\backup\%[Link]'
MAXPIECESIZE 4G;
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'C:\ORACLE\ORA92\DATABASE\[Link]'; #
default
RMAN>
Retention Policy:
This instructs RMAN on the backups that are eligible for deletion.
For example: A retention policy with redundancy 2 would mean that two backups -
the latest and the one prior to that - should be retained. All other backups are
candidates for deletion.
This can be "disk" or "sbt" (system backup to tape). We will backup to disk and then
have our OS backup utility copy the completed backup, and other supporting files, to
tape.
Controlfile Autobackup:
This can be set to "on" or "off". When set to "on", RMAN takes a backup of the
controlfile AND server parameter file each time a backup is performed. Note that
"off" is the default.
This tells RMAN where the controlfile backup is to be stored. The "%F" in the file
name instructs RMAN to append the database identifier and backup timestamp to the
backup filename. The database identifier, or DBID, is a unique integer identifier for
the database.
Parallelism:
This tells RMAN how many server processes you want dedicated to performing the
backups.
This specifies the location and name of the backup files. We need to specify the
format for each channel. The "%U" ensures that Oracle appends a unique identifier
to the backup file name. The MAXPIECESIZE attribute sets a maximum file size for
each file in the backup set.
Any of the above parameters can be changed using the commands displayed by the
"show all" command.
70
For example, one can turn off controlfile autobackups by issuing:
RMAN>
Recovery manager is a platform independent utility for coordinating your backup and
restoration procedures across multiple servers.
71
C:>rman catalog=rman/rman@w2k1
RMAN> exit
C:>
Register Database
RMAN>
Full Backup
72
First we configure several persistent parameters for this instance:
RMAN> run
SQL>
To fix this we simply copy [Link] from its multiplexed location on E: to the
above location on D:.
73
SQL> alter database open;
Database altered.
SQL>
That's it - the database is open for use.
Case 2: All members of a log group lost.
In this case an incomplete recovery is the best we can do. We will lose all
transactions from the missing log and all subsequent logs. We illustrate using the
same example as above. The error message indicates that members of log group 3
are missing. We don't have a copy of this file, so we know that an incomplete
recovery is required. The first step is to determine how much can be recovered. In
order to do this, we query the V$LOG view (when in the mount state) to find the
system change number (SCN) that we can recover to (Reminder: the SCN is a
monotonically increasing number that is incremented whenever a commit is issued)
--The database should be in the mount state for v$log access
FIRST_CHANGE#
-------------
370255
SQL>
The FIRST_CHANGE# is the first SCN stamped in the missing log. This implies that
the last SCN stamped in the previous log is 370254 (FIRST_CHANGE#-1). This is the
highest SCN that we can recover to. In order to do the recovery we must first restore
ALL datafiles to this SCN, followed by recovery (also up to this SCN). This is an
incomplete recovery, so we must open the database resetlogs after we're done.
Here's a transcript of the recovery session (typed commands in bold, comments in
italics, all other lines are RMAN feedback):
C:\>rman target /
74
restoring datafile 00003 to D:\ORACLE_DATA\DATAFILES\ORCL\[Link]
channel ORA_DISK_2: restored backup piece 1
piece handle=E:\BACKUP\13GB14IB_1_1.BAK tag=TAG20050124T171139
params=NUL
channel ORA_DISK_2: restore complete
channel ORA_DISK_1: restored backup piece 1
piece handle=E:\BACKUP\14GB14IB_1_1.BAK tag=TAG20050124T171139
params=NUL
channel ORA_DISK_1: restore complete
Finished restore at 26/JAN/05
--Recover database
database opened
RMAN>
The following points should be noted:
1. The entire database must be restored to the SCN that has been determined by
querying v$log.
2. All changes beyond that SCN are lost. This method of recovery should be used
only if you are sure that you cannot do better. Be sure to multiplex your redo logs,
and (space permitting) your archived logs!
3. The database must be opened with RESETLOGS, as a required log has not been
applied. This resets the log sequence to zero, thereby rendering all prior backups
worthless. Therefore, the first step after opening a database RESETLOGS is to take
a fresh backup. Note that the RESETLOGS option must be used for any incomplete
recovery.
75
Recovery from missing or corrupted control file
On startup Oracle must read the control file in order to find out where the datafiles
and online logs are located. Oracle expects to find control files at locations specified
in the CONTROL_FILE initialisation parameter. The instance will fail to mount the
database if any one of the control files are missing or corrupt. Here's an example:
SQL> startup
SQL>
The above corruption was introduced by manually editing the control file when the
database was closed.
The solution is simple, provided you have at least one uncorrupted control file -
replace the corrupted control file with a copy using operating system commands.
Remember to rename the copied file. The database should now start up without any
problems.
What if you lose all your control files? In that case you have no option but to use a
backup control file. The recovery needs to be performed from within RMAN, and
requires that all logs (archived and current online logs) since the last backup are
available. The logs are required because all datafiles must also be restored from
backup. The database will then have to be recovered up to the time the control files
went missing. This can only be done if all intervening logs are available. Here's an
annotated transcript of a recovery session (as usual, lines in bold are commands to
be typed, lines in italics are explanatory comments, other lines are RMAN feedback):
-- Connect to RMAN
C:\rman
76
Recovery Manager: Release [Link].1 - Production
(c) Copyright 2001 Oracle Corporation. All rights reserved.
set DBID - get this from the name of the controlfile autobackup. For example, if
autobackup name is
CTL_SP_BAK_C-1507972899-20050124-00 the the DBID is 1507972899. This step
will not be required if the instance is
-- Now that control files have been restored, the instance can mount the
-- database.
database mounted
-- All datafiles must be restored, since the controlfile is older than the current
-- datafiles. Datafile restore must be followed by recovery up to the current log.
77
piece handle=E:\BACKUP\0DGB0I79_1_1.BAK tag=TAG20050124T115832
params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to D:\ORACLE_DATA\DATAFILES\ORCL\[Link]
restoring datafile 00003 to D:\ORACLE_DATA\DATAFILES\ORCL\[Link]
channel ORA_DISK_1: restored backup piece 1
piece handle=E:\BACKUP\0CGB0I78_1_1.BAK tag=TAG20050124T115832
params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 26/JAN/05
--Database must be recovered because all datafiles have been restored from
-- backup
database opened
78
Several points are worth emphasizing.
1. Recovery using a backup controlfile should be done only if a current control file is
unavailable.
2. All datafiles must be restored from backup. This means the database will need to
be recovered using archived and online redo logs. These MUST be available for
recovery until the time of failure.
After recovery using a backup controlfile, all temporary files associated with locally-
managed tablespaces are no longer available. You can check that this is so by
querying the view V$TEMPFILE - no rows will be returned. Therefore tempfiles must
be added (or recreated) before the database is made available for general use. In
the case at hand, the tempfile already exists so we merely add it to the temporary
tablespace. This can be done using SQLPlus or any tool of your choice:
'D:\oracle_data\datafiles\ORCL\[Link]';
Tablespace altered.
SQL>
This scenario deals with a situation where a datafile has gone missing, or is
corrupted beyond repair. For concreteness, we look at a case where a datafile is
missing. Below is a transcript of an SQL Plus session that attempts to open a
database with a missing datafile (typed commands in bold, lines in italics are my
comments, all other lines are feedback from SQL Plus):
--logging on to database
C:\>sqlplus /nolog
79
--Connect to the idle Oracle process as a privileged user and start up instance
SQL> startup
SQL>
The error message tells us that file# 4 is missing. Note that although the startup
command has failed, the database is in the mount state. Thus, the database control
file, which is also the RMAN repository can be accessed by the instance and by
RMAN. We now recover the missing file using RMAN. The transcript of the recovery
session is reproduced below (bold lines are typed commands, comments in italics,
the rest is feedback from RMAN):
--logon to RMAN
C:\>rman target /
80
channel ORA_DISK_1: restore complete
Finished restore at 26/JAN/05
database opened
RMAN>
In the above scenario, the database is already in the mount state before the RMAN
session is initiated. If the database is not mounted, you should issue a "startup
mount" command before attempting to restore the missing datafile. The database
must be mounted before any datafile recovery can be done.
If the database is already open when datafile corruption is detected, you can recover
the datafile without shutting down the database. The only additional step is to take
the relevant tablespace offline before starting recovery. In this case you would
perform recovery at the tablespace level. The commands are:
C:\>rman target /
81
using target database controlfile instead of recovery catalog
sql statement: alter tablespace USERS offline immediate
RMAN>
Here we have used the SQL command, which allows us to execute arbitrary SQL
from within RMAN.
Connected.
Since we know the file and block number, we can perform block level recovery using
RMAN. This is best illustrated by example:
82
C:\>rman target /
RMAN>
Now our user should be able to query the table from her SQLPlus session. Here's her
session transcript after block recovery.
COUNT(*)
----------
217001
SQL>
3. Check all database files for corruption. This is important - there could be other
corrupted blocks. Verification of database files can be done using RMAN or the
dbverify utility. To verify using RMAN simply do a complete database backup with
default settings. If RMAN detects block corruption, it will exit with an error message
pointing out the guilty file/block.
83
Disaster Recovery
Introduction:
- i.e. a situation in which your database server has been destroyed and has taken all
your database files (control files, logs and data files) with it. Obviously, recovery
from a disaster of this nature is dependent on what you have in terms of backups
and hardware resources. We assume you have the following available after the
disaster:
With the above items at hand, it is possible to recover all data up to the last full
backup. One can do better if subsequent archive logs (after the last backup) are
available. In our case these aren't available, since our only archive destination was
on the destroyed server ). Oracle provides methods to achieve better data
protection. We will discuss some of these towards the end of the article.
Now on with the task at hand. The high-level steps involved in disaster recovery are:
You need a server to host the database, so the first step is to acquire or build the
new machine. This is not strictly a DBA task, so we won't delve into details here. The
main point to keep in mind is that the replacement server should, as far as possible,
be identical to the old one. In particular, pay attention to the following areas:
Ideally the server should have the same number of disks as the original. The
new disks should also have enough space to hold all software and data that
was on the original server.
The operating system environment should be the same as the original, right
up to service pack and patch level.
The new server must have enough memory to cater to Oracle and operating
system / other software requirements. Oracle memory structures (Shared
pool, db buffer caches etc) will be sized identically to the original database
instance. Use of the backup server parameter file will ensure this.
84
Step:3 Install Oracle Software
The next step is to install Oracle software on the machine. The following points
should be kept in mind when installing the software:
Install the same version of Oracle as was on the destroyed server. The
version number should match right down to the patch level, so this may be a
multi-step process involving installation followed by the application of one or
more patch sets and patches.
Do not create a new database at this stage.
Create a listener using the Network Configuration Assistant. Ensure that it has
the same name and listening ports as the original listener. Relevant listener
configuration information can be found in the backed up [Link] file.
After software installation is completed, create all directories required for datafiles,
(online and archived) logs, control files and backups. All directory paths should
match those on the original server.
Don't worry if you do not know where the database files should be located. You can
obtain the required information from the backup spfile and control file at a later
stage. Continue reading - we'll come back to this later.
An Oracle service must be exist before a database is created. The service is created
using the oradim utility, which must be run from the command line. The following
commands show how to create and modify a service (comments in italics, typed
commands in bold):
Unfortunately oradim does not give any feedback, but you can check that the
service exists via the Services administrative panel. The service has been configured
to start automatically when the computer is powered up.
Now it is time to get down to the nuts and bolts of database recovery. There are
several steps, so we'll list them in order:
85
files are ORACLE_HOME\database ORACLE_HOME\network\admin
respectively.
Set ORACLE_SID environment variable: ORACLE_SID should be set to the
proper SID name (ORCL in our case). This can be set either in the registry
(registry key: HKLM\Software\Oracle\HOME<X>\ORACLE_SID) or from the
system applet in the control panel.
Invoke RMAN and set the DBID: We invoke rman and connect to the target
database as usual. No login credentials are required since we connect from an
OS account belonging to ORA_DBA. Note that RMAN accepts a connection to
the database although the database is yet to be recovered. RMAN doesn't as
yet "know" which database we intend to connect to. We therefore need to
identify the (to be restored) database to RMAN. This is done through the
database identifier (DBID). The DBID can be figured out from the name of the
controlfile backup. Example: if you use the controlfile backup format , your
controlfile backup name will be something like "CTL_SP_BAK_C-1507972899-
20050228-00". In this case the DBID is 1507972899. Here's a transcript
illustrating the process of setting the DBID:
C:\>rman
RMAN>connect target /
RMAN>
Restore spfile from backup: To restore the spfile, you first need to startup the
database in the nomount state. This starts up the database using a dummy
parameter file. After that you can restore the spfile from the backup (which has been
restored from tape ). Finally you restart the database in nomount state. Here is an
example RMAN transcript for the foregoing procedure. Note the difference in SGA
size and components between the two startups:
86
Redo Buffers 667648 bytes
RMAN>
We are now in a position to determine the locations of control file and archive
destination, as this information sits in the spfile. This is done via SQL Plus as follows:
C:\>sqlplus /nolog
SQL>connect / as sysdba
Connected.
SQL> show parameter control_file
87
RMAN> restore controlfile from 'e:\backup\CTL_SP_BAK_C-1507972899-
20050228-00';
RMAN> shutdown
RMAN> exit
C:\>rman target /
RMAN>startup mount;
88
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT 'e:\backup\%[Link]'
MAXPIECESIZE 4G;
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT 'e:\backup\%[Link]'
MAXPIECESIZE 4G;
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'C:\ORACLE\ORA92\DATABASE\[Link]'; # default
RMAN>
At this stage we can determine the locations of data files and redo logs if we don't
know where they should go. This is done from SQL Plus as follows:
C:\>sqlplus /nolog
SQL>connect / as sysdba
Connected.
SQL>select name from v$datafile;
SQL>
The directories shown in the output should be created manually if this hasn't been
done earlier.
Restore all datafiles: This is easy. Simply issue a "restore database" command
from RMAN, and it will do all the rest for you:
89
params=NULL
channel ORA_DISK_2: restored backup piece 2
piece handle=E:\BACKUP\80G6E1TT_2_1.BAK tag=TAG20041130T222501
params=NULL
channel ORA_DISK_1: restored backup piece 2
piece handle=E:\BACKUP\81G6E1TU_2_1.BAK tag=TAG20041130T222501
params=NULL
channel ORA_DISK_1: restored backup piece 3
piece handle=E:\BACKUP\81G6E1TU_3_1.BAK tag=TAG20041130T222501
params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_2: restored backup piece 3
piece handle=E:\BACKUP\80G6E1TT_3_1.BAK tag=TAG20041130T222501
params=NULL
channel ORA_DISK_2: restore complete
Finished restore at 01/MAR/05
RMAN>
Recover database: The final step is to recover the database. Obviously recovery is
dependent on the available archived (and online) redo logs. Since we have lost our
database server and have no remote archive destination, we can recover only up to
the time of the backup. Further, since this is an incomplete recovery, we will have to
open the database with resetlogs. Here's a sample RMAN session illustrating this:
RMAN-00571: ==============================
RMAN-00569: =ERROR MESSAGE STACK FOLLOWS =
RMAN-00571: ===============================
RMAN-03002: failure of recover command at 04/01/2005 [Link]
RMAN-06054: media recovery requesting unknown log: thread 1 scn 32230460
database opened
RMAN>
Note that RMAN automatically applies all available archive logs. It first applies the
backed up log and then searches for subsequent logs in the archive destination. This
opens the door for further recovery if the necessary logs are available. In our case,
however, we have no more redo so we open the database with resetlogs. The error
message above simply indicates that RMAN has searched, unsuccessfully, for
subsequent logs.
90
That's it. The database has been recovered, from scratch, to the last available
backup. Now having done this, it is worth spending some time in discussing how one
can do better - i.e. recover up to a point beyond the backup. We do this in the next
section.
run {
allocate channel t1 type disk;
backup
tag whole_database_open
format '/oracle/backups/BFS/df_%u'
database;
91
# switch out of the current logfile
sql 'alter system archive log current';
The datafile numbers and location on host A are required. These datafile locations
will change on host B
file# name
----- ------------------------------
1 /oracle/OFA_base/u01/oradata/V805X/[Link]
2 /oracle/OFA_base/u01/oradata/V805X/[Link]
3 /oracle/OFA_base/u01/oradata/V805X/[Link]
4 /oracle/OFA_base/u01/oradata/V805X/[Link]
5 /oracle/OFA_base/u01/oradata/V805X/[Link]
6 /oracle/OFA_base/u01/oradata/V805X/[Link]
7 /oracle/OFA_base/u01/oradata/V805X/[Link]
8 /oracle/OFA_base/u01/oradata/V805X/[Link]
group# member
----- ------------------------------
1 /oracle/OFA_base/u01/oradata/V805X/[Link]
2 /oracle/OFA_base/u01/oradata/V805X/[Link]
3 /oracle/OFA_base/u01/oradata/V805X/[Link]
[Link] - Pay Per Click Advertising, Pay Per Click Affiliate Program, Free
Traffic Counters. More information about indiandba
Disk Backups
During restore, RMAN will expect the backup sets to be located in the same
directory as written to during the backup.
92
Tape Backups
The media management software must be configured such that host B is a media
manager client, and can read the backup sets. The media management vendor
should be consulted for support on this issue.
[Link] - Pay Per Click Advertising, Pay Per Click Affiliate Program, Free
Traffic Counters. More information about indiandba
The "[Link]" needs to be made available on host B. Any location specific parameters
must be amended. For example, ifile, *_dump_dest, log_archive_dest*, control_files
[Link] - Pay Per Click Advertising, Pay Per Click Affiliate Program, Free
Traffic Counters. More information about indiandba
[Link] - Pay Per Click Advertising, Pay Per Click Affiliate Program, Free
Traffic Counters. More information about indiandba
In order to allow RMAN remote connections, a password file must be setup for the
duplicated database. For example,
93
[Link] - Pay Per Click Advertising, Pay Per Click Affiliate Program, Free
Traffic Counters. More information about indiandba
For example,
run{
allocate channel c1 type disk;
restore controlfile;
}
RMAN can be used to change the location of the datafiles from the location on host
A to the new location on host B.
For example,
run {
restore database;
To Perform Block Media Recovery when there are OS-backups available, but NO
RMAN backups.
94
Consider that a block corruption is reported in the database and the corruption is not
wide spread.
Since RMAN is not used in the database the initial solution would be to restore the
file from backup and then recover. But this method will require the file should be
offline during the entire process. On the other hand if BMR can be used, the file does
not need to be taken offline.
Step 1 : Identify the backup of the datafilefile which has the corrupted
block(s) and catalog it within RMAN.
$ export ORACLE_SID=orcl
$ RMAN target=/
RMAN> catalog datafilecopy ‘/u01/backup/[Link]’;
RMAN is using the archived redologs which are known in V$ARCHIVED_LOG. If the
archivelog files are not reported in V$ARCHIVED_LOG because they are moved to
another location, or aged out of the controlfile, then they need to be cataloged as
well.
Having datafile(s) and all required archivelogs cataloged, we can run BMR as follows.
View
V$PROCESS
Identifies currently active processes.
V$SESSION
95
Identifies currently active sessions. Use this view to determine which
Oracle database server sessions correspond to which RMAN allocated channels.
V$SESSION_LONGOPS
Provides progress reports on long-running operations.
V$SESSION_WAIT
Lists the events or resources for which sessions are waiting.
To identify which server sessions correspond to which RMAN channels, use the set
command with the command id parameter. The command id parameter enters the
specified string into the CLIENT_INFO column of the V$SESSION dynamic
performance view. Join V$SESSION with V$PROCESS to correlate the server session
with the channel.
Step:2 Set the command id parameter after allocating the channels and then back
up the
desired object.
run {
allocate channel t1 type disk;
allocate channel t2 type disk;
set command id to 'rman';
backup
incremental level 0
filesperset 5
tablespace 'SYSTEM';
# optionally, issue a host command to access the operating system prompt
host;
sql 'ALTER SYSTEM ARCHIVE LOG ALL';
}
Step:3 Start a SQL*Plus session and then query the joined V$SESSION and
V$PROCESS
views while the RMAN job is executing.
96
8 21973 id=rman
16 22057 id=rman
17 22068 id=rman,ch=t1
18 22070 id=rman,ch=t2
Each server session performing a backup, restore, or copy reports its progress
compared to the total amount of work required for that particular part of the restore.
For example, if you perform a restore using two channels, and each channel has two
backup sets to restore (a total of 4 sets), then each server session reports its
progress through a single set. When that set is completely restored, RMAN starts
reporting progress on the next set to restore.
Step:1 Start RMAN and connect to the target database and, optionally, the recovery
catalog
database.
run {
allocate channel t1 type disk;
backup database;
}
Step:3 While the job is running, execute a script containing the following SQL
statement:
If you repeat the query while the backup progresses, then you see output such as
the following:
SQL>
SID SERIAL# CONTEXT SOFAR TOTALWORK %
Complete
8 19 1 10377 36617
28.34
SQL> /
SID SERIAL# CONTEXT SOFAR TOTALWORK %
Complete
8 19 1 21513 36617
58.75
97
SQL> /
SQL> /
no rows selected
NOTE: If you run the script at intervals of two minutes or more and the % Complete
column does not increase, then RMAN is encountering a problem.
Note: The V$SESSION_WAIT view shows only Oracle events, not media
manager events.
Another Query:
The database buffer cache is the area of the SGA that store database data in
memory block for access by user process.
98
The database buffer cache hit ratio represent the percentage of block-read request
that satisfied by a logical read to the database buffer cache.
A high ratio means that more reads form memory took place and a low ration means
that more physical reads are required. Because logical reads involve reads to
memory and physical reads involve reading from disk. It stands to reason that one
would prefer that logical reads occur rather than physical one.
Note: Hit ratio should be more then 90%, if hit ratio less then 90% then increase
database buffer cache size.
The Hit Ratio can be up or down. If database buffer cache ration less then 90% . You
can increase DB_CACHE_SIZE in init file.
A component of the shared pool is the data dictionary cache, which is used to store
data dictionary rows in the SGA. Much like the database buffer cache, the shared
pool has various hit ratios that can be calculated to determine its performance.
select (( 1 - (sum(getmisses) /
(sum(gets)+ sum(getmisses)))) * 100 ) " Data Dictionary Hit Ratio"
from v$rowcache
where
gets + getmisses <> 0
Note: If the hit ratio is less then 95% you probably need to add memory to the
Shared Pool. To be so, increase the SHARED_POOL_SIZE in init file.
This tells you how often the system went into the dictionary cache and found what it
was looking for.
Note: If ratio is more then 10% increase the Shared pool size.
99
Monitoring and Tuning the Library Cache
Library cache miss can occure in either the parse or execute phase of a SQL
operation. If a parse call is made by an application and the parsed statement is not
already in the shared pool, oracle will need to parse the statement and a library
cache miss will result. If an application makes an execute call for SQL statement, it is
possible that the parsed representation of that statement will have been aged out of
the library cache by another operation.
In this case , oracle will re parse the statement before executing it.
The first solution to both of these problems is to make sure that you have sufficient
memory allocation to the shared pool. This is done using the shared_pool_size.
Library cache hit ratio is a measure of how often the system finds the library cache
already loaded in the cache and how times the system needs to get then off the disk.
The Library cache reload ratio measures the overall hit ratio of the library cache. The
library cache reload ratio differs from the hit ratio in that it measures the reuse of
SQL objects that have already been in the library cache , aged out and then reload.
A low cache reload ratio indicate that oracle did not need to reload any previously
loaded library cache items. If the library cache reload ration is high (.5% to 1%) you
should check for SQL statement reusability.
A high cache reload ratio indicate that the database needs to reload library cache
items once they have already been loaded.
100
Library cache Pin Hit Ratio
The library cache pin hit ratio is a measure of how often oracle executed an object
that was already in the library cache and was valied. This rate should be as close to
100% as possible.
The fastest way that Oracle can read or modify a block is when the information is
already loaded in memory in the buffer cache. When this do not occur, Oracle will
need to read the information directly from the datafile incurring I/O operations,
which usually are much more expensive.
When data is retrieved from the physical disk you must takes steps to reduce disk
contention. Disk contention occurs when multiple processes try to access the same
disk simultaneously. Disk contention can be reduced, thereby increasing
performance, by distributing the disk I/O more evenly over the available disks.
Decreasing disk I/O can also reduce disk contention.
One can also determine file I/O problems by running the following query:
NOTE: A large difference in the number of physical writes and reads among disks will
show which disk is being burdened the most.
101
Conclusion:
SECOND_IN_WAIT value of the Log Buffer Space event indicate the time spent
waiting for space in the redo log buffer because the log switch does not occure. This
is an indication that the buffer are filled up faster than LGER is writing.
Action:
If SECOND_IN_WAIT is high the increase size of LOG_BUFFER parameter in init file.
FAQ- Statspack
Statspack is a set of SQL, PL/SQL and SQL*Plus scripts which allow the collection,
automation, storage and viewing of performance data. A user is automatically
created by the installation script - this user, PERFSTAT, owns all objects needed by
this package. This user is granted limited query-only
privileges on the V$views required for performance tuning.
Use Job schedular in the oracle RDBMS_JOB package to set up a recurring job that
execute to [Link] sql secipts.
102
2 1048576 CURRENT
3 1048576 INACTIVE
In this query , Logs are 1MB . and we increase size them to 10MB.
Step:2 Retrieve all the log member names for the groups:
GROUP# MEMBER
--------------- ----------------------------------------
1 /usr/oracle/dbs/[Link]
2 /usr/oracle/dbs/[Link]
3 /usr/oracle/dbs/[Link]
Step:3 Let's create 3 new log groups and name them groups 4, 5, and 6, each 10MB
in size:
GROUP# STATUS
--------- ----------------
1 INACTIVE
2 CURRENT
3 INACTIVE
4 UNUSED
5 UNUSED
6 UNUSED
From the above we can see log group 2 is current, and this is one of the smaller
groups we must drop. Therefore let's switch out of this group into one of the newly
created log groups.
Step:5 Switch until we are into log group 4, so we can drop log groups 1, 2, and 3:
Step:6 Run the query again to verify the current log group is group 4:
GROUP# STATUS
--------- ----------------
103
1 INACTIVE
2 INACTIVE
3 INACTIVE
4 CURRENT
5 UNUSED
6 UNUSED
Verify the groups were dropped, and the new groups' sizes are correct.
Step:9 You can now go out to the operating system and delete the files associated
with redo log groups 1, 2, and 3 in step 2 above as they are no longer needed:
rm /usr/oracle/dbs/[Link]
rm /usr/oracle/dbs/[Link]
rm /usr/oracle/dbs/[Link]
Step : 3 Calculate total size , free space and used space in tablespace
104
Step : 4 Create table which is store all free/use space related information of
tablespace
Step : 5 Insert free space information in DB_GROWTH table (if you want to
populate data Manually)
105
select * from db_growth;
Check Result
Session altered.
declare
jobno number;
begin
dbms_job.submit(
jobno, 'begin insert into db_growth select * from v_db_growth;commit;end;',
sysdate, 'SYSDATE+ 24', TRUE);
commit;
end;
exec dbms_job.run(ENTER_JOB_NUMBER)
106
SELECT (SUM(undoblks))/ SUM ((end_time - begin_time) * 86400) FROM
v$undostat;
The result of the query returns the number of undo blocks per second. This value
needs to be multiplied by the size of an undo block, which is the same size as the
database block defined in DB_BLOCK_SIZE.
Note: Column END_TIME and BEGIN_TIME are DATE data types. When DATE data
types are subtracted, the result is in days. To convert days to seconds, you multiply
by 86400, the number of seconds in a day.
Method:1
We can use SAR command to monitor CPU usage. The SAR commands gives you a
quick snapshot of haw heavily the CPU is bogged down.
# sar -u 5 5
Average 43 3 0 54
107
TIPS: Use the sar -u command to see how heavily the CPU is bogged down. The
Low CPU idle time can be an I/O issue and not a CPU issue.
Method:2
# vmstat 5 5
r b w avm fre re at pi po fr de sr d0 s1 d2 s3 in sy cs us sy id
000 0 1088 0 2 2 0 1 0 0 0 0 0 0 26 72 24 0 1 98
Note: The CPU is spending most of its time in IDLE mode (id). That means that the
CPU is not being heavily used at all. There are no processes that are waiting to be
run (r), blocked (b), or waiting for IO (w) in the RUN QUEUE.
Method:3
# sar -qu 5 5
Note: The CPU is spending most (94%) of its time in idle mode. This CPU is not
being heavily used at all. if CPU is using heavily, two solutions to this are:
Method :1
# sar -d 5 2
Note: This Command lists the % busy, avgue (average queue length), r+w/s, blks/s
( Number of block transfered), avwait and avserv.
Tips: A high % busy and high avque indicate a disk I/O bottleneck. if this condition
persist, an analysis of disk should lead to a reorganised of information from heavy
load to a less used disk.
Method: 2
# iostat -d 5 5
Note: iostat will display the number of kilobytes transferred per second, the number
of transfers per second, and the milliseconds per average seek.
108
Tips: KPS rates over 30 indicate heavy usage of a particular disk. If only one disk
shows heavy usage, consider moving some of your datafiles off it or striping your
data across several disks.
Method: 3
# sar -b 5 5
[Link] 0 2 90 1 2 38 0 0
Note: The "-b" option indicates the overall health of the IO subsystem.
Tips: The %rcache should be greater than 90% and %wcache should be greater
than 60%. If this is not the case, your system may be bound by disk IO. The sum
of bread, bwrit, pread, and pwrit gives a good indicator of how well your file
subsystem is doing. The sum should not be greater than 40 for 2 drives and 60 for
4-8 drives. If you exceed these values, your system may be IO bound.
When analyzing disk IO, make sure that you have balanced the load on your system.
Here is a tips of steps for designing a disk layout for Oracle:
Make sure that your logfiles and archived logfiles are NOT on the same disk
as your datafiles. This is a basic safety precaution against disk failure.
Allocate one disk for the User Data Tablespace.
Place Rollback, Index, and System Tablespaces on separate disks.
This command list the %CPU used , PID, USER and Command that was executed. if
the top user was Oracle User, you must to know the information on the process form
oracle.
109
APPS applprod 17929 108 17788
Tips: Enter SID and Serial# because the values retrieved in the first query.
Tips: If you had a ad-hoc query user problem and problem queries showed
up in this result regularly.
# mpstat 10 5
The mpstat command is tool that report per-processor statistics in tabular form.
Each row of the table represent the activity of one processor.
Pay attention on smtx measurement, it measure the number of times the CPU faild
to obtain a mutual exclusion lock.
TIPS: If the smtx column for the mpstat output is greater than 200, you are heading
toward CPU bottleneck problems.
Monitoring Paging/Swaping
One of the most common problems when running large numbers of concurrent users
on UNIX machines is lack of memory. In this case, a quick review memory
management is useful to see what effect lack of RAM can have on performance.
When analyzing your machine, make sure that the machine is not swapping at all
and at worst paging lightly. This indicates a system with a healthy amount of
memory available. To analyze paging and swapping, use the following commands.
$ vmstat 5 5
r b w avm fre re at pi po fr de sr d0 s1 d2 s3 in sy cs us sy id
000 0 1088 0 2 2 0 1 0 0 0 0 0 0 26 72 24 0 1 98
110
Note: There are NO pageouts (po) occurring on this system. There are also 1088 *
4k pages of free RAM available (4 Meg). It is OK and normal to have page out (po)
activity. You should get worried when the number of page ins (pi) starts rising.
This indicates that you system is starting to page.
$ sar -wpg 5 5
$ sar -r 5 5
This will give you a good indication of how much free swap and RAM you have on
your machine. There are 790 pages of memory available and 5862 disk blocks of
SWAP available.
Oracle Statspack
To install Statspack, you run an installation scripts called [Link]. You can find
this scripts in the $Oracle_home/rdbms/admin directory.
SQL> @?:\rdbms\admin\[Link]
Now that Statspack has been installed, you can start collecting database data.
111
SQL> execute [Link];
The SNAP procedure take a snapshot of your database and store the information
collected in that snapshot in the statspack repository. Leter , you can generat
statspack report based on the difference in snapshot, which occurred over a givin
period of time.
SQL> @?\rdbms\admin\[Link]
Oracle provide a single report that contains the collected information. This report is
run by using the scripts [Link]. When you run [Link] , it will provide you
with a list of snapshot currently store in the [Link] will then be prompted to
select the begining and ending snapshot to report on and to specify the output report
name.
To collect statistics on a regular, frequent basic, you will want to automate the
process. One way to schedule statistics is to use oracle job scheduler in the oracle
DBMS_JOB package to set up a recurring job that executes the [Link] sql
scripts.
Example: Issue the following command to have statistics collected on your system
once every 6 hours:
declare
jobno number;
begin
dbms_job.submit(jobno, '[Link];', trunc(sysdate+1/6,'HH'),
'trunc(SYSDATE+1/6,''HH'')');
commit;
end;
112
~~~~~~~~~~~~~~~~~
Buffer Cache: 160M Std Block Size: 8K
Shared Pool Size: 288M Log Buffer: 10,240K
The first section of the report include information about the database like db name ,
release number, db id and host. The Cache Size section show the values of the
Buffer Cache (DB_CACHE_SIZE), Shared Pool Size(SHARED_POOL_SIZE) standard
block size (DB_BLOCK_SIZE) and Log Buffer (LOG_BUFFER).
Load Profile
~~~~~~~~~~~ Per Second Per Transaction
--------------- --------------
Redo size: 7,674.80 7,230.16
Logical reads: 5,770.91 5,436.57
Block changes: 65.26 61.47
Physical reads: 372.73 351.14
Physical writes: 0.92 0.87
User calls: 41.13 38.74
Parses: 27.12 25.55
Hard parses: 0.04 0.04
Sorts: 12.87 12.13
Logons: 0.21 0.19
Executes: 74.27 69.97
Transactions: 1.06
Note: an increase in redo size, block changes and % Block changed per Read
indicate increased DML(insert/update/delete) activity.
Hard Parse occurs when a SQL statments is executed and is not currently in the
shared pool. Hard Parses should not be grater than 100/second. if it is grater than
100/second means bind variables are not being used effectively. In this situation,
there is a shared pool sizing problems.
Soft Parses occures when a SQL statment is executed and it is currently in the
shared pool. Soft Parses should not be grater than 300/second. if it is grater than
300/second means programme inefficiencies where statements are being parsed
over and over again instead of the program efficiently parsing the statement only
once per session.
113
The Instance efficiency section shows information for many of the common hit ratios.
If you regular run STATSPACK, comparing hit ratios from one day to another day can
be great barometer.
Note: Good hit ratio don't show the whole picture. There are always cases where the
database is working very efficiently but this report shows only database operations,
not the application operation , server action or network issues that also impact the
performance of the application.
The Buffer Nowait Ratio is the percentage of requests a server process makes for a
specific buffer where the buffer was available immediately. all buffer types are
included in this statistic. If the ratio is low, determine which type of block is being
contended for by examining the Buffer Wait Statistics section.
This means that when a request for a buffer took place, the buffer was available in
memory and physical disk I/O did not need to take place.
The Library Hit Ratio is also known as the library cache hit ratio. The ratio indicates
the number of pin requests which result in pin hits. A pin hit occurs when the SQL or
PL/SQL code you wish to execute is already in the library cache and is valid to
execute.
A low library cache hit percentage could mean SQL is prematurely aging out of the
shared pool as the shared pool may be small, or that unsharable SQL is being used.
Also compare with the soft parse ratio; if they are both low, then investigate whether
there is a parsing issue.
The Parse CPU is the amount of CPU time spent parsing SQL statements. The Parse
CPU filter represents the percentage of CPU time spent parsing SQL statements.
Parse time CPU can be a strong indication that an application has not been well
tuned. High parse time CPU usually indicates that the application may be spending
too much time opening and closing cursors or is not using bind variables.
If this is low, you may see "latch free" as one of your top wait events.
114
Redo NoWait %
Frequent, or slow log switches may be contributing to waits for redo log space. If you
are switching logs frequently (e.g. more than once every 15 minutes) this may be
improved by increasing the size of the online redo logs.
If the log switches are not frequent, check the disks the redo logs reside on to see if
log switches are taking a long time due to a slow IO system. If the IO system is
overloaded, either move the redo logs to disks with less activity, place the logs on
dedicated disks or faster devices.
The In Memory Sort Ratio is the percentage of sorts (from ORDER BY clauses or
index building) that are done to disk vs. in-memory. Disk sorts are done in the TEMP
tablespace, which is hundreds of times slower than a RAM sort. The in-memory sorts
are controlled by sort_area_size or by pga_aggregate_target.
At the time a session is established with Oracle, a private sort area is allocated in
RAM memory for use by the session for sorting. If the connection is via a dedicated
connection a Program Global Area (PGA) is allocated according to the sort_area_size
[Link] parameter.
For connections via the multithreaded server, sort space is allocated in the
large_pool. Unfortunately, the amount of memory used in sorting must be the same
for all sessions, and it is not possible to add additional sort areas for tasks that
require large sort operations.
This is an important one at least for OLTP systems. This means that your SQL is
being reused. If this is low (not between 95% and 100%) then make sure that SQL
is not being reused and need to be investigated.
If it's not then check out what your top wait events are to try to fix the problem
The Latch Hit Ratio is the ratio of the total number of latch misses to the number of
latch gets for all latches. A low value for this ratio indicates a latching problem,
whereas a high value is generally good
115
If the value is low then the memory is wasted. If its high the shared pool is used
heavily which means that you are aging certain components out from there.
SQL with executions > 1: This is indicate, How many SQL statements were found
in the shared pool executed more than once.
Memory for SQL w/exec>1: Measure of memory consumed by the SQL's used
frequently compared to sql's not used frequently.
Standby Oracle Database
Same Oracle software release must be used for both primary and
standby databases. The operating system running on primary and
standby locations must be same, but operating system release may not
need to be same.
The Primary Database must run in ARCHIVELOG mode.
The hardware and Operating system architecture on primary and standby
location must be same.
Each primary and standby database must have its own control file.
Architecture:
Log Transport Services - Control the automatic transfer of archive redo log
files from the primary database to one or more standby destinations.
Log Apply Services - Apply the archived redo logs to the standby database.
The Managed Recovery Process (MRP) actually does the work of maintaining and
applying the archived redo logs.
116
The services required on the primary database are:
Log Writer Process (LGWR) - Collects redo information and updates the
online redo logs. It can also create local archived redo logs and transmit online
redo to standby databases.
Fetch Archive Log (FAL) Server - Services requests for archive redo logs
from FAL clients running on multiple standby databases. Multiple FAL servers
can be run on a primary database, one for each FAL request.
Fetch Archive Log (FAL) Client - Pulls archived redo log files from the
primary site. Initiates transfer of archived redo logs when it detects a gap
sequence.
Remote File Server (RFS) - Receives archived and/or standby redo logs from
the primary database.
Archiver (ARCn) Processes - Archives the standby redo logs applied by the
managed recovery process (MRP).
117
(CONNECT_DATA =
(SERVICE_NAME = PROD)
)
)
Step3: Put your production database in Archive Log mode if your database not
running in Archive log mode add following entries in [Link] file in Production
Server.
LOG_ARCHIVE_START=TRUE
LOG_ARCHIVE_DEST_1='LOCATION=C:\oracle\database\archive MANDATORY
REOPEN=30'
LOG_ARCHIVE_DEST_2='SERVICE=STANDBY REOPEN=300'
LOG_ARCHIVE_DEST_STATE_1=enable
LOG_ARCHIVE_DEST_STATE_2=enable
LOG_ARCHIVE_FORMAT=ARC%[Link]
REMOTE_ARCHIVE_ENABLE=true
STANDBY_FILE_MANAGEMENT=AUTO
STANDBY_ARCHIVE_DEST = 'C:\standby\archive '
# db_file_name_convert: do not need; same directory structure
# log_file_name_convert: do not need; same directory structure
Step4 : After add above syntax in [Link] file, copy [Link] file from production
server to Standby server in Oracle_Home\Database\ folder.
Step5 : On the both system, the same directory structure was set-up
Step6 : Place production database in FORCE LOGGING mode by using following
statement:
SQL> alter database force logging;
Database altered.
Step8 : Make a copy of Production data files and redo flog file by performing
following steps:
Shutdown the Primary Database
Copy the Datafiles and redo log files to standby location by using OS Command
Step10 : Create Control file for Standby Database Issue the following command
on production database to create control file for the standby database.
SQL> Alter database create standby controlfile as
'c:\controlfile_standby.ctl';
118
Database altered.
Note: The filename for newly created standby control file must be different of
current control file of the production database. Also control file for standby
database must be created after the last timestamp for the backup Datafiles.
LOG_ARCHIVE_START = TRUE
LOG_ARCHIVE_DEST_1 = 'LOCATION=c:\oracle\database\archive MANDATORY'
LOG_ARCHIVE_FORMAT = arch%[Link]
REMOTE_ARCHIVE_ENABLE = true
STANDBY_FILE_MANAGEMENT = AUTO
LOG_ARCHIVE_MIN_SUCCEED_DEST=1
STANDBY_ARCHIVE_DEST = 'C:\standby\archive '
fal_server = FAL
fal_client = STANDBY
# db_file_name_convert: do not need; same directory structure
# log_file_name_convert: do not need; same directory structure
control_files - Specify the path name and filename for the standby control file.
standby_archive_dest - Specify the location of the archived redo logs that will
be received from the primary database.
119
standby_file_management - Set to AUTO.
C:\>set oracle_sid=PROD
C:\>sqlplus /nolog
SQL> conn sys/prod as sysdba
Database altered.
Step: 14 Initiate Log apply services The example includes the DISCONNECT
FROM SESSION option so that log apply services run in a background session.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
DISCONNECT FROM SESSION;
120
Database altered.
Database altered.
Result:
Archive the current log on the primary database using following statement.
Result:
121
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
DISCONNECT FROM SESSION;
Database altered.
Database altered. And check whether the changes applied on the standby
database or not.
Result:
ARCH CONNECTED 0 0 0 0
ARCH CONNECTED 0 0 0 0
RFS RECEIVING 0 0 0 0
From the query on the primary database, we see the current sequence being
written to in the redo log area is 4205, and on the standby database we also see
122
the current archive log being applied is for sequence 4205. In the directory that
receives archive files on the standby database, the file
DWH0P01_0000004205.arc will exist and will be the same size as the redo log
on the primary database. However the primary database will not have
DWH0P01_0000004205.arc as a file in the archive area, as a log switch will not
have occurred yet, but both databases are synchronized at the same sequence
and block number, 14947.
You can use the Recovery Manager DUPLICATE TARGET DATABASE FOR
STANDBY command to create a standby database.
After the standby database is created, RMAN can back up the standby
database and archived redo logs as part of your backup strategy. These
standby backups are fully interchangeable with primary backups. In other
words, you can restore a backup of a standby datafile to the primary
database, and you can restore a backup of a primary datafile to the standby
database.
123
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = Production IP)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = PROD)
)
)
# Connecting string for Standby Instance
STANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = STANDBY IP)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = PROD)
)
)
Step3: Put your production database in Archive Log mode if your database not
running in Archive log mode add following entries in [Link] file in Production
Server.
LOG_ARCHIVE_START=TRUE
LOG_ARCHIVE_DEST_1='LOCATION=C:\oracle\database\archive MANDATORY
REOPEN=30'
LOG_ARCHIVE_DEST_2='SERVICE=STANDBY REOPEN=300'
LOG_ARCHIVE_DEST_STATE_1=enable
LOG_ARCHIVE_DEST_STATE_2=enable
LOG_ARCHIVE_FORMAT=ARC%[Link]
REMOTE_ARCHIVE_ENABLE=true
STANDBY_FILE_MANAGEMENT=AUTO
STANDBY_ARCHIVE_DEST = 'C:\standby\archive '
# db_file_name_convert: do not need; same directory structure
# log_file_name_convert: do not need; same directory structure
124
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
100
Step10 : On the both system, the same directory structure was set-up
LOG_ARCHIVE_START = TRUE
LOG_ARCHIVE_DEST_1 = 'LOCATION=c:\oracle\database\archive MANDATORY'
LOG_ARCHIVE_FORMAT = arch%[Link]
REMOTE_ARCHIVE_ENABLE = true
STANDBY_FILE_MANAGEMENT = AUTO
LOG_ARCHIVE_MIN_SUCCEED_DEST=1
STANDBY_ARCHIVE_DEST = 'C:\standby\archive '
fal_server = FAL
fal_client = STANDBY
# db_file_name_convert: do not need; same directory structure
# log_file_name_convert: do not need; same directory structure
Note: Although most of the initialization parameter settings in the text initialization
parameter file that you copied from the primary system are also appropriate for the
physical standby database, some modifications need to be made.
C:\>set oracle_sid=PROD
C:\>sqlplus /nolog
SQL> conn sys/prod as sysdba
125
Step13 : Go to the Standby server and connect RMAN
Step14 : The following RUN block can be used to fully duplicate the target
database from the latest full backup. This will create the standby database:
run {
# Set the last log sequence number
set until sequence = 100 thread = 1;
# Allocate the channel for the duplicate work
allocate auxiliary channel ch1 type disk;
# Duplicate the database to ORA920
duplicate target database for standby dorecover nofilenamecheck ;
}
RMAN> exit
Database altered.
CONNECT / AS SYSDBA
126
SHUTDOWN IMMEDIATE
STARTUP NOMOUNT
ALTER DATABASE MOUNT STANDBY DATABASE;
RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM
SESSION;
Database Switchover
CONNECT / AS SYSDBA
ALTER DATABASE COMMIT TO SWITCHOVER TO STANDBY;
SHUTDOWN IMMEDIATE;
STARTUP NOMOUNT
ALTER DATABASE MOUNT STANDBY DATABASE;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
DISCONNECT FROM SESSION;
Now the original Primary database is in Standby mode and waiting for the new
Primary database to activate, which is done while connected to the standby database
(not the original primary)
CONNECT / AS SYSDBA
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
SHUTDOWN IMMEDIATE;
STARTUP
Graceful Database Fail over occurs when database fail over causes a standby
database to be converted to a primary database:
This process will recovery all or some of the application data using the standby redo
logs, therefore avoiding reinstantiation of other standby databases. If completed
successfully, only the primary database will need to be reinstatiated as a standby
database.
127
Query 1: protection_level should match the protection_mode after the next log
switch
1 row selected.
Query 2: ARCHIVER can be (STOPPED | STARTED | FAILED). FAILED means that the
archiver failed to archive a log last time, but will try again within 5 minutes.
LOG_SWITCH_WAIT The ARCHIVE LOG/CLEAR LOG/CHECKPOINT event log switching
is waiting for. Note that if ALTER SYSTEM SWITCH LOGFILE is hung, but there is
room in the current online redo log, then value is NULL
1 row selected.
1 row selected.
select
force_logging,remote_archive,supplemental_log_data_pk,supplemental_log
_data_ui, switchover_status,dataguard_broker from v$database;
128
FORCE_LOGGING REMOTE_ARCHIVE SUP SUP SWITCHOVER_STATUS
DATAGUARD_BROKER
NO ENABLED NO NO SESSIONS
ACTIVE DISABLED
1 row selected.
Query 5: This query produces a list of all archive destinations. It shows if they are
enabled, what process is servicing that destination, if the destination is local or
remote, and if remote what the current mount ID is.
........
........
10 rows selected.
Query 6: This select will give further detail on the destinations as to what options
have been set. Register indicates whether or not the archived redo log is registered
in the remote destination control file.
1 ARCH SYNCHRONOUS NO 0 0
0 300 YES MANDATORY
2 ARCH SYNCHRONOUS NO 0 0
0 300 YES OPTIONAL
...
...
129
10 rows selected.
Query 7: The following select will show any errors that occured the last time an
attempt to archive to the destination was attempted. If ERROR is blank and status is
VALID then the archive completed correctly.
1 VALID
2 VALID
3 INACTIVE
10 rows selected.
Query 8: The query below will determine if any error conditions have been reached
by querying the v$dataguard_status view (view only available in 9.2.0 and above):
no rows selected
Query 9: The following query will determine the current sequence number and the
last sequence archived. If you are remotely archiving using the LGWR process then
the archived sequence should be one higher than the current sequence. If remotely
archiving using the ARCH process then the archived sequence should be equal to the
current sequence. The applied sequence information is updated at log switch time.
1 233 233
2 233 233
2 rows selected.
Query 10: The following select will attempt to gather as much information as
possible from the standby. SRLs are not supported with Logical Standby until Version
10.1.
130
select dest_id id,database_mode db_mode,recovery_mode,
protection_mode,standby_logfile_count "SRLs", standby_logfile_active
ACTIVE, archived_seq# from v$archive_dest_status;
...
...
10 rows selected.
Query 11: Query v$managed_standby to see the status of processes involved in the
shipping redo on this system. Does not include processes needed to apply redo.
2 rows selected.
Query 12: The following query is run on the primary to see if SRL's have been
created in preparation for switchover.
no rows selected
Query 13: The above SRL's should match in number and in size with the ORL's
returned below:
Query 1: ARCHIVER can be (STOPPED | STARTED | FAILED) FAILED means that the
archiver failed to archive a log last time, but will try again within 5 minutes.
LOG_SWITCH_WAIT The ARCHIVE LOG/CLEAR LOG/CHECKPOINT event log switching
131
is waiting for. Note that if ALTER SYSTEM SWITCH LOGFILE is hung, but there is
room in the current online redo log, then value is NULL
1 row selected.
Query 2: The following select will give us the generic information about how this
standby is setup. The database_role should be standby as that is what this script is
intended to be ran on. If protection_level is different than protection_mode then for
some reason the mode listed in protection_mode experienced a need to downgrade.
Once the error condition has been corrected the protection_level should match the
protection_mode after the next log switch.
Selectname,database_role,log_mode,controlfile_type,protection_mode,prot
ection_level from v$database;
select
force_logging,remote_archive,supplemental_log_data_pk,supplemental_log
_data_ui, switchover_status,dataguard_broker from v$database;
NO ENABLED NO NO SESSIONS
ACTIVE DISABLED
1 row selected.
Query 4: This query produces a list of all archive destinations and shows if they are
enabled, what process is servicing that destination, if the destination is local or
remote, and if remote what the current mount ID is. For a physical standby we
should have at least one remote destination that points the primary set but it should
be deferred.
Query 5: If the protection mode of the standby is set to anything higher than max
performance then we need to make sure the remote destination that points to the
primary is set with the correct options else we will have issues during switchover.
132
select
dest_id,process,transmit_mode,async_blocks,net_timeout,delay_mins,reop
en_secs,register,binding from v$archive_dest;
Query 6: The following select will show any errors that occured the last time an
attempt to archive to the destination was attempted. If ERROR is blank and status is
VALID then the archive completed correctly.
Query 8: The following query is ran to get the status of the SRL's on the standby. If
the primary is archiving with the LGWR process and SRL's are present (in the correct
number and size) then we should see a group# active.
Query 9: The above SRL's should match in number and in size with the ORL's
returned below:
Query 10: Query v$managed_standby to see the status of processes involved in the
configuration.
selectprocess,status,client_process,sequence#,block#,active_agents,known
_agents from v$managed_standby;
Query 11: Verify that the last sequence# received and the last sequence# applied
to standby database.
Query 12: The V$ARCHIVE_GAP fixed view on a physical standby database only
returns the next gap that is currently blocking redo apply from continuing. After
resolving the identified gap and starting redo apply, query the V$ARCHIVE_GAP fixed
view again on the physical standby database to determine the next gap sequence, if
there is one. select * from v$archive_gap;
133