Interview Questions
Interview Questions
SNAPSHOT CONTROLFILE
A snapshot control file is created by RMAN during the backup process that serves as
a point-in-time copy of the database control file. This will ensure that that backups
being taken is consistent to a given point in time. For example, if you add a datafile or
tablespace to a database after the backup has started, (assuming an online backup and
before the backup has ended), that datafile and/or tablespace will not be included in
the backup. It is sometimes required that the location and name of the snapshot
control file be changed from its default.
To set the snapshot control file to a different location (and name) use the following:
RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/orabackup/rman/ORA920/scontrolfile.ctl';
NOTE: The default value for the snapshot control file name is platform-specific and
dependent on the Oracle home. For example, the default on some UNIX system
is?/dbs/[email protected]. If you clear the control file name, and you change the Oracle home,
then the default location of the snapshot control file changes as well.
As RMAN needs a consistent view of the control file it takes a backup of the controlfile by
creating a snapshot and during the backup RMAN uses the snapshot of the controlfile. By
default the snapshot controlfile is created in $ORACLE_HOME/dbs/snapcf_ORACLE_SID.f
which can be changed by setting the following parameter in RMAN
$ rman target /
display parameter value
RMAN> show all;
..
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/u01/10.2.0.4/TESTDB/snapcf_TESTDB.f'; # default
set to new path for controlfile snapshot
RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/u02/TESTDB/snapcf_TESTDB.f';
When multiple RMAN are running one could run into an issue RMAN-08512 where RMAN is
waiting for getting a lock on snapshot controlfile header. To find the session run the
following SQL.
SELECT vs.sid, vs.username, vs.program, vs.module, TO_CHAR(vs.logon_time, 'DDMON-YYYY HH24:MI:SS')
FROM v$session vs, v$enqueue_lock vel
WHERE vs.sid = vel.sid AND vel.type = 'CF' AND vel.id1 = 0 AND vel.id2 = 2
In this case, it is set to the default location. You can change it using the configure
command.
2)
How To Register Older Backups To RMAN
Catalog
W henever backups were taken using the OS utility the backup information is not updated in the
repository.Only the backups taken using rman utility were updated in the catalog.To update the catalog about
the backup information took @ os level we can use the catalog command.
.
3)
How to catalog and uncatalog a backup to
RMAN repository
4) Catalog Backup
Whenever we take any backup through RMAN, in the repository information of the backup is
recorded. The RMAN respository can be either controlfile or recovery catalog. However if I take a
backup through OS command then RMAN does not aware of that and hence recorded are not
reflected in the repository. This is also true whenever we create a new controlfile or a backup
taken by RMAN is transferred to another place using OS command then controlfile/recovery
catalog does not know about the prior backups of the database. So in order to restore database
with a new created controlfile we need to inform RMAN about the backups taken before so that it
can pick one to restore.
This task can be done by catalog command in RMAN. With catalog command it can
-Add information of backup pieces and image copies in the repository that are on disk.
-Record a datafile copy as a level 0 incremental backup in the RMAN repository.
-Record of a datafile copy that was taken by OS.
5)
6)
7)
Database incarnation is effectively a new version of the database that happens when you reset the online
redo logs using alter database open resetlogs;.
8)
Database incarnation falls into following category Current, Parent, Ancestor andSibling
9)
i) Current Incarnation : The database incarnation in which the database is currently generating redo.
10) ii) Parent Incarnation : The database incarnation from which the current incarnation branched following
an OPEN RESETLOGS operation.
11) iii) Ancestor Incarnation : The parent of the parent incarnation is an ancestor incarnation. Any parent of
an ancestor incarnation is also an ancestor incarnation.
12) iv) Sibling Incarnation : Two incarnations that share a common ancestor are sibling incarnations if
neither one is an ancestor of the other.
.
Q. How to view incarnation history of Database ?
13) Using SQL> select * from v$database_incarnation;
Using RMAN>LIST INCARNATION;
14) However, you can use the RESET DATABASE TO INCARNATION command to specify that SCNs are to
be interpreted in the frame of reference of another incarnation.
15) For example my current database INCARNATION is 3 and now I have used
FLASHBACK DATABASE TO SCN 3000;then SCN 3000 will be search in current incarnation which is 3.
However if I want to get back to SCN 3000 of INCARNATION 2 then I have to use,
16) RMAN> RESET DATABASE TO INCARNATION 2;
RMAN> RECOVER DATABASE TO SCN 3000;
6) What happens during the hot backup and why redolog generation is more during hot backups?
I am just trying to explain my little knowledge on hot backup process
During hot backup, a script or begin backup command puts a tablespace into backup mode, then copies the
datafiles to disk or tape, then takes the tablespace out of backup mode.
Many people are having a misconception regarding hot backup that, during hot backup DBWR process will
stop writing into datafiles. Also, they say that while the datafiles are not writable, changes are stored
somewhere in the SGA, the redologs, the rollback segments etc places and will be written back to datafiles
when the tablespace is taken out of backup mode.
In fact, Oracles tablespace hot backup does not work this way at all. It absolutely does not stop writing the
datafiles, and actually allows continued operation of the database almost exactly as during normal
operation.
1. The tablespace is checkpointed 2. The checkpoint SCN in the datafile header freeze to increment with
checkpoints 3. Full images of changed DB blocks are written to the redologs
The above three actions are all that is required to guarantee consistency once the file is restored and
recovery is applied. By freezing the checkpoint SCN in the file headers, any subsequent recovery on that
backup copy of the file will know that it must commence at that SCN. Having an old SCN in the file header
tells recovery that the file is an old one, and that it should look for the redolog file containing that SCN, and
apply recovery starting there. Note that checkpoints to datafiles in hot backup mode are not stopped during
the backup, only the incrementing of the main checkpoint SCN flag will stop increasing.
By initially checkpointing the datafiles that comprise the tablespace and logging full block images to redo,
Oracle guarantees that any blocks changed in the datafile while in hot backup mode will also be available in
the redologs in case they are ever used for a recovery.
Also we will observe that huge redo will be generated during hot backup. This is the result of the logging of
full images of changed blocks in these tablespaces to the redologs. Normally, Oracle logs an entry in the
redologs for every change in the database, but it does not log the whole image of the database block. By
logging full images of changed DB blocks to the redologs during backup mode, Oracle eliminates the
possibility of the backup containing fractured blocks. To understand this reasoning, you must first
understand what a fractured block is.
Typically, Oracle database blocks are a multiple of O/S blocks. For instance, most Unix filesystems have a
default block size of 4k, while Oracles default block size is 8k. This means that the filesystem stores data in
4k chunks, while Oracle performs reads and writes in 8k chunks, or multiples. While backing up a datafile,
your backup script makes a copy of the datafile from the filesystem, using O/S utilities such as copy, dd etc.
As it is making this copy, it is reading in O/S-block sized increments. If the database writer happens to be
writing a DB block into the datafile at the same time when backup is reading that block, your backup copy of
the DB block could contain some O/S blocks before and after writing by DBWR. This kind of blocks which are
having mismatched halves are called fractured blocks.
By logging the full block image of the changed block to the redologs, it guarantees that in the event of a
recovery, any fractured that might be in the backup copy of the datafile will be resolved by replacing them
with the full image of the block from the redologs.
7) What is the use of the crosscheck command and how to delete the expired backups?
When files are deleted @ os level using unix command the deletion information is not updated in the catalog. And
when you view the available backups it will show the non existing backups also as catalog will not get updated when
and reports to
locate "expired" or "obsolete" RMAN catalog entries we can use the crosscheck
command.
deletions happens @ os level. To update the catalog with the deletion information and also to
In other words crosscheck command is used to update the catalog with the available
physical backups by checking backups availability @ os level.
The RMAN crosscheck command is used when RMAN indicates that a file is
"missing:
RMAN> crosscheck backuppiece xxx;
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=xxx
crosschecked 1 objects
As we see the RMAN crosscheck command compares the RMAN catalog entries
with the actual OS files and reports to locate "expired" or "obsolete" RMAN catalog
entries.
Once a RMAN crosscheck identified expired, deleted on on obsolete catalog entries
you can run an RMAN delete command to remove these entries to synchronize the
RMAN catalog with the real database files:
RMAN> delete noprompt obsolete;
The RMAN crosscheck command can also be used to archive RMAN catalog entries:
crosscheck archivelog all ;
Today I have to rebuild a physical standby database because there is a gap between primary and
standby. After I deleted the previous full backup used to create the standby, I need to use crosscheck
backup and delete expired backup to remove the information about the deleted backup recorded in
primarys control file:
ora1024@cnrac1:/home/ora1024/stage> rman target /
Recovery Manager: Release 11.1.0.6.0 - Production on Thu Jun 2 14:06:15 2011
Copyright (c) 1982, 2007, Oracle.
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/home/ora1024/stage/Database01mb9q77_1_1 RECID=1 STAMP=750053608
deleted backup piece
backup piece handle=/home/ora1024/stage/Database02mb9q7h_1_1 RECID=2 STAMP=750053619
deleted backup piece
backup piece handle=/home/ora1024/stage/Database03mb9q98_1_1 RECID=3 STAMP=750053674
deleted backup piece
backup piece handle=/home/ora1024/stage/Database04mb9q9c_1_1 RECID=4 STAMP=750053676
deleted backup piece
backup piece handle=/home/ora1024/stage/Control05mb9qa0_1_1 RECID=5 STAMP=750053697
Deleted 5 EXPIRED objects
check whether backup pieces, proxy copies, or disk copies still exist in comparison to
the control file's repository.
Syntax:
CROSSCHECK
{
{ BACKUP [OF listObjList]
| COPY [OF listObjList]
| archivelogRecordSpecifier
} [maintQualifier [maintQualifier]]
| recordSpec [DEVICE TYPE deviceSpecifier [,
deviceSpecifier]]
};
listObjList::=
[ DATAFILE datafileSpec [, datafileSpec]
| TABLESPACE ['] tablespace_name ['] [, [']
tablespace_name [']]
| archivelogRecordSpecifier
| DATABASE [SKIP TABLESPACE ['] tablespace_name [']
[, ['] tablespace_name [']]]
| CONTROLFILE
| SPFILE
]
Use RMAN Crosscheck to check that files are in place ready for a restore.
To validate a restore has worked, use the RMAN restore validate command.
Examples:
Assuming you have configured automatic channels:
RMAN>
RMAN>
RMAN>
RMAN>
RMAN>
CROSSCHECK
CROSSCHECK
CROSSCHECK
CROSSCHECK
CROSSCHECK
BACKUP;
COPY;
backup of database;
backup of controlfile;
archivelog all;
Query the media manager for the status of backup sets in a given date range:
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt;
RMAN> CROSSCHECK BACKUP DEVICE TYPE sbt COMPLETED BETWEEN '01AUG-04' AND '31-DEC-04';
"Wealth heaped on wealth, nor truth nor safety buys,
The dangers gather as the treasures rise" - Samuel Johnson: The Vanity Of Human
Wishes
Related Commands:
RMAN Restore Validate
RMAN CHANGE - Update the status of a backup in the RMAN repository.
RMAN CONFIGURE - Persistent RMAN settings.
RMAN DELETE - Delete backups from disk or tape
RMAN LIST - List backups and copies
RMAN REPORT - Report backup status: database, files, backups
NLS_DATE_FORMAT parameter
Related Views:
RC_BACKUP_FILES V$BACKUP_FILES
repository.
RC_BACKUP_PIECE V$BACKUP_PIECE
RMAN> run
{
set newname for datafile 4 to '/tmp/datafile4.dbf';
restore datafile 4;
}
executing command: set newname
channel ORA_DISK_1: restoring datafile 00004 to /tmp/datafile4.dbf
To create a tempfile in a new directory while cloning the database, use the set
newname for tempfile to ?. command as follows:
RMAN> run
{
set newname for tempfile 1 to /tmp/temp01.dbf';
duplicate database;
}
RMAN will create a new tempfile with a specified name after the database is
recovered and opened.
This option is used to change all datafiles in a specified tablespace. When using this
option, you must use a substitution variable to avoid name collisions. Here is the list
of substitution variables which are used during name conversion:
%b: Specifies the file name without the directory that it locates.
%N: Specifies the tablespace name
%f: Specifies the absolute file number of a datafile
%I: Specifies DBID
See the following example to understand these substitution variables. In the following
example, the %b, %N and %f variables are used:
RMAN> run
2> {
3> set newname for tablespace users to '/tmp/db/%n_%f_%b';
4> restore tablespace users;
5> }
output file name=/tmp/db/USERS_4_users01.dbf RECID=8 STAMP=728496167
output file name=/tmp/db/USERS_5_user02.dbf RECID=9 STAMP=728496168
By using the %U variable, you can get the system-generated unique filename. Look at
the following example:
RMAN> run
2> {
3> set newname for tablespace users to '/tmp/db/%u';
4> restore tablespace users;
5> }
output file name=/tmp/db/data_d-test_ts-users_fno-4 recid=10
stamp=728496242
output file name=/tmp/db/data_d-test_ts-users_fno-5 recid=11 stamp=728496243
This option is used to set a new name for all datafiles and tempfiles in a database. This
option is also used with one of the above mentioned substitution variables.
9) How do you know that how much RMAN task has been completed?
When new incarnation happens, the old backup information in control file will be lost. It will be preserved
in recovery catalog.
In recovery catalog we can store scripts.
Recovery catalog is central and can have information of many databases.
11) Command to delete archive logs older than 7days?
Crosscheck will be useful to check whether the catalog information is intact with OS level information.
This command only updates repository records with the status of the backups.
e.g. If user removes archived logs from disk with an operating system command, the repository still
indicates that the logs are on disk, when in fact they are not.
13) What are the differences between crosscheck and validate commands?
Validate command is to examine a backup set and report whether it can be restored. RMAN scans all of
the backup pieces in the specified backup sets and looks at the checksum to verify that the contents are
intact so that backup can be successfully restored if necessary.
Crosscheck command is to verify the status of backups and copies recorded in the RMAN repository
against media such as disk or tape. The crosscheck command only processes files created on the same
device type as the channel running crosscheck.
14) What is obsolete backup & expired backup?
A status of expired means that the backup piece or backup set is not found in the backup destination.
A status of obsolete means the backup piece is still available, but it is no longer needed. The backup
piece is no longer needed since RMAN has been configured to no longer need this piece after so many
days have elapsed, or so many backups have been performed.
What is the difference between hot backup & RMAN backup?
For hot backup, we have to put database in begin backup mode, then take backup.
RMAN wont put database in backup mode.
15) In catalog database, if some of the blocks are corrupted due to system crash, How will you
recover?
using RMAN BLOCK RECOVER command
16) Using v$block_corruption view you can find which blocks corrupted.
Using the above statement You recover the corrupted blocks. First check whether the block is corrupted
or not by using this command
SQL>select file# block# from v$database_block_corruption;
file# block
2 507
the above block is corrupted
conn to Rman
To recover the block use this command
RMAN>blockrecover datafile 2 block 507;
the above command recover the block 507
Now just verify it..
Rman>blockrecover corruption list;
Redo log files are filled with redo records. A redo record, also called a redo entry, is made up of a
group of change vectors, each of which is a description of a change made to a single block in the
database. For example, if you change a salary value in an employee table, you generate a redo
record containing change vectors that describe changes to the data segment block for the table,
the undo segment data block, and the transaction table of the undo segments.
Change vector is the redo entry of Log buffer. It is generated with every DML operation and
stored in log buffer for keeping track of every transaction of database (database changes).
Change Vectors
A logically atomic database change to an Oracle database normally consists of two or
more physical block changes. For example, inserting a row into a table may involve
changes to several index blocks, as well as a change to one of the blocks of the table
itself. And for most block changes, there must be a corresponding change to at least
one rollback segment block. There may also be changes required to a rollback
segment header block, block cleanouts, freelist changes, and so on.
Before making a database change, a process must take buffer locks on each of the
buffers holding the current mode image of the database blocks affected, and prepare a
set of change vectors representing the intended changes -- one for each physical
database change. Before the set of change vectors can be applied to the database
blocks, they must all be copied into the redo stream as a single redo record. Redo
records are sometimes called redo entries.
One very useful feature about partitioning that is available since version 8 is the possibility
of partition pruning. That means, that the optimizer during the parse phase of a SQL statement is
able to exclude certain partitions from scanning because according to the definition of the
partitioned table present in the Data Dictionary, the desired rows cant be in those partitions.
When we for example have a table that is partitioned by range on a date column with one
partition for each quarter of the year, it is implicitly clear for a query like
select * from t where time_id=to_date('01-01-2009','dd-mm-yyyy');
some tables are so large that a Full Table Scan is unthinkable. If these tables are
not partitioned, they should be.
The most common (by far) form of partitioning is Range Partitioning on a DATE
column. For example, a table may be partitioned on TXN_DATE, with a separate
partition for each year, month, or even day (I have seen a multi-terabyte database
where daily partitions were the norm!).
If Oracle can use the WHERE predicates to eliminate some partitions from a search,
then it probably will. This is called Partition Pruning. For example:
SELECT *
FROM my_big_partition_table
WHERE calendar_date = :b1
SELECT STATEMENT
PARTITION RANGE SINGLE
TABLE ACCESS FULL MY_BIG_PARTITION_TABLE
SELECT *
FROM my_big_partition_table
WHERE calendar_date >= :b1
SELECT STATEMENT
PARTITION RANGE ITERATOR
TABLE ACCESS FULL MY_BIG_PARTITION_TABLE
Partition Pruning
This section discusses an optimization known as partition pruning. The core concept behind partition
pruning is relatively simple, and can be described as Do not scan partitions where there can be no
matching values. Suppose that you have a partitioned table t1 defined by this statement:
CREATE TABLE t1 (
fname VARCHAR(50) NOT NULL,
lname VARCHAR(50) NOT NULL,
region_code TINYINT UNSIGNED NOT NULL,
dob DATE NOT NULL
)
PARTITION BY RANGE( region_code ) (
PARTITION p0 VALUES LESS THAN (64),
PARTITION p1 VALUES LESS THAN (128),
Consider the case where you wish to obtain results from a SELECT statement such as this one:
SELECT fname, lname, region_code, dob
FROM t1
WHERE region_code > 125 AND region_code < 130;
It is easy to see that none of the rows which ought to be returned will be in either of the
partitions p0 or p3; that is, we need to search only in partitions p1 and p2 to find matching rows. By
doing so, it is possible to expend much less time and effort in finding matching rows than would be
required to scan all partitions in the table. This cutting awayof unneeded partitions is known
as pruning. When the optimizer can make use of partition pruning in performing this query, execution
of the query can be an order of magnitude faster than the same query against a nonpartitioned table
containing the same column definitions and data.
http://docs.oracle.com/cd/E17952_01/refman-5.5-en/partitioningpruning.html