oracle 10g dataguard物理standby配置 (数据文件以文件系统存储)

最近客户想给生产库搭建dataguard,oracle版本主要是10gR2版本,可能小版本有所不同。

数据库文件有的采用aix 的文件系统存储,有的则是使用的裸设备,所以分别在文件系统和裸设备上测试了一番,搭建起来差不多,裸设备的情况就是需要事先在备库上建好对应的裸设备文件。

下面记录了我在文件系统上搭建dataguard的过程,跟操作系统关系不大,aix,linux都通用

1.主库上 database force logging
alter database force logging;

2.如果主库是非归档模式,需要开启归档

3.创建主库口令文件
orapwd file='/oracle/dg_backup/orapwdevdb' password=oracle entries=5

4.修改主库参数:
alter system set log_archive_config='dg_config=(devdb,devdb_dg)'  scope=both;

alter system set log_archive_dest_1='LOCATION=/oracle/oradata/devdb/archive 
valid_for=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=devdb' scope=both;

alter system set LOG_ARCHIVE_DEST_2='SERVICE=devdb_dg LGWR ASYNC 
valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=devdb_dg' 
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 remote_login_passwordfile=EXCLUSIVE scope=both;

alter system set fal_server='devdb_dg' scope=both;
alter system set fal_client='devdb' scope=both;
alter system set standby_file_management='auto' scope=both;

5.给主库添加standby log,如果使用裸设备的话,需要先创建裸设备文件,大小要和redo日志一样

SQL> alter database add standby logfile group 4 '/oracle/oradata/devdb/standby_redo04.log' size 50m;
SQL> alter database add standby logfile group 5 '/oracle/oradata/devdb/standby_redo05.log' size 50m;
SQL> alter database add standby logfile group 6 '/oracle/oradata/devdb/standby_redo06.log' size 50m;
SQL> alter database add standby logfile group 7 '/oracle/oradata/devdb/standby_redo07.log' size 50m;

6.创建主库pfile文件,放到/u01/oracle/dg_backup目录下,该目录用来存放备份文件,统一传输到备库上

create pfile='/oracle/dg_backup/initdevdb.ora' from spfile;

7.配置监听文件和tnsnames文件

[oracle@Redhat admin]$ cat listener.ora
测试通过的:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = devdb)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = orcl)
    )
   )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = rac1)(PORT = 1521))
    )
  )

[oracle@Redhat admin]$ cat tnsnames.ora

devdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.95.250)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = devdb)
    )
  )

devdb_dg=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.95.251)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = devdb)
    )
  )

8.生成数据库备份 

 RMAN> backup database format='/oracle/dg_backup/%d_%s.dbf' plus archivelog;   

建立备用库的控制文件  
SQL> alter database create standby controlfile as '/oracle/dg_backup/standby_ctl01.ctl'; 

9.将dg_backup目录下的备份文件传送到备库上的dg_backup目录下
 Cd  /oracle/dg_backup
Scp * 192.168.95.251:/oracle/dg_backup/

10.修改备库参数文件
*.DB_UNIQUE_NAME='devdb_dg'
*.log_archive_config='DG_CONFIG=(devdb,devdb_dg)'
*.log_archive_dest_1='location=/oracle/oradata/devdb/archive/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=devdb_dg'
*.log_archive_dest_2='SERVICE=devdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=devdb'
*.STANDBY_FILE_MANAGEMENT=AUTO
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER='devdb'
*.FAL_CLIENT='devdb_dg'

11.配置监听和tnsnames文件,启动监听,验证主备库间的连通性,tnsping
将主库的listener.ora和tnsnames.ora拷贝过来即可

12.将oracle 口令文件放到dbs下面

13. 恢复数据库
使用修改过的pfile,创建spfile 启动数据库到nomount状态,使用rman进行恢复数据库
Create spfile from pfile='/oracle/dg_backup/initdevdb.ora';
Startup nomount

alter database mount standby database ;

rman target /
restore database;

--恢复数据库  ----sqlplus 
recover managed standby database disconnect from session;

alter database recover managed standby database cancel;

alter database recover managed standby database disconnect from session; 

在主库上执行次日志切换,查看备库上归档日志是否接收到,一切正常的话,环境就搭建成功了,细节问题需要自己慢慢推敲了。
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------


---停掉redo应用
alter database recover managed standby database cancel;

----更改到最大可用模式
alter system set LOG_ARCHIVE_DEST_2='SERVICE=devdb_dg LGWR SYNC AFFIRM
valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=devdb_dg' 
scope=both;

alter database set standby database to maximize availability;  ---最大保护:protection   最大性能:PERFORMANCE

alter database set standby database to maximize performance;

alter database set standby database to maximize protection;

---查看保护模式(主库执行)

select protection_mode ,protection_level from v$database;

---查看是否存在缺失的日志文件,做fail over的时候,可以将缺失的文件拷贝到备库上,
select * from v$archive_gap
alter database register physical standby '/u01/oracle/oradata/devdb/archive/xxx.dbf';
alter database recover managed standby database cancel ;
alter database recover managed standby database finish (force);

----查看日志传送方式是归档进程arch,还是日志读写进程lgwr
SQL> select dest_name,archiver from v$archive_dest;

---在备库上查看是否应用日志进行恢复

select process,status from v$managed_standby;

---查看switchoverzhuangt

select open_mode,database_role,switchover_status from v$database;

---打开到实时应用状态
alter database recover managed standby database using current logfile disconnect; --开启实时应用


你可能感兴趣的:(oracle 10g dataguard物理standby配置 (数据文件以文件系统存储))