搭建前环境准备

1.查看主库的oracle的uid和gid并在备库创建用户

# 主库查看oracle
$ id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba)
# 备库创建oracle用户,注意uid和gid
# groupadd -g 54322 dba
# groupadd -g 54321 oinstall
# useradd -u 54321 oracle -g oinstall -G dba

2.备库oracle软体安装

配置yum,设置内核参数,设置oracle环境变量,修改oracle_home、oracle_base目录的权限,安装oracle软体

3.主库生成pfile并传至备库

$ sqlplus / as sysdba
create pfile from spfile;
$ scp /oracle/11204/dbs/initdg01.ora xxx.xxx.xxx.xxx:/oracle/11204/dbs/

4.备库创建参数文件中的目录

*.audit_file_dest='/oracle/admin/dg01/adump'
*.control_files='/oradata01/dg01/control01.ctl','/oradata01/dg01/control02.ctl'
*.db_recovery_file_dest='/oracle/fast_recovery_area'

5.全备主库

$ rman target /
backup database to destination '/oradata01/backup';
$ scp -r /oradata01/backup xxx.xxx.xxx.xxx:/oradata01/

6.备库恢复控制文件

$ cd /oradata01/backup
$ rman target /
startup
restore standby controlfile from '/oradata01/backup/DG01/backupset/2019_08_13/o1_mf_ncsnf_TAG20190813T115827_go4fc84x_.bkp';

如果是10g,从主库copy过来一个controlfile,之后用命令穿件

$ scp /oradata01/dg01/control01.ctl xxx.xxx.xxx.xxx:/tmp
rman target /
restore standby controlfile from '/tmpcontrol01.ctl';

7.恢复数据库

查看主库的所有数据文件目录并在备库创建

select distinct substr(file_name,1, instr(file_name,'/',1, length(file_name)-length(replace(file_name,'/','')))) from DBA_DATA_FILES
$ rman target /
alter database mount;
restore database;
recover database until sequence 7;
# 这里的7是主库产生的最新一个归档,执行之后,会报出恢复需要的归档,把这些归档scp过来,继续执行上面的命令即

8.主库新建配置tnsnames.ora并scp至备库

可以使用netmgr图形化来配置

scp tnsnames.ora xxx.xxx.xxx.xxx:/oracle/11204/network/admin/

9.将主库的listener.ora传至备库并修改

$ scp listener.ora xxx.xxx.xxx.xxx:/oracle/11204/network/admin

10.将主库的密码文件传至备库

$ scp orapwdg01 xxx.xxx.xxx.xxx:/oracle/11204/dbs/

11.修改主备库的参数文件

主庫:
alter database force logging;
alter system set db_unique_name='dg01' scope=spfile;
alter system set log_archive_config='dg_config=(dg01,standby_dg01)' scope=both;
alter system set log_archive_dest_1='LOCATION=/archlog/dg01 valid_for=(all_logfiles,all_roles) db_unique_name=dg01';
alter system set log_archive_dest_2='service=standby_dg01 async valid_for=(online_logfiles, primary_role) db_unique_name=standby_dg01';
alter system set log_archive_dest_state_1=enable scope=both;
alter system set log_archive_dest_state_2=enable scope=both;
alter system set fal_client=dg01 scope=both;
alter system set fal_server=standby_dg01 scope=both;
alter system set log_archive_max_processes=30;
alter system set standby_file_management=auto scope=both; --主備庫都要更改,防止切換
備庫:
    alter database force logging;
    alter system set db_unique_name='standby_dg01' scope=spfile;
    alter system set log_archive_config='dg_config=(dg01,standby_dg01)' scope=both;
    alter system set log_archive_dest_1='LOCATION=/archlog/dg01  valid_for=(all_logfiles,all_roles) db_unique_name=standby_dg01';
   # 这里报错
# ERROR at line 1:
# ORA-02097: parameter cannot be modified because specified value is invalid
# ORA-16053: DB_UNIQUE_NAME standby_dg01 is not in the Data Guard Configuration
# 原因是db_unique_name没有生效,重启数据库后就可以了
    alter system set log_archive_dest_2='service=dg01 async valid_for=(online_logfiles, primary_role) db_unique_name=dg01';
    alter system set log_archive_dest_state_1=enable scope=both;
    alter system set log_archive_dest_state_2=enable scope=both;
    alter system set fal_client=standby_dg01 scope=both;
    alter system set fal_server=dg01 scope=both;
    alter system set log_archive_max_processes=30;
    alter system set standby_file_management=auto scope=both

12.重启备库

shutdown immediate;
startup nomount;
alter database mount standby database;
alter database open read only;
alter database recover managed standby database disconnect;

13.测试

--主库
create table test01(id number);
alter system switch logfile;
--备库查看是否有test01表

14.备库redo没有创建处理方法

修改参数

alter system set log_file_name_convert = '/oradata01/dg01','/oradata01/dg01' scope=spfile;
shutdown immediate;
startup;
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT='MANUAL';
alter database clear logfile group 1;
alter database drop logfile group 1;
$ rm -f redo01.log
alter database add logfile group 1 ('/oradata01/dg01/redo01.log') SIZE 50M;
--如果redo是current状态,主库切换日志即可

创建完redo后修改回参数

create pfile from spfile;

修改参数文件,删除log_file_name_convert 参数并修改STANDBY_FILE_MANAGEMENT为auto

create spfile from pfile;

startup nomount;

alter database mount standby database;

alter database open read only;

alter databse recover managed standby database disconnect;

最新文章

  1. PHP玩转微信公众平台自定义接口
  2. UWP Composition API - PullToRefresh
  3. yum提示This system is not registered with RHN.RHN support will be disabled.
  4. 深入理解PHP内核(二)概览-PHP生命周期与Zend引擎
  5. CodeDom
  6. Flex调用java webservice
  7. K近邻分类算法实现 in Python
  8. CentOS 6.4下编译安装 gcc-4.8.0(转)
  9. ASP.NET API盘点
  10. server2008服务器iis设置的一些经验
  11. Java之网络请求工具类(依赖:org.apache.http;注:HttpClient 4.4,HttpCore 4.4)
  12. Alyona and copybooks
  13. JavaScript高级程序设计---学习笔记(三)
  14. 使用Socket对序列化数据进行传输(基于C#)
  15. WIN10怎么安装SQL server2000数据库
  16. Go中的iota
  17. react-redux性能优化之reselect
  18. Linux 查看磁盘或文件夹及文件大小
  19. Jmeter(二十三)Jmeter-Question之“批量造数据”
  20. Zookeeper简介及单机、集群模式搭建

热门文章

  1. DRF框架笔记
  2. CSRF学习
  3. 作为Java新手,如何才能快速的看透一个Java项目?
  4. Tensorflow Windows安装
  5. HTC Vive使用WebVR的方法以及启用后头显无画面的解决方法
  6. C# 中国日历 农历 阳历 星座 二十四节气 二十八星宿 节日 天干地支
  7. html怎么在网页标题栏上添加图标
  8. webform中Repeater中调用后台方法
  9. winform 跨线程 调用控件
  10. (十三)、向shell脚本中传参