2台数据库,主库安装时需要建库;备库不需要,只安装oracle软件即可。


Hosts文件: 主备地址及名称都指定上


主物理库:

Listener 文件

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/db_1/network/admin/listener.ora

# Generated by Oracle configuration tools.


SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

     # (GLOBAL_DBNAME = orcl)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/db_1)

      (SID_NAME = DB11G)

    )

   # (SID_DESC =

    #  (GLOBAL_DBNAME = orcl)

     # (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/db_1)

     # (SID_NAME = DB11G_STBY)

    #)

  )


LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG2)(PORT = 1521))

    )

  )


ADR_BASE_LISTENER = /u01/app/oracle


Tnsnames文件:

# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.


ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG2)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = DB11G)

    )

  )


DB11G =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG2)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = DB11G)

    )

  )


DB11G_STBY =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG1)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = DB11G_STBY)

    )

  )


nomount参数修正:

#unique_name主备必须不一致。DB_NAME必须一致

alter system set db_unique_name=DB11G scope=spfile;

alter system set log_archive_config='DG_CONFIG=(DB11G,DB11G_stby)' scope=spfile;


#dest_1表示本库

alter system set log_archive_dest_1= 'LOCATION=/u01/app/oracle/archives VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DB11G’ scope=spfile;

#dest_2表示远程库。Lgwr配置adg实施模式,另一种方式是arch,两者差异是否有无lng实时传输服务。sync同步,还有async异步。affirm 代表提交事务时,需要redo日志磁盘必须写完,还有noaffirm,代表不需要等到redo日志写完。

alter system set log_archive_dest_2= 'SERVICE=DB11G_STBY LGWE SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB11G_STBY' scope=spfile;

alter system set log_archive_dest_state_1=ENABLE  scope=spfile;

alter system set log_archive_dest_state_2=ENABLE  scope=spfile;

alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;

#归档最大线程数

alter system set log_archive_max_processes=4  scope=spfile;

alter system set remote_login_passwordfile=exclusive scope=spfile;


#server为远程DB,client为本地DB

alter system set fal_server=DB11G_STBY  scope=spfile;

alter system set fal_client=DB11G  scope=spfile;


alter system set standby_file_management=auto scope=spfile;


#路径转换:将远程db/log文件路径匹配到本地。前远程后本地

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'



上述命令修改后initDB11G.ora配置文件如:

DB11G.__db_cache_size=620756992

DB11G.__java_pool_size=16777216

DB11G.__large_pool_size=83886080

DB11G.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

DB11G.__pga_aggregate_target=687865856

DB11G.__sga_target=973078528

DB11G.__shared_io_pool_size=0

DB11G.__shared_pool_size=234881024

DB11G.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'

*.db_name='orcl'

*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'

*.db_recovery_file_dest_size=4385144832

*.db_unique_name='DB11G'

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=DB11G)'

*.fal_client='DB11G'

*.fal_server='DB11G_STBY'

*.log_archive_config='DG_CONFIG=(DB11G,DB11G_STBY)'

*.log_archive_dest_1='LOCATION=/u01/app/oracle/archives/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES)  DB_UNIQUE_NAME=DB11G'

*.log_archive_dest_2='SERVICE=DB11G_STBY SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB11G_STBY'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='ENABLE'

*.log_archive_format='%t_%s_%r.arc'

*.log_archive_max_processes=4

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'

*.memory_target=1656750080

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.standby_file_management='AUTO'

*.undo_tablespace='UNDOTBS1'


备份控制文件、密码文件到备库

scp initDB11G.ora orapwDB11G oracleDG2:$ORACLE_HOME/dbs

scp -r admin/ diag/ fast_recovery_area/ oradata/ 172.22.8.99:$ORACLE_HOME


注:密码文件重设orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=2 force=y



手动备份数据库

$ rman target=/

RMAN> backup database plus archivelog;

alter database create standby controlfile as '/tmp/orcl_stby.ctl';

create pfile='/tmp/initORCL_stby.ora' from spfile;


添加归档日志

alter database add standby logfile group 21 '/u01/app/oracle/oradata/orcl/standby21.log' size 50M;

alter database add standby logfile group 22 '/u01/app/oracle/oradata/orcl/standby22.log' size 50M;

alter database add standby logfile group 23 '/u01/app/oracle/oradata/orcl/standby23.log' size 50M;



备物理库:

listener.ora文件

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      #(GLOBAL_DBNAME = orcl)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/db_1)

      (SID_NAME = DB11G)

    )

    (SID_DESC =

     # (GLOBAL_DBNAME = orcl)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/db_1)

      (SID_NAME = DB11G_STBY)

    )

  )


LISTENER =

 (DESCRIPTION_LIST =

   (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG1)(PORT = 1521))

    )

  )


ADR_BASE_LISTENER = /u01/app/oracle


tnsnames.ora文件

ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG1)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = DB11G_STBY)

    )

  )


DB11G =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG2)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = DB11G)

    )

  )


DB11G_STBY =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = oracleDG1)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = DB11G_STBY)

    )

  )


nomount参数修正

alter system set db_unique_name=DB11G_STBY scope=spfile;

alter system set log_archive_config= 'DG_CONFIG=(DB11G,DB11G_STBY)'  scope=spfile;


alter system set log_archive_dest_1= 'LOCATION=/u01/app/oracle/fast_recovery_area VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DB11G_STBY' scope=spfile;

alter system set log_archive_dest_2= 'SERVICE=DB11G_STBY LGWE SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl' scope=spfile;

alter system set log_archive_dest_state_1=ENABLE;

alter system set log_archive_dest_state_2=ENABLE;



alter system set fal_server=DB11G  scope=spfile;

alter system set fal_client=DB11G_STBY scope=spfile;


上述命令修改后initDB11G.ora配置文件如:

DB11G.__db_cache_size=671088640

DB11G.__java_pool_size=16777216

DB11G.__large_pool_size=33554432

DB11G.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

DB11G_STBY.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

DB11G.__pga_aggregate_target=687865856

DB11G.__sga_target=973078528

DB11G.__shared_io_pool_size=0

DB11G.__shared_pool_size=234881024

DB11G.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='orcl'

*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'

*.db_recovery_file_dest_size=4385144832

*.db_unique_name='DB11G_STBY'

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'

*.fal_server='DB11G'

*.fal_client='DB11G_STBY'

*.log_archive_config='DG_CONFIG=(DB11G,DB11G_STBY)'

*.log_archive_dest_1='LOCATION=/u01/app/oracle/fast_recovery_area/archives/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DB11G_STBY'

*.log_archive_dest_2='SERVICE=DB11G SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB11G'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='ENABLE'

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'

*.log_archive_format='%t_%s_%r.arc'

*.log_archive_max_processes=4

*.memory_target=1656750080

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.standby_file_management='AUTO'

*.undo_tablespace='UNDOTBS1'



主open database,备nomount


主执行RMAN命令复制

#nofilenamecheck,检查到文件名称重复时不会中断。

rman target sys/oracle@DB11G auxiliary sys/oracle@DB11G_STBY nocatalog

duplicate target database for standby from active database nofilenamecheck;


查询备份log文件号

SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM V$STANDBY_LOG;


备开启实时日志应用

SQL> recover managed standby database using current logfile disconnect from session;


主:

Archive log list;

Alter system switch logfile;


主备:

Archive log list;

查DG进程:

select process,client_process,sequence#,status from v$managed_standby;

select * from v$dataguard_status;



查看DB保护模式

select database_role,protection_mode,protection_level,open_mode from v$database;


DG模式切换:(备在切换保护模式时,需将DB 置为mount状态才能成功)

alter database set standby database to maximize performance/ maximize protection / maximize availability ;


ADG切换:

Alter database commit to switchover to physical standby;

Shutdown immediate

Startup

Alter database recover managed standby database disconnect from session;

Select database_role,open_mode,switchover_status from v$database;


Alter database commit to switchover to physical primary;

Shutdown immediate

Startup

Alter system switch logfile;

Select database_role,open_mode,switchover_status from v$database;


ADG fail over切换

备   Select database_role,open_mode,switchover_status from v$database;

主直接  shutdown abort


Startup mount

Alter systemflush redo to ‘DB11G’;

Select thread#, low_sequence#, high_sequence# from v$archive_gap;    如果没有gap,说明无数据损失。在备端进行关闭apply和结束应用动作

Alter database recover managed standby database cancel;

Alter database recover managed standby database finish;

Select database_role,open_mode,switchover_status from v$database;