Backup and recovery of Oracle read-only tablespace

Source: Internet
Author: User

-- ====================================

-- Backup and recovery of read-only tablespace

-- ====================================


I. Features of read-only tablespaces

Use read-only tablespace to avoid frequent backup of static data

When alter tablespace tbs read only is used, the data file will execute the Checkpoint Process (write all the contents of the dirty buffer to the disk ),

The current SCN number is marked, and the header of the data file storing the SCN is frozen. The frozen information of the data file is also recorded in the control file.

Read-Only tablespace objects can be cleared.


Ii. Backup of read-only tablespace

Generally, only one backup is required for the read-only tablespace. That is, when the tablespace status changes, backup immediately.

You can use the OS system cp command to back up or RMAN to back up read-only tablespaces.

We recommend that you enable backup optimization when using RMAN.

RMAN> configure backup optimization on;


Read-Only tablespace does not support Hot Backup

SQL> alter tablespace tbs1 begin backup;

Alter tablespace tbs1 begin backup

*

ERROR at line 1:

ORA-01642: begin backup not needed for read only tablespace 'tbs1'


Iii. Restoration and restoration of read-only tablespaces

The problem with restoring and restoring read-only tablespaces is that the control file controls read-only tablespaces in the following three situations:

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

Case backup 1 crash status recovery

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

Case 1 Read-Only copies the backup Read-Only tablespace to the destination (Restore)

Case 2 Read-Only Read-Write first Restore backup1, then recover (applied log)

Case 3 Read-Write Read-only first Restore backup1, then recover (applied log)


Read-Only tablespace recovery considerations

When recreating a control file

When renaming a data file

When a backup control file is used


The following table space tbs1 is set to read-only, and the script for recreating the control file is compared before and after the table space tbs1 is set to read-only.

SQL> alter database backup controlfile to trace as '/tmp/rectl1. SQL ';


SQL> alter tablespace tbs1 read only;


SQL> alter database backup controlfile to trace as '/tmp/rectl2. SQL ';


SQL> ho diff/tmp/rectl1. SQL/tmp/rectl2. SQL

69, 70c69

<'/U01/app/oracle/oradata/orcl/example01.dbf ',

<'/U01/app/oracle/oradata/orcl/tbs01.dbf'

---

> '/U01/app/oracle/oradata/orcl/example01.dbf'

97a97, 102

> -- Files in read-only tablespaces are now named.

> Alter database rename file 'missing00006'

> TO '/u01/app/oracle/oradata/orcl/tbs01.dbf ';

>

> -- Online the files in read-only tablespaces.

> Alter tablespace "TBS1" ONLINE;


Comparison

1. When the create controlfile command is used, the data files of the read-only tablespace are not listed in datafile.

2. After the control file is successfully created and opened, run the alter database rename file command to rename the data file of the read-only tablespace.

3. Use alter tablespace readonly_tablespacename online to bring the read-only tablespace online


Iv. demonstrate restoration of read-only tablespace changes

1. demonstrate that the entire process is a read-only tablespace (corresponding to case 1 described above)

SQL> create table scott. tb1 tablespace tbs1

2 as select * from scott. emp;


SQL> commit;


SQL> alter tablespace tbs1 read only;


SQL> select file #, name, enabled from v $ datafile where file # = 6;


FILE # NAME ENABLED

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

6/u01/app/oracle/oradata/orcl/tbs01.dbf READ ONLY


SQL> ho cp/u01/app/oracle/oradata/orcl/tbs01.dbf/tmp/tbs01.dbf


SQL> insert into scott. tb1 (empno, ename) values (3333, 'Thomas ');


SQL> update scott. tb1 set sal = sal * 1.2 where ename = 'Scott ';


SQL> delete from scott. tb1 where ename = 'Scott ';

-- Run the preceding three commands and receive the same error message:

ORA-00372: file 6 cannot be modified at this time

ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/tbs01.dbf'


From the above demonstration, we can see that any DML operation on the data in the read-only tablespace is not available.

In the Oracle tablespace and data file article, you can perform the delete operation on the read-only tablespace (Version: 10.2.0.1.0 ).

Database patch issues. This version is 10.2.0.4.0.

-- Open with vim? /Oradata/orcl/tbs01.dbf to simulate data files that destroy the read-only tablespace.

-- The following error message is returned after the database is restarted.

ORA-01157: cannot identify/lock data file 6-see DBWR trace file

ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/tbs01.dbf'


SQL> ho cp/tmp/tbs01.dbf/u01/app/oracle/oradata/orcl/tbs01.dbf


SQL> alter database open;


SQL> select count (1) from scott. tb1;


COUNT (1)

----------

16


2. Demonstrate the restoration of a read-only backup that is damaged after it is changed from read-only to read/write (corresponding to case 2 described above)

SQL> alter tablespace tbs1 read write;


SQL> insert into scott. tb1 (empno, ename) values (3333, 'Thomas ');


SQL> commit;


-- Use vim to open the/u01/app/oracle/oradata/orcl/tbs01.dbf file and perform any operation to simulate the destruction of data files in the read/write tablespace.

-- The error message is not received after the database is restarted.


SQL> insert into scott. tb1 (empno, ename) values (4444, 'Jackson ');

Insert into scott. tb1 (empno, ename) values (4444, 'Jackson ')

*

ERROR at line 1:

ORA-00376: file 6 cannot be read at this time

ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/tbs01.dbf'


SQL> select * from v $ recover_file;


FILE # ONLINE _ error change # TIME

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

6 offline file not found 0


SQL> ho cp/tmp/tbs01.dbf/u01/app/oracle/oradata/orcl/tbs01.dbf


SQL> recover datafile 6;

Media recovery complete.


SQL> alter tablespace tbs1 online;


Tablespace altered.

SQL> select * from scott. tb1 where ename = 'Thomas ';


EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO

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

3333 Thomas


3. demonstrate how to recover from a read/write tablespace to a read-only tablespace with only backup of the read/write tablespace (corresponding to case 3 described above)

SQL> select file #, name, enabled from v $ datafile where file # = 6;


FILE # NAME ENABLED

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

6/u01/app/oracle/oradata/orcl/tbs01.dbf READ WRITE


SQL> alter tablespace tbs1 begin backup;


SQL> ho cp/u01/app/oracle/oradata/orcl/tbs01.dbf/tmp/tbs01.dbf


SQL> alter tablespace tbs1 end backup;


SQL & gt; delete from scott. tb1 where empno = 3333;


SQL> commit;


SQL> alter tablespace tbs1 read only;


-- Open with vim? /Oradata/orcl/tbs01.dbf to simulate data files that destroy the read-only tablespace.

-- The following error message is returned after the database is restarted.


ORA-01157: cannot identify/lock data file 6-see DBWR trace file

ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/tbs01.dbf'


SQL> ho cp/tmp/tbs01.dbf/u01/app/oracle/oradata/orcl/tbs01.dbf


SQL> recover datafile 6;


SQL> alter database open;


SQL> select * from scott. tb1 where ename = 'Thomas ';

,;

No rows selected


4. demonstrate that the status of the data file has changed multiple times and there is no Backup Recovery Processing during the change (in fact, the log is used to reconstruct the data file)

SQL> select file #, name, enabled from v $ datafile where file # = 6;


FILE # NAME ENABLED

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

6/u01/app/oracle/oradata/orcl/tbs01.dbf READ WRITE


SQL> drop table scott. tb1;


SQL> commit;


SQL> alter tablespace tbs1 read only;


SQL> alter tablespace tbs1 read write;


SQL> create table scott. tb2 tablespace tbs1 as select * from scott. emp;


SQL> commit;


SQL> alter system checkpoint;


[Oracle @ oradb orcl] $ tail-n 50 $ ORACLE_BASE/admin/orcl/bdump/alert_orcl.log

Errors in file/u01/app/oracle/admin/orcl/bdump/orcl_ckpt_4064.trc:

ORA-01171: datafile 6 going offline due to error advancing checkpoint

ORA-01122: database file 6 failed verification check

ORA-01110: data file 6: '/u01/app/oracle/oradata/orcl/tbs01.dbf'

ORA-01251: Unknown File Header Version read for file number 6


SQL> select * from v $ recover_file;


FILE # ONLINE _ error change # TIME

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

6 offline file not found 0


SQL> select file #, name, status from v $ datafile where file # = 6;


FILE # NAME STATUS

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

6/u01/app/oracle/oradata/orcl/tbs01.dbf RECOVER


SQL> alter database create datafile 6;


SQL> recover datafile 6;

Media recovery complete.


SQL> alter database datafile 6 online;


SQL> select count (1) from scott. tb2;


COUNT (1)

----------

16


5. Demonstrate deleting objects in read-only tablespace

SQL> select file #, name, enabled from v $ datafile where file # = 6;


FILE # NAME ENABLED

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

6/u01/app/oracle/oradata/orcl/tbs01.dbf READ ONLY


SQL> select segment_name, segment_type, tablespace_name, owner from dba_segments where

2 tablespace_name = 'tbs1' and segment_name = 'tb2 ';


SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME OWNER

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

TB2 TABLE TBS1 SCOTT


SQL> drop table scott. tb2;


Table dropped.


V. Summary

1. When the tablespace is set to read-only, the data backup volume will be reduced.

2. Once the tablespace is set to read-only, no DML operations can be performed on the objects in the tablespace.

3. Objects in the read-only tablespace can be cleared because the drop command updates the data dictionary without updating the object itself.

4. When the tablespace status changes, immediately back up the tablespace to reduce recovery

5. If the status changes multiple times and the logs are not backed up in time, you can use online redo and archive logs to restore the logs if they are not damaged.

Run the following command:

Delete the damaged data file (rm dbfile. dbf)

Alter database create datafile n)

Restore media (recover datafile n)

Bringing damaged data files online (alter database datafile n online)

6. In the demo, the system recovers from the mount State and from the open state in the production environment. perform the following steps:

Remove the damaged read-only tablespace (data file) offline)

Use the backup tablespace (data file) to restore (restore)

Use archived and online logs for media recovery (recover)

Bring restored tablespaces (data files) online)

7. If the original media is damaged and cannot be recovered to the original position, use the following command to transfer the original media.

Alter database rename file '<dir1>' to '<dir2> ';


Oracle video tutorial follow: http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.