|
本帖最后由 botang 于 2014-9-30 08:33 编辑
以下内容为较为靠谱的说法,转帖,仅供参考
Section 8: Data Guard
主要流程
搭建一个Data Guard 在最大保护模式下经行两次切换 在切换前跑相应脚本
1. 设置LISTENER,把备库(PRODSTD)也设置进默认LISTENER里面
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = emrep)
(ORACLE_HOME = /home/oracle/prodect/10.2.0/db_1)
(SID_NAME = emrep)
)
(SID_DESC =
(GLOBAL_DBNAME = prod)
(ORACLE_HOME = /home/oracle/prodect/10.2.0/db_1)
(SID_NAME = prod)
)
(SID_DESC =
(GLOBAL_DBNAME = prodstd)
(ORACLE_HOME = /home/oracle/prodect/10.2.0/db_1)
(SID_NAME = prodstd)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = celty.localdomain)(PORT = 1521))
)
2. 数据库必须是归档状态,FORCE LOGGING状态
SQL> select FORCE_LOGGING from v$database;
FOR
---
NO
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/oradata/prod/arc/
Oldest online log sequence 17
Next log sequence to archive 21
Current log sequence 21
3. 在initPROD.ora的尾部加入修改后的参数(参考文档Data Guard Concepts and Administration中的3 Creating a Physical Standby Database)大致修改如下:
主库(PROD):
DB_UNIQUE_NAME=PROD
LOG_ARCHIVE_CONFIG='DG_CONFIG=( PROD, PRODSTD)'
LOG_ARCHIVE_DEST_1=
'LOCATION=/home/oracle/oradata/PROD/arc/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=PROD'
LOG_ARCHIVE_DEST_2=
'SERVICE= PRODSTD LGWR SYNC AFFIRM
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME= PRODSTD '
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
FAL_SERVER= PRODSTD
FAL_CLIENT=PROD
DB_FILE_NAME_CONVERT=' PRODSTD ','PROD'
LOG_FILE_NAME_CONVERT=' PRODSTD ',' PROD'
STANDBY_FILE_MANAGEMENT=AUTO
3.2复制一份initPROD.ora改名为initPRODSTD.ora
cd $ORACLE_HOME/dbs
cp initPROD.ora initPRODSTD.ora
3.3修改initPRODSTD.ora的参数如下
备库(PRODSTD)
DB_UNIQUE_NAME=PRODSTD
LOG_ARCHIVE_CONFIG='DG_CONFIG=( PRODSTD, PROD)'
LOG_ARCHIVE_DEST_1=
'LOCATION=/home/oracle/oradata/PRODSTD/arc/
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=PRODSTD'
LOG_ARCHIVE_DEST_2=
'SERVICE= PROD LGWR SYNC AFFIRM
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME= PROD '
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
FAL_SERVER= PROD
FAL_CLIENT=PRODSTD
DB_FILE_NAME_CONVERT=' PROD','PRODSTD'
LOG_FILE_NAME_CONVERT=' PROD',' PRODSTD'
STANDBY_FILE_MANAGEMENT=AUTO
4 配置密码文件
cd $ORACLE_HOME/dbs
orapwd file=orapwprodstd password=oracle
5 PROD打开至MOUNT状态,复制文件
[oracle@celty oradata]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 10 10:58:23 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 96470416 bytes
Database Buffers 213909504 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> !
[oracle@celty oradata]$ cp -R prod prodstd (复制全部文件)
6. 创建备库的控制文件
alter database create standby controlfile as '/home/oracle/oradata/prodstd/control01.ctl'
要跟原来的控制文件相同数量
cp /home/oracle/oradata/prodstd/control01.ctl /home/oracle/oradata/prodstd/control02.ctl
cp /home/oracle/oradata/prodstd/control01.ctl /home/oracle/oradata/prodstd/control03.ctl
7. 将PRODSTD打开也进入mount状态
加入STANDBY LOGFILE
在PROD中
Alter database add standby logfile
Group ‘/home/oracle/oradata/prod/stdredo01.log’ size 100M,
….
在PRODSTD中
Alter database add standby logfile
Group ‘/home/oracle/oradata/prodstd/stdredo01.log’ size 100M,
….
(注:standby logfile的大小必须与原本数据库的logfile大小相同,而且数量比原来多一个)
查询
Select name from v$datafile;
Select member from v$logfile;
看看是否已经转换成功
8. 此时将PROD切换至最大保护模式(在MOUNT状态才可以使用该命令)
SQL>ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PROTECTION
打开PROD数据库进入OPEN状态
跑脚本q1.sql
SQL>@q1.sql
9. 在PROD进行切换
SQL>Alter database commit to switchover to physical standby
成功后立刻shutdown immediate 然后再startup mount
此时数据库PROD的database_role已经变成physical standby
在PRODSTD经行一次恢复
SQL>Alter database recover managed standby database disconnect from session
等后台恢复结束后
Alter database commit to switchover to parimary
此时PRODSTD的database_role已经变成PRIMARY
运行脚本q2.sql
SQL>@q2.sql
10. 在PRODSTD经行切换
SQL>Alter database commit to switchover to physical standby
成功后立刻shutdown immediate 然后再startup mount
此时数据库PRODSTD的database_role已经变成physical standby
在PROD经行一次恢复
SQL>Alter database recover managed standby database disconnect from session
等后台恢复结束后
SQL>Alter database commit to switchover to parimary
此时PROD的database_role已经变成PRIMARY
运行脚本q3.sql
SQL>@q3.sql
11. 在PRODSTD经行一次恢复
SQL>Alter database recover managed standby database disconnect from session;
等待后台结束即可
至此,DG部分完成
|
|