码迷,mamicode.com
首页 > 其他好文 > 详细

DataGuard部署

时间:2018-01-17 00:02:57      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:current   ima   sed   属性   保护模式   恢复数据文件   switch   sql   add   

环境准备
 
主库 primary     10.63.230.10
备库 standby     10.63.230.13
 
软件版本
 
Oracle 11.2.0.4.0
 
搭建步骤
--主库
1.查看归档开启状态
SQL> archive log list;

2.创建归档目录

mkidr /oradata/arch

3.开启归档

SQL> alter database mount;
SQL> alter database archivelog;
SQL> alter system switch logfile;

4.修改主库属性

SQL> alter database force logging;
SQL> select FORCE_LOGGING from v$database; 

5.在主库创建密码文件、参数文件、以及standby控制文件

SQL> create pfile=/home/oracle/pfile.ora from spfile;

6.密码文件可以直接用现有的

ls $ORACLE_HOME/dbs/orapw*

7.创建standby控制文件

SQL> alter database create standby controlfile as /home/oracle/controlstd.ctl;

8.主库TNS配置

TEST=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.10)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

TESTBAK=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.13)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TESTBAK)
    )
  )

9.主库备份数据库

RMAN> run {
crosscheck backup ;
crosscheck archivelog all;
crosscheck backupset ;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
backup as compressed backupset full database format /oradata/rman/full_%d_%t_%s_%p plus archivelog format /oradata/rman/arch_%d_%t_%s_%p.bkp;
}

10.备份完毕后将rman备份文件,standby控制文件,密码文件,参数文件一起传到备库

参数文件和standby控制文件放在/home/oracle/目录下

密码文件放在 $ORACLE_HOME/dbs/目录下

 

注:如果目录属主不是 oracle.oinstall或者oracle.dba 需要修改目录权限,文件传完后,检查下文件的用户和组。

 

--备库

1.创建数据库目录,根据自己的参数文件中的参数目录而定

mkdir -p /u01/app/oracle/admin/test/adump
mkdir -p /oradata/rman
mkdir -p /oradata/arch
mkdir -p /oradata/test

2.使用参数文件开启数据库

SQL> startup nomount pfile=/home/oracle/pfile.ora;

3.导入standby控制文件

RMAN> restore controlfile from /home/oracle/controlstd.ctl;

4.恢复数据文件

SQL> alter database mount;
RMAN> catalog start with /oradata/rman/;
RMAN> restore database;

5.恢复归档文件

RMAN> recover database;

6.备库TNS配置

TEST=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.10)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

TESTBAK=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.13)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TESTBAK)
    )
  )

7.创建standby redo log

在使用最大保护模式或是最大可用模式的时候需要在standby数据库创建standby redo log,对于最大性能模式可以不用创建standby redo log
SQL> alter database add standby logfile
group 4 (/oradata/test/std_redo04a.log) size 100m,
group 5 (/oradata/test/std_redo05a.log) size 100m,
group 6 (/oradata/test/std_redo06a.log) size 100m,
group 7 (/oradata/test/std_redo07a.log) size 100m;
SQL> alter database clear logfile group 1;
SQL> alter database clear logfile group 2;
SQL> alter database clear logfile group 3;
添加standby日志文件的规则:
 standby日志最少应该比redo log 多一组。推荐的备重做日志数依赖于主数据库上的线程数。
 (每线程日志文件最大数目 + 1 ) * 线程数
否则standby日志在应用时报如下信息:
RFS[1]: No standby redo logfiles created

RFS[1]: Archived Log: /oradata/arch/1_30_633287861.dbf

在主库添加完standby logfile后,当主库切换为standby角色后会自动使用standby redo logfile,具体应用信息如下:

RFS[1]: Successfully opened standby log 4: /oradata/test/std_redo04a.log

 

 修改主备库参数

主库primary

SQL> alter system set db_unique_name=test scope=spfile;
SQL> alter system set fal_server=testbak sid=*scope=both;
SQL> alter system set fal_client=test sid=* scope=both; 
SQL> alter system set standby_file_management=auto sid=* scope=both;
SQL> alter system set log_archive_config=dg_config=(test,testbak) sid=* scope=both;
SQL> alter system set log_archive_dest_2=service=testbak lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=testbak sid=* scope=both;
SQL> alter system set log_archive_dest_state_2=enable;

 

备库standby

SQL> alter system set db_unique_name=testbak scope=spfile;
SQL> alter system set fal_server=test sid=*scope=both;
SQL> alter system set fal_client=testbak sid=* scope=both; 
SQL> alter system set standby_file_management=auto sid=* scope=both;
SQL> alter system set log_archive_config=dg_config=(test,testbak) sid=* scope=both;
SQL> alter system set log_archive_dest_2=service=test lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=test sid=* scope=both;
SQL> alter system set log_archive_dest_state_2=enable;

 

开启DG(10g不open)

SQL> alter database open;
SQL> alter database recover managed standby database disconnect from session using current logfile;
SQL> select process,client_process,sequence#,status from v$managed_standby;

停用DG

SQL> alter database recover managed standby database cancel;

如果主库传不过来归档,可以通过在主库侧手工修改参数如下:

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=DEFER SCOPE=MEMORY;
SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE SCOPE=MEMORY;

 

至此dg搭建完毕

查询dg延迟

SQL> col value for a20
SQL> col time_computed for a30
SQL> col name for a25
SQL> col unit for a30
SQL> col datum_time for a30
SQL> set line 400
SQL> select * from v$dataguard_stats;

DataGuard部署

标签:current   ima   sed   属性   保护模式   恢复数据文件   switch   sql   add   

原文地址:https://www.cnblogs.com/priestess-zhao/p/8298036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!