以前在学校从来玩过集群,上班了公司要用户dataguard,叫我来配置,这个过程之纠结,做了些记录:
1. 首先是在主库上创建一个数据库,取名叫orcl,配置好这个数据库的ORACLE_SID,使用sqlplus进入到数据库,执行下面的命令,设置数据库为归档模式:
a) SQL>shutdown immediate
b) SQL>startup mount
c) SQL>alter database archivelog;
d) SQL>alter database open;
e) SQL>archive log list;
2. 备库要成为主库的完全相同的复制,就必须接受来自主库的重做日志。这就要启用数据库的强制日志功能:
a) SQL>alter database force logging;
b) SQL>select name, force_logging from v$database;
3. 确认当主库添加或删除文件是,这些文件也会在备库添加或删除,启动的sql语句:
SQL> alter system setstandby_file_management = 'AUTO';
4. 接下来我们就要创建主库的备用日志文件,备库使用备份日志文件来保持从主库接受到的日志文件,当主库转换为备库后,也要使用日志文件,建立4组,一般比在线日志多一组,建立的方法:
a) alterdatabase add standby logfile group 11 (‘/opt/oracle/app/oradata/orcl/g11m01.sdo’,’/opt/oracle/app/oradata/orcl/g11m02.sdo’)size 51M;
b) alterdatabase add standby logfile group 12 (‘/opt/oracle/app/oradata/orcl/g12m01.sdo’,’/opt/oracle/app/oradata/orcl/g12m02.sdo’)size 51M;
c) alterdatabase add standby logfile group 13 (‘/opt/oracle/app/oradata/orcl/g13m01.sdo’,’/opt/oracle/app/oradata/orcl/g13m02.sdo’)size 51M;
d) alterdatabase add standby logfile group 14 (‘/opt/oracle/app/oradata/orcl/g14m01.sdo’,’/opt/oracle/app/oradata/orcl/g14m02.sdo’)size 51M;
5. 检查数据库的db_unique_name 参数是否设置,没有就设置:
a) SQL>show paramter db_unique_name;
b) SQL>alter system set db_unique_name=some_name scope=spfile;
6. 开启主库的闪回功能,若主库出现问题,我们就可以从闪回到故障前,我们就可以避免从备库中来恢复数据,启用闪回功能,必须先配置快速恢复区:
a) SQL>alter system set db_recovery_file_dest='/opt/oracle/app/flash_recovery_area ';
b) SQL>alter system set db_recovery_file_dest_size=400G;
7. 配置好回闪区后就要开启回闪日志的功能;
a) SQL>alter database flashback on;
b) SQL>select flashback_on from v$database;
8. 配置listener.ora和tnsnames.ora,
a) 在主库listener.ora中添加下面代码:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /opt/oracle/app
SID_LIST_LISTENER=
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /opt/oracle/app/product)
(SID_NAME = orcl)
)
)
b) 在备库的listener.ora中添加下面代码:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /opt/oracle/app/oracle
SID_LIST_LISTENER=
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /opt/oracle/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = orcl)
)
)
c) 在主库的tnsname.ora中添加下面的代码:(注释掉以前的内容)
cloudvastprimary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
cloudvaststandby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.133)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
d) 在备库的tnsname.ora中添加下面的代码:
cloudvaststandby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
cloudvastprimary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.112)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
9. 完成之后就可以使用tnsping在测试一下两台机器是否连通的
a) 在主机上tnsping cloudvaststandby
b) 在备机上tnsping cloudvastprimary
c) 若是没有通,出现了错误,那么就关掉防火墙
10. 配置重做日志的传输:
a) 配置归档位置:
SQL> alter system setlog_archive_dest_1 = 'location=use_db_recovery_file_dest valid_for=(all_logfiles,all_roles) db_unique_name=cloudvastprimary';
b) 配置重做日志传输到备库:
SQL> alter system set log_archive_dest_2= 'service=cloudvaststandby async valid_for=(online_logfile,primary_role)db_unique_name= cloudvaststandby;
c) 配置fal_server ,这个参数的作用就是当日志文件在传输出现了问题时,备库要到哪儿去到归档日志。比如在对备库进行维护期间,没有日志传输过来,这是重做日志间就会出现缺口,设置这个参数,备库就去找缺少的日志:
SQL> alter system setfal_server = 'cloudvaststandby’;
d) 让主库知道dataguard配置里的另外一个库的名字:
SQL> alter system setlog_archive_config = 'dg_config=(cloudvastprimary, cloudvaststandby)';
11. 备库环境的准备:
a) 在主库使用语句创建一个启动参数文件
SQL> create pfile fromspfile;
b) 然后就使用scp命令把主库的密码文件和刚才创建的启动文件传递到备库上,放到$ORACLE_HOME/dbs/这个目录下面,修改密码文件名为备库的SID,这里主备库都是orcl,所以就不修改
c) 打开启动参数文件initorcl.ora,修改里面参数的路径,改为备库的路径,修改db_unique_name=cloudvaststandby, fal_server=cloudvastprimary, log_archive_dest_1的db_unique_name修改为备库的唯一名,log_archive_dest_2修改对应的服务名和数据库的唯一名为cloudvastprimary
d) 若是主库和备库的安装路径不一样,还有设置dbfile_name_convert log_file_name_convert
e) 根据配置文件创建相应的文件目录
f) 将备库的信息添加到/etc/oratab文件
g) 现在可以启动备库的实例来创建数据库了,启动后创建spfile
SQL> startup nomountpfile=initJED2.ora
SQL> create spfile from pfile;
SQL> shutdown
SQL> startup nomount
SQL> show parameter spfile
SQL> exit
在这里可能会有问题,我的主库系统是centos6.3的,而备库的系统是centos6.4的,所以在启动数据库时出现了错误:
SQL> startup nomountpfile=initorcl.ora
ORA-00845: MEMORY_TARGET notsupported on this system
解决的方法有两种:一种就是把MEMORY_TARGET设置小,另一种就是该打
/dev/shm的大小
12. 备库的创建,使用rman命令来创建备库,在主库上执行下面的命令:
RMAN> connect target sys@cloudvastprimary
RMAN> connect catalog system@cloudvastprimary
RMAN> connect auxiliary sys@cloudvaststandby
RMAN> duplicate target databasefor standby from active database;
这里可能会出现的错误:
a) RMAN-04006: error from auxiliarydatabase: ORA-12528: TNS:listener: all appropriate instances are blocking newconnections
仔细检查listener.ora,tnsname.ora文件,重启监听器
b) Starting Duplicate Db at 27-APR-13
RMAN-00571: ===========================================================
RMAN-00569: ===============ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571:===========================================================
RMAN-03002: failure ofDuplicate Db command at 04/27/2013 16:00:07
RMAN-12010: automaticchannel allocation initialization failed
RMAN-06428: recoverycatalog is not installed
解决方法:
进入到sqlplus中,执行下面的语句:
SQL> create tablespacerman_ts datafile '/opt/oracle/app/oradata/orcl/rman_ts.dbf' size 50M;
SQL> grantrecovery_catalog_owner to system;
进入到rman中执行下面的语句:
create catalog tablespacerman_ts;
register database;
c) 当看到Finished Duplicate Db at 27-APR-13的时候就说明已经完成了备库的创建
13. 启用和取消重做日志应用
a) SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE FDISCONNECT FROM SESSION;
b) ALTERDATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
14. 确认日志应用是否正常
SQL> select DEST_ID,STATUS, DESTINATION, ERROR from V$ARCHIVE_DEST where DEST_ID<=2;
目的地状态显示的是valid
15. 检查日志是否有缺口
SQL> select STATUS,GAP_STATUS from V$ARCHIVE_DEST_STATUS where DEST_ID = 2;
正常的应该返回valid和no gap
16. 若想要查询备库的数据,就打开数据库
SQL> ALTER DATABASE OPENREAD ONLY;
17. 到此dataguard的配置就完成了
--转自
该贴由koei123转至本版2015-2-6 4:54:29