0% found this document useful (0 votes)
18 views21 pages

Rman

Oracle RMAN

Uploaded by

Nasir Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views21 pages

Rman

Oracle RMAN

Uploaded by

Nasir Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

How To Check The Default Size & Location of Oracle FRA

By default both these parameters are set to nothing. Unless it was


configured by OUI during the installation.

You can check the default Size and location of your Oracle FRA with the
help of ‘ db_recovery_file_dest ‘ parameter. Like this –
First open up the command prompt and log onto your database using the
sys user

C:>sqlplus / as sysdba
Next, to check the values that are set on above mentioned parameters we
just need to query the ‘ db_recovery_file_dest ‘ parameter like this –

SQL> SHOW PARAMETER db_recovery_file_dest;


That’s all you have to do. Just press enter and you will see the results.

How To Configure Fast Recovery Area?


In this demonstration I will be using Oracle Database 19c. This process is
valid for almost all the oracle database versions that are available hence
you can still follow the steps. You can click here to learn how to install
Oracle Database 19c on Windows Operating System.

Step 1: Create a Directory


First decide a location for your FRA on your system. As I said earlier it
could be on your local machine or on a remote backup server. Once you
have done that, then create a directory there. You can name it whatever
you want.

For the demonstration I have created a directory in my D:/ drive and


named it ‘Oracle_FRA’.

Step 2: Parameter Configuration


To configure the Oracle FRA we need to set two parameters. These are –

1. db_recovery_file_dest_size, and
2. db_recovery_file_dest
The first parameter is used for setting the maximum disk size for your
FRA. Using it you set how much space your FRA can take on your hard
drive.

And, the second parameter is used for setting the location of your fast
recovery area. Whatever directory path you will set in this parameter will
be used by RMAN to save all the backups. In our demonstration that path
will be ‘D:\Oracle_FRA’.

Process of configuring Oracle Fast Recovery Area –


#Log into your Oracle Database using Sys User.

#I am using Command Prompt as a preferred tool for this process

C:\>SQLPLUS / AS sysdba

#First Set the size for Oracle FRA directory

#For the demonstration I am allocating 2GB to my FRA directory.

#Please refer to the 'What is the Right Size of the FRA' section above.

SQL/> alter system set db_recovery_file_dest_size = 2G SCOPE = BOTH;

#Now Set The Oracle FRA location

SQL/> alter system set db_recovery_file_dest = 'd:/Oracle_FRA' SCOPE =


BOTH;
Oracle FRA location Is Dependent on Oracle FRA Size
In the comments of the above code block, I clearly said that ‘First Set the
size for Oracle FRA directory’. This is because the
parameter db_recovery_file_dest is dependent on the first
one db_recovery_file_dest_size. Which means without
setting db_recovery_file_dest_size you cannot
set db_recovery_file_dest. Doing so will raise an error. So always make
sure to specify the size for your Oracle FRA first.

How to check FRA size?


How to check, what is the maximum size that has been allocated to a FRA
and how much has been consumed? Is the most asked question on my
Instagram. So here I am going to answer it once and for all –

You can find the maximum size of your FRA and the amount of space that
has been used by writing a simple query
against v$recovery_file_dest dynamic view.

SQL> SELECT name, space_limit , space_used FROM v$recovery_file_dest


This view can give you all the information about the disk quote and the
disk usage of your Oracle Fast recovery area.

The information that v$recovery_file_dest can give you is –

1. Location of the FRA


2. Maximum amount of disk space allocated to FRA.
3. Amount of disk space used by Fast recovery area. This amount
will be in bytes
4. The amount of disk space that you can reclaim.
5. Number of files stored in Flash recovery area.
If you are planning to be a DBA then this dynamic performance view is
your best friend.

How To Disable Oracle Fast Recovery Area?


Disabling Oracle Fast Recovery Area is very simple. You just have to
change the value of ‘db_recovery_file_dest’ parameter to an ’empty
string’, that will reset the parameter to it’s default value. However you
cannot reset ‘db_recovery_file_dest_size’ to it’s default value. However
you can reduce the size to 1byte.

#Disable the fast recovery area

#Reset the db_recovery_file_dest parameter

SQL/> alter system set db_recovery_file_dest = '' SCOPE = BOTH;

#Reduce the size of db_recovery_file_dest_size parameter to 1byte

SQL/> alter system set db_recovery_file_dest_size = 1 SCOPE = BOTH;


That’s it for this tutorial. You can also watch the video on my YouTube
channel on the same topic for the real time demonstrations. Thanks and
have a great day.

How To Setup Archive Log Destination Directory.


There are two main parameters that we need to configure to setup
Archive log destination directory. These are –

1. LOG_ARCHIVE_DEST_n, and
2. LOG_ARCHIVE_MIN_SUCCEED_DEST

Log_Archive_Dest_n Parameter
Log_Archive_Dest_n parameter is used to set a location for Archive Log
Destination Directory. Here are a few things about this parameter –

 The prefix n is a number in range of 1 to 10.


 Using LOG_ARCHIVE_DEST_n we can define up to 10 destinations
for saving the archived logs. if you have more that one location
setup then you will have redundant copies of archive logs
created by the Oracle Database server. It will occupy some extra
storage space but from backup perspective it’s always better to
have multiple backups.
 By default there is no Archive log destination directory setup in
Oracle Database. Which means if you want to use one, then you
have to set it up first.
 Using LOG_ARCHIVE_DEST_n you can setup a location which
could either be a
o Local folder created on your hard drive somewhere on
your system.
o A network directory
o A NAS location
o Service Name, if you have a data guard setup.

How To Use Log_Archive_Dest_n Parameter

Step 1: Create a Directory at your prefer location.

C:/> mkdir D:\ArchLog


For the demonstration I will be using a directory named ‘ArchLog’ which I
have created in my D:/ drive.

Step 2: Issue an ALTER SYSTEM Command


Once you have decided a location that you want to use as your Archive
log destination then issue an ALTER SYSTEM command to register that
directory in Oracle Server.

SQL> ALTER SYSTEM SET log_archive_dest_1 = 'location = D:\ArchLog';


On execution of this statement – We configure our 1st directory. This
directory is the OPTIONAL Archive log directory.

Mind here I emphasize on the keyword OPTIONAL . Let’s talk more about
it.

Optional & Mandatory Archive log directory.


Any location set as Archive log directory using LOG_ARCHIVE_DEST_n
parameter can either be an Optional or Mandatory location.
By default any location set using LOG_ARCHIVE_DEST_n parameter is
always optional.

What does that mean –

Let’s say you have two archive log directories created and both these
directories are optional in Nature. Then the Archiver Process (The
background process that is responsible for archiving your redo logs) does
not guarantee that in which directory your redo logs will get written or
even get written all together.

How To Create Mandatory Archive Log Directory


Creating a Mandatory Archive log directory in Oracle Database is actually
very simple. We just have to add the Keyword Mandatory to the Alter
system statement that we wrote previously. Like this –

SQL> ALTER SYSTEM SET log_archive_dest_1 = 'location=c:\oracle\app


MANDATORY'
That’s all you have to do.

The Question
Now the question is – if by default archive log directories are optional then
How and When can we consider Online Redo logs archived successfully?

The answer to this question is – our second parameter


LOG_ARCHIVE_MIN_SUCCEED_DEST. Let’s find out.

LOG_ARCHIVE_MIN_SUCCEED_DEST.
LOG_ARCHIVE_MIN_SUCCEED_DEST parameter sets the total number of
Archive Log Destination Directories that need to have successful copies of
the online redo logs in order to be considered as successfully archived.

By default the value of the LOG_ARCHIVE_MIN_SUCCEED_DEST is set to 1.


That means – Online Redo Logs are considered successfully archived, only
and only when, the archiver process (ARCH) creates a valid copy of Online
Redo logs, into at least one Archive log destination directory.
How To Alter LOG_ARCHIVE_MIN_SUCCEED_DEST.
You can change the value of LOG_ARCHIVE_MIN_SUCCEED_DEST using
ALTER SYSTEM command. You can update its value to any number
between 1 to 10. like this –

SQL> ALTER SYSTEM SET log_archive_min_succeed_dest = 2;


On successful execution – the number of directories that needs to have a
valid copy of online redo logs to be called successfully archived will be 2.

That’s it for this tutorial. Hope you find it helpful. For more details watch
the video.
Thanks and have a great day.

How To Enable ArchiveLog mode in Oracle Database 18/19c.


Iwill be performing the procedure of enabling Archive log mode on Oracle
Database 19c. You can follow the steps for any version that is 12c or later
as the process is the same.

Step 1: Connect With Container Database


First connect with your container database using SYS user.

C:\> SQLPLUS / AS SYSDBA

Step 2: Check the status of log mode


Before you enable the Archive log mode just check to make sure whether
it’s already enabled or not. And you can do that just by writing a simple
statement, like this

SQL> ARCHIVE LOG LIST;


If the log mode of your database is set to “ARCHIVELOG” then you don’t
have to do anything. But if it is set to “NOARCHIVELOG” then follow along

Step 3: Shutdown the database


In order to switch the log mode we first need to shutdown the database
SQL> Shutdown immediate

Step 4: Mount The Database


To perform the ALTER DDL statement (that we need to do in order to
switch the log mode) we need to mount the database first.

SQL> STARTUP mount;

Step 5: Enable the Archive log mode.


Now we will switch the log mode from NO ARCHIVE LOG to ARCHIVE LOG
mode.

SQL> ALTER DATABASE archivelog;

Step 6: Open The Database


In order to use the database for normal database activities we need to
open it.

SQL> ALTER DATABASE open;

Step 7: Check The Log mode


Before we start working with our database, we must check if we have
successfully enabled the ARCHIVELOG mode or not?

SQL> SELECT log_mode FROM v$database;


If the result of this statement comes out as “ARCHIVELOG” then that
means we have successfully enabled the ARCHIVELOG mode in our Oracle
Database.

That is how we enable ARCHIVELOG mode in Oracle Database 12c, 18c,


19c and later versions.
How To Connect With
RMAN
Two Ways To Connect
There are two ways to connect with RMAN in Oracle Database.

1. Using RMAN TARGET command


2. Using RMAN CONNECT command
let’s start with RMAN TARGET command –

RMAN TARGET command


If we already know which database we want to backup or recover, then
RMAN TARGET command is what we must go for.

First let’s learn how to connect with the container database using SYS
user as well as the common user that we created in the previous tutorial.

Connect With CDB using SYS user


C:\\> RMAN TARGET sys
after execution the prompt will ask you to enter the password of the SYS
user. Once you enter the password you will be connected with the RMAN
using SYS user and the container will be the root container.

Connect with the CDB using external user


Another way of connecting with the RMAN is through External user which
uses OS authentication. Like this

C:\\> RMAN TARGET /


In this case, again we are connected with the database using SYS user
with SYSDBA privileges. Did you notice, that this time we didn’t have to
specify the password. This is because, forward slash (/) indicates the
external user. In case of an external user the authentication is managed
by external services like the Native operating system.

I have done a tutorial on how to create and manage External User in


Oracle Database. For More details check that out. Link is in the
description.

Connect with the CDB using Common User!


Another way to connect with the CDB is by using Common User. Here is
how –

C:\\> RMAN TARGET c##backupAdmin/pass101


This command will connect you to the target database, which in my case
is ORCL(root container), using a common user. The user c##backupAdmin
that I used here is the one that I created in the last tutorial.

RMAN TARGET command with NET SERVICE


When you want to connect with a Remote Database then NET service
can come in handy. Let me show you how you can connect with the target
database using NET SERVICE through RMAN.
In the above picture you can see my TNSnames.ora file. In this file we can
see I have two services. One is ORCL and another is PDBORCL.

ORCL is the net service for the root container whereas pdborcl is the
service for pluggable database. In your case these names could be
different.
Here is how you can connect with the root container using net
service ORCL.

C:\\> RMAN TARGET c##backupUser/pass101


So far the command is the same as the previous one, now we will add TNS
service to this command like this

C:\\> RMAN TARGET c##backupUser/pass101**@ORCL**


What did we do here? We put @ sign followed by the name of the
TNS service. Now on execution this command will connect us to the
database towards which the TNS service is pointing . Which in this case is
the root container

How to connect with the PDB?


Establishing a connection with the pluggable database using RMAN is very
similar to connecting with the ROOT CONTAINER using TNS service.

Here is how –

So, in my case the name of the TNS service which is registered for the
pluggable database is ORCLPDB. Let’s use this service to connect with
the pluggable database using RMAN

Connecting to RMAN with PDB using SYS user-


let’s use sys user to connect with the PDB using RMAN

c:\\> RMAN TARGET sys@orclpdb


On successful execution the prompt will ask you to specify the password.
Once you’ve done that you will be connected with the pluggable database
using SYS user through a TNS SERVICE orclpdb.

Connection of RMAN with PDB using COMMON


user-
Let’s connect with RMAN using the common user C##backupAdmin

C:\\> RMAN TARGET c##backupAdmin/pass101@ORCLPDB


That’s all we have to do.

This command will connect the Recovery manager with the pluggable
database with which the NET Service ORCLPDB is registered.

RMAN CONNECT command.


So far we learnt how we could connect to the target database
using RMAN TARGET command.

Now let’s suppose you are already connected with the pluggable database
and you want to switch to a container database. One way is to disconnect
from RMAN and reconnect with it using the desired root container. This
requires you to exit from the RMAN prompt which is an inefficient way.

The efficient approach is to use the RMAN CONNECT command. Let me


show you how.

C:\\> RMAN TARGET c##backupUser/pass101@ORCLPDB


This is a previous prompt where we connected with our pluggable
database. Let’s say we want to switch to the container database. This is
how we do that

RMAN> CONNECT TARGET sys/oracle@orcl


On execution we will be connected with the root container ORCL using
SYS user. We have switched our target database and that too without
coming out from the RMAN prompt.

These are the ways to connect with the Recovery manager (RMAN) in
Oracle Database. Hope you learnt something new. Thanks and have a
great day!
Configure Oracle
Database to Store
Archive Redo Logs into
Fast Recovery Area
FRA is where Oracle Recovery Manager (RMAN) saves all the backups of
the database and necessary configuration files along with the metadata.
After enabling archivelog mode you should configure your database to
keep all the Archive logs into the Fast Recovery Area. This tutorial will
show how you can configure Archive redo logs to go to the Fast Recovery
area every time they are generated.

Step 1 – Enable Archive Log Mode.


In order to configure the location for archive redo logs first, you need to
enable the archive log mode in your Oracle Database. I have already done
a tutorial on how to enable Archive Log Mode. I suggest you check that
out, Link is here

How To Enable Archive Log Mode In Oracle Database

Step 2 – Configure the location


Once you have enabled the archive log mode next you can configure the
location of your archive redo logs. For that, you have to run an ALTER
SYSTEM DDL like this

log on to the database using SYS user with SYSDBA privilege

C:/>SQLPLUS / as SYSDBA
Next, we will run the alter system command

SQL>alter system set log_archive_dest_1 =


'LOCATION=USE_DB_RECOVERY_FILE_DEST';
On successful execution, your Oracle Database will use the FAST
RECOVERY AREA to store your archive redo logs.
Step 3 – Let’s Test
You can check if you have successfully set the Fast Recovery Area for
storing your archive redo logs. Like this

Again make sure you are connected with your database using the SYS
user. Next, write

SQL> archive log list


In this result, if you will look closely, the ARCHIVE DESTINATION is set
to USE_DB_RECOVERY_FILE_DEST hence it’s confirmed that the
destination of your archive redo logs is set to the Fast Recovery Area.

RMAN Validate Command


In Oracle RMAN there are three different ways to check Data files,
Tablespaces, Archive redo logs, control files, SPFILE, Backup set pieces or
even an entire pluggable database for corruption like Missing files or even
for any physical or logical corruption.

These three different ways are –

1. RMAN Validate command


2. RMAN Backup…Validate command, and
3. RMAN Restore…Validate command
In this tutorial we will focus on RMAN validate command and in the next
tutorial we will explore the remaining commands.

VALIDATE command
VALIDATE command checks the SPFILE, CONTROL FILE, Data File, Archive
Redo logs and backup set pieces for corruptions like missing file or any
physical corruption.

#Connect with your target database using RMAN

C> RMAN Target /


Validate the database

RMAN>VALIDATE database;
This command will validate all the data files of your database, Including
data files of container database as well as all the pluggable databases.
This will also validate the current control file and SPFILE.

VALIDATE control files


Let’s say you just want to validate the control files of your database. You
can do so like this –

RMAN> VALIDATE current controlfile;

VALIDATE archive logs


Similar to control file you can validate archive logs as well-

RMAN> VALIDATE archivelog all;


This command will validate all the archive redo log files.

You can combine all these three commands into one and check your
database, control file and archive redo logs just by issuing only one
command like this –

RMAN>VAlIDATE database INCLUDE current controlfile PLUS


archivelog;
This command will run all the integrity checks at once.

CHECK LOGICAL clause


So far the command that I have showed will only check for corruptions like
Missing file or Physical corruption. What if we want to check our database
or control file against logical corruption. We can do that by simply
including “check logical” clause with our validate command like this –

Let’s say you want to check your database for Physical as well as logical
corruption. You can do that like so-

RMAN>VALIDATE CHECK LOGICAL database;


This command will check the database for missing files as well as Physical
and Logical corruptions.

Similarly you can take this command


RMAN>VAlIDATE database INCLUDE current controlfile PLUS
archivelog;
And put “check logical” clause in it. After that it will also validate all the
the mentioned components against missing file, physical corruption as
well as logical corruption.

Few More VALIDATE commands


You can validate the copy of the database like this

RMAN> validate copy of database;


You can also VALIDATE a tablespace

RMAN> validate tablespace system;


Also VALIDATE the SPFILE like this

RMAN> validate spfile;


That’s a detailed tutorial on VALIDATE command. Hope you liked it.

How To Read Control File


In Oracle Database
The third most asked question in is “How Do I Read a Control File” in
Oracle Database? Since the control file is a binary file thus it’s not directly
accessible to us. In order to read its content, we need a way to decrypt it
into a user-readable file. And there are two ways of doing that. Let’s start
with the first one which is –

Backup Control file to Trace.


The easiest way to read a control file is to alter the database to backup
the control file to trace. Like this-

Step 1- Connect With the database using the SYS user

C> SQLPLUS / as SYSDBA


Step 2- Write Alter Database Statement
SQL>ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS 'D:\\
trace_cf.txt';
On successful execution this statement will create a user-readable version
of the Control file and save it into my D: drive with the name ‘trace_cf.txt’.
You can change this name and location according to your preference.

Now let’s check out the second way to read a control file in Oracle.

The Oradebug utility


The second way to read a control file is through the ORADEBUG utility of
the Oracle Database. Let me show you the process-

Step 1- Connect With the database using the SYS user

C>SQLPLUS / as SYSDBA
Step 2- Debug the current process

SQL> ORADEBUG setmypid;


Step 3- Set the size of the trace file to unlimited

SQ>ORADEBUG UNLIMIT;
By default, the size of the trace file is not set to unlimited. We have to do
it manually

Step 4- Use the alter session statement to display the physical


content of the control file.

SQL> alter session set events 'immediate trace name controlf


level 9';
In the end, we need the name and location of the trace file into which the
ORADEBUG utility saved the control file content and we can find that like
this –

SQL> oradebug tracefile_name


On successful execution, you will have the name and location of the trace
file which has all the content of the control file in a user-readable format.

That is how you check what control file contains in Oracle Database. Do
make sure to subscribe to my YouTube channel. Since next we will be
learning how to multiplex control files in Oracle Database.
How To Multiplex a
Control File
There are many questions about multiplexing of control file that I am
going to address in this tutorial. Questions like, why multiplexing is
important and different ways of multiplexing control files in Oracle
database. And at the end I will demonstrate how to multiplex a control file
using SPFILE in Oracle Database.

What is multiplexing of Control Files?


Copying and maintaining an existing control file at different locations and
informing the database about these copies by modifying CONTROL_FILE
parameter is called Multiplexing of control file.

Why Multiplexing a Control File?


Let’s say your database uses only one control file, and that control file
gets damaged. In this case you will either restore the control file from the
backup and perform the recovery or you will recreate the control file.

But what if you don’t have a good backup of your control file. Now you are
stuck. In such scenarios, having more than one control file can come in
handy.

If you have multiple control files and one of them gets damaged then you
can use the other control files to get your database operational in no time.

That is why multiplexing of control file is important.

Different ways of control file multiplexing


In Oracle Database there are two ways to multiplex a control file.

1. Using SPFILE, and


2. Using PFILE also know as ‘INIT.ORA’
How to Multiplex The Control File In Oracle Database
In this tutorial I will demonstrate the steps of multiplexing control file
using SPFILE. In the next tutorial I will cover the multiplexing using PFILE.

Step 1: Connect With the Database

C> SQLPLUS / as SYSDBA


Step 2: Check if the database is using SPFILE or PFILE

SQL> SHOW PARAMETER spfile;


If the database is using SPFILE then there will be the name along with
the location in the VALUE column and if the database is using PFILE
then there will be nothing in this column.

Since we have a name and location of the SPFILE in the VALUE column,
this signifies that my database is using SPFILE.

Step 3: Find Out The Control File

First find out the control file. You can refer to my tutorial on how to find
the location of control file in Oracle. But for now

SQL> show parameter control_files


This will show you the name with the location of your control file. Now we
are going to create a copy of this control file. So, COPY the entire path of
the control file with the name.

Step 4: Alter the CONTROL_FILES parameter. To make the database


aware of the changes we will configure the CONTROL_FILES parameter.

SQL> ALTER SYSTEM set CONTROL_FILES='C:\APP\ORADATA\ORCL\


CONTROL01.CTL',
First write the name along with the location of the first control file which in
my case is CONTROL01.CTL. Next write the name and location of the
second control file. Make sure both the names are separated by comma.

SQL> ALTER SYSTEM set CONTROL_FILES='C:\APP\ORADATA\ORCL\


CONTROL01.CTL',
'C:\APP\ORADATA\ORCL\CONTROL02.CTL' SCOPE = spfile;
Also, make sure to end this ALTER SYSTEM statement with SCOPE
parameter which is set to SPFILE;

STEP 5: SHUTDOWN the DATABASE

Now we have to shutdown the database so that we can make a consistent


copy of the control file for multiplexing

SQL> SHUTDOWN IMMEDIATE;


STEP 6: Make a copy of the control file

Now we will make a copy of the control file whose name and location we
copied earlier. For this I will open up a new command prompt.

C> copy C:\APP\ORADATA\ORCL\CONTROL01.CTL C:\APP\ORADATA\ORCL\


CONTROL02.CTL
You can name your control file whatever you want, just make sure to end
its name with .CTL extension.

Step 7: Start the database

Now we will start our database. If everything goes well then our database
will Mount and open for all the operations.

SQL> startup
You can even check whether you have successfully multiplexed your
control file or not. Simply by checking the value of control_files parameter,
like this:

SQL> show parameter control_files


This time we should see both our control files in VALUE column. If that
happens then it means multiplexing of control files has been done
successfully. So that is how we multiplex control file in Oracle Database
using SPFILE. In the next tutorial I will show you how to multiplex control
file using PFILE. So Stay tuned! Thanks and have a great day!

You might also like