热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

利用rman搭建OracleDataGuard环境

DataGuard环境:操作系统:RedHat5.6Primary数据库:IP地址:192.168.48.131数据库SID:orclDB_UNIQUE_NAME:orcl_pdStandb

Data Guard 环境:操作系统: RedHat 5.6 Primary数据库:IP地址:192.168.48.131数据库SID:orclDB_UNIQUE_NAME:orcl_pdStandb

Data Guard 环境:
操作系统: RedHat 5.6
Primary数据库:
IP地址:192.168.48.131
数据库SID:orcl
DB_UNIQUE_NAME:orcl_pd

Standby数据库:
IP地址:192.168.48.132
数据库SID:orcl
DB_UNIQUE_NAME:orcl_st




1.主库设置成force logging 模式
SQL> alter database force logging;


Database altered.


2.主库设为归档模式
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/Oracle/product/dbs/arch
Oldest online log sequence 4
Current log sequence 6
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.


Total System Global Area 1653518336 bytes
Fixed Size 2228904 bytes
Variable Size 956304728 bytes
Database Buffers 687865856 bytes
Redo Buffers 7118848 bytes
Database mounted.
SQL> alter database archivelog;


Database altered.


SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oracle/product/dbs/arch
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6


SQL> create spfile from pfile='/u01/oracle/product/dbs/initorcl.ora';
3. 添加redo log file


SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/oracle/oradata/orcl/redo04.log') size 50M;


Database altered.


SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/oracle/oradata/orcl/redo05.log') size 50M;


Database altered.


SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/u01/oracle/oradata/orcl/redo06.log') size 50M;


Database altered.


SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/u01/oracle/oradata/orcl/redo07.log') size 50M;


Database altered.




4.创建备库的密码文件和控制文件

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


Database altered.


如果存在就不需要创建
[oracle@dg1 ~]$ orapwd file=/u01/orapworcl password=wwwwww


[oracle@dg1 u01]$ scp orapworcl 192.168.48.132:/u01/oracle/product/dbs/
The authenticity of host '192.168.48.132 (192.168.48.132)' can't be established.
RSA key fingerprint is ed:c9:32:48:57:38:60:f3:a3:9f:f1:e9:89:04:3a:46.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.48.132' (RSA) to the list of known hosts.
oracle@192.168.48.132's password:
orapworcl 100% 1536 1.5KB/s 00:00




Pfile 默认位置在$ORACLE_HOME/dbs目录下,也可以自己指定位置:
SQL> create pfile from spfile;


File created.






5.修改初始化参数文件
[root@dg1 admin]# cd /u01/oracle/product/dbs
在initorcl.ora 添加如下内容:
####主库参数######
*.DB_NAME ='orcl';
#--监听中配置的
*.DB_UNIQUE_NAME='orcl_pd'
#--列出DG中所有DB_UNIQUE_NAME
*.LOG_ARCHIVE_COnFIG='DG_COnFIG=(orcl_pd,orcl_st)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_pd'
*.LOG_ARCHIVE_DEST_2='service=orcl_st DB_UNIQUE_NAME=orcl_st'


*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
#####备库参数#######
*.FAL_SERVER=orcl_st
*.FAL_CLIENT=orcl_pd
*.standby_file_management='AUTO'
*.standby_archive_dest='/u01/archive'








6.用刚修改的pfile 启动数据库,并生成spfile。
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup pfile=?/dbs/initorcl.ora
ORACLE instance started.
Total System Global Area 247463936 bytes
Fixed Size 1218748 bytes
Variable Size 75499332 bytes
Database Buffers 163577856 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
SQL> !echo $ORACLE_HOME
/u01/oracle/product
SQL> create spfile from pfile='/u01/oracle/product/dbs/initorcl.ora';
File created.


SQL> startup pfile=?/dbs/initorcl.ora
ORA-32006: STANDBY_ARCHIVE_DEST initialization parameter has been deprecated
ORACLE instance started.


Total System Global Area 1653518336 bytes
Fixed Size 2228904 bytes
Variable Size 956304728 bytes
Database Buffers 687865856 bytes
Redo Buffers 7118848 bytes
Database mounted.
Database opened.


SQL> !echo $ORACLE_HOME
/u01/oracle/product


SQL> create spfile from pfile='/u01/oracle/product/dbs/initorcl.ora';


File created.



6. 修改listener.ora 和tnsnames.ora 文件
[root@dg1 admin]# cat listener.ora
# listener.ora Network Configuration File: /u01/oracle/product/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/oracle/product)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME =orcl)
(ORACLE_HOME = /u01/oracle/product)
(SID_NAME =orcl)
)
(SID_DESC =
(GLOBAL_DBNAME =orcl1)
(ORACLE_HOME = /u01/oracle/product)
(SID_NAME =orcl)
)
)




[root@dg1 admin]# cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/oracle/product/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.




ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)




ORCL_ST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)






ORCL_PD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)


二standby节点设置


二. Standby 端配置
1. 创建备库存放数据文件和后台跟踪目录。
[oracle@dg2 trace]$ echo $ORACLE_BASE
/u01/oracle
[oracle@dg2 trace]$mkdir -p /u01/oracle/oradata/orcl
[oracle@dg2 trace]$mkdir -p /u01/oracle/admin/orcl
[oracle@dg2 trace]$mkdir -p /u01/oracle/admin/orcl/adump
[oracle@dg2 trace]$mkdir -p /u01/oracle/admin/orcl/bdump
[oracle@dg2 trace]$mkdir -p /u01/oracle/admin/orcl/cdump
[oracle@dg2 trace]$mkdir -p /u01/oracle/admin/orcl/ddump
[oracle@dg2 trace]$mkdir -p /u01/oracle/admin/orcl/pfile
[oracle@dg2 trace]$mkdir -p /u01/oracle/admin/orcl/udump


2.初始化拷贝过来的参数
[oracle@dg2 trace]cd /u01/oracle/product/dbs
从主库copy过来,修改如下:
*.DB_NAME ='orcl';
#--监听中配置的
*.DB_UNIQUE_NAME='orcl_st'
#--列出DG中所有DB_UNIQUE_NAME
*.LOG_ARCHIVE_COnFIG='DG_COnFIG=(orcl_pd,orcl_st)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_st'
*.LOG_ARCHIVE_DEST_2='service=orcl_pd DB_UNIQUE_NAME=orcl_pd'


*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
#####备库参数#######
*.FAL_SERVER=orcl_pd
*.FAL_CLIENT=orcl_st
*.standby_file_management='AUTO'
*.standby_archive_dest='/u01/archive'




3. 修改listener.ora 和 tnsnames.ora 文件,如果不存在,就从主库上copy 过去。
拷贝初始化参数文件
[oracle@dg1 admin]$scp initorcl.ora 192.168.48.132:/u01/oracle/product/dbs

拷贝listener.ora和tnsnames.ora文件
[oracle@dg1 admin]$ scp listener.ora 192.168.48.132:/u01/oracle/product/network/admin
oracle@192.168.48.132's password:
listener.ora 100% 609 0.6KB/s 00:00
[oracle@dg1 admin]$ scp tnsnames.ora 192.168.48.132:/u01/oracle/product/network/admin
oracle@192.168.48.132's password:
tnsnames.ora 100% 734 0.7KB/s 00:00


4.rman备份
[oracle@dg1 admin]$ rman target /


Recovery Manager: Release 11.2.0.3.0 - Production on Mon Jan 27 16:59:37 2014


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


connected to target database: ORCL (DBID=1365744995)




RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
sql 'alter system archive log current';
backup current controlfile for standby format='/oradata/backup/control_%U';
BACKUP FORMAT '/oradata/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE ;
sql 'alter system archive log current';
BACKUP FORMAT '/oradata/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
release channel c2;
release channel c1;
}
backup full database include current controlfile for standby plus archivelog FORMAT '/oradata/backup/orcl_%U_%T' skip inaccessible filesperset 5;


5.拷贝backup文件夹到dg2服务器
[oracle@dg1 oradata]$ cd /oradata/backup/
[oracle@dg1 backup]$ scp * 192.168.48.132:/oradata/backup




6.执行duplicate 复制standby库
[oracle@dg1 admin]$ rman target / auxiliary sys/wwwwww@orcl_st;
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Jul 20 22:32:59 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1248423599)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby nofilenamecheck dorecover;




7. 在备库添加redo log file
如果主库没有添加redo log file,,可以先用copy 过来的初始化文件将数据库启动到mount 状态。在创建个spfile,最后添加redo log。
SQL> create spfile from pfile='/u01/oracle/product/dbs/initorcl.ora';
添加一个新的Standby Redologs组(注意组号不要与当前存在的Online Redologs组重复),并为该组指定一个成员:
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/oracle/oradata/orcl/redo04.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/oracle/oradata/orcl/redo05.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/u01/oracle/oradata/orcl/redo06.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/u01/oracle/oradata/orcl/redo07.log') size 50M;




启动顺序:先standby ,后primary;
闭顺序:先primary 后standby;

在备库将实例启动到mount 状态:
SQL> startup nomount;
SQL>alter database mount standby database ;
SQL>alter database recover managed standby database disconnect from session;
在备库启动监听:
$lsnrctl start
在主库启动实例:
SQL> startup;
在主库启动监听:
$lsnrctl start






8.验证dg
在主机执行:
SQL> create user hbhe identified by wwwwww default tablespace users temporary tablespace temp;


User created.


SQL> grant select on dba_pending_transactions to hbhe;


Grant succeeded.


SQL> grant connect, resource to hbhe;


Grant succeeded.


SQL> grant insert any table to hbhe;


Grant succeeded.


SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@dg1 dbs]$ sqlplus hbhe/wwwwww


SQL*Plus: Release 11.2.0.3.0 Production on Tue Jan 28 18:45:36 2014


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




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> create table sales1(empid number,depid number,area varchar(20),salenum number);


Table created.


SQL> insert into sales1 values(1,1,'china',10);


1 row created.


SQL> insert into sales1 values(2,1,'china',10);


1 row created.




在备机执行:
[oracle@dg2 dbs]$ sqlplus "/as sysdba"


SQL*Plus: Release 11.2.0.3.0 Production on Tue Jan 28 19:14:36 2014


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




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options




SQL> alter database recover managed standby database cancel;


Database altered.


SQL> alter database open;


Database altered.


SQL> conn hbhe/wwwwww
Connected.
SQL> select * from sales1;


EMPID DEPID
---------- ----------
AREA SALENUM
------------------------------------------------------------ ----------
1 1
china 10


2 1
china 10

相关参考:

Oracle Data Guard 重要配置参数

基于同一主机配置 Oracle 11g Data Guard

探索Oracle之11g DataGuard

Oracle Data Guard (RAC+DG) 归档删除策略及脚本

Oracle Data Guard 的角色转换

Oracle Data Guard的日志FAL gap问题

Oracle 11g Data Guard Error 16143 Heartbeat failed to connect to standby 处理方法

linux

推荐阅读
  • 本文深入探讨了SQL数据库中常见的面试问题,包括如何获取自增字段的当前值、防止SQL注入的方法、游标的作用与使用、索引的形式及其优缺点,以及事务和存储过程的概念。通过详细的解答和示例,帮助读者更好地理解和应对这些技术问题。 ... [详细]
  • MySQL缓存机制深度解析
    本文详细探讨了MySQL的缓存机制,包括主从复制、读写分离以及缓存同步策略等内容。通过理解这些概念和技术,读者可以更好地优化数据库性能。 ... [详细]
  • 使用Python在SAE上开发新浪微博应用的初步探索
    最近重新审视了新浪云平台(SAE)提供的服务,发现其已支持Python开发。本文将详细介绍如何利用Django框架构建一个简单的新浪微博应用,并分享开发过程中的关键步骤。 ... [详细]
  • MySQL 数据库迁移指南:从本地到远程及磁盘间迁移
    本文详细介绍了如何在不同场景下进行 MySQL 数据库的迁移,包括从一个硬盘迁移到另一个硬盘、从一台计算机迁移到另一台计算机,以及解决迁移过程中可能遇到的问题。 ... [详细]
  • Hadoop入门与核心组件详解
    本文详细介绍了Hadoop的基础知识及其核心组件,包括HDFS、MapReduce和YARN。通过本文,读者可以全面了解Hadoop的生态系统及应用场景。 ... [详细]
  • 本文详细介绍了 MySQL 中 LAST_INSERT_ID() 函数的使用方法及其工作原理,包括如何获取最后一个插入记录的自增 ID、多行插入时的行为以及在不同客户端环境下的表现。 ... [详细]
  • 深入探讨CPU虚拟化与KVM内存管理
    本文详细介绍了现代服务器架构中的CPU虚拟化技术,包括SMP、NUMA和MPP三种多处理器结构,并深入探讨了KVM的内存虚拟化机制。通过对比不同架构的特点和应用场景,帮助读者理解如何选择最适合的架构以优化性能。 ... [详细]
  • 探讨如何真正掌握Java EE,包括所需技能、工具和实践经验。资深软件教学总监李刚分享了对毕业生简历中常见问题的看法,并提供了详尽的标准。 ... [详细]
  • 作者:守望者1028链接:https:www.nowcoder.comdiscuss55353来源:牛客网面试高频题:校招过程中参考过牛客诸位大佬的面经,但是具体哪一块是参考谁的我 ... [详细]
  • PostgreSQL 10 离线安装指南
    本文详细介绍了如何在无法联网的服务器上进行 PostgreSQL 10 的离线安装,并涵盖了从下载安装包到配置远程访问的完整步骤。 ... [详细]
  • 本文详细探讨了HTML表单中GET和POST请求的区别,包括它们的工作原理、数据传输方式、安全性及适用场景。同时,通过实例展示了如何在Servlet中处理这两种请求。 ... [详细]
  • 在现代Web应用中,当用户滚动到页面底部时,自动加载更多内容的功能变得越来越普遍。这种无刷新加载技术不仅提升了用户体验,还优化了页面性能。本文将探讨如何实现这一功能,并介绍一些实际应用案例。 ... [详细]
  • 本文详细探讨了HTTP 500内部服务器错误的成因、解决方案及其在Web开发中的影响。通过对具体案例的分析,帮助读者理解并解决此类问题。 ... [详细]
  • 本文介绍了如何使用PHP代码实现微信平台的媒体素材上传功能,详细解释了API接口的使用方法和注意事项,确保文件路径正确以避免常见的错误。 ... [详细]
  • 在现代网络环境中,两台计算机之间的文件传输需求日益增长。传统的FTP和SSH方式虽然有效,但其配置复杂、步骤繁琐,难以满足快速且安全的传输需求。本文将介绍一种基于Go语言开发的新一代文件传输工具——Croc,它不仅简化了操作流程,还提供了强大的加密和跨平台支持。 ... [详细]
author-avatar
云中之锦书
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有