Backup Your Database With RMAN
Backup Your Database With RMAN
One (if not the, most important) jobs of the Oracle DBA is to ensure that the databases in their
care are protected. Databases, or data in the database, can be lost through a variety of ways
including:
* User error
* Hardware failure
* Software failure
* Disasters
* Application errors
To protect your database, you will need to know how to back it up and you will need to know
how to recover your database. Backup and recovery is what this last chapter is all about. Backup
and recovery can be a very difficult and complex topic, for there are a number of different
options for you to choose from when it comes to backing up a database. In this chapter, we aim
to set you on the right course, showing you how to perform basic database backup and recovery
operations.
In this chapter we will use the Oracle RMAN tool. It comes with the Oracle RDBMS and it’s
free. In this chapter we will cover:
So, without further delay, let’s get started on getting your database backed up.
Starting RMAN
The RMAN client is started from the operating system prompt. To use RMAN, simply set the
Oracle environment as you would before you use any other Oracle client (like SQL*Plus). Once
the environment is set, then you start RMAN as seen in this example:
rman target=/
Once you have started RMAN you will find yourself at the RMAN prompt. We are then ready to
begin our database backup.
Before we can use RMAN we need to configure a few settings. In this section we will look at
configuring the database for our backup, and then we will proceed to do the backup.
1. That you will be backing up to a file system called /u01/app/oracle/backup. You will need to
create this file system if it does not already exist.
Note that if you created your database as we described earlier in the book, you should already be
using an SPFILE.
The configuration is pretty basic. First, we need to configure a couple of database parameters.
These parameters will configure the Flash Recovery Area of the database.
This is the location that all the disk backups will be made to. To configure the flash recovery
area we will use the alter system command to set the value of two database parameters:
* db_recovery_file_dest_size – Determines how much space can be used by Oracle in the flash
recovery area.
We will configure the flash recovery area to the value of /u01/app/oracle/backup, and we will
assign it a 2 Gigabyte limit. Note! Oracle flash recovery area re-named to fast recovery area
You may need to assign your flash recovery area more space depending on the following factors:
* If you are running your database in ARCHIVELOG mode (which we will discuss later in this
chapter).
Here is an example of configuring the flash recovery area for the settlings listed previously. This
assumes your database is using a SPFILE which we discussed in earlier chapters:
Alter system set db_recovery_file_dest=’/u01/app/oracle/backup’;
We will also want to set a couple of RMAN settings before we do our first backup. Start RMAN
as detailed earlier in this section with:
$ rman target /
Next, we can use the RMAN configure command to configure these settings as seen in this
example:
-- Configure the retention policy to redundancy of 2.
-- This means RMAN will try to keep 2 copies of the database backups.
RMAN> configure retention policy to redundancy 2;
-- Configure automated backups of the control file and SPFILE.
RMAN>configure controlfile autobackup on;
Now that RMAN and the database are configured, we are ready to proceed to backup the
database.
Also, see my notes on the different backup types and the differences between incremental
cumulative and incremental differential backups.
Two improvements have been made in the backup and recovery areas in Oracle 10g. When
user errors and logical corruptions occur in the database, flashback functionalities provide
fast and flexible data recovery. When physical or media corruption occurs in the database,
RMAN delivers an improved and simplified recovery method.
Flashback Standby Database - This feature improves the switchover and failover time
of a standby database. You no longer need to specify a log apply delay, because you can
now roll back the standby database if an error occurs on the primary and is propagated to
the standby.
Flashback Reinstantiation - This feature reduces the need to reinstantiate the old
primary database following a failover. This in turn lets you restore full resiliency after a
failure more quickly. You can do this by using the SQL statement FLASHBACK
DATABASE to roll back the primary database in time to synchronize with the standby
database.
Flashback Drop - Oracle now provides a way to restore tables that were dropped
accidentally.
Flashback Table - This feature introduces the FLASHBACK TABLE statement in SQL,
which lets you quickly recover a table to a previous point in time without restoring a
backup.
Flashback Row History - Using undo data stored in the database, you can now view
the changes to one or more rows along with all the metadata of the changes.
Flashback Transaction History - This feature lets you examine changes to the
database at the transaction level. With flashback transaction history, you can diagnose
problems, perform analysis, and audit transactions.
Automated File Creation During Recovery - This feature enhances RMAN recovery
by automatically creating and recovering datafiles that have never been backed up.
Simplified Backups to Disk - Image backups provide fast recovery by being readily
usable. The Recovery Manager (RMAN) BACKUP command has been enhanced to
perform image copy backups at the database, tablespace, and datafile level.
Proxy Copy Backup of Archivelogs - You can now back up archive logs by using the
Recovery Manager (RMAN) Proxy Copy.
Incrementally Updated Backups - You can now apply a Recovery Manager (RMAN)
incremental backup to a datafile image backup. This results in reduced recovery time,
because fewer logs need to be applied, and reduced time to back up the database, because
you do not always have to back up the whole database.
Changes to the ALTER DATABASE END BACKUP Command - You can issue the
ALTER DATABASE END BACKUP command when the database is open.
Change-Aware Incremental Backups - By using a new type of log file to track blocks
that have changed in the database, Recovery Manager (RMAN) can avoid scanning the
entire datafile during an incremental backup. Instead, the amount of data scanned is
proportional to the amount of data changed.
RMAN Database Dropping and Deregistration - The new DROP DATABASE and
UNREGISTER DATABASE RMAN commands remove the database and its entry from the
RMAN recovery catalog.
Simplified Recovery Manager Cataloging of Backup Files - You can now catalog
RMAN proprietary backup metadata into a backup repository. If a backup is overwritten
in the control file, or a backup file is moved to a new location on disk, then you can easily
uncatalog the backup metadata from the repository.
Flashback Database
Flashback Database reduces the time required to recover the database to a previous point.
The time to restore a database is proportional to the number of changes that need to be
backed out, not the size of the database.
When Flashback Database is enabled, a new RVWR background process is started. This
process is similar to the LGWR (log writer) process. The new process writes Flashback
Database data to the Flashback Database logs.
Figure 12.1 RVWR Background process and Flashback Database Logs
The list below shows all the background processes for the 'grid' instance.
25 rows selected.
You can use the v$flashback_database_log to monitor the Flashback Database retention
target.
SQL> select *
2 from v$flashback_database_log;
You can also use the v$flashback_database_log view to assist in adjusting the recovery
area disk quota:
ESTIMATED_FLASHBACK_SIZE
------------------------
21823488
If you have multiple standby sites, you may utilize the DELAY option in Data Guard to
prevent physical/logical corruption or user errors in your primary database.
For example, the first scenario in the diagram below has only one standby database. Here,
a logical or physical corruption in the primary database will cause an immediate
corruption in the standby database.
To avoid such a pitfall, you can implement a second standby database with the 'Delay'
option (introducing a delay of minutes or hours on the second standby database for
applying archive log changes). This will prevent the corruptions on the second standby
database and allow recovery from a possible physical/logical corruption or user errors in
the primary database.
However, in Oracle 10g, you can configure the standby database with Flashback Database
to achieve the same benefit as the DELAY option. Therefore, there is no need to
implement a second standby database with the DELAY option.
Flashback Re-instantiation
The new Flashback Re-instantiation feature reduces the need to reinstantiate the old
primary database following a failover. This feature allows you to quickly restore full
resiliency after a failure. This is accomplished by using the SQL statement FLASHBACK
DATABASE to roll back the old primary database in time to synchronize with the old
standby database.
Flashback Drop
Prior to Oracle 10g, a DROP command permanently removed objects from the database.
In Oracle 10g, a DROP command places the object in the recycle bin. The extents allocated
to the segment are not reallocated until you purge the object. You can restore the object
from the recycle bin at any time.
This feature eliminates the need to perform a point-in-time recovery operation. Therefore,
it has minimum impact to other database users.
Recycle Bin
You can view the dropped objects in the recycle bin from two dictionary views:
In the example below, the name of the object is changed when it is dropped and moved to
the recycle bin. The recycle bin also keeps the original name of the object. This feature
allows you to create a new object of the same name and then drop it again.
Flashback complete.
Example 3: Dropping a Table Permanently
You can only issue this command when the tablespace users is empty. Objects in the
recycle bin of tablespace users will be purged:
When you issue this command, objects in the tablespace users are dropped. They are not
placed in the recycle bin. Any objects in the recycle bin belonging to the tablespace users
are purged.
Recyclebin purged.
This statement purges all objects from tablespace users in the recycle bin:
Tablespace purged.
Flashback Table
Flashback Table allows you to recover a table or tables to a specific point in time without
restoring a backup. When you use the Flashback Table feature to restore a table to a
specific point in time, all associated objects, such as indexes, constraints, and triggers will
be restored.
Flashback Table operations are not valid for the following object types:
Flashback Table is extremely useful when a user accidentally inserts, deletes, or updates
the wrong rows in a table. It provides a way for users to easily and quickly recover a table
to a previous point in time.
However, if the following DDL commands are issued, the flashback table command does
not work:
undo_retention Parameter
Data used to recover a table is stored in the undo tablespace. You can use the parameter
undo_retention to set the amount of time you want undo information retained in the
database.
To create an undo tablespace with the RETENTION GUARANTEE option, issue the
following command:
Guaranteed Retention
When an active transaction uses all the available undo tablespace, the system will start
reusing undo space that would have been retained, unless you have specified RETENTION
GUARANTEE for the tablespace.
You must have the FLASHBACK TABLE or FLASHBACK ANY TABLE system privilege to
use the Flashback Table feature.
This statement brings a table 'billing' back to a certain SCN number; table row movement
must be enabled as a prerequisite:
Flashback Query was first introduced in Oracle9i to provide a way to view historical data.
In Oracle 10g, this feature has been extended. You can now retrieve all versions of the
rows that exist or ever existed between the time the query was issued and a point back in
time. This type of query is called Flashback Row History.
You can use the VERSIONS BETWEEN clauses to retrieve all historical data related to a
row.
As you can see, the Flashback Row History feature retrieves all committed occurrences of
the row. It provides you with a way to view and repair historical data. In addition, it also
provides a new way to audit the rows of a table and retrieve information about the
transactions that changed the rows. You can use the transaction ID obtained from
Flashback Row History to perform transaction mining using LogMiner or Flashback
Transaction History (see next section) to obtain additional information about the
transaction.
The VERSION BETWEEN clause does not change the query plan. You can use the clause
in a SELECT statement against a view. However, you cannot use the VERSION BETWEEN
clause in a view definition.
The row history data is stored in the undo tablespace. The undo_retention initialization
parameter specifies how long the database will keep the committed undo information. If a
new transaction needs to use undo space and there is not enough free space left, any undo
information older than the specified undo retention period will be overwritten. Therefore,
you may not be able to see all the row histories. However, you can set the undo tablespace
option to RETENTION GUARANTEE to retain all row histories.
To verify the retention value for the tablespace, you can issue the following statement:
The Flashback Transaction History feature provides a way to view changes made to the
database at the transaction level. It allows you to diagnose problems in your database and
perform analysis and audit transactions. You can use this feature in conjunction with the
Flash Row History feature to roll back the changes made by a transaction. You can also
use this feature to audit user and application transactions. The Flashback Transaction
History provides a faster way to undo a transaction than LogMiner.
The above is an excerpt from the bestselling Oracle10g book Oracle Database 10g New Features by
Mike Ault, Madhu Tumma and Daniel Liu, published by Rampant TechPress.
Mike Ault, one of the world's most widely-read Oracle experts, has finally consented to release his
complete collection of more than 450 Oracle scripts, covering every possible area of Oracle
administration and management.
This is the definitive collection of Oracle monitoring and tuning scripts, and it would take
thousands of hours to re-create this vast arsenal of scripts from scratch.
Mike has priced his collection of 465 scripts at $39.95, less than a dime per script. You can
download them immediately at this link:
http://www.rampant-books.com/download_adv_mon_tuning.htm