[terry笔记]11gR2_DataGuard搭建_primary零停机

11gR2搭建dataguard环境,此篇文章是利用rman搭建dataguard,这样的好处是primary不用停机,当然,前提条件是primary已经开启归档。

相对于可以停机,零停机传送数据文件的方式,不能冷备然后拷贝数据文件,只能利用rman技术备份,并恢复至standby中,当然rman备份恢复我只用了最简单的一种,一条命令备份,两条命令恢复。

可以参考拷贝数据文件方式:http://www.cnblogs.com/kkterry/p/3819322.html

主备切换、模式调整等实验会在以后更新。

 

环境信息介绍:

primary(正在运行,已经开启归档,可正常交易): OS:OEL6.4

database:11.2.0.4.0

hostname:node4

192.168.100.131

ORACLE_SID=good

ORACLE_HOME=/u01/product/11.2.0

db_unique_name=good



standby(装好database软件): OS:OEL6.4

database:11.2.0.4.0

hostname:node5

192.168.100.132

ORACLE_SID=good

ORACLE_HOME=/u01/product/11.2.0

db_unique_name=bad



两边oracle用户的环境变量: export ORACLE_BASE=/u01

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0

export ORACLE_SID=good

export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

alias s='sqlplus / as sysdba'

 

1.  primary已经处于归档状态(归档目录/u01/arch),然后打开force logging:

SQL> archive log list

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            /u01/arch

Oldest online log sequence     24

Next log sequence to archive   26

Current log sequence           26

alter database force logging;

 

2. 配置listener与tnsnames,然后传至standby

(primary可以是动态监听,但是standby需要静态监听,因为动态监听需要数据库启动至mount状态才能监听得到。standby目前只有软件,没有实例,所以动态监听无法向外提供服务,以至于primary无法连接至standby的库,导致无法测试连通性,并向向standby传递归档)

listner.ora:

# listener.ora Network Configuration File: /u01/product/11.2.0/network/admin/listener.ora



# Generated by Oracle configuration tools.



SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = PLSExtProc)

        (ORACLE_HOME = /u01/product/11.2.0)

          (PROGRAM = extproc)

    )

    (SID_DESC =

      (GLOBAL_DBNAME = good)

        (ORACLE_HOME = /u01/product/11.2.0)

      (SID_NAME = good)

  )

)

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

    )

  )



ADR_BASE_LISTENER = /u01

 tnsnames.ora:

# tnsnames.ora Network Configuration File: /u01/product/11.2.0/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

GOOD =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.131)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = good)

    )

  )

 

BAD =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.132)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = good)

    )

  )

 

3.两边打开监听

lsnrctl start

此时可以测试两边是否连通

sqlplus sys/xxx@good as sysdba

sqlplus sys/xxx@bad as sysdba

 

4.配置primary参数,并添加standby logfile,以用来将来主备切换,standby logfile要比redo多一个组

此时的primary参数文件,里面没有相关dg的参数。 

good.__db_cache_size=205520896

good.__java_pool_size=4194304

good.__large_pool_size=8388608

good.__oracle_base='/u01'#ORACLE_BASE set from environment

good.__pga_aggregate_target=209715200

good.__sga_target=343932928

good.__shared_io_pool_size=0

good.__shared_pool_size=113246208

good.__streams_pool_size=0

*.audit_file_dest='/u01/admin/good/adump'

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='/u01/oradata/good/control01.ctl','/u01/fast_recovery_area/good/control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='good'

*.db_recovery_file_dest='/u01/fast_recovery_area'

*.db_recovery_file_dest_size=4385144832

*.diagnostic_dest='/u01'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=goodXDB)'

*.memory_target=550502400

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.undo_tablespace='UNDOTBS1'

*.log_archive_dest_1='location=/u01/arch'

 

运行如下命令:具体参数含义在文章最后的附录表中,也可以查询官方文档,解释的更详细。

(不用设置primary的db_unique_name,默认就有)



alter system set log_archive_config= 'DG_CONFIG=(good,bad)';



alter system set log_archive_dest_1= 'LOCATION=/u01/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=good';



alter system set log_archive_dest_2= 'SERVICE=bad LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=bad';



alter system set log_archive_dest_state_1 = enable;



alter system set log_archive_dest_state_2 = enable;



alter system set fal_server=bad;



alter system set fal_client=good;



alter system set standby_file_management=AUTO;

添加standby redo: 

alter database add standby logfile

group 4 ('/u01/oradata/good/standby04.log')size 50m,

group 5 ('/u01/oradata/good/standby05.log')size 50m,

group 6 ('/u01/oradata/good/standby06.log')size 50m,

group 7 ('/u01/oradata/good/standby07.log')size 50m;

 

5.创建standby controlfile、pfile

alter database create standby controlfile as '/u01/control01.ctl';



create pfile from spfile;

 

6.利用rman备份primary,做全备即可

rman target /



backup database format '/u01/backup/full_%U'; 

 

7.把相关文件从primary传递至standby

监听文件:listener.ora、tnsnames.ora --$ORACLE_HOME/network/admin(在之前已经传过去了)



参数文件:initgood.ora  --$ORACLE_HOME/dbs



密码文件:orapwgood  --$ORACLE_HOME/dbs



sty控制文件:control01.ctl  --$ORACLE_BASE/oradata/good



日志目录(或直接创建文件夹):$ORACLE_BASE/admin、$ORACLE_BASE/diag、$ORACLE_BASE/flash_recovery_area  --$ORACLE_BASE



备份文件:/u01/backup/* --/u01/backup/

 

8.修改standby参数文件,重点注意蓝色的参数,绿色是重点要修改的。

good.__db_cache_size=222298112

good.__java_pool_size=4194304

good.__large_pool_size=8388608

good.__oracle_base='/u01'#ORACLE_BASE set from environment

good.__pga_aggregate_target=192937984

good.__sga_target=360710144

good.__shared_io_pool_size=0

good.__shared_pool_size=113246208

good.__streams_pool_size=0

*.audit_file_dest='/u01/admin/good/adump'

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='/u01/oradata/good/control01.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='good'

*.db_recovery_file_dest='/u01/fast_recovery_area'

*.db_recovery_file_dest_size=4385144832

*.db_unique_name='bad'

*.diagnostic_dest='/u01'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=goodXDB)'

*.fal_client='bad'

*.fal_server='good‘

*.log_archive_config='dg_config=(good,bad)'

*.log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=bad'

*.log_archive_dest_2='service=good lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=good'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='ENABLE'

*.memory_target=550502400

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.standby_file_management='AUTO'

*.undo_tablespace='UNDOTBS1'

 

9.standby启动至mount,然后rman恢复

SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 2 20:32:36 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.



SQL> startup nomount

ORACLE instance started.



Total System Global Area  551165952 bytes

Fixed Size                  2255112 bytes

Variable Size             385877752 bytes

Database Buffers          155189248 bytes

Redo Buffers                7843840 bytes



SQL> alter database mount;

Database altered.

 

SQL> exit

 

[oracle@node5 dbs]$ rman target /



Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jul 2 20:33:57 2014

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

connected to target database: GOOD (DBID=1820366808, not open)



RMAN> catalog start with '/u01/backup/';



Starting implicit crosscheck backup at 02-JUL-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=14 device type=DISK

Crosschecked 2 objects

Finished implicit crosscheck backup at 02-JUL-14



Starting implicit crosscheck copy at 02-JUL-14

using channel ORA_DISK_1

Crosschecked 2 objects

Finished implicit crosscheck copy at 02-JUL-14



searching for all files in the recovery area

cataloging files...

no files cataloged



searching for all files that match the pattern /u01/backup/



List of Files Unknown to the Database

=====================================

File Name: /u01/backup/full_03pcdktt_1_1

File Name: /u01/backup/full_04pcdkvl_1_1



Do you really want to catalog the above files (enter YES or NO)? yes



cataloging files...

cataloging done



List of Cataloged Files

=======================

File Name: /u01/backup/full_03pcdktt_1_1

File Name: /u01/backup/full_04pcdkvl_1_1



RMAN> restore database;



Starting restore at 02-JUL-14

using channel ORA_DISK_1



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 00001 to /u01/oradata/good/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/oradata/good/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/oradata/good/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/oradata/good/users01.dbf

channel ORA_DISK_1: reading from backup piece /u01/backup/full_03pcdktt_1_1

channel ORA_DISK_1: piece handle=/u01/backup/full_03pcdktt_1_1 tag=TAG20140702T202533

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:45

Finished restore at 02-JUL-14

 

此时standby的/u01/arch会出现归档。

可以在primary进行alter system switch logfile测试,归档必须同时出现在两端,这点很重要,不然standby无法进行恢复。

 

10.standby应用日志

alter database recover managed standby database using current logfile disconnect from session;

 

11.验证

观察primary与standby的/u01/arch

primary:alter system switch logfile;

SELECT STATUS,DESTINATION, ERROR FROM V$ARCHIVE_DEST;

select sequence#,status from v$archived_log;--主备一致

 

14.standby可以选择是否启动read only with apply

如果启动可以在standby库进行查询,同时从primary日志恢复(此为11g特性,10g如果read only打开standby库,不可以同时恢复)

alter database recover managed standby database cancel;



alter database open;



alter database recover managed standby database using current logfile disconnect from session;



select open_mode from v$database;

到这里可以算是完成了,可以正常登录主库、备库进行数据查询。 

 

15.此时会发现一个现象,v$logfile中的文件可以查询得到,但是文件并不存在,这种情况可以忽略,主备互转的时候会自动创建。

SQL> col member for a30

SQL> select * from v$logfile;



    GROUP# STATUS  TYPE    MEMBER                         IS_

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

         3         ONLINE  /u01/oradata/good/redo03.log   NO

         2         ONLINE  /u01/oradata/good/redo02.log   NO

         1         ONLINE  /u01/oradata/good/redo01.log   NO

         4         STANDBY /u01/oradata/good/redo04.log   NO

         5         STANDBY /u01/oradata/good/redo05.log   NO

         6         STANDBY /u01/oradata/good/redo06.log   NO

         7         STANDBY /u01/oradata/good/redo07.log   NO



7 rows selected.

 

 参数附录:

角色

参数名称

介绍

Pri

DB_NAME

数据库名称,primary端和standby端必须相同

DB_UNIQUE_NAME

指定唯一名称,区别primary端和 standby端

LOG_ARCHIVE_CONFIG

指定DG的全局日志配置,包含所有数据库的名称,及归档路径

CONTROL_FILES

控制文件路径及名称

LOG_ARCHIVE_DEST_n

指定主备库的归档路径

LOG_ARCHIVE_DEST_STATE_n

配置是否允许通过redo进行日志传输及路径

REMOTE_LOGIN_PASSWORDFILE

配置远程登陆模式,是否独享还是共享

LOG_ARCHIVE_FORMAT

配置归档日志文件存储格式规范

LOG_ARCHIVE_MAX_PROCESS=integer

配置归档进程数量,默认为4

FAL_SERVER

配置服务器角色

DB_FILE_NAME_CONVERT

配置数据库数据文件转换,用在主备库数据文件路径不一致

LOG_FILE_NAME_CONVERT

配置数据库redo日志文件转换,用在主备库redo日志文件路径不一致

STANDBY_FILE_MANAGEMENT

配置备库是否同步主库的表空间添加或数据文件添加。

st

DB_UNIQUE_NAME

指定唯一名称,区别pri 端和 sty端

CONTROL_FILES

控制文件路径及名称

DB_FILE_NAME_CONVERT

配置数据库数据文件转换,用在主备库数据文件路径不一致

LOG_FILE_NAME_CONVERT

配置数据库数据文件转换,用在主备库数据文件路径不一致

LOG_ARCHIVE_DEST_n

指定主备库的归档路径

FAL_SERVER

配置服务器角色

 

你可能感兴趣的:(dataguard)