操作系统:OEL 5.6

Oracle 版本:11.2.0.4.0

DataGuard规划说明
DATABASE_ROLE DB_NAME IPADDR
Primary lgr 192.168.10.5
Standby DG 192.168.10.88

1. 主库开启归档,开启强制日志,关闭闪回,删除外部表

SYS@lgr> startup mount;
ORACLE instance started. Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 536874064 bytes
Database Buffers 289406976 bytes
Redo Buffers 6565888 bytes
Database mounted.
SYS@lgr> alter database archivelog; Database altered. SYS@lgr> alter database open; Database altered. SYS@lgr> select force_logging from v$database; FOR
---
NO SYS@lgr> alter database force logging; Database altered. SYS@lgr> select flashback_on from v$database; FLASHBACK_ON
------------------
NO ##xxx_external_locations 可以知道当前所有的目录对象以及相关的外部表,还会查询出这些外部表所对应的操作系统文件的名字。 ##select * from all_external_locations; ##select * from user_external_locations; ##select * from dba_external_locations;

2.主库创建standby logfile

配置原则:

①standby logfile大小要和redo logfile大小相同;
②standby logfile要比redo logfile多一组,我的redo logfile是3组,所以创建4组standby logfile; ③为了安全,standby logfile可以包含多个member。 SYS@lgr> select group#,member from v$logfile; GROUP# MEMBER
---------- --------------------------------------------------
3 /u01/app/oracle/oradata/lgr/redo03.log
2 /u01/app/oracle/oradata/lgr/redo02.log
1 /u01/app/oracle/oradata/lgr/redo01.log SYS@lgr>
SYS@lgr> select group#,bytes/1024/1024 size_M from v$log; GROUP# SIZE_M
---------- ----------
1 50
2 50
3 50 SYS@lgr> alter database add standby logfile group 4('/u01/app/oracle/oradata/lgr/sredo04.log') size 50M; Database altered. SYS@lgr> alter database add standby logfile group 5('/u01/app/oracle/oradata/lgr/sredo05.log') size 50M; Database altered. SYS@lgr> alter database add standby logfile group 6('/u01/app/oracle/oradata/lgr/sredo06.log') size 50M; Database altered. SYS@lgr> alter database add standby logfile group 7('/u01/app/oracle/oradata/lgr/sredo07.log') size 50M; Database altered. SYS@lgr>
SYS@lgr> select group#,member from v$logfile; GROUP# MEMBER
---------- --------------------------------------------------
3 /u01/app/oracle/oradata/lgr/redo03.log
2 /u01/app/oracle/oradata/lgr/redo02.log
1 /u01/app/oracle/oradata/lgr/redo01.log
4 /u01/app/oracle/oradata/lgr/sredo04.log
5 /u01/app/oracle/oradata/lgr/sredo05.log
6 /u01/app/oracle/oradata/lgr/sredo06.log
7 /u01/app/oracle/oradata/lgr/sredo07.log 7 rows selected.
SYS@lgr>
SYS@lgr> select group#,thread#,sequence#,bytes,status from v$standby_log; GROUP# THREAD# SEQUENCE# BYTES STATUS
---------- ---------- ---------- ---------- ----------
4 0 0 52428800 UNASSIGNED
5 0 0 52428800 UNASSIGNED
6 0 0 52428800 UNASSIGNED
7 0 0 52428800 UNASSIGNED

3.主库配置listener

---修改local_listener为默认监听
SYS@lgr> alter system set local_listener=''; System altered. SYS@lgr> show parameter local_listener NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string ---配置listener.ora
[oracle@lgr ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.5)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
sid_list_listener=
(sid_list=
(sid_desc=
(global_dbname=lgr)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(sid_name=lgr))
) ADR_BASE_LISTENER = /u01/app/oracle

4.主库配置tnsnames

[oracle@lgr ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
lgr =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.5)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = lgr)
)
) DG =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.88)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DG)
)
)

5.主库修改参数

5.1.生成pfile

SYS@lgr> startup
ORACLE instance started. Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 536874064 bytes
Database Buffers 289406976 bytes
Redo Buffers 6565888 bytes
Database mounted.
Database opened.
SYS@lgr> create pfile from spfile; File created. SYS@lgr> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@lgr>

5.2.修改参数

##参数模板可以在官方文档中查到,把其中的名称用自己的数据库名称替换即可。
[oracle@lgr ~]$ cd $ORACLE_HOME/dbs
[oracle@lgr dbs]$ vi initlgr.ora
----追加如下内容----
#Primary Role Initialization Parameters
DB_UNIQUE_NAME=lgr
LOG_ARCHIVE_CONFIG='DG_CONFIG=(lgr,DG)'
LOG_ARCHIVE_DEST_1=
'LOCATION=/arch1/lgr/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=lgr'
LOG_ARCHIVE_DEST_2=
'SERVICE=DG ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=DG'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30 #Standby Role Initialization Parameters
FAL_SERVER=DG
DB_FILE_NAME_CONVERT='DG','lgr'
LOG_FILE_NAME_CONVERT='DG','lgr'
STANDBY_FILE_MANAGEMENT=AUTO ##根据参数文件创建不存在的目录
[root@lgr ~]# mkdir -p /arch1/lgr/
[root@lgr ~]# chown -R oracle:oinstall /arch1/lgr/

5.3.通过pfile重新生成spfile并启动数据库

SYS@lgr> create spfile from pfile;

File created.

SYS@lgr>
SYS@lgr>
SYS@lgr> startup
ORACLE instance started. Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 536874064 bytes
Database Buffers 289406976 bytes
Redo Buffers 6565888 bytes
Database mounted.
Database opened.
SYS@lgr>
SYS@lgr> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@lgr>

6.拷贝相关文件至备库

[oracle@lgr dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@lgr dbs]$ ll
total 24
-rw-rw---- 1 oracle oinstall 1544 Jan 4 23:29 hc_lgr.dat
-rw-r--r-- 1 oracle oinstall 1487 Jan 4 23:26 initlgr.ora
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r----- 1 oracle oinstall 24 Jan 4 19:15 lkLGR
-rw-r----- 1 oracle oinstall 1536 Jan 4 19:20 orapwlgr
-rw-r----- 1 oracle oinstall 3584 Jan 4 23:29 spfilelgr.ora
[oracle@lgr dbs]$
[oracle@lgr dbs]$
[oracle@lgr dbs]$ scp initlgr.ora oracle@192.168.10.88:/u01/app/oracle/product/11.2.0/db_1/dbs/initDG.ora
The authenticity of host '192.168.10.88 (192.168.10.88)' can't be established.
RSA key fingerprint is c8:bb:ef:15:8b:1c:e0:ad:e4:3f:eb:3b:a7:17:e7:dd.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.88' (RSA) to the list of known hosts.
oracle@192.168.10.88's password:
initlgr.ora 100% 1487 1.5KB/s 00:00
[oracle@lgr dbs]$
[oracle@lgr dbs]$
[oracle@lgr dbs]$ scp orapwlgr oracle@192.168.10.88:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwDG
oracle@192.168.10.88's password:
orapwlgr 100% 1536 1.5KB/s 00:00
[oracle@lgr dbs]$
[oracle@lgr dbs]$ scp /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora oracle@192.168.10.88:/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
oracle@192.168.10.88's password:
tnsnames.ora 100% 404 0.4KB/s 00:00
[oracle@lgr dbs]$

7.备库创建静态监听并启动监听

[oracle@DG ~]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
[oracle@DG admin]$ vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.88)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
sid_list_listener=
(sid_list=
(sid_desc=
(global_dbname=DG)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(sid_name=DG))
) ADR_BASE_LISTENER = /u01/app/oracle [oracle@DG dbs]$ lsnrctl LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 04-JAN-2017 23:36:18 Copyright (c) 1991, 2013, Oracle. All rights reserved. Welcome to LSNRCTL, type "help" for information. LSNRCTL> start listener
Starting /u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/DG/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.10.88)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.88)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias listener
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 04-JAN-2017 23:36:25
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/DG/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.10.88)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "DG" has 1 instance(s).
Instance "DG", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

8.备库参数修改

8.1.修改备库pfile

##把主库名称修改为备库名称,备库名称修改为主库名称,但参数文件中的db_name要和主库名称一致。
[oracle@lgr dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@DG dbs]$ vi initDG.ora
lgr.__db_cache_size=289406976
lgr.__java_pool_size=4194304
lgr.__large_pool_size=71303168
lgr.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
lgr.__pga_aggregate_target=335544320
lgr.__sga_target=503316480
lgr.__shared_io_pool_size=0
lgr.__shared_pool_size=125829120
lgr.__streams_pool_size=0
删除以上内容,并将剩余的内容修改为DG的目录
*.audit_file_dest='/u01/app/oracle/admin/DG/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/DG/control01.ctl','/u01/app/oracle/fast_recovery_area/DG/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='lgr'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=DGXDB)'
*.local_listener=''
*.memory_target=838860800
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1' DB_UNIQUE_NAME=DG
LOG_ARCHIVE_CONFIG='DG_CONFIG=(DG,lgr)'
LOG_ARCHIVE_DEST_1=
'LOCATION=/arch1/DG/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=DG'
LOG_ARCHIVE_DEST_2=
'SERVICE=lgr ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=lgr'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30 #Standby Role Initialization Parameters
FAL_SERVER=lgr
DB_FILE_NAME_CONVERT='lgr','DG'
LOG_FILE_NAME_CONVERT='lgr','DG'
STANDBY_FILE_MANAGEMENT=AUTO

8.2.备库按照参数文件创建目录

[oracle@DG dbs]$ mkdir -p /u01/app/oracle/admin/DG/adump
[oracle@DG dbs]$ mkdir -p /u01/app/oracle/oradata/DG
[oracle@DG dbs]$ mkdir -p /arch1/DG/
[oracle@DG dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area

8.3.备库通过pfile生成spfile并启动数据库至nomount

[oracle@DG dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Jan 4 23:56:25 2017

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

Connected to an idle instance.

SQL> create spfile from pfile;

File created.

SQL> startup nomount;
ORACLE instance started. Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 536874064 bytes
Database Buffers 289406976 bytes
Redo Buffers 6565888 bytes
SQL>

9.使用RMAN auxiliary恢复数据库

主库为open状态,备库为nomount
监听为启动状态
[oracle@lgr ~]$ rman target sys/oracle@lgr auxiliary sys/oracle@DG Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jan 5 00:04:12 2017 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: LGR (DBID=1711819363)
connected to auxiliary database: LGR (not mounted) RMAN> duplicate target database for standby from active database dorecover nofilenamecheck; Starting Duplicate Db at 05-JAN-17
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=10 device type=DISK
..... media recovery complete, elapsed time: 00:00:00
Finished recover at 05-JAN-17
Finished Duplicate Db at 05-JAN-17 RMAN>

10.备库同步数据

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED SQL> alter database recover managed standby database using current logfile disconnect from session; Database altered. SQL> select database_role,open_mode from v$database; DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY MOUNTED

至此,DataGuard搭建完成!

【Oracle】搭建DG(DataGuard)的更多相关文章

  1. Oracle - 通过dg,完成单实例到rac的迁移

    一.概述 本文将介绍如何给单实例搭建一个rac dg,以及如何对其进行角色转换,完成从单实例到rac的迁移.预先具备的知识(rac搭建,单实例-单实例dg搭建) 二.实验环境介绍 主库(已有数据库实例 ...

  2. ORA-16019搭建DG设置归档线程参数报错

    #操作描述:搭建DG,主库修改参数log_archive_dest_1线程路径报错 ORA-16019: cannot use LOG_ARCHIVE_DEST_1 with LOG_ARCHIVE_ ...

  3. Oracle 11g 物理Dataguard日常操作维护(二)

    Oracle 11g 物理Dataguard日常操作维护(二) 2017年8月25日 14:34 3.3 3.3.1 查看备库进程状态 SYS(125_7)@fpyj123> select pr ...

  4. RAC环境上搭建DG

    首先RAC要确实是开归档的状态archive log list;如果是非归档状态,需要执行下面几步srvctl stop database -d +数据库实例名 关闭数据库--节点1(要做DG主库的) ...

  5. Oracle 11g DG配置简明版

    环境: 主库A机:在线生产环境,RHEL 6.4 + Oracle 11.2.0.3 备库B机:新增备机,RHEL 6.4 需求: 对生产环境最小影响前提下配置DG备库. 目录: 一.B机安装相同版本 ...

  6. Oracle 11g DG手工switchover切换标准化流程

    Oracle 11g DG手工switchover切换标准化流程 环境:RHEL 6.5 + Oracle GI 11.2.0.4 + Oracle DB 11.2.0.4 Primary RAC(2 ...

  7. Oracle物理DG自动切换——Dataguard Broker配置

    1.前言部分 1.1 导读 各位技术爱好者,看完本文后,你可以掌握如下的技能: ① Data Guard Broker 的配置 ② Fast-Start Failover 的配置 ③ Oracle D ...

  8. Oracle 10g DG 环境搭建详解

    环境描述:线上招聘库在物理机上,需要上云主机,于是申请两台云主机:由于云主机变态性,分配的云主机具有很多局限性:1.没有/tmp,2.没有 swap 3. /home 目录非常小:于是申请两块云硬盘, ...

  9. RHEL6.4 + Oracle 11g DG测试环境快速搭建参考

    环境现状: 两台虚拟主机A和B: 1. A机器已安装ASM存储的Oracle 11g 实例      参考:http://www.cnblogs.com/jyzhao/p/4332410.html 2 ...

随机推荐

  1. BZOJ 3510: 首都 LCT + multiset维护子树信息 + 树的重心

    Code: #include<bits/stdc++.h> #define maxn 200000 #define inf 1000000000 using namespace std; ...

  2. 想要远程服务器长时间挂机不断开ssh连接的技巧

    使用top命令挂着就好了,top命令执行的“查看系统进程和资源占用”的任务会一直输出动态的数据,一直有数据传输就不会因为长时间挂机而断开ssh链接了,尤其针对于海外服务器,因为高延迟经常出现挂机久了自 ...

  3. Day 25 面向对象

    面向对象基础 面向对象编程 面向过程编程:类似于工厂的流水线 优点:逻辑清晰 缺点:扩展性差 面向对象编程:核心是对象二字,对象属性和方法的集合体,面向对象编程就是一堆对象交互 优点:扩展性强 缺点: ...

  4. HttpRunnerManager 搭建使用方法

    HttpRunnerManager Design Philosophy 基于HttpRunner的接口自动化测试平台: HttpRunner, djcelery and Django_. HttpRu ...

  5. pytorch基础(4)-----搭建模型网络的两种方法

    方法一:采用torch.nn.Module模块 import torch import torch.nn.functional as F #法1 class Net(torch.nn.Module): ...

  6. 多态(day10)

    二十二 多态(Polymorphic) 函数重写(虚函数覆盖).多态概念 如果将基类中的某个成员函数声明为虚函数,那么子类与其具有相同原型的成员函数就也将是虚函数,并且对基类中的版本形成覆盖. 这时, ...

  7. 操作符重载、继承(day08)

    二十 操作符重载 函数操作符"()" 功能:让对象当做函数来使用 注:对参数的个数.返回类型没有限制 eg: class A{...}; A a; //a.operator()(1 ...

  8. 9.Spring的IOC+MyBaits+log4j+Servlet

    1.创建如下mysql脚本 drop table if exists book_info; create table if not exists book_info( book_id ) primar ...

  9. css sprites拼合

    一.什么是css sprites css sprites直译过来就是CSS精灵.通常被解释为“CSS图像拼合”或“CSS贴图定位”.就是把网页中一些背景图片整合拼合成一张图片中,再利用DIV CSS的 ...

  10. 用DIME格式来组织自定义格式

    直接网际消息封装(Direct Internet Message Encapsulation,即DIME)格式提供了一种简单而又标准的机制,这个机制可以把多文本(multiple text)和二进制数 ...