zoukankan      html  css  js  c++  java
  • oracle dataguard搭建

    搭建前环境准备

    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;

  • 相关阅读:
    js正则表达式
    js遍历对象属性
    C# 带Cookies发送请求
    C# Cookies设置和读取
    C# ref 和 out 的使用
    jq 禁用复选框 和输入框
    C++学习之嵌套类和局部类
    C++学习之this指针
    C++学习之运算符重载的总结
    Labview中引用,属性节点,局部变量之间的区别
  • 原文地址:https://www.cnblogs.com/monkey6/p/11345522.html
Copyright © 2011-2022 走看看