Oracle 10g DG 环境搭建详解
环境描述:线上招聘库在物理机上,需要上云主机,于是申请两台云主机;由于云主机变态性,分配的云主机具有很多局限性:1.没有/tmp,2.没有 swap 3. /home 目录非常小;于是申请两块云硬盘,每块500GB,用做数据盘和备份盘使用;
物理机数据库运行环境说明:软件安装、数据在/home/oracle 目录下,备份、归档放在/data/目录下;
云主机数据库环境规划: 软件安装、数据存放 /oradata2/oradata 目录,备份、归档 /oradata1/oradata
那么开始搭建环境:
1。首先备份主库:
RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
sql 'alter system archive log current';
Backup as compress format '' database;
release channel c2;
release channel c1;
}
2.主库创建备库控制文件:
Sqlplus / as sysdba <<EOF
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/standby.ctl';
Create pfile='tmp/initora.ora' from spfile;
EOF
3.拷贝备份文件,以及控制文件,参数文件,密码文件到备库
4.修改参数文件相应参数:
4.1 db_uniq_name,audit_file_dest,background_dump_dest,control_files,core_dump_dest,db_create_file_dest,db_create_online_log_dest_1,db_recovery_file_dest,service_names,user_dump_dest 等相应参数
4.2 重命名参数文件
4.3 启动实例nomount 状态: create spfile from pfile; startup nomount; alter database mount;
4.4 开始恢复数据库做准备工作:
1. 连上RMAN,做crosscheck 检查文件存在性; RMAN target / <<EOF
Crosscheck backup;
Crosscheck archivelog all;
EOF
仔细观看输出结果,如果有 EXPIRED, 或者没有输出的,表示拷贝过来的文件没有和主库上备份位置一致,即rman 更具主库上创建的控制文件到主库对应的相应目录下去找不到文件。
此时一般有两种做法: 1. 建立软链接,2.重新注册目录 eg:注册ARCH目录 catalog start with '/oradata1/oradata/RMSHZPRI/arch/';
此时再次检查,就会出结果了
4.5 开始restore database;
RMAN target / <<EOF
run
{
ALLOCATE CHANNEL dev1 DEVICE TYPE DISK;
ALLOCATE CHANNEL dev2 DEVICE TYPE DISK;
ALLOCATE CHANNEL dev3 DEVICE TYPE DISK;
ALLOCATE CHANNEL dev4 DEVICE TYPE DISK;
set newname for datafile 1 to '/oradata1/oradata/RMSHZSTD/system01.dbf';
set newname for datafile 2 to '/oradata1/oradata/RMSHZSTD/undotbs01.dbf';
set newname for datafile 3 to '/oradata1/oradata/RMSHZSTD/sysaux01.dbf';
set newname for datafile 4 to '/oradata1/oradata/RMSHZSTD/users01.dbf';
set newname for datafile 5 to '/oradata1/oradata/RMSHZSTD/data_rms_01.dbf';
set newname for datafile 6 to '/oradata1/oradata/RMSHZSTD/indx_rms_01.dbf';
set newname for datafile 7 to '/oradata1/oradata/RMSHZSTD/lob_rms_01.dbf';
set newname for datafile 8 to '/oradata1/oradata/RMSHZSTD/lob_rms_02.dbf';
set newname for datafile 9 to '/oradata1/oradata/RMSHZSTD/cat_01.dbf';
set newname for datafile 10 to '/oradata1/oradata/RMSHZSTD/data_exam_01.dbf';
set newname for datafile 11 to '/oradata1/oradata/RMSHZSTD/indx_exam_01.dbf';
set newname for datafile 12 to '/oradata1/oradata/RMSHZSTD/lob_rms_05.dbf';
set newname for datafile 13 to '/oradata1/oradata/RMSHZSTD/lob_rms_03.dbf';
set newname for datafile 14 to '/oradata1/oradata/RMSHZSTD/lob_rms_04.dbf';
set newname for datafile 15 to '/oradata1/oradata/RMSHZSTD/lob_rms_06.dbf';
set newname for datafile 16 to '/oradata1/oradata/RMSHZSTD/lob_rms_07.dbf';
set newname for datafile 17 to '/oradata1/oradata/RMSHZSTD/lob_rms_08.dbf';
restore database;
release CHANNEL dev1;
release CHANNEL dev2;
release CHANNEL dev3;
release CHANNEL dev4;
switch datafile all;
}
Exit;
EOF
4.6 在rman都认知到归档日志时候,方可recover database操作;
Rman target / <<EOF
Recover database until time '2015-04-09 10:00:00';
EOF
4.7 好了如果备份文件全部都拷贝过来,并且归档在需要的时间点都全部拷贝过来, 那么以上量步会很顺畅的。
4.8 备库恢复好以后我们就可以开始配置DG环境了
5.重新为备库指定新的 redo 以及 standby redo 文件
这里有两种办法,1. alter database drop redo group 1 ; alter database add standby logfile group 4 ('/u/app/oracle/oradata/orcl/st_redo04.log','/u/app/oracle/…/redo.log') size 50m;
2. startup mount; alter database rename file '/data/orarms/oradata/RMS/redo03.log' to '/oradata2/oradata/RMSHZSTD/redo03.log';
注意,如果是删除重建,请确保一下两点:1. standby redo 大小必须和redo大小一致;2.standby redo 必须大于 redo 数量
6.位备库创建临时文件 tempfile; startup mount; 此时也有两种办法,如上所示 :
6.1
alter database tempfile '/oradata1/oradata/RMSHZSTD/temp01.dbf' drop;
alter database add tempfile '' size 100m autoextend on maxsize 20G;
6.2
alter database rename file '/home/orarms/oradata/RMS/temp01.dbf' to '/oradata1/oradata/RMSHZSTD/temp01.dbf';
7.配置主库归档传送位置,以及tnsnames.ora文件配置:
alter system set log_archive_config='dg_config=()' scope=both;
alter system set log_archive_dest_3='service=rmshzpri reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=rmshzpri' scope=both;
8.备库配置归档存储位置:
备库和主库配置命名基本上一样:
- 备库开启恢复:
如果备库采用实时恢复, 在备库端则执行如下命令:
SQL> startup nomount;
SQL> alter database mount standby database;
SQL> alter database open read only;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;