Move Oracle (rejoice999) between Unix bare devices and file systems)

Source: Internet
Author: User
Tags tru64

Dd description:

Assume that I have a file named aaa.gz with a size of 81234 kb. I want to use the DD command to implement the following Backup results: first, divide the snapshot into three shards. The first Shard is the first 10000 KB of the original file named aaa.gz, and the second Shard is the 70000 kb in the middle.

The backup method is as follows:
Dd if=aaa.gz of=aaa.gz. bak1 BS = 1 k count = 10000
Dd if=aaa.gz of=aaa.gz. bak2 BS = 1 K skip = 10000 COUNT = 70000
Dd if=aaa.gz of=aaa.gz. bak3 BS = 1 K skip = 80000

The recovery method is as follows:
Dd if=aaa.gz. bak1 of=aaa.gz
Dd if=aaa.gz. bak2 of=aaa.gz BS = 1 K seek = 10000
Dd if=aaa.gz. bak3 of1_aaa.gz BS = 1 K seek = 80000

Now you can check that the recovered file will be exactly the same as your original file, indicating that the backup is successful!

* ** Note :***
BS = xxx this option refers to the block size that you create at one time when backing up, while COUNT = xxx refers to the total number of blocks backed up starting from the beginning of the backup.
That is to say, if your BS = 3 K and count = 5, it means that you have 3 K blocks, a total of 5 blocks, back up the 15 K (3 K * 5 = 15 K) of the original file ).
Skip = xxx indicates the part after if during backup, that is, how many parts of the original file are skipped before the backup starts, on the contrary, seek = xxx indicates the part of the object after the backup, that is, the number of skipped parts of the target file before writing.

 

 

**************************************** **************************************** *******************************

1. About Bare Devices

1.1 What is a raw device)

A bare device is a raw partition or raw logical volume that has not been created for a file system.

Character device driver to access it. How to read and write data on the device depends on the application that uses it. Because operations on bare devices do not pass through the UNIX buffer, data is directly transferred between the Oracle data buffer (buffer cache) and the disk, therefore, the use of bare devices can improve I/O performance to a certain extent, and is suitable for systems with large I/O volumes. In addition, in OPS/RAC (Oracle Parallel Server/real application cluster) environments, multiple nodes simultaneously access the same database, therefore, control file, data file, and redo log must all be created on the raw device.

1.2 bare device space available

Different UNIX systems do not have the same management of bare devices. In particular, Some UNIX systems need to retain a certain amount of space in the header of each bare device, applications cannot overwrite this part when using a bare device; otherwise, it may cause damage to the bare device. Therefore, the actual available space of a bare device is the space allocated to the bare device and then the reserved space of this part of the operating system. The following is a list of commonly used Unix OS reserved size:

Unixos reserved size

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

Sun solaris0

HP-UX0

IBM aix4k

Tru64 unix64k

Linux0

1.3 dd command

For read/write bare devices on UNIX, commands such as CP, cpio, and tar cannot be used. DD is required. Below are some simple descriptions of common dd parameters, for more information, see the Unix user manual or use the man dd command.

Dd [operand = value...]

If = file specifies the input file. The default value is standard input.

Of = file specifies the output file. The default value is standard output.

BS = N set the size of the input and output blocks to n Bytes. You can also use "K" as the unit.

Skip = n skip N input blocks before copying. The default value is 0.

Seek = n skip n blocks from the output file header before copying. The default value is 0.

Count = n indicates the number of copies. By default, the copy ends with the input file.

1.4 Description of the examples in this article

A. In all examples, the db_block_size of Oracle is 8 K.

B./oradata is a file system directory.

C./dev/rlv_data,/dev/rlv_redo and/dev/rlv_ctrl are three raw devices, both of which are 8 MB (8192 K) in size)

D. If the operating system is not mentioned, the default value is AIX and OS _reserved_size = 4 K.

2. datafile)

2.1 create data files on bare Devices

Run the following command to create a tablespace:

SQL> Create tablespace ts_test datafile '/dev/rlv_data' size 8180 K;

The value specified by size must be less than or equal to 8180 K; otherwise, the statement will fail:

ORA-01119: Error in creating database file '/dev/rlv_data'

ORA-27042: not enough space on raw partition to fullfill request

The maximum value is calculated as follows:

8192 K (raw device size)-4 K (OS _reserved_size)-8 K (db_block_size) = 8180 K

Why do we need to subtract a db_block_size? This is because when Oracle creates a datafile, in addition to the size specified in the command, it also adds a block to the file header, which is called "Oracle OS header block ", contains the logical block size and number of file blocks of the file. This is not exclusive to datafile on raw device. If you create a datafile on the file system and specify a size of KB, the file size you can see using the LS-l or dir command will be 1008 K (db_block_size = 8 K ).

2.2 move data files between file systems and bare Devices

2.2.1 from File System to bare Device

A. Create a 4 m datafile on the file system

SQL> Create tablespace test datafile '/oradata/test. dbf' size 4 m;

B. Check the size of the new datafile (Note: 4202496 = 4 m + 8 K)

$ LS-L/oradata/test. DBF

-RW-r ----- 1 Oracle DBA 4202496 Aug 29/oradata/test. DBF

C. Confirm the DD parameters according to the formula below.

D. If the database is not open, copy it with DD. The following command and output are provided.

AIX $ dd If =/oradata/test. DBF of =/dev/rlv_data BS = 4 K seek = 1

1026 + 0 records in

1026 + 0 records out

Tru64 $ dd If =/oradata/test. DBF of =/dev/rlv_data BS = 64 K seek = 1

64 + 1 records in

64 + 1 records out

Other $ dd If =/oradata/test. DBF of =/dev/rlv_data BS = 1024 K

4 + 1 records in

4 + 1 records out

2.2.2 from bare devices to file systems

A. determine the actual size of the data file file_size, which is used to calculate the DD parameter count in the next step. If the Count calculation is incorrect, the copied data file is invalid and the database cannot be opened.

SQL> select bytes, blocks, Bytes/blocks db_block_size, bytes + Bytes/blocks file_size

From dba_data_files where file_name = '/dev/rlv_data ';

Bytesblocksdb_block_sizefile_size

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

419430451281924202496

B. Determine the DD parameter according to the formula below. Min indicates that the values of the two are smaller.

C. If the database is not open, copy it with DD. The following command and output are provided.

AIX $ dd If =/dev/rlv_data of =/oradata/test2.dbf BS = 4 K skip = 1 COUNT = 1026

1026 + 0 records in

1026 + 0 records out

Tru64 $ dd If =/dev/rlv_data of =/oradata/test2.dbf BS = 8 K skip = 8 count = 513

513 + 0 records in

513 + 0 records out

Other $ dd If =/dev/rlv_data of =/oradata/test2.dbf BS = 8 k count = 513

513 + 0 records in

513 + 0 records out

2.2.3 whether copying data from File System to raw device or vice versa, you must perform the RENAME operation to enable Oracle to open the database with a new data file.

SQL> startup Mount;

SQL> alter database rename file 'oldfilename' to 'newfilename ';

SQL> alter database open;

3. Online redo log)

3.1 create online redo log on bare Devices

Run the following command to add an online redo log:

SQL> alter database add logfile group 4'/dev/rlv_redo 'size xxxxk;

When creating a redo log on a bare device, you also need to calculate the maximum value that can be used by the size clause. This method is similar to the calculation method used when creating a datafile in 2.1, the only difference is that you should replace db_block_size in the formula with redo_block_size (that is, the logical block size of redo log ). This redo_block_size has different values on different operating systems. You can obtain this value using either of the following methods, and calculate the actual file size of the redo log file_size ):

Method 1: dump existing redo log file

SQL> alter system dump logfile '/oradata/redo01.log ';

SQL> show parameter user_dump_dest

View the generated TRC file in the user_dump_dest directory:

File Header:

Software vsn = 135294976 = 0x8107000, compatibility vsn = 135290880 = 0x8106000

DB id = 3227187598 = 0xc05af98e, DB name = 'v817'

Control seq = 12474 = 0x30ba, file size = 8192 = 0x2000

File number = 5, blksiz = 512, file type = 2 log

Method 2: dbfsize, a tool provided by Oracle, is applicable to files on the file system and raw device.

$ Dbfsize/oradata/redo01.log

Database File:/oradata/redo01.log

Database file type: File System

Database file size: 8192 512 byte Blocks

From the above two outputs, we can see that redo_block_size = 512, blocks = 8192

File_size = (blocks + 1) * redo_block_size = (8192 + 1) * 512 = 4194816

If the redo_block_size of the platform is known, you can also query the data dictionary to calculate the file_size:

SQL> select B. Member, B. bytes, B. bytes + 512 file_size from V $ logfile A, V $ log B

Where a. Group # = B. Group # and A. Member = '/oradata/redo01.log ';

Memberbytes file_size

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

/Oradata/redo01.log41942644194816

The following table lists Oracle redo_block_size on common operating systems:

Osredo_block_size

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

Windows512

Sun solaris512

HP-UX1024

IBM aix512

Compaq Tru64 unix1024

Linux512

3.2 move the online redo log between the file system and the bare Device

For details, refer to the 2.2 datafile copy process. The only difference is that you need to replace db_block_size with redo_block_size. In addition, the redo log can be copied without DD, but the method of deleting and recreating is used:

SQL> select * from V $ log; -- be sure it's not current and archived

SQL> alter system switch logfile; -- if it's current, force Switch

SQL> alter database drop logfile group N;

SQL> alter database add logfile group N 'newlogfilename 'size xxxxm;

4. Control File)

4.1 create control files on bare Devices

The Oracle control file is generated when the create database or create controlfile statement is executed. Its name is specified by the control_files parameter in the initialization parameter file init $ oracle_sid.ora. The size of the control file cannot be explicitly specified, and it will automatically increase as the database runs. Therefore, when dividing the control file into bare devices, you should leave enough margin based on experience, to avoid unnecessary troubles. The Logical Block Size of the control file is the same as that of db_block_size, and the file header has an oracle OS header block like that of datafile ".

4.2 move control files between file systems and bare Devices

4.2.1 use dd Replication

The method for copying control file is basically the same as that for copying datafile in 2.2. The only difference is that when a bare device copies data to the file system, how to determine the actual size of the control file file_size (Oracle Data dictionary does not contain data of the control file size ). The following describes two methods:

Method 1: After the following SQL statement is executed, go to the user_dump_dest directory to view the generated TRC file.

SQL> alter session set events 'immediate trace name controlf level 10 ';

File Header:

Software vsn = 135266304 = 0x8100000, compatibility vsn = 134217728 = 0x8000000

DB id = 1937054535 = 0x73751b47, DB name = 'o817'

Control seq = 5838 = 0x16ce, file size = 476 = 0x1dc

File number = 0, blksiz = 8192, file type = 1 Control

Method 2: Use the tool dbfsize provided by Oracle

$ Dbfsize/oradata/control01.ctl

Database File:/oradata/control01.ctl

Database file type: File System

Database file size: 476 8192 byte Blocks

File_size = (476 + 1) * 8192 = 3907584

4.2.2 copy using SQL commands

Compared to copying control file with DD described in 4.2.1, the following method of copying with SQL statements is more concise:

SQL> startup Mount

SQL> alter Database Backup controlfile to 'newcontrolfile ';

In the statement, newcontrolfile can be either a file system file or a raw device. Therefore, you can run this command in the Mount state to generate a control file replica that is exactly the same as the existing control file.

4.2.3 modify the initialization parameter file (init $ oracle_sid.ora)

Whether 4.2.1 or 4.2.2 is used to generate a new control file, you only need to modify the control_files parameter in init $ oracle_sid.ora to make the database use the new control file.

V. Recovery Manager (RMAN)

RMAN is a backup and recovery tool provided by oracle8. It can automatically and correctly skip the OS reserved block in the bare device header by using RMAN backup and restore functions, you can easily move datafile and control file between the file system and bare devices. The specific operation process is not described here. See the RMAN manual.

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.