Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2378639
  • 博文数量: 195
  • 博客积分: 3409
  • 博客等级: 中校
  • 技术积分: 3954
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 10:21
个人简介

● ITPUB名人堂嘉宾 ● ChinaUnix社区博客专家 ● ChinaUnix社区Oracle板块版主 ● 优酷网认证音乐牛人:EricGuitar ● SDOUG 核心成员 ●E-mail:gaoqiangdba@163.com

文章分类

全部博文(195)

文章存档

2020年(7)

2019年(7)

2016年(5)

2015年(36)

2014年(23)

2013年(15)

2012年(23)

2011年(61)

2010年(18)

分类: Oracle

2019-08-10 19:27:55

  


Oracle 11G起,RMAN多了一个parallelim参数,可以设置并行度。下面我们实际操作一下,直观的体验一下该参数的效果:

查看RMAN配置:
RMAN> show all ;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

可以看到默认值是设置的并行度为1,即不并行。


设置并行度为4:
RMAN> configure device type disk parallelism 4 ;

new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored


RMAN> show all;


RMAN configuration parameters for database with db_unique_name ORCL are:

CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;

验证参数已修改。


发起备份:
RMAN> backup incremental level 0 database tag 'Para_Bak'  format '/backup/orcl_%d_%T_%U_L0'  plus archivelog delete all input;
crosscheck archivelog all;



Starting backup at 31-JUL-15
current log archived
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
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=228 RECID=217 STAMP=886495816
channel ORA_DISK_1: starting piece 1 at 31-JUL-15
channel ORA_DISK_1: finished piece 1 at 31-JUL-15
piece handle=/backup/orcl_ORCL_20150731_6vqddmi8_1_1_L1 tag=TAG20150731T085016 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/archlog/orcl/1_228_820195525.dbf RECID=217 STAMP=886495816
Finished backup at 31-JUL-15


Starting backup at 31-JUL-15
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
省略多行...


在删除的时候也会自动分配通道:
RMAN> delete backup;


using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4


List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
223     209     1   1   AVAILABLE   DISK        /backup/orcl_ORCL_20150731_6vqddmi8_1_1_L1
224     210     1   1   AVAILABLE   DISK        /backup/orcl_ORCL_20150731_73qddmib_1_1_L0
225     211     1   1   AVAILABLE   DISK        /backup/orcl_ORCL_20150731_72qddmib_1_1_L0
226     212     1   1   AVAILABLE   DISK        /backup/orcl_ORCL_20150731_71qddmib_1_1_L0
227     213     1   1   AVAILABLE   DISK        /backup/orcl_ORCL_20150731_70qddmib_1_1_L0
228     214     1   1   AVAILABLE   DISK        /backup/orcl_ORCL_20150731_74qddmj4_1_1_L1
229     215     1   1   AVAILABLE   DISK        /backup/ctl_c-1347976258-20150731-0b


Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/backup/orcl_ORCL_20150731_6vqddmi8_1_1_L1 RECID=223 STAMP=886495816
deleted backup piece
backup piece handle=/backup/orcl_ORCL_20150731_73qddmib_1_1_L0 RECID=224 STAMP=886495819
deleted backup piece
backup piece handle=/backup/orcl_ORCL_20150731_72qddmib_1_1_L0 RECID=225 STAMP=886495819
deleted backup piece
backup piece handle=/backup/orcl_ORCL_20150731_71qddmib_1_1_L0 RECID=226 STAMP=886495819
deleted backup piece
backup piece handle=/backup/orcl_ORCL_20150731_70qddmib_1_1_L0 RECID=227 STAMP=886495819
deleted backup piece
backup piece handle=/backup/orcl_ORCL_20150731_74qddmj4_1_1_L1 RECID=228 STAMP=886495844
deleted backup piece
backup piece handle=/backup/ctl_c-1347976258-20150731-0b RECID=229 STAMP=886495846
Deleted 7 objects

此时的系统状态可以看到4个CPU全部都有负载:




但是如果生硬的套用一些脚本,有分配通道的命令的话,可能会影响并行度,我们测试一下:

1.设置并行度:configure device type disk parallelism 4 ;
2.备份数据库,分配1条通道:

run{
allocate channel c1 type disk ;
backup as compressed backupset incremental level 0 database tag 'Para_Bak'  format '/backup/orcl_%d_%T_%U_L0'  filesperset 8
plus archivelog delete all input;
crosscheck archivelog all;
delete noprompt expired archivelog all;
crosscheck backup;
delete noprompt obsolete; 
release channel c1;
}

此时并行参数失效,仅调用了1个CPU在工作:






此参数设置的话,是对所有备份生效的,如果担心开并发对系统性能有影响,仅对个别的自动或手动备份生效的话,可关闭该参数,手动分配通道:

RMAN> CONFIGURE DEVICE TYPE DISK clear;


old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
RMAN configuration parameters are successfully reset to default value
released channel: ORA_DISK_1
released channel: ORA_DISK_2
released channel: ORA_DISK_3
released channel: ORA_DISK_4

使用类似如下脚本进行备份:
run{
allocate channel c1 type disk ;
allocate channel c2 type disk ;
allocate channel c3 type disk ;
allocate channel c4 type disk ;
backup as compressed backupset incremental level 0 database tag 'Para_Bak'  format '/backup/orcl_%d_%T_%U_L0' 
plus archivelog delete all input;
crosscheck archivelog all;
delete noprompt expired archivelog all;
crosscheck backup;
delete noprompt obsolete; 
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}


此时可以看到系统也是调用了4个CPU进行工作:





那在恢复的时候,并行参数是否可以开启?当初开启并行备份时恢复的话不开并行是否可以?或者是为了不影响性能,开一小部分并行是否OK?答案是肯定的,Oracle就是这么牛。

我们删除数据库,然后再恢复一下看看:
删除数据库:
SQL> shutdown abort;
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.


Total System Global Area  417546240 bytes
Fixed Size    2213936 bytes
Variable Size  364906448 bytes
Database Buffers   41943040 bytes
Redo Buffers    8482816 bytes
Database mounted.



SQL> alter system enable restricted session;
System altered.

SQL> drop database;
Database dropped.

Disconnected from 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> exit

[oracle@dbserver backup]$ export ORACLE_SID=orcl
[oracle@dbserver backup]$ rman target /


Recovery Manager: Release 11.2.0.1.0 - Production on Fri Jul 31 11:44:32 2015


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


connected to target database (not started)


清空并行参数配置,还原为默认值:
RMAN> CONFIGURE DEVICE TYPE DISK clear;

old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
RMAN configuration parameters are successfully reset to default value


RMAN> show all ;


RMAN configuration parameters for database with db_unique_name ORCL are:

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default




在不并行的情况下恢复一下参数文件和控制文件:
RMAN> restore spfile from '/backup/ctl_c-1347976258-20150731-0c' ;
Starting restore at 31-JUL-15
using channel ORA_DISK_1
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /backup/ctl_c-1347976258-20150731-0c
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 31-JUL-15


RMAN> restore controlfile from '/backup/ctl_c-1347976258-20150731-0c';

Starting restore at 31-JUL-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/app/oradata/ORCL/controlfile/o1_mf_8xm4g27m_.ctl
Finished restore at 31-JUL-15


在恢复数据库的过程中,进行并行数设置,设置为2,与之前的parallelism=4不同。
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

RMAN> configure device type disk parallelism 2;

old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored


RMAN> restore database;


Starting restore at 31-JUL-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=129 device type=DISK
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 00006 to /oracle/app/oradata/catalog_rman/rmantbs01.dbf
channel ORA_DISK_1: restoring datafile 00011 to /oracle/app/oradata/ORCL/datafile/CA_DATA.dbf
channel ORA_DISK_1: restoring datafile 00012 to /oracle/app/oradata/ORCL/datafile/CA_TEMP.dbf
channel ORA_DISK_1: restoring datafile 00021 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORA92DATABASEKMC_DATA.DBF
channel ORA_DISK_1: restoring datafile 00022 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORA92DATABASEKMC_INDEX.DBF
channel ORA_DISK_1: restoring datafile 00025 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORA92DATABASETSADB_DATA.DBF
channel ORA_DISK_1: restoring datafile 00028 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORA92DATABASERA_DATA_01.DBF
channel ORA_DISK_1: reading from backup piece /backup/orcl_ORCL_20150731_7bqddvno_1_1_L0
channel ORA_DISK_2: starting datafile backup set restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_DISK_2: restoring datafile 00002 to /oracle/app/oradata/ORCL/datafile/o1_mf_sysaux_8xm483f7_.dbf
channel ORA_DISK_2: restoring datafile 00009 to /oracle/app/oradata/ORCL/datafile/lee.dbf
channel ORA_DISK_2: restoring datafile 00013 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORADATAORCLCWMLITE01.DBF
channel ORA_DISK_2: restoring datafile 00015 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORADATAORCLINDX01.DBF
channel ORA_DISK_2: restoring datafile 00018 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORADATAORCLXDB01.DBF
channel ORA_DISK_2: restoring datafile 00020 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORA92DATABASECA_INDEX.DBF
channel ORA_DISK_2: restoring datafile 00026 to /oracle/app/oracle/product/11.2.0/db_1/dbs/E:ORACLEORA92DATABASETSADB_INDEX.DBF
channel ORA_DISK_2: reading from backup piece /backup/orcl_ORCL_20150731_79qddvno_1_1_L0


省略多行...


channel ORA_DISK_2: piece handle=/backup/orcl_ORCL_20150731_7aqddvno_1_1_L0 tag=PARA_BAK
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: piece handle=/backup/orcl_ORCL_20150731_78qddvno_1_1_L0 tag=PARA_BAK
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:26
Finished restore at 31-JUL-15


恢复数据库到最新的状态:
[oracle@dbserver backup]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 31 13:33:32 2015


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> recover database using backup controlfile until cancel;  
ORA-00279: change 380035364 generated at 07/31/2015 11:27:13 needed for thread
1
ORA-00289: suggestion :
/oracle/app/oracle/product/11.2.0/db_1/dbs/arch1_233_820195525.dbf
ORA-00280: change 380035364 for thread 1 is in sequence #233

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL
Media recovery cancelled.
SQL> ALTER DATABASE OPEN RESETLOGS;
Database altered.


SQL> connect eric/gao
ERROR:
ORA-28002: the password will expire within 7 days
Connected.
SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
SUMMARY
MUSIC_EMP
WALLPAPER


SQL> select count(*) from music_emp;

  COUNT(*)
----------
14


SQL> select count(*) from wallpaper;

  COUNT(*)
----------
6






SQL> select * from music_emp
  2  ;


     EMPNO ENAME
---------- --------------------
      7369 SMITH
      7499 ALLEN
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7839 KING
      7876 ADAMS
      7934 MILLER
      7521 WARD
      7566 JONES
      7788 SCOTT


     EMPNO ENAME
---------- --------------------
      7844 TURNER
      7900 JAMES
      7902 FORD


14 rows selected.


可以看到,在恢复参数文件和控制文件的时候,使用的是单进程恢复,在restore和recover的时候使用的是parallelism为2的并发,不影响数据库恢复的内容,仅影响性能而已。


OK!~~~

阅读(5279) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~