Wednesday, June 19, 2013

Backup and Recovery Best Practices using Oracle RMAN

Backup and Recovery Best Practices using Oracle RMAN

1. Turn on block checking
REASON: The aim is to detect, very early the presence of corrupt blocks in the database. This has a slight performance overhead, but Checksums allow Oracle to detect early corruption caused by underlying disk, storage system, or I/O system problems.

SQL> alter system set db_block_checking = true scope=both;

2. Turn on block tracking when using RMAN backups (if running 10g or above)
REASON: This will allow RMAN to backup only those blocks that have changed since the last full backup, which will reduce the time taken to back up, as less blocks will be backed up.

SQL> alter database enable block change tracking using file ‘/u01/oradata/ora1/change_tracking.f’;

3. Duplex log groups and members and have more than one archive log dest
REASON: If an archivelog is corrupted or lost, by having multiple copies in multiple locations, the other logs will still be available and could be used.

If an online log is deleted or becomes corrupt, you will have another member that can be used to recover if required.

SQL> alter system set log_archive_dest_2=’location=/new/location/archive2′ scope=both;
SQL> alter database add logfile member ‘/new/location/redo21.log’ to group 1;

4. When backing up the database use the ‘check logical’ parameter
REASON: This will cause RMAN to check for logical corruption within a block as well as the normal
head/tail checksumming. This is the best way to ensure that you will get a good backup.

RMAN> backup check logical database plus archivelog delete input;

5. Test your backup
REASON: This will do everything except actually restore the database. This is the best method to determine if your backup is good and usable before being in a situation where it is
critical and issues exist.

RMAN> restore validate database;

6. Have each datafile in a single backup piece
REASON: When doing a partial restore RMAN must read through the entire piece to get the
datafile/archivelog requested. The smaller the backup piece the quicker the restore can
complete. This is especially relevent with tape backups of large databases or where the
restore is only on individual / few files.

RMAN> backup database filesperset 1 plus archivelog delete input;

7. Maintain your RMAN catalog/controlfile
REASON: Choose your retention policy carefully. Make sure that it compliments your tape subsystem
retention policy, requirements for backup recovery strategy. If not using a catalog, ensure that your controlfile record keep time instance parameter matches your retention policy.

SQL> alter system set control_file_record_keep_time=21 scope=both;
This will keep 21 days of backup records.

Run regular catalog maintenance.
REASON: Delete obsolete will remove backups that are outside your retention policy. If obsolete backups are not deleted, the catalog will continue to grow until performance becomes an issue.

RMAN> delete obsolete;

REASON: crosschecking will check that the catalog/controlfile matches the physical backups. If a backup is missing, it will set the piece to ‘EXPIRED’ so when a restore is started, that it will not be eligible, and an earlier backup will be used. To remove the expired backups from the catalog/controlfile use the delete expired command.

RMAN> crosscheck backup;
RMAN> delete expired backup;

8. Prepare for loss of controlfiles set autobackup on
REASON: This will ensure that you always have an up to date controlfile available that has been taken at the end of the current backup not during.

RMAN> configure controlfile autobackup on;

keep your backup logs
REASON: The backup log contains parameters for your tape access, locations on controlfile backups that can be utilised if complete loss occurs.

9. Test your recovery
REASON: During a recovery situation this will let you know how the recovery will go without actually doing it, and can avoid having to restore source datafiles again.

SQL> recover database test;

10. Do not specify ‘delete all input’ when backing up archivelogs
REASON: Delete all input’ will backup from one destination then delete both copies of the archivelog where as ‘delete input’ will backup from one location and then delete what has been backed up. The next backup will back up those from location 2 as well as new logs from location 1, then delete all that are backed up. This means that you will have the archivelogs since the last backup available on disk in location 2 (as well as backed up once) and two copies backup up prior to the previous backup

NOARCHIVELOG DATABASE RECOVERY VIA RMAN





  • Your database is running in No Archive log mode and you have daily/weekly RMAN backup configured.

  • One fine day, your server crashed and you lose one of the disks or all the disks.

  • You have no other option but to restore the whole database backup to point of last valid backup.

rman target / catalog rman10/rman10@rman10s

Recovery Manager: Release 10.1.0.3.0 - Production
Copyright (c) 1995, 2004, Oracle.  All rights reserved.

Connected to target database (not started)
Connected to recovery catalog database


RMAN>

RMAN>
RUN
{
STARTUP NOMOUNT FORCE;
ALLOCATE CHANNEL CH1 DEVICE TYPE 'SBT_TAPE'
PARMS  'ENV=(TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/bin/tdpo.orcld.opt)';
RESTORE SPFILE;
SHUTDOWN IMMEDIATE;
STARTUP NOMOUNT;
RESTORE CONTROLFILE;
ALTER DATABASE MOUNT;
RESTORE DATABASE;
ALTER DATABASE OPEN RESETLOGS;
}

Startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/freespace/ORACLE/OCM/prod10gr1/dbs/initorcl.ora'

Trying to start the Oracle instance without parameter files...
Oracle instance started

Total System Global Area     142606336 bytes
Fixed Size                      778072 bytes
Variable Size                 70525096 bytes
Database Buffers              67108864 bytes
Redo Buffers                   4194304 bytes

Allocated channel: CH1
Channel CH1: Sid=28 devtype=DISK

Starting restore at 11-FEB-07

Channel CH1: starting datafile backupset restore
Channel CH1: restoring SPFILE
Output filename=/freespace/ORACLE/OCM/prod10gr1/dbs/spfileorcl.ora
Channel CH1: restored backup piece 1
Piece handle=/freespace/ORACLE/OCM/orcl/ORCL.20070211.8.1.1.614285217 tag=TAG20070211T184641
Channel CH1: restore complete
Finished restore at 11-FEB-07

Oracle instance shut down

connected to target database (not started)
Oracle instance started

Total System Global Area    1241513984 bytes

Fixed Size                      778896 bytes
Variable Size                347348336 bytes
Database Buffers             889192448 bytes
Redo Buffers                   4194304 bytes

Starting restore at 11-FEB-07
allocated channel: ORA_DISK_1
Channel ORA_DISK_1: Sid=159 devtype=DISK

Channel ORA_DISK_1: starting datafile backupset restore
Channel ORA_DISK_1: restoring controlfile
Channel ORA_DISK_1: restored backup piece 1
Piece handle=/freespace/ORACLE/OCM/orcl/ORCL.20070211.8.1.1.614285217 tag=TAG20070211T184641
Channel ORA_DISK_1: restore complete
Output filename=/freespace/ORACLE/OCM/orcl/control01.ctl
Output filename=/freespace/ORACLE/OCM/orcl/control02.ctl
Output filename=/freespace/ORACLE/OCM/orcl/control03.ctl
Finished restore at 11-FEB-07

Database mounted
Released channel: ORA_DISK_1

Starting restore at 11-FEB-07
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: Sid=159 devtype=DISK

Channel ORA_DISK_1: starting datafile backupset restore
Channel ORA_DISK_1: specifying datafile(s) to restore from backup set
Restoring datafile 00001 to /freespace/ORACLE/OCM/orcl/system01.dbf
Restoring datafile 00002 to /freespace/ORACLE/OCM/orcl/undotbs01.dbf
Restoring datafile 00003 to /freespace/ORACLE/OCM/orcl/sysaux01.dbf
Restoring datafile 00004 to /freespace/ORACLE/OCM/orcl/users01.dbf
Channel ORA_DISK_1: restored backup piece 1
Piece handle=/freespace/ORACLE/OCM/orcl/ORCL.20070211.7.1.1.614285202 tag=TAG20070211T184641
Channel ORA_DISK_1: restore complete
Finished restore at 11-FEB-07

Database opened
New incarnation of database registered in recovery catalog
Starting full resync of recovery catalog
Full resync complete

Oracle Enterprise Manager 12C installation




Oracle Enterprise Manager Cloud Control 12c Release 1 Installation on Oracle Linux 5.7 and 6.1
Enterprise Manager Cloud Control is the new name for what was previously know as Enterprise Manager Grid Control. Depending on the source of the material, you may still see the product described as Grid Control. This article describes the installation of Oracle Enterprise Manager Cloud Control 12c Release 1 on Oracle Linux 5.7 and 6.1. (x86_64).
Software
Download the following software:
Note. Previous versions of the database can be used to hold the repository, but anything earlier than 11.2.0.2 will require additional patches.
OS Installation
Install Oracle Linux (OL) 5.7 or 6.1 in the same way you would for a regular Oracle Database installation. You can see examples of these types of installations below. Remember to check the relevant database installation article (listed below) for the specific package group selection.
During this installation I used a virtual machine with 6G RAM and 30G disk space. The swap size was set at 8G and the firewall and SELinux were disabled.
Database Installation
Use one of the following articles to install the 11.2.0.3 database.
The installation documentation says the following packages are necessary for the cloud control installation. If you have performed the database installation as described in one of the above articles, these prerequisites will already have been met.
# OL 5.x and 6.x
make-3*
binutils-2*
gcc-4*
libaio-0*
glibc-common-2*
libstdc++-4*
sysstat-5*

# OL 5.x only
setarch-1*
rng-utils-2*
If you have performed a default database installation you will need to deconfigure Enterprise Manager Database Control. Run the following command as the "oracle" user.
$ emca -deconfig dbcontrol db -repos drop -SYS_PWD <sys pasword> -SYSMAN_PWD <sysman password>
Make the following initialization parameter changes and restart the instance.
sqlplus / AS SYSDBA

ALTER SYSTEM SET processes=300 SCOPE=SPFILE;
ALTER SYSTEM SET session_cached_cursors=200 SCOPE=SPFILE;
ALTER SYSTEM SET sga_target=2G SCOPE=SPFILE;
ALTER SYSTEM SET shared_pool_size=600M SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=1G SCOPE=SPFILE;
ALTER SYSTEM SET job_queue_processes=20 SCOPE=SPFILE;

-- May be required if using older versions of DB.
--ALTER SYSTEM SET log_buffer=10485760 SCOPE=SPFILE;
--ALTER SYSTEM SET open_cursors=300 SCOPE=SPFILE;

-- Restart the instance.
SHUTDOWN IMMEDIATE
STARTUP
If you have done a default installation as described here, the UNDO tablespace will be autoextensible. If you have done a custom installation make sure the UNDO tablespace is at least 200M in size. Also, make sure you have 3 redo logs of at least 300M to prevent a warning during the installation.
The database installation is now complete.
Cloud Control 12c Installation
Make a directory to hold the Middleware installation.
$ mkdir -p /u01/app/oracle/Middleware
Unzip the Cloud Control media, the start the installation by running the "runInstller" script.
$ unzip em12_linux64_disk1of2.zip
$ unzip em12_linux64_disk2of2.zip

$ ./runInstaller
If you wish to receive support information, enter the required details, or uncheck the security updates checkbox and click the "Next" button. Click the "Yes" button the subsequent warning dialog.
My Oracle Support Details
If you wish to check for updates, enter the required details, or check the "Skip" option and click the "Next" button.
Software Updates
If you have performed the prerequisites as described, the installation on OL5.7 should pass all prerequisite checks. On OL6.1 there is one failure due to the presence of "glibc-devel.i686", rather than the expected "glibc-devel.i386". This can be ignored by pressing the "Ignore" button, followed by the "Next" button.
Prerequisite Checks
Select the "Create a new Enterprise Manager System" and "Simple" options, enter the middleware home ("/u01/app/oracle/Middleware") and click the "Next" button.
Install Types
Enter the administrator password and database repository details, then click the "Next" button.
Configuration Details
On the first warning dialog, click the "Yes" button to disable the stats gathering job.
Repository Warning 1
Check the additional warnings, then click the "OK" button to continue.
Repository Warning 2
If you are happy with the review information, click the "Install" button.
Review
Wait while the installation and configuration take place.
Installation Progress Details
When prompted, run the root scripts, then click the "OK" button.
Root Scripts
Make note of the URLs, then click the "Close" button to exit the installer. A copy of this information is available in the "/u01/app/oracle/Middleware/oms/install/setupinfo.txt" file.
Finish
The login screen is available from a browser using the URL provided in the previous screen ("https://ol6-gc12c.localdomain:7803/em"). Log in with the username "sysman" and the password you specified during your installation.
Login
Once logged in, you are presented with a with the "License Agreement" screen. Click the "I Agree" button and you are presented with the homepage selector screen. Select the desired homepage (I chose Summary) and click the "Preview" button.
Homepage Selector
You are presented with the selected screen as the console homepage.
Console
Startup/Shutdown
Use the following commands to turn on all components installed by this article.
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export OMS_HOME=/u01/app/oracle/Middleware/oms
export AGENT_HOME=/u01/app/oracle/Middleware/agent/core/12.1.0.1.0

# Start everything
$ORACLE_HOME/bin/dbstart $ORACLE_HOME

$OMS_HOME/bin/emctl start oms

$AGENT_HOME/bin/emctl start agent
Use the following commands to turn off all components installed by this article.
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export OMS_HOME=/u01/app/oracle/Middleware/oms
export AGENT_HOME=/u01/app/oracle/Middleware/agent/core/12.1.0.1.0

# Stop everything
$OMS_HOME/bin/emctl stop oms -all

$AGENT_HOME/bin/emctl stop agent

$ORACLE_HOME/bin/dbshut $ORACLE_HOME