主库不停的情况下联机创建active dataguard

 

目标:在主库不停机的情况下搭建active standby  数据库

环境说明:
数据库版本:Release 11.2.0.4.0
操作系统  :Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Primary db_unique_name : hjprddb1 
standby db_unique_name : hjprddb2

解决方案
1.对主数据库进行必要的更改。
a. 启用 force logging。
b. 如果没有密码文件,则创建密码文件。
c. 创建备用 redo 日志。
d. 修改参数文件,使其适用于 Dataguard。
2. 确保 sql*net 连接正常。
3. 使用主数据库活动文件,通过网络创建备用数据库。
a. 创建密码文件
b. 为备用数据库(辅助数据库)创建初始化参数文件
c. 为数据库文件创建需要的装载点或文件夹
d. 连接至主数据库作为其目标数据库,以运行创建备用 ON STANDBY。
DUPLICATE TARGET DATABASE
 FOR STANDBY
 FROM ACTIVE DATABASE
 SPFILE
    PARAMETER_VALUE_CONVERT '', ''
    SET DB_FILE_NAME_CONVERT '', ''
    SET LOG_FILE_NAME_CONVERT '', ''
    SET SGA_MAX_SIZE 200M
    SET SGA_TARGET 125M;
 4. 检查日志传送和应用。
 
 操作过程:
 1. 为生产数据库成为主数据库做准备

a. 确保数据库是 archivelog 模式。

SQL> select log_mode from v$database;

 LOG_MODE
 ------------
 ARCHIVELOG
 
 b. 启用 force logging

 SQL> ALTER DATABASE FORCE LOGGING;
 c. 创建备用 redo 日志

SQL> alter database add standby logfile '' size ;
SQL> alter database add standby logfile thread 1 group 4 ('/opt/app/oracle/hjprddb1/redo01_a.log') size 50m ;

Database altered.

SQL> alter database add standby logfile thread 1 group 5 ('/opt/app/oracle/hjprddb1/redo02_a.log') size 50m ;

Database altered.

SQL> alter database add standby logfile thread 1 group 6 ('/opt/app/oracle/hjprddb1/redo03_a.log') size 50m ;

Database altered.


d. 修改主要初始化参数,使其适用于主数据库的 dataguard

SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(hjprddb1,hjprddb2)';

System altered.

SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/opt/app/oracle/hjprddb1 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=hjprddb1';

System altered.

SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=hjprddb2 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=hjprddb2';

System altered.

SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;

System altered.

SQL> alter system set FAL_SERVER=hjprddb2;

System altered.

SQL> alter system set FAL_CLIENT=hjprddb1;

System altered.

SQL> alter system set DB_FILE_NAME_CONVERT='/opt/app/oracle/hjprddb2','/opt/app/oracle/hjprddb1' scope=spfile;

System altered.

SQL> alter system set LOG_FILE_NAME_CONVERT='/opt/app/oracle/hjprddb2','/opt/app/oracle/hjprddb1' scope=spfile;

System altered.

 2. 确保 sql*net 连接正常。
 在备库的 listener.ora 文件中插入 hjprddb2 的静态条目。

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST =hjprddb2.com.cn )(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /opt/app/oracle

ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON              # line added by Agent

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (GLOBAL_DBNAME = hjprddb2.com.cn )
     (ORACLE_HOME = /opt/app/oracle/product/10.2.0/db_1 )
     (SID_NAME = hjprddb2)
    )
   )


主库和备库的 TNSNAMES.ORA 应该有两个条目
hjprddb1=
          (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.236.128)(PORT = 1521))
    )
    (CONNECT_DATA =
      (service_name =hjprddb1)
    )
  )

hjprddb2=
           (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.236.129)(PORT = 1521))
    )
    (CONNECT_DATA =
      (service_name = hjprddb2.com.cn )
    )
  )

在主数据库和备用数据库中使用以下命令,检查 SQL*Net 配置
% tnsping hjprddb1
 % tnsping hjprddb2
 
 3. 创建备用数据库

a. 从主数据库 $ORACLE_HOME/dbs 中复制密码文件,并将其重命名为备用数据库名称。

 用户名必须为 SYS 且主数据库和备用数据库的密码需相同。
 此处的最佳做法是按照建议复制密码文件。
 密码文件名称必须和备用站点上使用的实例名称/SID 匹配,而非 DB_NAME。

b. 仅用一个参数 DB_NAME 创建初始化参数。

DB_NAME=chicago
 DB_UNIQUE_NAME=boston
 DB_BLOCK_SIZE=

 c. 在备库创建需要的目录以放置 $ADR_HOME 中的数据文件和跟踪文件。

d. 将环境变量 ORACLE_SID 设置为备用服务并启动备用实例。

% export ORACLE_SID=boston
 % sqlplus "/ as sysdba"
     SQL> startup nomount pfile=$ORACLE_HOME/dbs/initcore1.ora注意:使用 PFILE 或 SPFILE
 # 附加注释
# 如果使用了 DUPLICATE without TARGET connection,则不能使用 SPFILE
 # 否则将得到以下错误消息

RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause

 e. 验证“AS SYSDBA”连接正在运行

% sqlplus /nolog
 SQL> connect sys/          connect sys/@chicago AS SYSDBA
 f. 在主系统上执行RMAN 并连接主数据库和辅助数据库(即备用数据库)
 [oracle@hjprddb1 ~]$ rman target sys/oracle@hjprddb1 auxiliary sys/oracle@hjprddb2

Recovery Manager: Release 11.2.0.4.0 - Production on Sat Dec 28 22:34:31 2013

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

connected to target database: HJPRDDB1 (DBID=3777025748)
connected to auxiliary database: HJPRDDB2 (not mounted)

RMAN> run {
2>  allocate channel prmy1 type disk;
3>  allocate channel prmy2 type disk;
4>  allocate channel prmy3 type disk;
5>  allocate channel prmy4 type disk;
6>  allocate auxiliary channel stby type disk;
7>
8>  duplicate target database for standby from active database spfile
9>    parameter_value_convert 'hjprddb1','hjprddb2'
10>    set db_unique_name='hjprddb2'
11>    set db_file_name_convert='/hjprddb1/','/hjprddb2/'
12>    set log_file_name_convert='/hjprddb1/','/hjprddb2/'
13>    set control_files='/opt/app/oracle/hjprddb2/control01.ctl'    ---该路径为备库上控制文件的存放路径
14>    set log_archive_max_processes='5'
15>    set fal_client='hjprddb2'
16>    set fal_server='hjprddb1'
17>    set standby_file_management='AUTO'
18>    set log_archive_config='dg_config=(hjprddb1,hjprddb2)'
19>    set log_archive_dest_2='service=hjprddb1 ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=hjprddb1' ;
20>  }

using target database control file instead of recovery catalog
allocated channel: prmy1
channel prmy1: SID=1 device type=DISK

allocated channel: prmy2
channel prmy2: SID=47 device type=DISK

allocated channel: prmy3
channel prmy3: SID=32 device type=DISK

allocated channel: prmy4
channel prmy4: SID=43 device type=DISK

allocated channel: stby
channel stby: SID=20 device type=DISK

Starting Duplicate Db at 28-DEC-13

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/opt/app/oracle/product/11.2.0/db_1/dbs/orapwhjprddb1' auxiliary format
 '/opt/app/oracle/product/10.2.0/db_1/dbs/orapwhjprddb2'   targetfile
 '/opt/app/oracle/product/11.2.0/db_1/dbs/spfilehjprddb1.ora' auxiliary format
 '/opt/app/oracle/product/10.2.0/db_1/dbs/spfilehjprddb2.ora'   ;
   sql clone "alter system set spfile= ''/opt/app/oracle/product/10.2.0/db_1/dbs/spfilehjprddb2.ora''";
}
executing Memory Script

Starting backup at 28-DEC-13
Finished backup at 28-DEC-13

sql statement: alter system set spfile= ''/opt/app/oracle/product/10.2.0/db_1/dbs/spfilehjprddb2.ora''

contents of Memory Script:
{
   sql clone "alter system set  audit_file_dest =
 ''/opt/app/oracle/admin/hjprddb2/adump'' comment=
 '''' scope=spfile";
   sql clone "alter system set  dispatchers =
 ''(PROTOCOL=TCP) (SERVICE=hjprddb2XDB)'' comment=
 '''' scope=spfile";
   sql clone "alter system set  log_archive_dest_1 =
 ''LOCATION=/opt/app/oracle/hjprddb2 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=hjprddb1'' comment=
 '''' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''hjprddb2'' comment=
 '''' scope=spfile";
   sql clone "alter system set  db_file_name_convert =
 ''/hjprddb1/'', ''/hjprddb2/'' comment=
 '''' scope=spfile";
   sql clone "alter system set  log_file_name_convert =
 ''/hjprddb1/'', ''/hjprddb2/'' comment=
 '''' scope=spfile";
   sql clone "alter system set  control_files =
 ''/opt/app/oracle/hjprddb2/control01.ctl'' comment=
 '''' scope=spfile";
   sql clone "alter system set  log_archive_max_processes =
 5 comment=
 '''' scope=spfile";
   sql clone "alter system set  fal_client =
 ''hjprddb2'' comment=
 '''' scope=spfile";
   sql clone "alter system set  fal_server =
 ''hjprddb1'' comment=
 '''' scope=spfile";
   sql clone "alter system set  standby_file_management =
 ''AUTO'' comment=
 '''' scope=spfile";
   sql clone "alter system set  log_archive_config =
 ''dg_config=(hjprddb1,hjprddb2)'' comment=
 '''' scope=spfile";
   sql clone "alter system set  log_archive_dest_2 =
 ''service=hjprddb1 ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=hjprddb1'' comment=
 '''' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  audit_file_dest =  ''/opt/app/oracle/admin/hjprddb2/adump'' comment= '''' scope=spfile

sql statement: alter system set  dispatchers =  ''(PROTOCOL=TCP) (SERVICE=hjprddb2XDB)'' comment= '''' scope=spfile

sql statement: alter system set  log_archive_dest_1 =  ''LOCATION=/opt/app/oracle/hjprddb2 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=hjprddb1'' comment= '''' scope=spfile

sql statement: alter system set  db_unique_name =  ''hjprddb2'' comment= '''' scope=spfile

sql statement: alter system set  db_file_name_convert =  ''/hjprddb1/'', ''/hjprddb2/'' comment= '''' scope=spfile

sql statement: alter system set  log_file_name_convert =  ''/hjprddb1/'', ''/hjprddb2/'' comment= '''' scope=spfile

sql statement: alter system set  control_files =  ''/opt/app/oracle/hjprddb2/control01.ctl'' comment= '''' scope=spfile

sql statement: alter system set  log_archive_max_processes =  5 comment= '''' scope=spfile

sql statement: alter system set  fal_client =  ''hjprddb2'' comment= '''' scope=spfile

sql statement: alter system set  fal_server =  ''hjprddb1'' comment= '''' scope=spfile

sql statement: alter system set  standby_file_management =  ''AUTO'' comment= '''' scope=spfile

sql statement: alter system set  log_archive_config =  ''dg_config=(hjprddb1,hjprddb2)'' comment= '''' scope=spfile

sql statement: alter system set  log_archive_dest_2 =  ''service=hjprddb1 ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=hjprddb1'' comment= '''' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     551165952 bytes

Fixed Size                     2255112 bytes
Variable Size                436209400 bytes
Database Buffers             109051904 bytes
Redo Buffers                   3649536 bytes
allocated channel: stby
channel stby: SID=18 device type=DISK

contents of Memory Script:
{
   backup as copy current controlfile for standby auxiliary format  '/opt/app/oracle/hjprddb2/control01.ctl';
}
executing Memory Script

Starting backup at 28-DEC-13
channel prmy1: starting datafile copy
copying standby control file
output file name=/opt/app/oracle/product/11.2.0/db_1/dbs/snapcf_hjprddb1.f tag=TAG20131228T223457 RECID=1 STAMP=835396499
channel prmy1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 28-DEC-13

contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:
{
   set newname for tempfile  1 to
 "/opt/app/oracle/hjprddb2/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/opt/app/oracle/hjprddb2/system01.dbf";
   set newname for datafile  2 to
 "/opt/app/oracle/hjprddb2/sysaux01.dbf";
   set newname for datafile  3 to
 "/opt/app/oracle/hjprddb2/undotbs01.dbf";
   set newname for datafile  4 to
 "/opt/app/oracle/hjprddb2/users01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format
 "/opt/app/oracle/hjprddb2/system01.dbf"   datafile
 2 auxiliary format
 "/opt/app/oracle/hjprddb2/sysaux01.dbf"   datafile
 3 auxiliary format
 "/opt/app/oracle/hjprddb2/undotbs01.dbf"   datafile
 4 auxiliary format
 "/opt/app/oracle/hjprddb2/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /opt/app/oracle/hjprddb2/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 28-DEC-13
channel prmy1: starting datafile copy
input datafile file number=00001 name=/opt/app/oracle/hjprddb1/system01.dbf
channel prmy2: starting datafile copy
input datafile file number=00002 name=/opt/app/oracle/hjprddb1/sysaux01.dbf
channel prmy3: starting datafile copy
input datafile file number=00003 name=/opt/app/oracle/hjprddb1/undotbs01.dbf
channel prmy4: starting datafile copy
input datafile file number=00004 name=/opt/app/oracle/hjprddb1/users01.dbf
output file name=/opt/app/oracle/hjprddb2/users01.dbf tag=TAG20131228T223511
channel prmy4: datafile copy complete, elapsed time: 00:00:19
output file name=/opt/app/oracle/hjprddb2/undotbs01.dbf tag=TAG20131228T223511
channel prmy3: datafile copy complete, elapsed time: 00:07:46
output file name=/opt/app/oracle/hjprddb2/sysaux01.dbf tag=TAG20131228T223511
channel prmy2: datafile copy complete, elapsed time: 00:13:56
output file name=/opt/app/oracle/hjprddb2/system01.dbf tag=TAG20131228T223511
channel prmy1: datafile copy complete, elapsed time: 00:14:26
Finished backup at 28-DEC-13

sql statement: alter system archive log current

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=835397373 file name=/opt/app/oracle/hjprddb2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=835397373 file name=/opt/app/oracle/hjprddb2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=835397373 file name=/opt/app/oracle/hjprddb2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=835397373 file name=/opt/app/oracle/hjprddb2/users01.dbf
Finished Duplicate Db at 28-DEC-13
released channel: prmy1
released channel: prmy2
released channel: prmy3
released channel: prmy4
released channel: stby

RMAN> exit

4. 现在连接备用数据库 sqlplus 并启动 MRP(管理恢复进程)。比较主数据库的最新序列和 MRP(管理恢复进程)的应用序列。

 示例:

SQL> alter database recover managed standby database disconnect from session;
 5. 如果您是购买了ADG 许可证的客户可以用只读模式打开 DB 并启动恢复。

SQL> alter database recover managed standby database cancel;
 SQL> alter database open;
 SQL> alter database recover managed standby database disconnect;
 
 

参考metalink文档 ID 1526160.1)

你可能感兴趣的:(Oracle)