How To Connect With RMAN in Oracle Database

In order to perform a backup or recovery of a database one must know how to connect with recovery manager (RMAN) in Oracle Database. There are multiple ways to connect with RMAN and in this tutorial I am going to cover almost all of them. This blog will show you how you can connect with the RMAN using local database as well as remote database using TNS service.

Target Database

So what is the target database?

The database whose backup or recovery we want to perform using RMAN is known as the target database.

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.

connect with RMAN using TNS service in Oracle Database

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!