Oracle DataGuard 太TMD恶心了,弄了这么长时间~下面我来介绍一下最简单的安装方法~
1,首先装两个相同目录的oracle(可以选择不同的目录),因为我用的是虚机,所以默认装在c:/app下
2,在primary库上配置client参数,tnsnames.ora 和 listener.ora, standby上面也是同理~
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:/app/product/11.2.0/dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:/app/product/11.2.0/dbhome_1/bin/oraclr11.dll")
)
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = C:/app/product/11.2.0/dbhome_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.70.254)(PORT = 1521))
)
)
ORCL254 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.70.254)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL253 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.70.253)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
3, enable logging:
进入sqlplus,执行alter database force logging;
4,查看日志是否归档
archive log list;
如果没有的话就执行,
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
5,重新定义pfile文件
create pfile='c:/pfile.ora' from spfile
修改对应的pfile文件(其他文档说还要备份,不用累他们~),在后面加上下面这些内容
DB_UNIQUE_NAME=orcl254
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl254,orcl253)'
LOG_ARCHIVE_DEST_1='LOCATION=c:/app/oradata/orcl/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl254'
LOG_ARCHIVE_DEST_2='SERVICE=orcl253 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl253'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
FAL_SERVER=orcl
FAL_CLIENT=orcl
DB_FILE_NAME_CONVERT='oradata/orcl253','oradata/orcl254'
LOG_FILE_NAME_CONVERT='oradata/orcl253','oradata/orcl254'
STANDBY_FILE_MANAGEMENT=AUTO
执行:
create spfile from pfile='c:/pfile.ora'
6, 为standby库创建控制文件
alter database create standby controlfile as ‘c:/configurfile.ctl';
7,重启oracle 和listener
8,copy ctl 文件和ora文件到standby库,主库暂时告一段落
Standby 库操作
1,因为我们两个库都是新建的,所以不用copy oracledata文件,这里只需要把ctl文件copy到oracledata和flash_recovery_area下,并改成相应的名字,我这里是CONTROL02.CTL 和CONTROL01.CTL,网上说一共有三个,我是没找到,如果你要发现了,你就改一下~
2,修改pfile文件,把之前填加的内容删除掉后,在加下以下内容:
db_unique_name=orcl253
LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl254,orcl253)'
DB_FILE_NAME_CONVERT='oradata/orcl254','oradata/orcl253'
LOG_FILE_NAME_CONVERT='oradata/orcl254','oradata/orcl253'
LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
LOG_ARCHIVE_DEST_1='LOCATION=c:/app/oradata/orcl/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl253'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_2='SERVICE=orcl254 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl254'
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
FAL_SERVER=orcl254
FAL_CLIENT=orcl253
STANDBY_FILE_MANAGEMENT=AUTO
3,为standby库建立spfile文件
create spfile from pfile='c:/pfile.ora'
4, 用mount方式启动standby
startup mount
5,启动redo 应用
SQL> alter database recover managed standby database disconnect from session;
这时候基本就搞定了,以下为测试~
在主库上执行:
alter system switch logfile;
select max(sequence#) from v$archived_log;
在standby库上执行:
select max(sequence#) from v$archived_log;
如果两边的max(sequence#) 执行的结果都一样,那么恭喜,你成功了~