Friday, May 20, 2011

Rebuilding Indexes


select 'ALTER INDEX '|| index_name ||' REBUILD TABLESPACE INDX;’ from USER_INDEXES -- TO GET ALL THE INDEXES

alter system enable restricted  session;


Run the indexes rebuild script

alter system disable restricted  session;





Sunday, May 15, 2011

RMAN Script: POINT IN TIME RECOVERY


[point_intime_recovery.scp]
# This scenario assumes that all initializaiton filesa nd the current controlfile arein place and you want to recover to a point in time '2001-04-09"14:30:00'.

# Ensure you set your NLS_LANG enviroment variable

        STARTUP MOUNT FORCE;
        RUN
        {
        SET UNTIL TIME "TO_DATE('2001-04-09:14:30:00','yyyy-dd-mm:hh24:mi:ss')";
        RESTORE DATABASE;
        RECOVER DATABASE;
        ALTER DATABASE OPEN RESETLOGS;
        }

# You must take a new whole database backup after resetlogs,since backups of previous incarnation are not easily usable

RMAN SCRIPT : DISASTER RECOVERY


[ disaster_recovery.scp]
# The commands below assume that all initialization parameters files are in place and the complete directory structure for the datafiles is recreated
# Ensure uou set your NLS_LANG environment variable
# e.g in unix (csh);
# >setenv NLS_LANG amarican_america.we8dec

# Start RMAN without the target option, and use the following commands to restor
e and recover the database

# SET DBID; use database if from RMAN output
# not required if using recovery catalog

        connect target sys/password@omr
        startup nomount;
        run
        {
# you need to allocate channels if not using recovery catalog.

        allocate channel c1 type disk;

# optionally you can set newname and switch commands to restore datafiles to a new location

        restore controlfile from autobackup;
        alter database mount;
        restore database;
        reocver database;
        alter database open resetlogs;

# you must take  a new whole database backup after resetlogs, since backups of previous incarnatin are not easily usable.

RMAN SCRIPT : CONTROLFILE RECOVERY


[controlfile_recovery.scp]
# Oracle strongly recommends that you specify multiple controlfiles, on separate  physical disks and controllers, in the CONTROL_FILE initialization parameter.
# - If one copy is lost due to media failure, copy one of the others over the lost controlfile and restart the instance.
# - If you lose all copies of the controlfile, you must re-create it using the create controlfile sql command
# You should use RMAN to recover a backup controlfile only if you have lost all copies of the current controlfile, because after restoring a backup controlfile, you will have to open RESETLOGS and take a new whole database backup.
# This section assumes that all copies of the current controlfile have been lost, and than all initialization parameter files, datafiles and online logs are intact.
# Ensure you set your NLS_LANG environment variable e.g. in unix (csh):
#  >setenv NLS_LANG american_america.we8dec
# Start RMAN without the TARGET option, and use the following commands to restore and recover the database;
# SET DBID ;  use database id from RMAN output; not required if using recovery catalog


        connect target sys/password@omr
        startup nomount;
        run
        {

# you need to allocate channels if not using recovery catalog.
# allocate channel foo type sbt parms'';

        allocate channel c1 type disk;
        restore controlfile from autobackup # or ;
        alter database mount;
        recover database;
        alter database open resetlogs;
        }

# you must take a new whole database backup after reerlogs, since backups of pre
vious incarnation are not easily usable
$

RMAN Script: DATAFILE RECOVERY


[datafile_recovery.scp]
# This section assumes that datafile 5 has been damaged and needs to be restored
 and recovered, and that the current controlfile and all other datafiles are int
act. the database is mounted during the restore and recovery.

# the steps are:
# - offlie the datafile that needs recovery
# - restore the datafile from backups
# - apply incrementals and archivelogs as necessary to recover.
# - make online recovered datafile

        run
        {
        sql 'alter database datafile 5 offline';

#if you want to restore to a different location,uncomment the following command
# Set newname for datafile 5 to '/newdirectory/new_filename.f';

        restore datafile 5;

# if you restored to a different locatin, uncomment the command below to
# switch the controlfile to point to the file in the new location
# SWITCH DATAFILE ALL;

        recover datafile 5;
        sql 'alter database datafile 5 online';
        }