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

744  Appendix A  n  Lab Exercises

Lab 9.3: Using Flashback Data Archive

In this lab you’ll exercise the Flashback Data Archive feature. You’ll create an archive table for a populated base table and observe the audit migrations to the archive table, then observe purging from the archive table.

1.Create the flashback data archive.

SQL>create flashback archive default default_flash_archive tablespace user_data quota 10m retention 1 day;

2.Now we’ll use the previously created flashback_query_test table as the base table for the archive.

SQL> alter table flashback_query_test flashback archive default_flash_archive;

Table altered.

3.Now we’ll manipulate the data and observe the flashback data archive.

SQL> select sysdate from dual;

SYSDATE

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

21-nov-2008 15:58:44

SQL> delete from flashback_query_test where x > 15; 5 rows deleted.

SQL> commit;

Commit complete.

SQL> select * from flashback_query_test;

X

Y

Z

 

----------

----------

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

1

row 1

21-nov-2008 13:48:51

2

row 2

21-nov-2008 13:48:51

3

row 3

21-nov-2008

13:48:51

4

row 4

21-nov-2008

13:48:51

5

row 5

21-nov-2008

13:48:51

Lab 9.3: Using Flashback Data Archive 

745

6 row 6 21-nov-2008 13:50:00

7 row 7 21-nov-2008 13:50:00

8 row 8 21-nov-2008 13:50:00

9 row 9 21-nov-2008 13:50:00

10 row 10 21-nov-2008 13:50:00

11 row 11 21-nov-2008 13:55:00

12 row 12 21-nov-2008 13:55:00

13 row 13 21-nov-2008 13:55:00

14 row 14 21-nov-2008 13:55:00

15 row 15 21-nov-2008 13:55:00

15 rows selected.

4.Query the base table using the AS OF clause, specifying a timestamp prior to the delete timestamp. You’ll observe that all the rows are returned.

SQL> select * from flashback_query_test

as of timestamp(to_timestamp(‘21-nov-2008 15:58:00’, ‘DD-MON-YYYY HH24:MI:SS’));

X

Y

Z

----------

----------

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

16

row 16

21-nov-2008 15:08:54

17

row 17

21-nov-2008 15:08:54

18

row 18

21-nov-2008 15:08:54

19

row 19

21-nov-2008 15:08:54

20

row 20

21-nov-2008 15:08:54

2

row 2

21-nov-2008 13:48:51

4

row 4

21-nov-2008 13:48:51

14

row 14

21-nov-2008 13:55:00

1

row 1

21-nov-2008 13:48:51

7

row 7

21-nov-2008 13:50:00

13

row 13

21-nov-2008 13:55:00

15

row 15

21-nov-2008 13:55:00

3

row 3

21-nov-2008 13:48:51

8

row 8

21-nov-2008 13:50:00

6

row 6

21-nov-2008 13:50:00

9

row 9

21-nov-2008 13:50:00

10

row 10

21-nov-2008 13:50:00

5

row 5

21-nov-2008 13:48:51

11

row 11

21-nov-2008 13:55:00

746  Appendix A  n  Lab Exercises

12 row 12 21-nov-2008 13:55:00

20 rows selected.

5.Verify the timestamp for the delete.

SQL> select * from flashback_query_test

as of timestamp(to_timestamp(‘21-nov-2008 16:00:00’, ‘DD-MON-YYYY HH24:MI:SS’));

X

Y

Z

----------

----------

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

2

row 2

21-nov-2008 13:48:51

4

row 4

21-nov-2008 13:48:51

14

row 14

21-nov-2008 13:55:00

1

row 1

21-nov-2008 13:48:51

7

row 7

21-nov-2008 13:50:00

13

row 13

21-nov-2008 13:55:00

15

row 15

21-nov-2008 13:55:00

3

row 3

21-nov-2008 13:48:51

8

row 8

21-nov-2008 13:50:00

6

row 6

21-nov-2008 13:50:00

9

row 9

21-nov-2008 13:50:00

10

row 10

21-nov-2008 13:50:00

5

row 5

21-nov-2008 13:48:51

11

row 11

21-nov-2008 13:55:00

12

row 12

21-nov-2008 13:55:00

15 rows selected.

6.Now run the query again as many times as you like prior to the end of the 10-day retention period, and you should see the following results:

SQL> select * from flashback_query_test

as of timestamp(to_timestamp(‘21-nov-2008 15:58:00’, ‘DD-MON-YYYY HH24:MI:SS’));

X

Y

Z

 

----------

----------

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

16

row 16

21-nov-2008

15:08:54

17

row 17

21-nov-2008

15:08:54

18

row 18

21-nov-2008

15:08:54

Lab 10.1: Using Support Workbench to Report a Problem to Oracle Support  

747

19 row 19 21-nov-2008 15:08:54

20 row 20 21-nov-2008 15:08:54

2 row 2 21-nov-2008 13:48:51

4 row 4 21-nov-2008 13:48:51

14 row 14 21-nov-2008 13:55:00

1 row 1 21-nov-2008 13:48:51

7 row 7 21-nov-2008 13:50:00

13 row 13 21-nov-2008 13:55:00

15 row 15 21-nov-2008 13:55:00

3 row 3 21-nov-2008 13:48:51

8 row 8 21-nov-2008 13:50:00

6 row 6 21-nov-2008 13:50:00

9 row 9 21-nov-2008 13:50:00

10 row 10 21-nov-2008 13:50:00

5 row 5 21-nov-2008 13:48:51

11 row 11 21-nov-2008 13:55:00

12 row 12 21-nov-2008 13:55:00

20 rows selected. SQL>

Just to verify that you are using the flasback data archive and not undo, you can shut down and start up the database to clear the undo tablespace, and you will still see the query results demonstrated in this section.

Lab 10.1: Using Support Workbench to Report a Problem to Oracle Support

This lab was created using Oracle Enterprise Manager (OEM) running on Windows XP. However, it should also work using Unix.

This lab shows you the basic steps to follow to use the Oracle Support Workbench to open a support ticket with Oracle. Using the OEM user interface, the directions will be presented to you on each page, so you should have no problem opening the support ticket—that is, if you have an Oracle support agreement. If you have an Oracle support agreement, perform the following steps to completion. If you don’t have an Oracle support agreement, follow until step 5.

1.Open Support Workbench.

2.View your alerts and select a critical error alert.

3.View the problem details.

4.Gather any additional diagnostic information.

748  Appendix A  n  Lab Exercises

5.Create a service request.

6.Package and upload the data to Oracle Support.

7.Track the service request and implement any recommended changes.

8.Close the incident.

Lab 10.2: Performing Block

Media Recovery

In this lab, you will perform block media recovery of a corrupt data file. This lab was created on Windows XP and uses a tool specifically for Windows. However, it should also work using Unix, using Unix-specific commands.

These are the basic prerequisites and steps for this exercise:

1.Make sure you have a hex editor.

2.Ensure that the database is in ARCHIVELOG mode.

3.Create a new tablespace called USER_DATA.

4.Create a new table in the USER_DATA tablespace.

5.Take a hot full backup of the database.

6.Use the hex editor to corrupt the datafile for the USER_DATA tablespace.

7.Run the dbv command and the SQL queries to identify the corrupt blocks.

8.Perform the block media recovery.

9.Validate the results.

Here are the specific steps:

1. If using Windows, download and install a hex editor. 2. Make sure the database is in ARCHIVELOG mode.

SQL> show parameter log_archive_start

 

 

NAME

TYPE

VALUE

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

-----------

-----------

log_archive_start

boolean

FALSE

SQL> shutdown immediate;

 

 

Database closed.

 

 

Database dismounted.

 

 

ORACLE instance shut down.

 

 

SQL> exit

 

 

sqlplus sys/orcl as sysdba

 

 

Lab 10.2: Performing Block Media Recovery 

749

SQL*Plus: Release 11.1.0.6.0 - Production on Sat Nov 22 17:55:34 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup

mount

 

 

ORACLE instance started.

 

 

Total System

Global Area

732352512

bytes

Fixed Size

 

1335696

bytes

Variable Size

 

444599920

bytes

Database Buffers

281018368

bytes

Redo Buffers

 

5398528

bytes

Database mounted.

 

 

SQL> alter database archivelog;

Database altered.

SQL> archive log start;

Statement processed.

SQL> alter database open;

Database altered.

SQL>

3.Create a new tablespace called USER_DATA.

SQL> create tablespace user_data datafile ‘c:\oracle\oradata\orcl\user_data01.dbf’ size 10 m;

Tablespace created. SQL>

4.Create a new table in the USER_DATA tablespace.

SQL> create table block_corruption_test tablespace user_data

as select * from flashback_query_test;

Table created. SQL>

750  Appendix A  n  Lab Exercises

5.Take a hot full RMAN backup of the database. rman target=sys/orcl

Recovery Manager: Release 11.1.0.6.0 - Production on Sat Nov 22 18:17:45 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: ORCL (DBID=1190467526)

RMAN> backup database plus archivelog; Starting backup at 22-NOV-08

current log archived allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=130 device type=DISK channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=210 RECID=184 STAMP=670763775 input archived log thread=1 sequence=211 RECID=185 STAMP=670765527 input archived log thread=1 sequence=212 RECID=186 STAMP=670847849 input archived log thread=1 sequence=213 RECID=187 STAMP=671056681 input archived log thread=1 sequence=214 RECID=188 STAMP=671313636 input archived log thread=1 sequence=215 RECID=189 STAMP=671387999 input archived log thread=1 sequence=216 RECID=190 STAMP=671459676 input archived log thread=1 sequence=217 RECID=191 STAMP=671461419 input archived log thread=1 sequence=218 RECID=192 STAMP=671481182 input archived log thread=1 sequence=219 RECID=194 STAMP=671481209 channel ORA_DISK_1: starting piece 1 at 22-NOV-08

channel ORA_DISK_1: finished piece 1 at 22-NOV-08 piece handle=C:\TEMP\ORABACKUP\41K0BVRH_1_1 tag=TAG20081122T183330 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:03:46 Finished backup at 22-NOV-08

Starting backup at 22-NOV-08 using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set

Lab 10.2: Performing Block Media Recovery 

751

input datafile file number=00001 name=C:\ORACLE\ORADATA\ORCL\SYSTEM01.DBF

 

input datafile file number=00002 name=C:\ORACLE\ORADATA\ORCL\SYSAUX01.DBF

 

input datafile file number=00003 name=C:\ORACLE\ORADATA\ORCL\UNDOTBS01.DBF

 

input datafile file number=00005 name=C:\ORACLE\ORADATA\ORCL\EXAMPLE01.DBF

 

input datafile file number=00006

 

name=C:\ORACLE\ORADATA\ORCL\USER_DATA01.DBF

 

input datafile file number=00004 name=C:\ORACLE\ORADATA\ORCL\USERS01.DBF

 

channel ORA_DISK_1: starting piece 1 at 22-NOV-08 channel ORA_DISK_1: finished piece 1 at 22-NOV-08 piece handle=C:\TEMP\ORABACKUP\42K0C03A_1_1 tag=TAG20081122T184601 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:02:26 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

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 22-NOV-08 channel ORA_DISK_1: finished piece 1 at 22-NOV-08 piece handle=C:\TEMP\ORABACKUP\43K0C08F_1_1 tag=TAG20081122T184601 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 22-NOV-08

Starting backup at 22-NOV-08 current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=220 RECID=195 STAMP=671482150 channel ORA_DISK_1: starting piece 1 at 22-NOV-08

channel ORA_DISK_1: finished piece 1 at 22-NOV-08 piece handle=C:\TEMP\ORABACKUP\44K0C097_1_1 tag=TAG20081122T184910 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 22-NOV-08

RMAN>

752  Appendix A  n  Lab Exercises

In Step 6 you will use a hex editor to corrupt a datafile. You will lose data, so complete Step 6 only in an isolated testing environment!

6.Use the hex editor to corrupt the datafile for the USER_DATA tablespace. First issue the SQL command to make the USER_DATA tablespace offline, then use the hex editor to search for a text string found in the target table (for example, row 1), and then replace the data with zeroes. Save the file, exit, then issue the command to make the tablespace online.

SQL> alter tablespace user_data offline; Tablespace altered.

SQL>

Lab 10.2: Performing Block Media Recovery 

753

SQL> alter tablespace user_data online;

Tablespace altered.

SQL>

7.Run the dbv command and the SQL queries to identify the corrupt blocks.

c:\dbv file=c:\oracle\oradata\orcl\user_data01.dbf

DBVERIFY: Release 11.1.0.6.0 - Production on Sat Nov 22 19:27:57 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = c:\oracle\oradata\orcl\user_data01.dbf

Page 12 is influx - most likely media corrupt

Corrupt block relative dba: 0x0180000c (file 6, block 12) Fractured block found during dbv:

754  Appendix A  n  Lab Exercises

Data in bad block:

type: 6 format: 2 rdba: 0x0180000c

last change scn: 0x0000.00622269 seq: 0x2 flg: 0x04 spare1: 0x0 spare2: 0x0 spare3: 0x0

consistency value in tail: 0x00000000 check value in block header: 0xc476 computed block checksum: 0xdd1e

DBVERIFY - Verification complete

Total Pages Examined

 

:

1280

Total Pages Processed

(Data) :

0

Total Pages Failing

(Data) :

0

Total Pages Processed

(Index):

0

Total Pages Failing

(Index):

0

Total Pages Processed

(Other):

11

Total Pages Processed

(Seg)

:

0

Total Pages Failing

(Seg)

:

0

Total Pages Empty

 

:

1268

Total Pages Marked Corrupt

:

1

Total Pages Influx

 

:

1

Total Pages Encrypted

 

:

0

Highest block SCN

 

:

6431341 (0.6431341)

SQL> select * from block_corruption_test; select * from block_corruption_test

*

ERROR at line 1:

ORA-01578: ORACLE data block corrupted (file # 6, block # 12) ORA-01110: data file 6: ‘C:\ORACLE\ORADATA\ORCL\USER_DATA01.DBF’

SQL>

SQL> select file#, block#, blocks, corruption_type “TYPE”

Lab 10.2: Performing Block Media Recovery 

755

from v$database_block_corruption;

FILE#

BLOCK#

BLOCKS

TYPE

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

---------

6

12

1

FRACTURED

SQL>

8.Perform the block media recovery using RMAN. Either recover the specific block or recover all the blocks in the corruption list.

RMAN> recover datafile 6 block 12;

RMAN> recover corruption list; C:\rman target=sys/orcl

Recovery Manager: Release 11.1.0.6.0 - Production on Sat Nov 22 19:37:52 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: ORCL (DBID=1190467526) RMAN> recover datafile 6 block 12;

Starting recover at 22-NOV-08

using target database control file instead of recovery catalog allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=138 device type=DISK

channel ORA_DISK_1: restoring block(s)

channel ORA_DISK_1: specifying block(s) to restore from backup set restoring blocks of datafile 00006

channel ORA_DISK_1: reading from backup piece C:\TEMP\ORABACKUP\42K0C03A_1_1

channel ORA_DISK_1: piece handle=C:\TEMP\ORABACKUP\42K0C03A_1_1 tag=TAG20081122T

184601

channel ORA_DISK_1: restored block(s) from backup piece 1

channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01

756  Appendix A  n  Lab Exercises

starting media recovery

media recovery complete, elapsed time: 00:00:03

Finished recover at 22-NOV-08

RMAN>

9.Validate the results.

SQL>select file#, block#, blocks, corruption_type “TYPE” from v$database_block_corruption;

no rows selected

SQL> select * from block_corruption_test;

X

Y

Z

----------

----------

---------

1

row 1

22-NOV-08

2

row 2

22-NOV-08

3

row 3

22-NOV-08

4

row 4

22-NOV-08

5

row 5

22-NOV-08

6

row 6

22-NOV-08

7

row 7

22-NOV-08

8

row 8

22-NOV-08

9

row 9

22-NOV-08

10

row 10

22-NOV-08

11

row 11

22-NOV-08

12

row 12

22-NOV-08

13

row 13

22-NOV-08

14

row 14

22-NOV-08

15

row 15

22-NOV-08

15 rows selected.

SQL>

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