搭建物理备库

Primary db configure:
1. 开启主库强制日志
  查询当前是否强制日志:
  SQL> select force_logging from v$database;
   FOR
  ---
  NO
 
  开启强制日志
  SQL> alter database force logging;
 
  Database altered.
 
  查询
  SQL> select force_logging from v$database;
 
  FOR
  ---
  YES
2. 开启归档模式
  SQL> alter system set log_archive_dest_1=’/oradata/arch’;
 
  System altered.
 
  SQL> alter system set log_archive_format=’arch_%t_%s_%r’ scope=spfile;
 
  System altered.
 
  SQL> shutdown immediate
  
  SQL> startup mount
 
  SQL> alter database archivelog;
 
  SQL> archive log list
  Database log mode Archive Mode
  Automatic archival Enabled
  Archive destination /oradata/arch
  Oldest online log sequence 13
  Next log sequence to archive 15
  Current log sequence 15
3. 创建pfile,设置DG参数
  SQL> create pfile=‘/tmp/pfile‘ from spfile;
 
  File created.
  $ vi /tmp/pfile
  设置以下参数
  *.db_name=‘orcl‘
  *.remote_login_passwordfile=‘EXCLUSIVE‘
  *.db_unique_name=primary
  *.log_archive_config=‘DG_CONFIG=(primary,standby)‘
  *.log_archive_dest_1=‘LOCATION=/oradata/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary‘
  *.log_archive_dest_2=‘SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby‘
  *.log_archive_dest_state_1=enable
  *.log_archive_dest_state_2=enable
  *.log_archive_format=‘arch_%t_%s_%r‘
  *.log_archive_max_processes=30
  *.fal_server=standby
  *.fal_client=primary
  *.standby_file_management=auto
  --db file and log file 在主备库的存储位置不一样,需要加以下参数
  *.db_file_name_convert=‘primary‘,‘standby‘
  *.log_file_name_convert=‘/oradata/orcl‘,‘/oradata/orcl‘
 
  SQL> create spfile from pfile=‘/tmp/pfile‘;
 
  File created.
4. 创建standby logfile,最好在主备库都创建
  1) 确保主和备数据库上的日志文件大小是相同的
  2) 确定备重做日志文件组的适当数目
    Standby logfile数 =(每个线程的日志文件的最大数目+1)×线程最大数目
  3) 检查create database时指定的MAXLOGFILES和MAXLOGMEMBERS参数,可以通过trace controlfile出来查看
  4) 创建standby logfile,rac环境指定线程创建,单机环境group#不重复即可
 
  查看主库的group#,thread#,size
  SQL> col member for a25
  SQL> select a.group#,a.thread#,b.member,a.bytes/1024/1024 MB from v$log a,v$logfile b where a.group#=b.group#;
 
    GROUP#   THREAD#           MEMBER     MB
  ---------- ---------- ------------------------- ----------
       1      1 /oradata/orcl/redo01.log      50
       2      1 /oradata/orcl/redo02.log      50
       3      1 /oradata/orcl/redo03.log      50
 
  主库添加standby logfile
  SQL> alter database add logfile group 4 ‘/oradata/orcl/standby04.log‘ size 50M,group 5 ‘/oradata/orcl/standby05.log‘ size 50M,

    group 6 ‘/oradata/orcl/standby06.log‘ size 50M,group 7 ‘/oradata/orcl/standby07.log‘ size 50M;
5. 主库创建监听文件,密码文件,网络服务名
  1)监听文件(listener.ora)
  $ vi $ORACLE_HOME/network/admin/listener.ora
  LISTENER =
    (ADDRESS_LIST=
    (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.100)(PORT=1521))
    (ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY))
    )
 
  SID_LIST_LISTENER=
    (SID_LIST=
    (SID_DESC=
     (GLOBAL_DBNAME=orcl)
     (SID_NAME=orcl)
      (ORACLE_HOME=/oracle/app/oracle/product/11.2.0/db_1)
      (PRESPAWN_MAX=20)
      (PRESPAWN_LIST=
       (PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1))
      )
     )
    )
  2) 网络服务名(tnsnames.ora)
  $ vi $ORACLE_HOME/network/admin/tnsnames.ora
  PRIMARY =
   (DESCRIPTION =
    (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.100)(PORT = 1521))
      )
    (CONNECT_DATA =
     (SERVICE_NAME = orcl)
     )
    )
 
  STANDBY =
    (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
     )
    (CONNECT_DATA =
     (SERVICE_NAME = orcl)
    )
  3) 密码文件
  $ cd $ORACLE_HOME/dbs
  $ orapwd file=orapworcl password=oracle
  4) 如果是在windows平台,则需要通过oradim工具创建一个基于windows的服务
  oradim -NEW -SID orcl -INTPWD oracle -STARTMODE manual
 
  启动监听
  $ lsnrctl start
6. rman 备份主库
  我是在修改完DG参数后做了次全备,此时delete input参数不能删除archivelog,所以加了force强制删除archivelog,在修改DG参数前备份则不需要加force 就可以删除archivelog
  $ rman target / log=/oradata/bak/rman.log
  RMAN> run
  {allocate channel c1 type disk;
  allocate channel c2 type disk;
  backup filesperset 2 database format ‘/oradata/bak/full_%d_%T_%s_%p‘;
  sql ‘alter system archive log current‘;
  backup archivelog all format ‘/oradata/bak/arch_%d_%T_%s_p‘ delete input force;
  backup current controlfile for standby format ‘/oradata/bak/c_%d_%T_s_%p‘;
  }

standby db configure:
1. 创建备库参数文件
  拷贝主库pfile过来,修改以下参数设置
  $ scp primary:/tmp/pfile /tmp
  $ vi /tmp/pfile
  *.db_name=‘orcl‘
  *.remote_login_passwordfile=‘EXCLUSIVE‘
  *.db_unique_name=standby
  *.log_archive_config=‘DG_CONFIG=(primary,standby)‘
  *.log_archive_dest_1=‘LOCATION=/oradata/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby‘
  *.log_archive_dest_2=‘SERVICE=primary LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary‘
  *.log_archive_dest_state_1=enable
  *.log_archive_dest_state_2=enable
  *.log_archive_format=‘arch_%t_%s_%r‘
  *.log_archive_max_processes=30
  *.fal_server=primary
  *.fal_client=standby
  *.standby_file_management=auto
  --db file and log file 在主备库的存储位置不一样,需要加以下参数
  *.db_file_name_convert=‘primary‘,‘standby‘
  *.log_file_name_convert=‘/oradata/orcl‘,‘/oradata/orcl‘
2. 创建备库监听文件,密码文件,网络服务名
  1)监听文件(listener.ora)
  $ vi $ORACLE_HOME/network/admin/listener.ora
  LISTENER =
    (ADDRESS_LIST=
    (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.101)(PORT=1521))
    (ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY))
    ) 
 
  SID_LIST_LISTENER=
    (SID_LIST=
    (SID_DESC=
     (GLOBAL_DBNAME=orcl)
     (SID_NAME=orcl) 
      (ORACLE_HOME=/oracle/app/oracle/product/11.2.0/db_1)
      (PRESPAWN_MAX=20)
      (PRESPAWN_LIST=
       (PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1))
      )
     )
    )
  2) 网络服务名(tnsnames.ora)
  $ vi $ORACLE_HOME/network/admin/tnsnames.ora
  PRIMARY =
   (DESCRIPTION =
    (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.100)(PORT = 1521))
      )
    (CONNECT_DATA =
     (SERVICE_NAME = orcl)
     )
    )
 
  STANDBY =
    (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
     )
    (CONNECT_DATA =
     (SERVICE_NAME = orcl)
    ) 
  3) 密码文件
  $ cd $ORACLE_HOME/dbs
  $ orapwd file=orapworcl password=oracle
  4) 如果是在windows平台,则需要通过oradim工具创建一个基于windows的服务
  oradim -NEW -SID orcl -INTPWD oracle -STARTMODE manual
 
  启动监听
  $ lsnrctl start
3. 把主库备份集传到备库上
  为方便起见,备库使用与主库同样的目录,可以使用NFS挂载,我的测试库比较下,就用scp了
  $ cd /oradata/bak
  $ ll
  $ ll /oradata/bak/
  total 280208
  -rw-r----- 1 oracle oinstall 512512 Sep 28 16:50 arch_ORCL_20140928_42_p
  -rw-r----- 1 oracle oinstall 45056 Sep 28 16:50 arch_ORCL_20140928_43_p
  -rw-r----- 1 oracle oinstall 2560 Sep 28 16:50 arch_ORCL_20140928_44_p
  -rw-r----- 1 oracle oinstall 9895936 Sep 28 16:50 c_ORCL_20140928_s_1
  -rw-r----- 1 oracle oinstall 208125952 Sep 28 16:50 full_ORCL_20140928_38_1
  -rw-r----- 1 oracle oinstall 58040320 Sep 28 16:50 full_ORCL_20140928_39_1
  -rw-r----- 1 oracle oinstall 9895936 Sep 28 16:50 full_ORCL_20140928_40_1
  -rw-r----- 1 oracle oinstall 98304 Sep 28 16:50 full_ORCL_20140928_41_1
  $ scp * standby:/oradata/bak
  arch_ORCL_20140928_42_p 100% 501KB 500.5KB/s 00:00
  arch_ORCL_20140928_43_p 100% 44KB 44.0KB/s 00:00
  arch_ORCL_20140928_44_p 100% 2560 2.5KB/s 00:00
  c_ORCL_20140928_s_1 100% 9664KB 9.4MB/s 00:01
  full_ORCL_20140928_38_1 100% 198MB 22.1MB/s 00:09
  full_ORCL_20140928_39_1 100% 55MB 13.8MB/s 00:04
  full_ORCL_20140928_40_1 100% 9664KB 9.4MB/s 00:00
  full_ORCL_20140928_41_1 100% 96KB 96.0KB/s 00:00
 
4. 还原备库控制文件
  SQL> create spfile from pfile=‘/tmp/pfile‘;
 
  File created.
 
  SQL> startup nomount
  
  RMAN> restore standby controlfile from ‘/oradata/bak/c_ORCL_20140928_s_1‘;

5. 启动备库到mount,还原备库,恢复备库到指定的序列号的归档
  RMAN> sql ‘alter database mount standby database‘;

  RMAN> restore database;
 
  查看当前备份集里的最大归档序列号
  RMAN> list backup of archivelog all;
 
 
  List of Backup Sets
  ===================
  BS Key Size Device Type Elapsed Time Completion Time
  ------- ---------- ----------- ------------ ---------------
  38 500.00K DISK 00:00:00 28-SEP-14
  BP Key: 38 Status: AVAILABLE Compressed: NO Tag: TAG20140928T164416
  Piece Name: /oradata/bak/arch_ORCL_20140928_42_p
 
  List of Archived Logs in backup set 38
  Thrd Seq Low SCN Low Time Next SCN Next Time
  ---- ------- ---------- --------- ---------- ---------
  1 43 253551 28-SEP-14 254459 28-SEP-14
 
  BS Key Size Device Type Elapsed Time Completion Time
  ------- ---------- ----------- ------------ ---------------
  39 43.50K DISK 00:00:00 28-SEP-14
  BP Key: 39 Status: AVAILABLE Compressed: NO Tag: TAG20140928T164416
  Piece Name: /oradata/bak/arch_ORCL_20140928_43_p
 
  List of Archived Logs in backup set 39
  Thrd Seq Low SCN Low Time Next SCN Next Time
  ---- ------- ---------- --------- ---------- ---------
  1 44 254459 28-SEP-14 254465 28-SEP-14
  1 45 254465 28-SEP-14 254469 28-SEP-14
  1 46 254469 28-SEP-14 254603 28-SEP-14
 
  BS Key Size Device Type Elapsed Time Completion Time
  ------- ---------- ----------- ------------ ---------------
  40 2.00K DISK 00:00:00 28-SEP-14
  BP Key: 40 Status: AVAILABLE Compressed: NO Tag: TAG20140928T164416
  Piece Name: /oradata/bak/arch_ORCL_20140928_44_p
 
  List of Archived Logs in backup set 40
  Thrd Seq Low SCN Low Time Next SCN Next Time
  ---- ------- ---------- --------- ---------- ---------
  1 47 254603 28-SEP-14 254611 28-SEP-14
 
  最大归档序列号为47,指定归档序列号,恢复备库,也可以不指定,则在应用完备份集里最后一组归档时,会报错找不到下一个归档,实际上已经恢复完成,因为备份集本来就没有下一个归档
 
  RMAN> recover database until sequence 48;
 
6. 打开备库至恢复模式,开始应用归档
  SQL> alter database recover managed standby database disconnect from session;
 
  Database altered.
 
测试:
  主库切一次归档,查看备库应用情况
 
  primary:
  SQL> alter system switch logfile;
 
  System altered.
  SQL> select max(sequence#) from v$archived_log;
 
  MAX(SEQUENCE#)
  --------------
  49
  standby:
  SQL> select max(sequence#) from v$archived_log;
 
  MAX(SEQUENCE#)
  --------------
  49

时间: 2024-10-08 09:29:40

搭建物理备库的相关文章

DG搭建物理备库

搭建过程难免会出现各种错误,所以之前最好做一个备份!!! service iptables stop 关闭防火墙 [[email protected] ~]# setenforce 0 [[email protected] ~]# getenforce Permissive 主库 [[email protected] ~]# su - oracle [[email protected] ~]$ db11g [[email protected] ~]$ sqlplus / as sysdba SQ

搭建逻辑备库

1. 搭建物理备库 2. 在物理备库上停止重做应用,如果备库是RAC,则必须停止所有执行以下语句以外的实例 SQL> alter database recover managed standby database cancel; Database altered. 3. 为角色转换准备主库 这一步仅在执行切换时有用 修改初始化参数: alter system set LOG_ARCHIVE_DEST_1='LOCATION=/oradata/arch/ VALID_FOR=(ONLINE_LOG

oracle11g dataguard物理备库搭建

Dataguard 环境: 操作系统:Redhat6.4 Primary数据库: IP 地址:192.168.1.122 数据库SID:ora11g DB_UNIQUE_NAME:ora11g_primary Standby数据库: IP 地址:192.168.1.123 数据库SID:ora11g DB_UNIQUE_NAME:ora11g_standby (注:oracle数据库版本是11.2.0.1.0) 1.Primary端的配置 (1).检查数据库是否支持 Data Guard(企业版

DG搭建逻辑备库

逻辑备库是在物理备库的基础上搭建的,所以需要先搭建好物理备库. 备库执行如下操作: [[email protected] ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production onFri Nov 7 15:03:30 2014 Copyright (c) 1982, 2011, Oracle.  All rights reserved. Connected to: Oracle Database 11g Enterpris

Oracle 11g Data Guard 物理备库快速配置指南(上)

缘起 最近做了10g和11g的物理备库配置实验,发现 Data Guard 其实很容易,但是缺少好文档.我是参考官方文档做的实验,觉得它写的不是很清楚的. Google 出来两个pdf文档,读了觉得比官方文档强很多.翻译下,也许会对某些朋友有用.翻译的同时我也好更熟悉下这两个文档.好久没翻译过英文了,可以顺便练练手. 原文档下载地址(墙外): Configure Dataguard 11gR2 Physical Standby Part 1 Configure Dataguard 11gR2 P

Dataguard搭建灾备库操作手册

数据库:Oracle11gr2 主库 alter database force logging; alter system set db_unique_name='erpdb' scope=spfile;  --我们让主库db_name=db_unique_name alter system set REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE scope=spfile; alter system set LOG_ARCHIVE_FORMAT='%t_%s_%r.arc

DG之主库、备库切换(物理备库)

DG之主库.备库切换 一.开库与关库顺序 开库顺序 先启备库,再启主库(启动监听.打开告警日志) 关库顺序 先关主库,再关备库 二.主备库切换 1.操作过程一览 步骤1:启动备库.监听.告警: 步骤2:启动主库.监听.告警: 步骤3:主库(bj)查询信息 SQL>selectname,dbid,database_role,protection_mode from v$database; 步骤4:备库(sh)上做recover SQL>recovermanaged standby databas

Oracle 11g Data Guard 之物理备库角色转换

一.物理备库的Switchover操作 本节主要内容是物理备库的switchover操作,该操作起始于主库,结束于目标备库. 1.确认主库可以切换为standby角色 SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE; 如果结果显示TO STANDBY或者SESSIONS ACTIVE,则表明主库可以切换为standby角色,否则,切换操作将不可行,因为redo传输不是配置错误就是不能正常进行. 2.主库启动switchover 执行如下SQL语句将主库

Oracle 11g Dataguard 暂停物理备库的日志传输

Oracle 11g Dataguard 暂停物理备库的日志传输分类: Oracle2017-07-18 10:03:17这两天生产端的日志产生过多导致灾备端的归档日志目录满的现象,在清除灾备端的日志后发现log_archive_dest_2处于error状态,需要将其enable.在实际生产系统中,通常有这样的场景,例如在系统维护日,对主库进行大量的业务更新,会有大量的DML操作:为了避免主库中的业务更新对备库造成影响,可以暂停主库对备库的日志传输,这样的话,如果主库的更新出现问题,备库还保留