oracle 11g dataguard环境搭建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle 11g dataguard环境搭建相关的知识,希望对你有一定的参考价值。

硬件和系统软件说明:

操作系统:Oracle Linux 5.8 64位

oracle软件:oracle 11.2.0.1


角色    主机名  IP地址      数据库  服务名

primary   dg1   192.168.3.55   tong    tong

standby   dg2   192.168.3.56   tong    cheng


一.primary主库操作

1.在primary服务器安装oracle软件,并创建数据库.在standby服务器只安装oracle软件,不创建数据库.


2.配置监听

[[email protected] dbs]$ cd /u01/product/11.2.0.1/db_1/network/admin/

[[email protected] admin]$ vim listener.ora 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = tong)    --primary库的名字

      (ORACLE_HOME = /u01/product/11.2.0.1/db_1)

      (SID_NAME = tong)

    )

  )

LISTENER =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.55)(PORT = 1521))  --prmary库的IP地址

  )

ADR_BASE_LISTENER = /u01

[[email protected] admin]$ vim tnsnames.ora 

tong =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.55)(PORT = 1521)) --primary库的IP地址

    )

    (CONNECT_DATA =

      (SERVICE_NAME = tong)  --primary库的服务名

    )

  )

cheng =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.56)(PORT = 1521)) --standby库的IP地址

    )

    (CONNECT_DATA =

      (SERVICE_NAME = cheng)   --standby库的服务名

    ) 

  )

[[email protected] admin]$  lsnrctl stop

[[email protected] admin]$  lsnrctl start


3.在primary库启用归档和日志强行写入redo文件

SQL> shutdown immediate

SQL> startup mount

SQL> alter database archivelog;

SQL> alter database open;

SQL>  alter database force logging;

SQL>  select force_logging from v$database;


4.在primary 库添加standbt日志文件(standby文件和redo文件大小一至,文件个数比redo多一个)

SQL> alter database add standby logfile group 4 (‘/u01/oradata/tong/sredo04.log‘) size 50m;

SQL> alter database add standby logfile group 4 (‘/u01/oradata/tong/sredo04.log‘) size 50m;

SQL> alter database add standby logfile group 4 (‘/u01/oradata/tong/sredo04.log‘) size 50m;

SQL> alter database add standby logfile group 4 (‘/u01/oradata/tong/sredo04.log‘) size 50m;

SQL> select * from v$logfile order by 1;


5.利用spfile文件内容生成pfile文件

SQL> create pfile from spfile;

SQL> shutdown immediate


6.修改pfile文件的内容

[[email protected] dbs]$ vim inittong.ora 

*.db_name=‘tong‘                       --数据库名

*.db_unique_name=tong            --数据库服务名

*.fal_server=‘tong‘     --primary数据库服务名,是监听文件里面的名字(在standby库名字要和fal_client对调)

*.fal_client=‘cheng‘     --standby数据库服务名,是监听文件里面的名字

*.standby_file_management=auto

*.log_archive_start=true

*.db_file_name_convert=‘/u01/oradata/tong/‘,‘/u01/oradata/tong/‘

*.log_file_name_convert=‘/u01/oradata/tong/‘,‘/u01/oradata/tong/‘

*.log_archive_config=‘dg_config=(tong,cheng)‘ 

*.log_archive_dest_1=‘LOCATION=/u01/oradata/tong/archive valid_for=(all_logfiles,all_roles) db_unique_name=tong‘   --归档文件存放的路径  

*.log_archive_dest_2=‘service=cheng LGWR SYNC AFFIRM valid_for=(online_logfiles,all_roles) db_unique_name=cheng‘   --cheng是standby库的服务名

*.log_archive_dest_state_1=‘ENABLE‘

*.log_archive_dest_state_2=‘ENABLE‘

[[email protected] dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 9 11:56:26 2016

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

Connected to an idle instance.

SQL> create spfile from pfile;         --用pfile文件创建spfile文件  
SQL> 


7.启动主库

[[email protected] dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 9 11:56:26 2016

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

Connected to an idle instance.

SQL> startup

ORACLE instancestarted

SQL> alterdatabase set standby database to maximize availability;

Databasealtered.

SQL> exit


8.备份数据库(备份文件在闪恢复区)

[[email protected] dbs]$ rman target /

RMAN> backup database plus archivelog;

RMAN> backup curent controlfile for standby;


9.考贝文件到standby服务器

[[email protected] dbs]$ cd /u01/flash_recovery_area/     --考贝闪回恢复区的备份文件

[[email protected] flash_recovery_area]$ scp *  [email protected];/u01/flash_recovery_area/ 

[[email protected] flash_recovery_area]$ cd /u01/product/11.2.0.1/db_1/dbs/

[[email protected] dbs]$ scp *.ora   [email protected]:/u01/product/11.2.0.1/db_1/dbs/  --考贝pfile和spfile参数文件

[[email protected] dbs]$ cd /u01/product/11.2.0.1/db_1/network/admin/   

[[email protected] admin]$ scp listener.ora tnsnames.ora [email protected]:/u01/product/11.2.0.1/db_1/network/admin/   --考贝监听文件

[[email protected] admin]$


二.standby从库操作

10.修改监听的地址

[[email protected] ~]$ cd /u01/product/11.2.0.1/db_1/network/admin/

[[email protected] admin]$ vim listener.ora 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = cheng)

      (ORACLE_HOME = /u01/product/11.2.0.1/db_1)

      (SID_NAME = cheng)

    )

  )

LISTENER =

  (DESCRIPTION =

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

  )

ADR_BASE_LISTENER = /u01

[[email protected] admin]$ vim tnsnames.ora 

tong =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = tong)

    )

  )

cheng =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = cheng)

    )

  )

[[email protected] admin]$  lsnrctl stop

[[email protected] admin]$  lsnrctl start


11.修改pfile和spfile文件名

[[email protected] admin]$ cd /u01/product/11.2.0.1/db_1/dbs/

[[email protected] dbs]$ mv inittong.ora  initcheng.ora     --修改pfile文件名

[[email protected] ~]$ cp  /u01/flash_recovery_area/tong/control02.ctl /u01/oradata/tong/control01.ctl   --新的控制文件替换旧控制文件


12.恢复数据库

[[email protected] ~]$  rman target sys/[email protected]  auxiliary /

RMAN> duplicate target database for standbynofilenamecheck;


13.修改pfile参数文件

SQL> shutdown immediate

[[email protected] dbs]$ cd /u01/product/11.2.0.1/db_1/dbs/

[[email protected] dbs]$ vim initcheng.ora 

*.db_name=‘tong‘

*.db_recovery_file_dest=‘/u01/flash_recovery_area‘

*.db_recovery_file_dest_size=4070572032

*.diagnostic_dest=‘/u01‘

*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=tongXDB)‘

*.log_archive_format=‘%t_%s_%r.dbf‘

*.memory_target=833617920

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile=‘EXCLUSIVE‘

*.undo_tablespace=‘UNDOTBS1‘

*.db_unique_name=cheng

*.fal_server=‘tong

*.fal_client=‘cheng

*.standby_file_management=auto

*.db_file_name_convert=‘/u01/oradata/tong/‘,‘/u01/oradata/tong/‘

*.log_file_name_convert=‘/u01/oradata/tong/‘,‘/u01/oradata/tong/‘

*.log_archive_config=‘dg_config=(tong,cheng)‘

*.log_archive_dest_1=‘LOCATION=/u01/oradata/tong/archive valid_for=(all_logfiles,all_roles) db_unique_name=cheng‘

*.log_archive_dest_2=‘service=cheng LGWR SYNC AFFIRM valid_for=(online_logfiles,all_roles) db_unique_name=cheng‘

*.log_archive_dest_state_1=‘ENABLE‘

*.log_archive_dest_state_2=‘ENABLE‘

[[email protected] dbs]$


14.启动standby库

SQL> startupnomount;

SQL> alterdatabase mount standby database;

SQL> alterdatabase add standby logfile;

SQL> alterdatabase recover managed standby database using current logfile disconnect fromsession; 


15.检查standby的日志

[[email protected] dbs]$ tailf  /u01/diag/rdbms/cheng/cheng/trace/alert_cheng.log 

Tue Nov 08 22:47:42 2016

SMON: enabling cache recovery

Tue Nov 08 22:47:43 2016

Dictionary check beginning

Dictionary check complete

Database Characterset is AL32UTF8

No Resource Manager plan active

replication_dependency_tracking turned off (no async multimaster replication found)

Physical standby database opened for read only access.

Completed: alter database open read only


本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1871023

以上是关于oracle 11g dataguard环境搭建的主要内容,如果未能解决你的问题,请参考以下文章

搭建Oracle 11G单实例Active DataGuard

Oracle11g搭建DataGuard及主备切换方法总结亲测可用

ORACLE 11G 搭建dataguard详细步骤(所有操作总结)

oracle 11g dataguard之dgmgrl

Oracle 11g DataGuard搭建 - 单节点到单节点

手把手教你搭建Oracle 11G dataguard