Before you start RMAN and connect to your Oracle database 12C, you need to ensure that you have the proper OS variables set and that you have access to an account with sys* privileges. Once those are in place, you can start RMAN and connect to your target database via the rman command-line utility. These are the same conditions that need to be in place before connecting to your database as a privileged user are described earlier in this blog.
You can connect to RMAN either through the operating system command-line interface or through Enterprise Manager (EM). Using EM for backup and recovery is out of scope for my blog. We focuses on the command-line interface for its examples.
Tip Even if you use the screen based Enterprise Manager tool, it’s useful to understand the RMAN commands used for backup and recovery operations. This knowledge the foundation for using RMAN regardless of the interface. This awareness is particularly useful when debugging and troubleshooting problems.
The following example assumes you have logged on to a Linux/Unix server using the oracle operating system account assigned to a privileged group, such as dba and have established the required OS variables. You can then invoke RMAN and connect to the target database as follows:
$ rman target /
Here is a snippet of the output:
connected to target database: O12C (DBID=3458744089)
If you’re using a password file, then you need to specify the username and password that have been granted proper system privileges:
$ rman target <user>/<password>
If you’re accessing your target database remotely via Oracle Net, you will need a password file on the target server and will also need to specify a connection string as follows:
$ rman target <user with sys* priv>/<password>@<database connection string>
You can also invoke RMAN and then connect to your target database as a second step, from the RMAN prompt:
$ rman RMAN> connect target /
To exit RMAN, enter the exit command as follows:
Tip On Linux systems, when typing in the rman command from the OS prompt, if you get an error, such as “rman: can’t open target,” make sure your PATH variable includes ORACLE_HOME/bin directory before the /usr/X11R6/bin directory.
(NOT) CALLING RMAN FROM SQL*PLUS
I teach Oracle B&R classes at a local institute of higher learning. Nearly every term, one of the students asks why the following RMAN command doesn’t work:
SP2-0042: unknown command "rman" - rest of line ignored.
The answer is short: the rman client is an OS utility, not an SQL*Plus function. You must invoke the rman client from the OS prompt.
Notice that when connecting to RMAN, you do not have to specify the sys* clause (like you do when connecting as a SYSDBA privileged user via SQL*Plus). This is because RMAN always requires that you connect as a user with sys* privileges. Therefore, you must connect to RMAN with either a user who is OS authenticated or a username/password with sys* privileges granted to it (and therefore exists in the password file). This is unlike SQL*Plus, where you have the option of connecting as a non-privileged user. In SQL*Plus, if you want to connect as a user with sys* privileges, you are required to specify a sys* clause when connecting.
If you attempt to connect to RMAN without the proper privileges, you’ll receive this error:
ORA-01031: insufficient privileges
A useful way to troubleshoot the root cause of an ORA-01031 error is to attempt to log in to SQL*Plus with the same authentication information as when trying to connect through RMAN. This will help verify either that you are using an OS-authenticated account or that the username and password are correct. If OS authentication is working, you should be able to log in to SQL*Plus as follows:
$ sqlplus / as sysdba
If you’re using a password file, you can verify that the username and password are correct (and that the user has sysdba privileges) by logging in as shown here:
$ sqlplus <username>/<password> as sysdba
If you receive an ORA-01031 error from attempting to log in to SQL*Plus, then either you aren’t using an OS-authenticated account or your username and password combination does not match what is stored in the password file (for users attempting to connect with sys* privileges).
Once connected to RMAN, you can issue administrative commands, such as startup, shutdown, backup, restore, and recover. For example, if you want to start and stop your database, you can do so from within RMAN as follows:
$ rman target / RMAN> startup; RMAN> shutdown immediate;
This saves you the inconvenience of having to jump back and forth between SQL*Plus and RMAN (when issuing administrative commands).
RUNNING SQL COMMANDS FROM WITHIN RMAN
Starting with Oracle 12c, you can run many SQL commands directly from the RMAN command line. In prior versions of Oracle, when running certain SQL commands from within RMAN, you had to specify the sql clause. For example, say you wanted to run the alter system switch logfile command. Prior to Oracle 12c, you would have to specify that command as shown:
RMAN> sql 'alter system switch logfile';
In Oracle 12c, you can now run the SQL directly:
RMAN> alter system switch logfile;
This is a nice ease-of-use enhancement because it eliminates the need for additional clauses and quotes around the command.