Databases Reference
In-Depth Information
When you invoke an RMAN script, you must do so only within a
run
block, as shown in the following example,
where the script
backup_db
is executed using a
run
block:
run {execute script backup_db; }
We discuss RMAN scripting in detail in Chapter 9.
Issuing SQL Statements from the RMAN Client
Problem
You're using RMAN to issue backup and recovery commands, and you find that you need to issue some SQL
statements as well.
Solution
It's easy to execute an SQL statement from RMAN. All you need to do is type the keyword
SQL
followed by the actual
SQL statement. Make sure you enclose the actual SQL statement inside single or double quotes, if you're dealing with
a pre-Oracle Database 12c release database. For example:
RMAN> SQL 'alter system archive log all';
You can execute SQL statements from within a
run
block, too. The following
run
block restores and then recovers
the tablespace tools:
run
{
SQL "alter tablespace tools offline immediate";
restore tablespace tools;
recover tablespace tools;
SQL "alter tablespace tools online";
}
The example shown here illustrates how you can interleave SQL statements and RMAN commands within a
single
run
block. The first SQL statement takes the tools tablespace offline. Following this, the two RMAN commands
first restore and then recover the tools tablespace. The final SQL statement at the end of the
run
block brings the tools
tablespace online.
In Oracle Database 12c (12.1), it's easier to execute SQL commands and PL/SQL procedures because you don't
have to enclose the SQL commands in quotes—nor do you need to prefix them with the keyword
SQL
as we did in our
examples here. So, if you want to switch a log file in an Oracle Datbase 12c database from RMAN, all you need to do is
issue the following statement:
RMAN> alter system switch logfile;
Statement processed
RMAN>