Professional Documents
Culture Documents
In this article, I am demonstrating some of the following recovery scenarios that may help
you in hard situations. Its good practice to test recovery scenarios on DG environment.
A Recovery Catalog is required when you use RMAN in Data Guard environment. RMAN uses a
Recovery Catalog to track file names for all database files in DR environment. A Recovery
Catalog Schema is used by RMAN to store metadata about all registered databases.
The Primary database is explicitly registered to the RMAN Catalog; and Physical Standby
databases are registered automatically if they are connected as target while connected to
the Recovery Catalog. RMAN is using db_unique_name parameter to identify one database from
another; but both the Primary and Standby database have the same database ID number.
INTERCHANGEABILITY OF BACKUPS
In DR environment, you can backup a tablespace on a Physical Standby database; its possible
to restore and recover it on the Primary database. Similarly you can backup a tablespace
on a Primary database and restore and recover it on a Physical Standby database.
Let's simulate a case where a datafile is lost by (renaming or moving to some other location)
one of the datafile on the Primary database. Two options are available.
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/crms/system01.dbf
/u01/app/oracle/oradata/crms/sysaux01.dbf
/u01/app/oracle/oradata/crms/undotbs01.dbf
/u01/app/oracle/oradata/crms/users01.dbf
/u01/app/oracle/oradata/crms/example01.dbf
/u01/app/oracle/oradata/crms/tbs01.dbf
6 rows selected.
$ mv /u01/app/oracle/oradata/crms/tbs01* /u01/app/oracle/oradata/crms/tbs01.dbf.bkp
$ ls /u01/app/oracle/oradata/crms/tbs*
/u01/app/oracle/oradata/crms/tbs01.dbf.bkp
We can see the error message ORA-27041, it clearly says No such file or directory, so we
need to recover it; lets start the recovery process.
$ rman
..
...
It's NOT mandatory to connect RMAN Catalog because we'll register the backup file to the
Primary database's control file manually. Now take IMAGECOPY backup of tbs01.dbf datafile
using Standby database so that backup file is created on Primary database Server.
The datafile copy must be created in some other location and NOT in datafiles original
location. A copy cannot exist in the same location and name as the source of which it is a
copy. If I place the filecopy in datafiles original location, lets see what would happen.
The Image copy has been created on the Primary database server.
More over image copies can be transported over network using RMAN.
$ ls /u01/app/oracle/oradata/crms/tbs*
/u01/app/oracle/oradata/crms/tbs01.dbf
/u01/app/oracle/oradata/crms/tbs01.dbf.old
...
connected to target database: CRMS (DBID=1611053225)
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of catalog command on default channel at 04/20/2016 15:29:06
ORA-19657: cannot inspect current datafile /u01/app/oracle/oradata/crms/tbs01.dbf
A copy cannot exist in the same location and name as the source of which it is a copy.
$ ls /u03/crmsdb-dbfiles/tbs*
/u03/crmsdb-dbfiles/tbs01.dbf/tbs01.dbf
We need to register the backup file to the Primary database control file with the RMAN
CATALOG command; so that Primary database controlfile gets updated with this backup copy.
Connect the Primary database as target and to the recovery catalog.
$ rman target /
..
...
connected to target database: CRMS (DBID=1611053225)
Name: /u03/crmsdb-dbfiles/tbs01.dbf
Tag: TAG20160420T161841
Switch the datafile 6 to the backup copy that we registered in the previous step.
===========================
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/crms/system01.dbf
/u01/app/oracle/oradata/crms/sysaux01.dbf
/u01/app/oracle/oradata/crms/undotbs01.dbf
/u01/app/oracle/oradata/crms/users01.dbf
/u01/app/oracle/oradata/crms/example01.dbf
/u03/crmsdb-dbfiles/tbs01.dbf
6 rows selected.
Tablespace altered.
RMAN> exit
RELOCATING DATAFILE
$ cd /u01/app/oracle/oradata/crms/
$ mv users* /tmp
$ ls users*
ls: users*: No such file or directory
..
...
RMAN> exit
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/stbycrms/system01.dbf
/u01/app/oracle/oradata/stbycrms/sysaux01.dbf
/u01/app/oracle/oradata/stbycrms/undotbs01.dbf
/u01/app/oracle/oradata/stbycrms/users01.dbf
/u01/app/oracle/oradata/stbycrms/example01.dbf
/u01/app/oracle/oradata/stbycrms/tbs01.dbf
/u01/app/oracle/oradata/stbycrms/users02.dbf
7 rows selected.
RELOCATING DATAFILES(S)
$ cd /u01/app/oracle/oradata/stbycrms/
$ mv users* /tmp
$ ls l users*
ls: users*: No such file or directory
$ tail -f /u01/app/oracle/diag/rdbms/stbycrms/stbycrms/tarce/alert_stbycrms.log
Errors in file
/u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace/stbycrms_dbw0_13589.trc:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/stbycrms/users01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Errors in file
/u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace/stbycrms_dbw0_13589.trc:
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
ORA-01110: data file 7: '/u01/app/oracle/oradata/stbycrms/users02.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
MRP0: Background Media Recovery terminated with error 1110
...
$ dgmgrl
...
Configuration - dgcrms
Configuration Status:
ERROR
CONNECT RMAN
Configuration - dgcrms
Oracle database is providing to multiplex control files in different locations. If any one
of the control file cannot be updated then the database instance is shutdown automatically.
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/crms/control01.ctl
/u01/app/oracle/flash_recovery_area/crms/control02.ctl
$ cd /u01/app/oracle/oradata/crms/control01.ctl
$ mv control01.ctl /tmp/
$ ls -l *.ctl
ls: *.ctl: No such file or directory
STATUS
------------
OPEN
A good copy of the control file can be copied over the failed copy and rename as in
control_files parameter and start the database instance without restore or recovery.
$ cd /u01/app/oracle/flash_recovery_area/crms
$ cp control02.ctl /u01/app/oracle/oradata/crms/control01.ctl
You should NOT copy the good control file over the bad one when the database is in OPEN
or MOUNT state. The copy should only be done in NOMOUNT or SHUTDOWN state.
SYS> startup;
If all control files are lost on the Primary, there are three options, depending on the
length of acceptable downtime.
FAILOVER TO STANDBY DATABSE: This option minimizes downtime. Flashback is not possible if
all control files are lost. So, restore and recover is only option.
RECOVERY USING BACKUP CONTROL FILE: Its possible to restore a backup control file from
the Primary database then perform recovery but need to open with RESETLOGS.
CREATE A NEW CONTROL FILE: This option requires additional downtime compared to failover.
A new control file can be created using the NORESETLOGS option followed by media recovery.
POINTS TO NOTE
If you perform incomplete recovery (resetlogs) on Primary database, you must have flashback
enabled on Standby database, then you can flashback Standby database to resetlogs_change#
on Primary and can be sync with Primary database. If flashback is not enabled on standby,
you may have to rebuild the Standby database.
If we have all online redo logs, then just restore backup control file and then perform
recovery; after recovery open the database with the RESETLOGS option.
NAME
-----------------------------------------------------
/u01/app/oracle/oradata/crms/control01.ctl
/u01/app/oracle/flash_recovery_area/crms/control02.ctl
$ cd /u01/app/oracle/oradata/crms
$ mv control01.ctl control01.ctl.bkp
$ cd /u01/app/oracle/flash_reocvery_area/crms
$ mv control02.ctl control02.ctl.bkp
$ tail f /u01/app/oracle/diag/rdbms/crms/crms/trace/alert_crms.log
...
When a control file is inaccessible, you can start the instance, but not mount the database.
If you attempt to mount the database when the control file is unavailable, you would receive
error - (ORA-00205 error in identifying control file, check alert log for more info).
database mounted
released channel: ORA_DISK_1
$ tail f /u01/app/oracle/diag/rdbms/crms/crms/trace/alert_crms.log
OPEN_RESETLOGS
---------------
Required.
database opened
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
Once the Primary database has been opened with the RSETLOGS option, the incarnation of the
database changes then creating a new branch of redo data. When a Physical Standby database
receives a new branch of redo data, the Standby database will automatically register the
new redo branch and it will automatically follow the new redo branch.
$ tail -f /u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace/alert_stbycrms.log
Once the Primary database has been opened with the RSETLOGS option, the incarnation of the
database changes then creating a new branch of redo data. When a Physical Standby database
receives a new branch of redo data, the Standby database will automatically register the
new redo branch and it will automatically follow the new redo branch.
To check whether the new redo branch has been registered at the standby, perform the
following query at the Primary and Standby and verify that the results match.
The following steps helps to avoid re-creating a Physical Standby database after you issued
the OPEN RESETLOGS statement on the primary database.
First determine the SCN before the RESETLOGS operation occurred. You can use the following
query to obtain the value of the (SCN) that is 2 SCNs before the RESETLOGS operation
occurred on the Primary database.
# On Primary database
RESETLOGS_CHANGE#
-----------------
958291
# On Standby database
CURRENT_SCN
-----------
958522
If the value of CURRENT_SCN is larger than the value of <resetlogs_change# 2>, issue
the following statement to flash back the standby database.
$ tail -f /u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace/alert_stbycrms.log
RESETLOGS_ID RESETLOGS_CHANGE#
------------ -----------------
910030253 958293
Restoring control files does not mean Incomplete Recovery always. Oracle still can do a
Complete Recovery if it has all the Archive logs and Online Redo Logs.
Get more information here.
LOST OF ALL CONTROL FILES & ALL ONLINE REDO LOG FILES
MEMBER
------------------------------------------
/u01/app/oracle/oradata/crms/redo03.log
/u01/app/oracle/oradata/crms/redo02.log
/u01/app/oracle/oradata/crms/redo01.log
NAME
------------------------------------------
/u01/app/oracle/oradata/crms/control01.ctl
/u01/app/oracle/flash_recovery_area/crms/control02.ctl
$ cd /u01/app/oracle/oradata/crms
$ mv redo* /tmp/
$ mv control01.ctl control01.ctl.bkp
$ cd /u01/app/oracle/flash_recovery_area/crms/
$ mv control02.ctl control02.ctl.bkp
$ tail f /u01/app/oracle/diag/rdbms/crms/crms/trace/
...
SYS> select group#, sequence#, archived, status, first_change#, next_change# from v$log;
Current -- The online redo log is active. The database is currently writing.
Active -- The online redo log is active but not the current log.
RMAN> run
{
set until sequence 15; #(always set one number higher than the current log sequence)
restore database;
recover database;
}
RMAN.txt
# On Primary database
RESETLOGS_ID RESETLOGS_CHANGE#
------------ -----------------
910659267 982626
# On Standby database
CURRENT_SCN
-----------
985287
Now Standby database has diverged from Primary database. Now the Standby database SCN is
ahead of reset logs change# so it needs to be flashback.
RESETLOGS_ID RESETLOGS_CHANGE#
------------ -----------------
910659267 982626
FB-DB.txt
SYS> alter database recover managed standby database using current logfile disconnect;
Database altered.
NAME
-----------------------------------------------------------------
/u01/app/oracle/oradata/stbycrms/control01.ctl
/u01/app/oracle/flash_recovery_area/stbycrms/control02.ctl
$ cd /u01/app/oracle/oradata/stbycrms/
[oracle@OEL5 stbycrms]$ mv control01.ctl control01.ctl.bkp
We can copy an intact copy of the control file over the lost copy, then restart the Standby
instance using the following commands.
$ cd /u01/app/oracle/flash_recovery_area/stbycrms/
[oracle@OEL5 stbycrms]$ cp control02.ctl /u01/app/oracle/oradata/stbycrms/control01.ctl
SYS> alter database recover managed standby database disconnect from session;
Database altered.
Database mounted.
Database opened.
SYS> alter database recover managed standby database using current logfile disconnect;
Database altered.
Steps to recreate control file for Standby database in Data Guard environment.
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/stbycrms/control01.ctl
/u01/app/oracle/flash_recovery_area/stbycrms/control02.ctl
$ cd /u01/app/oracle/flash_recovery_area/stbycrms
$ mv control01.ctl control01.ctl.bkp
$ cd /u01/app/oracle/oradata/stbycrms
$ mv control02.ctl control02.ctl.bkp
# On Primary database
Copy the created controlfile from the Primary database server to the Standby server.
$ cd /u03/rman-bkp/
$ scp standby.ctl oracle@192.168.222.134:/tmp
oracle@192.168.222.134's password:
standby.ctl 100% 9904KB 9.7MB/s 00:00
# On Standby database
$ cd /tmp
$ cp standby.ctl /u01/app/oracle/oradata/stbycrms/control01.ctl
$ cp standby.ctl /u01/app/oracle/flash_recovery_area/stbycrms/control02.ctl
Startup the Standby database Instance and mount it using newly created controlfile.
As we know Oracle recommends to multiplex redo log files in different locations. If the
online redo log files are multiplexed, then the loss of one member will not impact the
database. You can then shut down the database and copy the other members of the same group
over the missing or damaged member.
If all of the members of an inactive group that has been archived are lost, the group can
be dropped and re-created.
If the Current group or an Inactive group that has not yet been archived is damaged or
missing, you must failover to the Standby database. Lets jump to action immediately.
MEMBER
------------------------------------------------------
/u01/app/oracle/oradata/crms/redo03.log
/u01/app/oracle/oradata/crms/redo02.log
/u01/app/oracle/oradata/crms/redo01.log
SYS> select group#, sequence#, archived, status, first_change#, next_change# from v$log;
Configuration - dgcrms
$ cd /u01/app/oracle/oradata/crms/
$ mv redo0* /tmp
$ ls redo*
Configuration - dgcrms
Configuration Status:
SUCCESS
If flashback option was not enabled on Primary, you need to rebuild Physical Standby.
When the database is logically corrupted we can go for Incomplete Recovery of the database.
Flashback database offers simple way to perform point-in-time recovery.
Flashback feature enables you to rewind an entire database to a past TIME/SCN to correct
any problems caused by Physical/Logical corruptions. Using command Flashback database to
rewind the database to a Target Time, SCN or LSN (Log Sequence Number). A Flashback database
operation applies to the whole database; cannot use flashback on the individual tablespaces.
In SGA a buffer which is periodically logs before images of data blocks is called Flashback
Buffer. This buffer records images of all changed data blocks in the database. Whenever a
data block is altered, oracle writes a before image of that block to the flashback buffer.
This before image can be used to reconstruct a data file to the particular point of time.
The background process RCWR (Recovery Writer) writes contents of the flashback buffer to
flashback database log files. This process is started automatically when flashback database
future is enabled. Flashback log files can be created under Flash Recovery Area (FRA). The
Parameter db_recovery_file_dest defines the location of the Flash Recovery Area.
RVWR process creates flashback log files into a directory named 'flashback' under FRA.
V$flashback_database_logfile view can be used to check & monitor generated flashback logs.
V$RECOVER_FILE_DEST displays info about disk quota and current disk usage in the FRA. I.e.
(The physical location allocated space, space reclaimable, number of files in the directory.
If any Logical or Physical corruption in the Primary database would cause an immediate
corruption in the Standby database. To avoid such a pitfall, we can enable flashback
database on Primary and Standby. Its better at-least enable flashback feature on the Standby
database Server. Lets see some examples.
Dropped Tables.
Truncated Tables.
Logical data corruption by insert/update/delete.
Flashback database can only undo changes to a datafile made by an Oracle database. It cant
be used to repair media failures, or to recover from accidential deletion of datafiles.
Configuring the flashback database future on the Primary database eliminates the need for
recreating the database after a failover operation.
If logical corruption has propagated to the Standby database, flashback Primary and Standby
databases prior to the logical corruption, open RESETLOGS on primary database, and re-start
apply on Standby database.
If flashback option configured on the Standby database server, perform flashback prior to
logical corruption on that server, failover, and activate the Standby database as the new
Primary database.
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIME
-------------------- ----------------------
1068414 12.05.2016 14:16:09
I have a schema USR1 and contains few tables. Lets see how to recover dropped schema
(including schema objects) using flashback feature.
TABLE_NAME OWNER
------------------------------ ------------------------------
OBJS1 USR1
OBJS2 USR1
OBJS3 USR1
COUNT(*)
----------
2552
COUNT(*)
----------
2873
COUNT(*)
----------
7244
SEGMENT_NAME SUM(BYTES/1024/1024)
-------------------- --------------------
OBJS2 188
OBJS3 422
OBJS1 256
# On Primary database (note the SCN before drop the schema usr1)
CURRENT_SCN
-----------
1295300
# On Standby database
$ cd /u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace/
$ tail f alert_stbycrms.log
# On Primary database
SYS> alter user usr1 default tablespace tbs1 quota unlimited on tbs1;
User altered.
Now we have to export the schema (usr1) from the standby database to the Primary database.
Once we create a database link in the Primary database pointing to the standby database,
using NETWORK_LINK its possible to export the schema (usr1) from the Standby database.
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** directory=dpdir
network_link=exp_crms schemas=usr1 dumpfile=schema_usr.dmp logfile=schema_usr.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 988 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "USR1"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** directory=dpdir
remap_schema=usr1:usr1 dumpfile=schema_usr1.dmp
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "USR1"."OBJS1" 256 MB 2552 rows
. . imported "USR1"."OBJS2" 188 MB 2873 rows
. . imported "USR1"."OBJS3" 422 MB 7244 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "USR1"."SYS_IMPORT_FULL_01" successfully completed at 06:48:04
# On Primary database
SYS> alter database recover managed standby database using current logfile disconnect;
Database altered.
# On Primary database
CURRENT_SCN
-----------
1313692
# On Standby database
CURRENT_SCN
-----------
1313687
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIME
-------------------- ----------------------
1670128 22.05.2016 14:16:09
CURRENT_SCN
-----------
1705286
SCN_TO_TIMESTAMP(1640599)
---------------------------------------------------------------------------
23-MAY-16 03.51.01.000000000 AM
Verify whether the table is existing or NOT on (Primary and Standby database).
Flashback complete.
$ cd /u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace
$ tail f alert_stbycrms.log
Creating public database link pointing to the Standby database on Primary database
Already we have created a DB link in the primary database pointing to the Standby database,
we can use NETWORK_LINK to export the table from the Standby database.
Import the pspruf_khb_tab.dmp file into the sony schema of the Primary database.
# On Primary database
COUNT(*)
----------
340344
SONY>@enable_monitoring.sql;
Index altered.
Index altered.
Index altered.
Index altered.
If the column USED is YES when the index is used to access the table. -- due to an update,
merge, delete or SELECT statement(s).
SYS> alter database recover managed standby database using current logfile disconnect;
Database altered.
# On Primary database
THREAD# MAX(SEQUENCE#)
---------- --------------
1 358
# On Standby database
THREAD# MAX(SEQUENCE#)
---------- --------------
1 358
# On Primary database
TABLESPACE_NAME TABLE_NAME
------------------------------ ------------------------------
TBS1 TAB1
# On Standby database
COUNT(*)
----------
131072
I am taking a backup copy of the datafile #7 (image copy) from the standby database
Copy the backup piece to the Primary database Server from the Standby database Server.
$ ls /u03/bkp/
tbs01.dbf
[oracle@OEL5 bkp] $ scp tbs01.dbf oracle@192.168.222.133:/u03/rman-bkp
oracle@192.168.222.133's password:
tbs01.dbf 100% 140MB 14.0MB/s 00:10
# On Primary database
We need to register the backup file using RMAN catalog command to the Primary database
controlfile; so that the controlfile of the Primary gets updated with this backup copy.
# On Primary database
COUNT(*)
----------
131072
MAX(SEQUENCE#)
--------------
364
# On Standby database
MAX(SEQUENCE#)
--------------
364
# On Primary database
# On Standby database
# On Primary database
7 rows selected.
Tablespace created.
SYS> create user myusr identified by passwd default tablespace mytbs quota 1g on mytbs;
User created.
SYS> /
...
SYS> /
...
COUNT(*)
----------
4096
# On Primary database
FILE# NAME
---------- ------------------------------------------
1 /u01/app/oracle/oradata/crms/system01.dbf
2 /u01/app/oracle/oradata/crms/sysaux01.dbf
3 /u01/app/oracle/oradata/crms/undotbs01.dbf
4 /u01/app/oracle/oradata/crms/users01.dbf
5 /u01/app/oracle/oradata/crms/example01.dbf
6 /u01/app/oracle/oradata/crms/example02.dbf
7 /u01/app/oracle/oradata/crms/tbs01.dbf
8 /u01/app/oracle/oradata/crms/mytbs01.dbf
8 rows selected.
# On Standby database
FILE# NAME
---------- --------------------------------------------------------------
1 /u01/app/oracle/oradata/stbycrms/system01.dbf
2 /u01/app/oracle/oradata/stbycrms/sysaux01.dbf
3 /u01/app/oracle/oradata/stbycrms/undotbs01.dbf
4 /u01/app/oracle/oradata/stbycrms/users01.dbf
5 /u01/app/oracle/oradata/stbycrms/example01.dbf
6 /u01/app/oracle/oradata/stbycrms/example02.dbf
7 /u01/app/oracle/oradata/stbycrms/tbs01.dbf
8 /u01/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00008
8 rows selected.
Here we can notice that datafile #8 on the Standby database is created at the location
$ORACLE_HOME/dbs with the name as UNNAMED rather than getting created at the specified
location as per db_file_name_convert parameter (check value of the parameter on Primary).
Now we got the file# and name from the Primary database and check the filename UNNAMED00008
that is created on the Standby database. We need to recreate on Standby database.
Database altered.
$ cd /u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace
$ tail f alert_stbycrms.log
# Restart MRP
SYS> alter database recover managed standby database disconnect from session;
Database altered.
COUNT(*)
----------
4096
MAX(SEQUENCE#)
--------------
367
MAX(SEQUENCE#)
--------------
367
DEST_NAME RECOVERY_MODE
---------------------- -----------------------
LOG_ARCHIVE_DEST_1 MANAGED REAL TIME APPLY
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY
SYS> alter database recover managed standby database using current logfile disconnect;
Database altered.
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY
DEST_NAME RECOVERY_MODE
---------------------- -----------------------
LOG_ARCHIVE_DEST_1 MANAGED REAL TIME APPLY
Points to Note:
READ ONLY WITH APPLY - A Physical Standby database is open in real-time query mode.
MANAGED REAL TIME APPLY - Log apply services recover redo data from the Standby redo logs
at the same time the logs are being written to, as opposed to recovering redo from archived
redo logs when a log switch occurs.
# On Primary database
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
MYTAB USERS
MIN(DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID))
-----------------------------------------
787
# On Primary database
COUNT(*)
----------
61958
# On Standby database
COUNT(*)
----------
61958
$ which dbv
/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbv
$ dbv file=/u01/app/oracle/oradata/crms/users01.dbf
..
...
DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/crms/users01.dbf
2+0 records in
2+0 records out
16384 bytes (16 kB) copied, 0.000127939 seconds, 128 MB/s
$ dbv file=/u01/app/oracle/oradata/crms/users01.dbf
..
...
$ tail -f alert_crms.log
A detected corrupt block through a users SQL query is repaired automatically by using good
block from a Physical Standby database. Lets check count of scott.mytab table.
COUNT(*)
----------
61958
PONTS TO NOTE
If block media recovery to work automatically, the Physical Standby must be in Real-Time
query mode. If automatic repair is not possible, an ORA-1578 error is returned.
If a corrupt data block is discovered on a Physical Standby database, the Server attempts
to repair the corruption by obtaining a good copy of the block from the primary database.
The repair is performed in the background. Automatic block repair is attempted if the
following database initialization parameters are configured on the Standby database.
The FAL_SERVER parameter is configured and its value contains an Oracle Net service name
for the primary database. When using (log_archive_dest_2 or fal_server) parameters Oracle
internally uses tnsnames.ora file to connect to the Primary database.
# On Standby database
The Standby database Server disk space is insufficient at specific mount point (/u01), When
you create a data file on the Primary site, how the Standby database going to react.
# On Primary database
THREAD# MAX(SEQUENCE#)
---------- --------------
1 493
# On Standby database
THREAD# MAX(SEQUENCE#)
---------- --------------
1 493
$ df -TH /u01/
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext3 27G 26G 20M 100% /u01
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/crms/users01.dbf
# On Primary database
Tablespace altered.
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/crms/users01.dbf
/u01/app/oracle/oradata/crms/users02.dbf
# On Standby database
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/crms/users01.dbf
$ tail -f alert_stbycrms.log
..
File #7 added to control file as 'UNNAMED00007'.
Originally created as:
'/u01/app/oracle/oradata/crms/users02.dbf'
Recovery was unable to create the file as:
'/u01/app/oracle/oradata/stbycrms/users02.dbf'
MRP0: Background Media Recovery terminated with error 1274
Errors in file
/u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace/stbycrms_mrp0_19139.trc:
ORA-01274: cannot add datafile '/u01/app/oracle/oradata/crms/users02.dbf' - file could
not be created
..
...
Recovery interrupted!
Recovered data files to a consistent state at change 2528425
Errors in file
/u01/app/oracle/diag/rdbms/stbycrms/stbycrms/trace/stbycrms_mrp0_19139.trc:
ORA-01274: cannot add datafile '/u01/app/oracle/oradata/crms/users02.dbf' - file could
not be created
MRP0: Background Media Recovery process shutdown (stbycrms)
** Space issue with data files Data Guard always create the UNNAMED datafiles. **
# On Standby database
FILE# NAME
---------- --------------------------------------------------------------
7 /u01/app/oracle/product/11.2.0/dbhome_1/dbs/UNNAMED00007
Its possible to extend /u01, if you can use lvm + enough free disk space.
If possible, delete unwanted files to reclaim disk space or move to some other locations.
Once you get free space on /u01 mount point, you can proceed following steps.
Database altered
SYS> alter database recover managed standby database using current logfile disconnect;
Database altered.
FILE_NAME
--------------------------------------------------------------------------------------
/u01/app/oracle/oradata/stbycrms/users01.dbf
/u01/app/oracle/oradata/stbycrms/users02.dbf
Best Solution: It would be best to avoid this kind of issues by monitoring the space on
the Standby(s) daily since that takes minutes.
# On Primary database
# On Standby database
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/crms/control01.ctl
/u01/app/oracle/flash_recovery_area/crms/control02.ctl
# On Primary database
THREAD# MAX(SEQUENCE#)
---------- --------------
1 499
# On Standby database
THREAD# MAX(SEQUENCE#)
---------- --------------
1 499
$ cd /u01/app/oracle/oradata/crms/
$ mv control01.ctl control01.ctl.bkp
$ cd /u01/app/oracle/flash_recovery_area/crms/
$ mv control02.ctl control02.ctl.bkp
$ cat ctrl.sql
Lets start the Instance without control files, but instance cannot be mounted.
Above error clearly states if the control files are missing, then the database cannot be
mounted, so at most, the database state is NOMOUNT. Any attempt to mount would fail because
of missing control files. Lets check status of the instance.
STATUS
------------
STARTED
SYS> @/home/oracle/ctrl.sql;
OPEN_RESETL
-----------
NOT ALLOWED
THREAD# MAX(SEQUENCE#)
---------- --------------
1 502
# On Standby database
THREAD# MAX(SEQUENCE#)
---------- --------------
1 502
If all control files have been lost but all online redo log members remain intact then its
possible to recover the database after creating new control files. Its NOT required to
open the database with RESETLOGS option after the recovery. Control files will get metadata
from database files. Reference doc here
# On Primary database
# On Standby database
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/stbycrms/temp01.dbf
# On Primary database
Tablespace altered.
POINTS TO NOTE
Restoring a control file does not mean Incomplete Recovery. Oracle can still do a Complete
Recovery if it has all the Archive logs and Online Redo Logs.
If we perform incomplete recovery (reset logs) on Primary, you must have flashback enabled
on Standby database, you can then flashback Standby database to resetlogs_change# on primary
and its possible to sync with Primary database. If flashback is NOT enabled on the Standby
database, you have to rebuild the Standby database.
Using this feature you can recover the database from logical corruptions to specified point
in TIME/SCN. Flashback logs contain only "before-images of data blocks" related to some
SCN so Flashback logs are NOT independent. They can be used only with redo data that
contains database changes around the desired SCN.
The view v$FLASHBACK_DATABASE_LOGFILE displays info about flashback logs. There is a record
section within the control file header named as FLASHBACK LOGFILE RECORDS, this section
contains info about the lowest and highest SCN of all flashback log files. You can query
v$FLASHBACK_DATABASE_LOGFILE to find about flashback logs.
When you use (flashback database to timestamp) command, (Oracle reads flashback logfile
section in the control file and checks availability of required flashback logs) it rewinds
a database to a past target time; Oracle restores old version blocks (which blocks has
changed after the target time and restores them from the flashback logs). The database
restores the version of each block before the target time. Then the database uses redo logs
to reapply changes that were made after these block were written to the flashback logs
Without that redo data, the flashback operation cannot succeed. If desired restore point
of time is 10:00 AM and the oldest restored data block is from 09:47 AM then you need all
archived log files that contain redo data since 09:47 AM to 10:00 AM.