Showing posts with label archivelog. Show all posts
Showing posts with label archivelog. Show all posts

Saturday, March 21, 2015

Re-Creating Datafiles When Backups Are Unavailable

I found an old copy of the Oracle 9i User-Managed Backup and Recovery Guide and read the following:
 
If a datafile is damaged and no backup of the file is available, then you can still recover the datafile if:
 
·         All archived log files written after the creation of the original datafile are available
·         The control file contains the name of the damaged file (that is, the control file is current, or is a backup taken after the damaged datafile was added to the database)
 
I decided to try this out in an Oracle 12.1 database. First I checked that the database was in ARCHIVELOG mode:

SQL> select log_mode from v$database
  2  /
 
LOG_MODE
------------
ARCHIVELOG
 
SQL>

I created a tablespace called ANDREW:

SQL> create tablespace andrew
  2  datafile 'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\ANDREW.DBF'
  3  size 20m
  4  /
 
Tablespace created.
 
SQL>

I created a table in the tablespace:

SQL> l
  1  create table marker
  2  tablespace andrew as
  3  select 'Andrew was here again' message
  4* from dual
SQL> /
 
Table created.
 
SQL>

I closed the database:

SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

I deleted the tablespace’s datafile:

C:\app\Administrator\oradata\ORCL1\DATAFILE>dir
Volume in drive C has no label.
Volume Serial Number is 269C-9AD9
 
Directory of C:\app\Administrator\oradata\ORCL1\DATAFILE
 
19/03/2015  18:32    <DIR>          .
19/03/2015  18:32    <DIR>          ..
19/03/2015  18:39        20,979,712 ANDREW.DBF
19/03/2015  18:39     3,722,452,992 O1_MF_SYSAUX_BDGVW9OT_.DBF
19/03/2015  18:39       964,698,112 O1_MF_SYSTEM_BDGVZ93W_.DBF
19/03/2015  11:08     1,906,319,360 O1_MF_TEMP_BDGW88KG_.TMP
19/03/2015  18:39     1,378,885,632 O1_MF_UNDOTBS1_BDGW2MY6_.DBF
19/03/2015  18:39     4,650,442,752 O1_MF_USERS_BDGW2LNZ_.DBF
               6 File(s) 12,643,778,560 bytes
               2 Dir(s)   5,940,617,216 bytes free
 
C:\app\Administrator\oradata\ORCL1\DATAFILE>del andrew.dbf
 
C:\app\Administrator\oradata\ORCL1\DATAFILE>dir
Volume in drive C has no label.
Volume Serial Number is 269C-9AD9
 
Directory of C:\app\Administrator\oradata\ORCL1\DATAFILE
 
19/03/2015  18:42    <DIR>          .
19/03/2015  18:42    <DIR>          ..
19/03/2015  18:39     3,722,452,992 O1_MF_SYSAUX_BDGVW9OT_.DBF
19/03/2015  18:39       964,698,112 O1_MF_SYSTEM_BDGVZ93W_.DBF
19/03/2015  11:08     1,906,319,360 O1_MF_TEMP_BDGW88KG_.TMP
19/03/2015  18:39     1,378,885,632 O1_MF_UNDOTBS1_BDGW2MY6_.DBF
19/03/2015  18:39     4,650,442,752 O1_MF_USERS_BDGW2LNZ_.DBF
               5 File(s) 12,622,798,848 bytes
               2 Dir(s)   5,961,596,928 bytes free
 
C:\app\Administrator\oradata\ORCL1\DATAFILE>

I tried to open the database:

C:\app\Administrator\oradata\ORCL1\DATAFILE>sqlplus / as sysdba
 
SQL*Plus: Release 12.1.0.1.0 Production on Thu Mar 19 18:43:02 2015
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
Connected to an idle instance.
 
SQL> startup
ORACLE instance started.
 
Total System Global Area 1720328192 bytes
Fixed Size                  2403496 bytes
Variable Size            1023411032 bytes
Database Buffers          687865856 bytes
Redo Buffers                6647808 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
ORA-01110: data file 2:
'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\ANDREW.DBF'
 
SQL>
 
I created the missing datafile:

SQL> alter database create datafile
  2  'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\ANDREW.DBF'
  3  /
 
Database altered.
 
SQL>

I recovered the datafile:

SQL> recover datafile 'C:\APP\ADMINISTRATOR\ORADATA\ORCL1\DATAFILE\ANDREW.DBF'
Media recovery complete.
SQL>

I looked for the MARKER table but realized that the database was not open:

SQL> select * from marker
  2  /
select * from marker
              *
ERROR at line 1:
ORA-01219: database or pluggable database not open: queries allowed on fixed
tables or views only
 
SQL>
 
I opened the database:

SQL> alter database open
  2  /
 
Database altered.
 
SQL>

… and the MARKER table was there as before:

SQL> select * from marker
  2  /
 
MESSAGE
---------------------
Andrew was here again
 
SQL> select tablespace_name
  2  from dba_tables
  3  where table_name = 'MARKER'
  4  /
 
TABLESPACE_NAME
------------------------------
ANDREW
 
SQL>
 
The Oracle guide went on to say:
 
Note: You cannot re-create any of the datafiles for the SYSTEM tablespace by using the CREATE DATAFILE clause of the ALTER DATABASE statement because the necessary redo data is not available.
 
I will see what happens if you try to do this in a future post.

Thursday, September 18, 2014

ORA-01123

I was reading through an old book recently and it said that you could not put a tablespace into hot backup mode if the database was in NOARCHIVELOG mode. This seemed reasonable to me but I wondered what might happen if you tried to do this so I ran the following SQL in an Oracle 11.2 database:  

SQL> l
  1* alter tablespace users begin backup
SQL> /
alter tablespace users begin backup
*
ERROR at line 1:
ORA-01123: cannot start online backup; media recovery
not enabled
 
SQL>

If this happens to you, you have two choices:
  •  Don't do it again OR
  • Put the database into ARCHIVELOG mode first.
I hope to be doing some more serious posts about hot backup and recovery in the near future.

Thursday, August 23, 2012

rman Backup and Recovery - example 3

This was tested on Oracle 11.2. The Oracle rman user guide says:  If a database runs in ARCHIVELOG mode, then you can back up the database while it is open. This suggests that if your database is running in NOARCHIVELOG mode, you cannot back it up while it is open. I decided to try this out. First I checked that the database was still in NOARCHIVELOG mode:
 
SQL> select log_mode, open_mode from v$database;
 
LOG_MODE     OPEN_MODE
------------ --------------------
NOARCHIVELOG READ WRITE
 
SQL>
 
Then I tried to back it up with rman:
 
RMAN> backup database;
 
Starting backup at 23-AUG-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=586 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 08/23/2012 18:42:22
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 23-AUG-12
channel ORA_DISK_1: finished piece 1 at 23-AUG-12
piece handle=/database/Andrew/ANDREW01/backupset/2012_08_23/o1_mf_ncnnf_TAG20120823T184221_83dtw1pb_.bkp tag=TAG20120823T184221 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
 
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 08/23/2012 18:42:22
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
 
RMAN>
 
It failed, as you might expect, so, if you see these messages yourself, you should know what to do. I will pick this up in future examples.

Sunday, August 12, 2012

rman Backup and Recovery - example 1

In this test I:
 
(1)    Create a table called andrews_test1.
(2)    Do an offline backup of the database using rman.
(3)    Create a table called andrews_test2.
(4)    Restore the database from the offline backup.
(5)    Check that andrews_test1 is restored but andrews_test2 is not.
 
The test was run on Oracle 11.2. I created the database using dbca. To make it easy to demonstrate, I put the datafiles, redo logs and control files all in the same place. Here they are:
 
ANDREW01 /database/Andrew/ANDREW01 > ls -lt
total 2732896
-rw-r-----   1 oracle   dba      9748480 Aug 22 15:24 control01.ctl
-rw-r-----   1 oracle   dba      9748480 Aug 22 15:24 control02.ctl
-rw-r-----   1 oracle   dba      52429312 Aug 22 15:23 redo02.log
-rw-r-----   1 oracle   dba      5251072 Aug 22 15:23 users01.dbf
-rw-r-----   1 oracle   dba      31465472 Aug 22 15:23 undotbs01.dbf
-rw-r-----   1 oracle   dba      461381632 Aug 22 15:23 sysaux01.dbf
-rw-r-----   1 oracle   dba      702554112 Aug 22 15:23 system01.dbf
-rw-r-----   1 oracle   dba      52429312 Aug 22 15:23 redo03.log
-rw-r-----   1 oracle   dba      52429312 Aug 22 15:23 redo01.log
-rw-r-----   1 oracle   dba      20979712 Aug 22 12:53 temp01.dbf
drwxr-x---   3 oracle   dba         1024 Aug 22 12:20 backupset
drwxr-xr-x   2 oracle   dba         1024 Aug  8 12:58 offline_backup
drwxr-x---   2 oracle   dba           80 Aug  8 11:48 archivelog
drwxr-x---   2 oracle   dba           80 Aug  7 15:33 onlinelog
ANDREW01 /database/Andrew/ANDREW01 >
 
I checked to see if the database was in ARCHIVELOG or NOARCHIVELOG mode:
 
SQL> select log_mode from v$database;
 
LOG_MODE
------------
NOARCHIVELOG
 
SQL>
 
Then I created a test table and counted the number of rows in it. As the backup has not been done yet, I expect this table to appear after the restore:
 
SQL> create table andrews_test1
  2  as select * from dba_tables;
 
Table created.
 
SQL> select count(*) from andrews_test1;
 
  COUNT(*)
----------
     2723
 
SQL>
 
I closed the database and mounted it:
 
ANDREW01 /database/Andrew/ANDREW01 > rman nocatalog target /
 
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Aug 22 15:28:36 2012
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: ANDREW01 (DBID=385736687)
using target database control file instead of recovery catalog
 
RMAN> shutdown
 
database closed
database dismounted
Oracle instance shut down
 
RMAN> startup mount
 
connected to target database (not started)
Oracle instance started
database mounted
 
Total System Global Area     417669120 bytes
 
Fixed Size                     2148672 bytes
Variable Size                255858368 bytes
Database Buffers             155189248 bytes
Redo Buffers                   4472832 bytes
 
RMAN>
 
Then I checked that there were no backups, did a backup and checked that rman could see it:
 
ANDREW01 /database/Andrew/ANDREW01 > rman nocatalog target /
 
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Aug 22 15:52:36 2012
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: ANDREW01 (DBID=385736687, not open)
using target database control file instead of recovery catalog
 
RMAN> list backup;
 
specification does not match any backup in the repository
 
RMAN> backup database;
 
Starting backup at 22-AUG-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=292 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/database/Andrew/ANDREW01/system01.dbf
input datafile file number=00002 name=/database/Andrew/ANDREW01/sysaux01.dbf
input datafile file number=00003 name=/database/Andrew/ANDREW01/undotbs01.dbf
input datafile file number=00004 name=/database/Andrew/ANDREW01/users01.dbf
channel ORA_DISK_1: starting piece 1 at 22-AUG-12
channel ORA_DISK_1: finished piece 1 at 22-AUG-12
piece handle=/database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_nnndf_TAG20120822T155255_839wl8dj_.bkp tag=TAG20120822T155255 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 22-AUG-12
channel ORA_DISK_1: finished piece 1 at 22-AUG-12
piece handle=/database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_ncnnf_TAG20120822T155255_839wmdo5_.bkp tag=TAG20120822T155255 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 22-AUG-12
 
RMAN> list backup;
 
List of Backup Sets
===================
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    943.45M    DISK        00:00:27     22-AUG-12
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20120822T155255
        Piece Name: /database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_nnndf_TAG20120822T155255_839wl8dj_.bkp
  List of Datafiles in backup set 3
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 947201     22-AUG-12 /database/Andrew/ANDREW01/system01.dbf
  2       Full 947201     22-AUG-12 /database/Andrew/ANDREW01/sysaux01.dbf
  3       Full 947201     22-AUG-12 /database/Andrew/ANDREW01/undotbs01.dbf
  4       Full 947201     22-AUG-12 /database/Andrew/ANDREW01/users01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4       Full    9.33M      DISK        00:00:02     22-AUG-12
        BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: TAG20120822T155255
        Piece Name: /database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_ncnnf_TAG20120822T155255_839wmdo5_.bkp
  Control File Included: Ckp SCN: 947201       Ckp time: 22-AUG-12
 
RMAN>
 
This is the backup at the UNIX level:
 
ANDREW01 /database/Andrew/ANDREW01/backupset/2012_08_22 > ls -l
total 1952304
-rw-r-----   1 oracle   dba      9797632 Aug 22 15:53 o1_mf_ncnnf_TAG20120822T155255_839wmdo5_.bkp
-rw-r-----   1 oracle   dba      989282304 Aug 22 15:53 o1_mf_nnndf_TAG20120822T155255_839wl8dj_.bkp
ANDREW01 /database/Andrew/ANDREW01/backupset/2012_08_22 >

I opened the database (this is not shown), created another test table and counted the number of rows in it. As the backup has now been done, I do not expect this table to appear after the restore:
 
SQL> create table andrews_test2
  2  as select * from dba_indexes;
 
Table created.
 
SQL> select count(*) from andrews_test2;
 
  COUNT(*)
----------
      4656
 
SQL>
 
I closed the database (this is not shown) then I deleted the database’s datafiles:
 
ANDREW01 /database/Andrew/ANDREW01 > ls -lt
total 2753392
-rw-r-----   1 oracle   dba      9748480 Aug 22 16:31 control01.ctl
-rw-r-----   1 oracle   dba      9748480 Aug 22 16:31 control02.ctl
-rw-r-----   1 oracle   dba      5251072 Aug 22 16:31 users01.dbf
-rw-r-----   1 oracle   dba      461381632 Aug 22 16:31 sysaux01.dbf
-rw-r-----   1 oracle   dba      31465472 Aug 22 16:31 undotbs01.dbf
-rw-r-----   1 oracle   dba      713039872 Aug 22 16:31 system01.dbf
-rw-r-----   1 oracle   dba      52429312 Aug 22 16:31 redo02.log
-rw-r-----   1 oracle   dba      52429312 Aug 22 16:28 redo03.log
-rw-r-----   1 oracle   dba      52429312 Aug 22 16:28 redo01.log
-rw-r-----   1 oracle   dba      20979712 Aug 22 15:27 temp01.dbf
drwxr-x---   3 oracle   dba         1024 Aug 22 12:20 backupset
drwxr-xr-x   2 oracle   dba         1024 Aug  8 12:58 offline_backup
drwxr-x---   2 oracle   dba           80 Aug  8 11:48 archivelog
drwxr-x---   2 oracle   dba           80 Aug  7 15:33 onlinelog
ANDREW01 /database/Andrew/ANDREW01 > rm *dbf
ANDREW01 /database/Andrew/ANDREW01 > ls -lt
total 345632
-rw-r-----   1 oracle   dba      9748480 Aug 22 16:31 control01.ctl
-rw-r-----   1 oracle   dba      9748480 Aug 22 16:31 control02.ctl
-rw-r-----   1 oracle   dba      52429312 Aug 22 16:31 redo02.log
-rw-r-----   1 oracle   dba      52429312 Aug 22 16:28 redo03.log
-rw-r-----   1 oracle   dba      52429312 Aug 22 16:28 redo01.log
drwxr-x---   3 oracle   dba         1024 Aug 22 12:20 backupset
drwxr-xr-x   2 oracle   dba         1024 Aug  8 12:58 offline_backup
drwxr-x---   2 oracle   dba           80 Aug  8 11:48 archivelog
drwxr-x---   2 oracle   dba           80 Aug  7 15:33 onlinelog
ANDREW01 /database/Andrew/ANDREW01 >
 
I restored the database as follows:
 
ANDREW01 /database/Andrew/ANDREW01 > rman nocatalog target /
 
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Aug 23 14:53:25 2012
 
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database (not started)
 
RMAN> startup nomount
 
Oracle instance started
 
Total System Global Area     417669120 bytes
 
Fixed Size                     2148672 bytes
Variable Size                255858368 bytes
Database Buffers             155189248 bytes
Redo Buffers                   4472832 bytes
 
RMAN> restore controlfile from '/database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_ncnnf_TAG20120822T155255_839wmdo5_.bkp';
 
Starting restore at 23-AUG-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=99 device type=DISK
 
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/database/Andrew/ANDREW01/control01.ctl
output file name=/database/Andrew/ANDREW01/control02.ctl
Finished restore at 23-AUG-12
 
RMAN> alter database mount;
 
database mounted
released channel: ORA_DISK_1
 
RMAN> restore database;
 
Starting restore at 23-AUG-12
Starting implicit crosscheck backup at 23-AUG-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=292 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 23-AUG-12
 
Starting implicit crosscheck copy at 23-AUG-12
using channel ORA_DISK_1
Finished implicit crosscheck copy at 23-AUG-12
 
searching for all files in the recovery area
cataloging files...
cataloging done
 
List of Cataloged Files
=======================
File Name: /database/Andrew/ANDREW01/offline_backup/sysaux01.dbf
File Name: /database/Andrew/ANDREW01/offline_backup/system01.dbf
File Name: /database/Andrew/ANDREW01/offline_backup/temp01.dbf
File Name: /database/Andrew/ANDREW01/offline_backup/undotbs01.dbf
File Name: /database/Andrew/ANDREW01/offline_backup/users01.dbf
File Name: /database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_ncnnf_TAG20120822T155255_839wmdo5_.bkp
 
using channel ORA_DISK_1
 
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /database/Andrew/ANDREW01/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /database/Andrew/ANDREW01/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /database/Andrew/ANDREW01/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /database/Andrew/ANDREW01/users01.dbf
channel ORA_DISK_1: reading from backup piece /database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_nnndf_TAG20120822T155255_839wl8dj_.bkp
channel ORA_DISK_1: piece handle=/database/Andrew/ANDREW01/backupset/2012_08_22/o1_mf_nnndf_TAG20120822T155255_839wl8dj_.bkp tag=TAG20120822T155255
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
Finished restore at 23-AUG-12
 
RMAN> alter database open resetlogs;
 
database opened
 
RMAN>
 
I checked that andrews_test1 had the same number of rows as before and that andrews_test2 had not been restored:
 
ANDREW01 /database/Andrew/ANDREW01 > sqlplus / as sysdba
 
SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 23 14:59:12 2012
 
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL> select count(*) from andrews_test1;
 
  COUNT(*)
----------
      2723
 
SQL> select count(*) from andrews_test2;
select count(*) from andrews_test2
                     *
ERROR at line 1:
ORA-00942: table or view does not exist
 
SQL>