六.实施步骤
Physical Standby配置
修改控制文件,修改最大日志组为10
alter database backup controlfile to trace;
ORACLE_HOME为/export/home/oracle/app/oracle/product/9.2.0
190作为primary,185作为Standby
创建Standby的Oracle软件
打包Primary上的oracle软件
cd /export/home/oracle/app/oracle/product
tar cvf db.tar 9.2.0
ftp到Standby服务器相应目录
创建Standby上的Oracle软件目录结构
mkdir -p /export/home/oracle/app/oracle/product
tar xvf db.tar
cd /export/home/oracle/app/oracle
mkdir -p admin/ctsdb/bdump
mkdir -p admin/ctsdb/cdump
mkdir -p admin/ctsdb/udump
创建Standby上的dba组,oracle用户,修改oracle用户的环境变量,修改/etc/system文件
1。设置Primary强制Logging
ALTER DATABASE FORCE LOGGING;
2。设置Primary为归档模式,启动自动归档
3。检查Primary中所有数据文件
4。关闭Primary,关闭应用服务器,停止监听
5。cp所有数据文件到本地备份路径
6。启动Primary,保持监听和应用服务器处于停止状态
7。生成Standby控制文件
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/control01.ctl';
8。生成初始化参数文件
CREATE PFILE='/tmp/initctsdb.ora' FROM SPFILE;
9。将5,7,8中生成的所有文件以及密码文件cp到Standby服务器
10。修改Standby的初始化参数文件
添加下面行:
*.standby_archive_dest='/export/spare/oradata/ctsdb/archive'
*.fal_server='ctsdb.primary'
*.fal_client='ctsdb.standby'
*.standby_file_management=auto
*.remote_archive_enable=TRUE
11。修改Primary和Standby的lisener.ora和tnsnames.ora文件
# LISTENER.ORA Network Configuration File: /export/home/oracle/app/oracle/product/9.2.0/
network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER_DG =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ctsdb)
(ORACLE_HOME = /export/home/oracle/app/oracle/product/9.2.0)
(SID_NAME = ctsdb)
)
LISTENER_DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.5.210)(PORT = 1522))
# TNSNAMES.ORA Network Configuration File: /export/home/oracle/app/oracle/product/9.2.0/
network/admin/tnsnames.ora
CTSDB.STANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.5.211)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = ctsdb)
CTSDB.PRIMARY =
12。设置Standby的SQLNET.ORA文件
添加SQLNET.EXPIRE_TIME=2,该配置表示在Standby由于故障不可用时,Primary将持续检测2分钟,如果仍然不可用,则返回网络连接错误。
13。创建Standby的spfile
CREATE SPFILE FROM PFILE='/tmp/initctsdb.ora';
14。启动Standby
STARTUP NOMOUNT;
ALTER DATABASE MOUNTSTANDBY DATABASE;
如果要使用LGWR进程传递redo数据,那么需要添加standby redolog,如果使用ARCH进程传递redo数据,那么这步可以省略
alter database add standby logfile group 4
('/global/oradata/ctsdb/stdby_redo04.log') size 1024K;
alter database add standby logfile group 5
('/global/oradata/ctsdb/stdby_redo05.log') size 1024K;
alter database add standby logfile group 6
('/global/oradata/ctsdb/stdby_redo06.log') size 1024K;
alter database add standby logfile group 7
('/global/oradata/ctsdb/stdby_redo07.log') size 1024K;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE PARALLEL
<CPU*2> DISCONNECT FROM SESSION;
为了防止以后primary和standby切换,可以在primary上也建立相应的standby redolog
15。设置Primary的归档地址
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=CTSDB.STANDBY LGWR' SCOPE=BOTH;
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE SCOPE=BOTH;
16。测试Primary的归档能否应用到Standby
ALTER SYSTEM ARCHIVE LOG CURRENT;
17。停止Standby
alter database recover managed standby database cancel;
shutdown immediate;
18。切换到只读模式
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
ALTER DATABASE OPEN READ ONLY;
19。切换回管理恢复模式
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE PARALLEL 8 DISCONNECT FROM SESSION;
以上为MAX PERFORMANCE模式的DataGuard
如果要改为MAX AVAILABILITY,进行如下操作:
检查当前Primary库的保护模式
select protection_mode from v$database;
转换数据库模式为MAX AVAILABILITY:
startup mount;
alter database set standby database to maximize availability;
alter database open;
如果要强制Primary一分种归档一次,那么设置Primary的初始化参数ARCHIVE_LAG_TARGET:
alter system set ARCHIVE_LAG_TARGET=60 scope=both;
如果想要自动在Standby上应用Primary中创建数据文件等操作,需要在Standby上设置:
alter system set STANDBY_FILE_MANAGEMENT=AUTO scope=both;
使用RMAN进行DataGuard环境的快速配置总结:
1. 预先设置好Standby上所需的参数文件和路径, 修改standby的fal_server和fal_client参数
2. 作Primay的联机RMAN备份
3. 启动Primay,随时都可以生成standby control file
4. 在Standby端,用生成的standby control file, mount database
5. 在Standby端,RMAN中作restore databse
6. 设置standby到RECOVER MANAGED状态
Pirmay和Standby之间作switchover,此时Primary和Standby均为正常状态,并且网络正常。
Primary:
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
SHUTDOWN IMMEDIATE;
Standby:
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
SHUTDOWN;
STARTUP;
Primay:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Standby Failover到Primary,此时由于故障Primary宕机或者网络不通