Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5205344
  • 博文数量: 1004
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13042
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1004)

文章存档

2020年(1)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Oracle

2014-01-07 14:34:56

环境:
OS:Linux As 5
DB:11.2.0.1

  为了不停止业务系统,我们可以采用rman创建dataguard,在操作之前最好先备份下主库.

------------------------------------------主库上的操作-----------------------------------
1.设置主库为force logging模式
SQL> alter database force logging;
Database altered.

2.添加standby日志文件,大小跟v$log中的日志文件大小保持一致,这里的日志组从4开始,因为已经创建了3组online日志组了.
alter database add standby logfile group 4 ('/u01/app/oracle/oradata/oracl/stdbyredo01.log') SIZE 512m;
alter database add standby logfile group 5 ('/u01/app/oracle/oradata/oracl/stdbyredo02.log') SIZE 512m;
alter database add standby logfile group 6 ('/u01/app/oracle/oradata/oracl/stdbyredo03.log') SIZE 512m;
alter database add standby logfile group 7 ('/u01/app/oracle/oradata/oracl/stdbyredo04.log') SIZE 512m;

3.配置tnsnames文件

使用netca配置tnsnames,文件内容如下:
[oracle@primary admin]$ more tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

TAR_ORACL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = oracl)
    )
  )

DUP_ORACL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = oraclbak)
    )
  )

4.查看数据文件和日志文件的目录,在备库上我们需要rman转换到oraclbak目录下
SQL> select name from v$datafile;

NAME
--------------------------------------------------
/u01/app/oracle/oradata/oracl/system01.dbf
/u01/app/oracle/oradata/oracl/sysaux01.dbf
/u01/app/oracle/oradata/oracl/undotbs01.dbf
/u01/app/oracle/oradata/oracl/users01.dbf
/u01/app/oracle/oradata/oracl/hxl001.dbf
/u01/app/oracle/oradata/oracl/hxl002.dbf
 

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------
/u01/app/oracle/oradata/oracl/redo0301.log
/u01/app/oracle/oradata/oracl/redo0302.log
/u01/app/oracle/oradata/oracl/redo0201.log
/u01/app/oracle/oradata/oracl/redo0202.log
/u01/app/oracle/oradata/oracl/redo0101.log
/u01/app/oracle/oradata/oracl/redo0102.log
/u01/app/oracle/oradata/oracl/stdbyredo01.log
/u01/app/oracle/oradata/oracl/stdbyredo02.log
/u01/app/oracle/oradata/oracl/stdbyredo03.log
/u01/app/oracle/oradata/oracl/stdbyredo04.log

SQL>select name from v$controlfile;

NAME

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

/u01/app/oracle/oradata/oracl/control01.ctl
/u01/app/oracle/oradata/oracl/control02.ctl

5.在主库上添加如下参数
alter system set db_unique_name=oracl scope=spfile;
alter system set log_archive_config='dg_config=(oracl,oraclbak)' scope=both;
alter system set log_archive_dest_1= 'location=/u01/archivelog/ valid_for=(all_logfiles,all_roles)  db_unique_name=oracl' scope=both;
alter system set log_archive_dest_2= 'service=dup_oracl async  valid_for=(online_logfiles,primary_role)  db_unique_name=oraclbak' scope=both;
alter system set log_archive_dest_state_1=enable scope=both;
alter system set log_archive_dest_state_2=enable scope=both;
alter system set standby_file_management=auto scope=both;
alter system set fal_server=dup_oracl scope=both;
alter system set fal_client=tar_oracl scope=both;
alter system set db_file_name_convert='/u01/app/oracle/oradata/oraclbak/','/u01/app/oracle/oradata/oracl/' scope=spfile;
alter system set log_file_name_convert='/u01/app/oracle/oradata/oraclbak/','/u01/app/oracle/oradata/oracl/' scope=spfile;

6.备份主库
run{
allocate channel dup type disk;
backup format '/bak/df_t%t_s%s_p%p' database;
sql 'alter system archive log current';
backup format '/bak/archive_log_t%t_s%s_p%p' archivelog all;
backup spfile format '/bak/spfile_%u_%T.bak';
release channel dup;
}

7.生成standby控制文件
rman>copy current controlfile for standby to '/bak/standby.ctl';

8.将以上生成的备份集,密码文件,和tnsnames文件传到备库上.
primary-> scp archive_log_t835943148_s4_p1 oracle@192.168.50.202:/bak
primary-> scp df_t835942983_s2_p1 oracle@192.168.50.202:/bak
primary-> scp df_t835943125_s3_p1 oracle@192.168.50.202:/bak
primary-> scp spfile_05ot6uog_20140104.bak oracle@192.168.50.202:/bak
primary-> scp standby.ctl oracle@192.168.50.202:/bak
primary->scp tnsnames.ora oracle@192.168.50.202:/bak -- tns文件
primary->scp orapworacl oracle@192.168.50.202:/bak   -- 密码文件

------------------------------------------备库上的操作-----------------------------------
1.从备份集恢复spfile
RMAN>set dbid 1820932955  --在主库上获取数据的dbid:Select dbid From v$database
RMAN>startup nomount
RMAN>restore spfile to pfile '/u01/export/home/oracle/pfile.ora' from '/bak/spfile_05ot6uog_20140104.bak';

2.修改pfile
修改后的内容如下,注意红色部分.
[oracle@stdby ftp]$ more pfile.txt
oraclbak.__db_cache_size=272629760
oraclbak.__java_pool_size=4194304
oraclbak.__large_pool_size=4194304
oraclbak.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
oraclbak.__pga_aggregate_target=276824064
oraclbak.__sga_target=415236096
oraclbak.__shared_io_pool_size=0
oraclbak.__shared_pool_size=125829120
oraclbak.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/oraclbak/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/oraclbak/control01.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='oracl'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=oraclXDB)'
*.memory_target=692060160
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'

 
*.db_unique_name=oraclbak
*.log_archive_config='dg_config=(oracl,oraclbak)'
*.log_archive_dest_1=
 'location=/u01/archive_log/
  valid_for=(all_logfiles,all_roles)
  db_unique_name=oraclbak'
*.log_archive_dest_2=
 'service=tar_oracl async
  valid_for=(online_logfiles,primary_role)
  db_unique_name=oracl'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management=auto
*.fal_server=tar_oracl
*.fal_client=dup_oracl
*.db_file_name_convert='/u01/app/oracle/oradata/oracl/','/u01/app/oracle/oradata/oraclbak/'
*.log_file_name_convert='/u01/app/oracle/oradata/oracl/','/u01/app/oracle/oradata/oraclbak/'

创建参数文件中定义的目录(仔细检查每个目录,没有创建的话需要创建)
standby->mkdir -p /u01/archive_log/
standby->mkdir -p /u01/app/oracle/admin/oraclbak/adump
standby->mkdir -p /u01/app/oracle/oradata/oraclbak


3.直接使用主库传过来的密码文件
standby->cp orapworacl  $ORACLE_HOME/dbs
standby->mv orapworacl orapworaclbak

4.将主机上生成的standby控制文件放到初始化参数指定的目录
standby-> cp standby.ctl /u01/app/oracle/oradata/oraclbak/
standby-> mv standby.ctl control01.ctl
standby-> ls
control01.ctl

5.启动数据库到nomount状态
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup nomount pfile=/u01/export/home/oracle/pfile.ora

6.mount状态
RMAN> alter database mount;
using target database control file instead of recovery catalog
database mounted

7.指定备份集路径,bak目录下是从主库传过来的备份集
rman>catalog start with '/bak/';

8.利用rman恢复出备库
RMAN> run{
set newname for datafile 1  to  '/u01/app/oracle/oradata/oraclbak/system01.dbf';
set newname for datafile 2  to  '/u01/app/oracle/oradata/oraclbak/sysaux01.dbf';
set newname for datafile 3  to  '/u01/app/oracle/oradata/oraclbak/undotbs01.dbf';
set newname for datafile 4  to  '/u01/app/oracle/oradata/oraclbak/users01.dbf';
set newname for datafile 5  to  '/u01/app/oracle/oradata/oraclbak/tps_hxl01.dbf';
set newname for datafile 6  to  '/u01/app/oracle/oradata/oraclbak/tps_hxl02.dbf';
set newname for datafile 7  to  '/u01/app/oracle/oradata/oraclbak/tps_hxl03.dbf';
set newname for datafile 8  to  '/u01/app/oracle/oradata/oraclbak/tps_hxl04.dbf';
set newname for datafile 9  to  '/u01/app/oracle/oradata/oraclbak/tps_hxl05.dbf';
set newname for datafile 10  to  '/u01/app/oracle/oradata/oraclbak/tps_hxl06.dbf';
set newname for datafile 11  to  '/u01/app/oracle/oradata/oraclbak/undotbs02.dbf';
set newname for datafile 12  to  '/u01/app/oracle/oradata/oraclbak/TPS_HXL01_01.dbf';
restore database;
switch datafile all;

}

9.应用日志
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.




-- The  End --
 

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