Physical Standby配置
修改控制文件,修改最大日志组为10
alter database backup controlfile to trace;
ORACLE_HOME为/opt/oracle/app/oracle/product/
190作为primary,185作为Standby
创建Standby的Oracle软件
打包Primary上的oracle软件
cd /opt/oracle/app/oracle/product
tar cvf db.tar
ftp到Standby服务器相应目录
创建Standby上的Oracle软件目录结构
mkdir -p /opt/oracle/app/oracle/product
cd /opt/oracle/app/oracle/product
tar xvf db.tar
cd /opt/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/stdby.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: /opt/oracle/app/oracle/product/
network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER_DG =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ctsdb)
(ORACLE_HOME = /opt/oracle/app/oracle/product/
(SID_NAME = ctsdb)
)
)
LISTENER_DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 129.200.9.190)(PORT = 1522))
)
# TNSNAMES.ORA Network Configuration File: /opt/oracle/app/oracle/product/
network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
CTSDB.STANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 129.200.9.185)(PORT = 1522))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = ctsdb)
)
)
CTSDB.PRIMARY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 129.200.9.190)(PORT = 1522))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = ctsdb)
)
)
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
添加standby redolog
alter database add standby logfile group 4 ('/export/spare/oradata/ctsdb/stdby_redo04.log') size 10240K;
alter database add standby logfile group 5 ('/export/spare/oradata/ctsdb/stdby_redo05.log') size 10240K;
alter database add standby logfile group 6 ('/export/spare/oradata/ctsdb/stdby_redo06.log') size 10240K;
alter database add standby logfile group 7 ('/export/spare/oradata/ctsdb/stdby_redo07.log') size 10240K;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE 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 finish;
shutdown immediate;
18。切换到只读模式
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
ALTER DATABASE OPEN READ ONLY;
19。切换回管理恢复模式
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
以上为MAX PERFORMANCE模式的DataGuard
如果要改为MAX AVAILABILITY,进行如下操作:
检查当前Primary库的保护模式
select protection_mode from v$database;
转换:
shutdown immediate;
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;