Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Oracle Database 11g.pdf
Скачиваний:
78
Добавлен:
10.06.2015
Размер:
12.69 Mб
Скачать

Lab 3.1: Executing a Time-Based Point-in-Time Recovery  

697

13.This is an optional step. Now that we know our archived redo logs were copied successfully, we can remove them from the archive-log directory if we want.

SQL> Host del c:\oracle\arch\orcl\ARC00003_0662757171.001 SQL> Host del c:\oracle\arch\orcl\ARC00004_0662757171.001 SQL> Host del c:\oracle\arch\orcl\ARC00005_0662757171.001 SQL> Host del c:\oracle\arch\orcl\ARC00006_0662757171.001 SQL> Host del c:\oracle\arch\orcl\ARC00007_0662757171.001

This completes your online backup. You will use this backup to recover your database in a Chapter 3 lab.

In the Chapter 3 labs, we will be doing full database recoveries. This will require all of the archived redo logs generated by the database, including those created after this backup. Make sure you do not delete any archived redo logs that are not backed up. If you want to back up later archived redo logs, simply repeat step 8 of Lab 2.3 as often as needed.

Lab 3.1: Executing a Time-Based

Point-in-Time Recovery

In this exercise, you will do a point-in-time recovery by restoring the database to a given point in time.

1.Back up the database. Details on how to do a full online database backup are found in Chapter 2. In summary, follow these steps:

a.Put the database in hot backup mode.

b.Copy all database datafiles to a backup location.

c.Take the database out of hot backup mode.

d.Force a log switch. Back up the archived redo logs.

Here is an example of a backup:

[oracle@localhost orcl]$ sqlplus “/ as sysdba”

SQL*Plus: Release 11.1.0.6.0 - Production on Sun Aug 17 15:35:48 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining

698  Appendix A  n  Lab Exercises

and Real Application Testing options SQL> alter database begin backup; Database altered.

SQL> host cp /oracle01/oradata/orcl/*.dbf /oracle01/backup/orcl SQL> alter database end backup;

Database altered.

SQL> alter system switch logfile; System altered.

SQL> host cp /oracle01/backup/arch/* /oracle01/backup/orcl/* SQL> alter database backup controlfile to trace;

Database altered.

SQL> alter database backup controlfile to ‘/oracle01/oradata/orcl/control1.bak’; Database altered.

2.Next, log into the database as scott/tiger and create a new table. Insert two records into the new table and commit the insert.

SQL> connect scott/tiger Connected.

SQL> create table time_table (col_one date); Table created.

SQL> insert into time_table values (sysdate); 1 row created.

SQL> insert into time_table values (sysdate); 1 row created.

SQL> commit; Commit complete.

SQL> alter session set nls_date_format=’mm/dd/yyyy hh24:mi:ss’; Session altered.

SQL> select * from time_table; COL_ONE

-------------------

08/17/2008 22:03:59 08/17/2008 22:03:59

3.Wait a minute or so (however long you like) and add two more records. Commit the inserts.

SQL> insert into time_table values (sysdate); 1 row created.

SQL> insert into time_table values (sysdate);

Lab 3.1: Executing a Time-Based Point-in-Time Recovery  

699

1 row created. SQL> commit; Commit complete.

SQL> select * from time_table; COL_ONE

-------------------

08/17/2008 22:03:59 08/17/2008 22:03:59 08/17/2008 22:04:45 08/17/2008 22:04:45

4.Shut down the database.

SQL> connect sys as sysdba Enter password: Connected.

SQL> shutdown immediate Database closed. Database dismounted.

ORACLE instance shut down.

5.Once you are sure the database is down, restore the database datafiles from their backup location to the location where the database files belong.

[oracle@localhost orcl]$ pwd /oracle01/backup/orcl

[oracle@localhost orcl]$ cp *.dbf /oracle01/oradata/orcl/*

6.Mount the database.

[oracle@localhost orcl]$ sqlplus “/ as sysdba”

SQL*Plus: Release 11.1.0.6.0 - Production on Sun Aug 17 17:53:14 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to an idle instance. SQL> startup mount

ORACLE instance started.

 

 

Total System Global Area

167395328

bytes

Fixed Size

1298612

bytes

Variable Size

142610252

bytes

Database Buffers

20971520

bytes

Redo Buffers

2514944

bytes

Database mounted.

 

 

700  Appendix A  n  Lab Exercises

7.Recover the database using the recover database until time command. Use a time that is after the time listed in the second insert in the TIME_TABLE (22:03:59 in our example). In this case, we will recover to 22:04:00. Enter AUTO if prompted for an archived redo log to apply.

SQL> recover database until time ‘2008-08-17:22:04:00’; Media recovery complete.

8.Open the database with the alter database open resetlogs command. Note that once you have done this, you will not be able to recover any data that was entered after the point of the recovery.

SQL> alter database open resetlogs; Database altered.

9.Log into the scott schema. Do a select * from test_table. You should have only two records in the table.

SQL> Connect scott/tiger Connected.

SQL> select * from time_table; COL_ONE

-------------------

08/17/2008 22:03:59 08/17/2008 22:03:59

Lab 3.2: Recovering from Control-File Loss with a Backup Control File

In this lab we will be recovering a database that has experienced the complete loss of its control files. We will be using a backup control file to perform the recovery.

1.Back up the database. Details on how to do a full online database backup are found in Chapter 2. In summary, follow these steps:

a.Put the database in hot backup mode.

b.Copy all database datafiles to a backup location.

c.Take the database out of hot backup mode.

d.Force a log switch. Back up the archived redo logs.

Lab 3.2: Recovering from Control-File Loss with a Backup Control File 

701

Here is an example of a backup:

[oracle@localhost orcl]$ sqlplus “/ as sysdba”

SQL*Plus: Release 11.1.0.6.0 - Production on Sun Aug 17 15:35:48 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining

and Real Application Testing options SQL> alter database begin backup; Database altered.

SQL> host cp /oracle01/oradata/orcl/*.dbf /oracle01/backup/orcl SQL> alter database end backup;

Database altered.

SQL> alter system switch logfile; System altered.

SQL> host cp /oracle01/backup/arch/* /oracle01/backup/orcl/* SQL> alter database backup controlfile to trace;

Database altered.

SQL> alter database backup controlfile to ‘/oracle01/oradata/orcl/control1.bak’; Database altered.

2.Find the location of the control files.

SQL> select name from v$controlfile; NAME

--------------------------------------------------------------------------

/oracle01/oradata/orcl/control01.ctl

/oracle01/oradata/orcl/control02.ctl

/oracle01/oradata/orcl/control03.ctl

3.Shut down the database.

SQL> connect sys as sysdba Enter password: Connected.

SQL> shutdown immediate Database closed. Database dismounted.

ORACLE instance shut down.

702  Appendix A  n  Lab Exercises

4.Remove all control files.

SQL> host rm /oracle01/oradata/orcl/control01.ctl SQL> host rm /oracle01/oradata/orcl/control02.ctl SQL> host rm /oracle01/oradata/orcl/control03.ctl

5.Start up the database. Notice the error resulting from loss of all control files.

SQL> startup

ORACLE instance started.

 

 

Total System Global Area

159027200

bytes

Fixed Size

1298556

bytes

Variable Size

134221700

bytes

Database Buffers

20971520

bytes

Redo Buffers

2535424

bytes

ORA-00205: error in identifying control file, check alert log for more info

6.Copy the backup control file into place.

SQL>Host cp /oracle01/backup/orcl/control.bak /oracle01/oradata/orcl/control01.ctl SQL>Host cp /oracle01/backup/orcl/control.bak /oracle01/oradata/orcl/control02.ctl SQL>Host cp /oracle01/backup/orcl/control.bak /oracle01/oradata/orcl/control03.ctl

7.Mount the database with the alter database mount command.

SQL> alter database mount; Database altered.

8.Recover the database by issuing the recover database using backup controlfile command. Since you have all the online redo logs, you can do a complete recovery. If prompted to recover using archived redo logs, enter AUTO.

SQL> recover database using backup controlfile; ORA-00279: change 5026597 generated at 08/19/2008 16:23:33 needed for thread 1

ORA-00289: suggestion : /oracle01/flash_recovery_area/ORCL/archivelog/2008_08_19/o1_mf_1_10_%u_.arc ORA-00280: change 5026597 for thread 1 is in sequence #10

Specify log: {<RET>=suggested | filename | AUTO | CANCEL} auto

ORA-00308: cannot open archived log

Lab 3.2: Recovering from Control-File Loss with a Backup Control File 

703

‘/oracle01/flash_recovery_area/ORCL/archivelog/2008_08_19 /o1_mf_1_10_%u_.arc’

ORA-27037: unable to obtain file status Linux Error: 2: No such file or directory Additional information: 3

ORA-00308: cannot open archived log ‘/oracle01/flash_recovery_area/ORCL/archivelog/2008_08_19 /o1_mf_1_10_%u_.arc’

ORA-27037: unable to obtain file status Linux Error: 2: No such file or directory Additional information: 3

9.(This step is not required if step 8 completed with a message that said media recovery successful.) If you get the error message we got above (you may not), determine which online redo log contains the sequence number needing to be restored by querying V$LOG and V$LOGFILE as shown here.

SQL> select a.group#, a.member, b.sequence#

 

2 from v$logfile a, v$log b

 

3* where a.group#=b.group#;

 

GROUP# MEMBER

SEQUENCE#

---------- ---------------------------------------- ----------

1

/oracle01/oradata/orcl/redo01.log

10

1

/oracle01/oradata/orcl/redo01a.log

10

2

/oracle01/oradata/orcl/redo02a.log

8

2

/oracle01/oradata/orcl/redo02.log

8

3

/oracle01/oradata/orcl/redo03a.log

9

3

/oracle01/oradata/orcl/redo03.log

9

In this case, the online redo-log file /oracle01/oradata/orcl/redo01.log contains sequence 10, which we need to restore. Start recovery again, and apply the online redolog file as shown here.

SQL> recover database using backup controlfile; ORA-00279: change 5026597 generated at 08/19/2008 16:23:33 needed for thread 1

ORA-00289: suggestion : /oracle01/flash_recovery_area/ORCL/archivelog/2008_08_19/o1_mf_1_10_%u_.arc ORA-00280: change 5026597 for thread 1 is in sequence #10

Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /oracle01/oradata/orcl/redo01.log

Log applied.

Media recovery complete.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]