萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> oracle教程 >> oracle 11gR2 物理備用數據庫搭建及切換

oracle 11gR2 物理備用數據庫搭建及切換

  在同一台機器上搭建物理備用數據庫的步驟,linux環境 oracle 11.2.0.1

  主庫:orcl

  備庫:stby

  1 檢查偵聽是否啟動

  2 配置主備數據庫的初始化參數文件

  sqlplus "/as sysdba"

  create pfile='/home/oracle/initprim.ora' from spfile;

  cp /home/oracle/initprim.ora /home/oracle/initstby.ora

  vi /home/oracle/initprim.ora

  orcl.__db_cache_size=104857600

  orcl.__java_pool_size=4194304

  orcl.__large_pool_size=4194304

  orcl.__oracle_base='/oracle'#ORACLE_BASE set from environment

  orcl.__pga_aggregate_target=155189248

  orcl.__sga_target=268435456

  orcl.__shared_io_pool_size=0

  orcl.__shared_pool_size=142606336

  orcl.__streams_pool_size=4194304

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

  *.audit_trail='db'

  *.compatible='11.2.0.0.0'

  *.control_files='/oradata/orcl/control01.ctl','/oradata/flash_recovery_area/orcl/control02.ctl'

  *.db_block_size=8192

  *.db_domain=''

  *.db_name='orcl'

  *.db_recovery_file_dest='/oradata/flash_recovery_area'

  *.db_recovery_file_dest_size=4039114752

  *.diagnostic_dest='/oracle'

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

  *.memory_target=422576128

  *.open_cursors=300

  *.processes=150

  *.remote_login_passwordfile='EXCLUSIVE'

  *.undo_tablespace='UNDOTBS1'

  *.fal_client='prim'

  *.fal_server='stby'

  *.standby_file_management=auto

  *.log_archive_dest_1='location=/oradata/arch/orcl valid_for=(all_logfiles,all_roles) db_unique_name=prim'

  *.log_archive_dest_2='service=stby valid_for=(online_logfiles,primary_role) db_unique_name=stby'

  *.DB_UNIQUE_NAME=prim

  *.log_archive_config='dg_config=(prim,stby)'

  編輯備庫的參數文件

  vi /home/oracle/initstby.ora

  stby.__db_cache_size=104857600

  stby.__java_pool_size=4194304

  stby.__large_pool_size=4194304

  stby.__oracle_base='/oracle'#ORACLE_BASE set from environment

  stby.__pga_aggregate_target=155189248

  stby.__sga_target=268435456

  stby.__shared_io_pool_size=0

  stby.__shared_pool_size=142606336

  stby.__streams_pool_size=4194304

  *.audit_file_dest='/oracle/admin/stby/adump'

  *.audit_trail='db'

  *.compatible='11.2.0.0.0'

  *.control_files='/oradata/stby/control01.ctl','/oradata/flash_recovery_area/stby/control02.ctl'

  *.db_block_size=8192

  *.db_domain=''

  *.db_name='orcl' #<-- 在同一台機器上搭建dg 要與主庫的一樣 否則ora-01103

  *.db_recovery_file_dest='/oradata/flash_recovery_area'

  *.db_recovery_file_dest_size=4039114752

  *.diagnostic_dest='/oracle'

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

  *.memory_target=622576128

  *.open_cursors=300

  *.processes=150

  *.remote_login_passwordfile='EXCLUSIVE'

  *.undo_tablespace='UNDOTBS1'

  *.DB_FILE_NAME_CONVERT='/oradata/orcl','/oradata/stby'

  *.LOG_FILE_NAME_CONVERT='/oradata/orcl','/oradata/stby'

  *.fal_client='stby'

  *.fal_server='prim'

  *.standby_file_management=auto

  *.log_archive_dest_1='location=/oradata/arch/stby valid_for=(all_logfiles,all_roles) db_unique_name=stby'

  *.log_archive_dest_2='service=prim valid_for=(online_logfiles,primary_role) db_unique_name=prim'

  *.DB_UNIQUE_NAME='stby'

  *.log_archive_config='dg_config=(prim,stby)'

  備份主庫

  rman target /

  backup database format '/u01/oradata/dbfull%U';

  創建備庫控制文件

  export ORACLE_SID=orcl

  sqlplus "/as sysdba"

  alter database create standby controlfile as '/oradata/stby/stbycontrol.ctl';

  cp /oradata/stby/stbycontrol.ctl /oradata/stby/control01.ctl

  cp /oradata/stby/stbycontrol.ctl /oradata/flash_recovery_area/stby/control02.ctl

  處理備庫

  export ORACLE_SID=stby

  orapwd file=/oracle/product/11.2.0/db_1/dbs/orapwstby password=oracle entries=5 ignorecase=y #一定要加ignorecase=y 要不然歸檔傳不到備用庫上

  sqlplus "/as sysdba"

  startup nomount

  alter database mount;

  rman target /

  restore database;

  重啟主庫

  export ORACLE_SID=orcl

  sqlplus "/as sysdba"

  shutdown immediate

  startup pfile='/home/oracle/initprim.ora'

  配置tnsnames.ora(因為在同一台機器上,所以就改這一個文件)

  orcl =

  (DESCRIPTION =

  (ADDRESS_LIST =

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

  )

  (CONNECT_DATA =

  (SID = orcl)

  (SERVER = DEDICATED)

  )

  )

  stby =

  (DESCRIPTION =

  (ADDRESS_LIST =

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

  )

  (CONNECT_DATA =

  (SID = stby)

  (SERVER = DEDICATED)

  )

  )

  將備庫置於接收歸檔日志狀態

  export ORACLE_SID=stby

  sqlplus "/as sysdba"

  alter database recover managed standby database disconnect from session;

  過一會兒檢查是否收到日志

  export ORACLE_SID=orcl

  sqlplus "/as sysdba"

  select max(sequence#) from v$archived_log; --查看歸檔日志序列號

  alter system switch logfile;

  alter system switch logfile;

  export ORACLE_SID=stby

  sqlplus "/as sysdba"

  select sequence#,applied from v$archived_log order by 1; --查看歸檔日志序列號

  主備庫角色切換

  角色切換

  步驟1:驗證主庫能否進行角色切換,TO STANDBY表示可以進行

  SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

  SWITCHOVER_STATUS

  -----------------

  TO STANDBY

  步驟2:在主庫上執行角色切換到從庫角色

  SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

  步驟3:關閉並重新啟動之前的主庫實例

  SQL> SHUTDOWN IMMEDIATE

  SQL> STARTUP MOUNT

  步驟4:在備庫的V$DATABASE視圖中查看備庫的切換狀態

  SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

  SWITCHOVER_STATUS

  -----------------

  TO_PRIMARY

  步驟5:切換備庫到主庫角色

  SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

  步驟6:完成備庫到主庫的切換

  1. 如果備庫沒有以只讀模式打開,直接執行以下語句打開到新的主庫。

  SQL> ALTER DATABASE OPEN;

  2. 如果備庫以只讀模式打開,先關閉數據,然後再重新啟動。

  SQL> SHUTDOWN IMMEDIATE;

  SQL> STARTUP;

  步驟7:如果有必要,重新啟動一下新的備庫上的重做日志應用服務

  SQL> alter database recover managed standby database disconnect from session;

  (注:可以通過select message from v$dataguard_status;查看當前備庫應用重做日志的狀態)

  步驟8:開始發送重做數據到備庫上

  Issue the following statement on the new primary database:

  SQL> ALTER SYSTEM SWITCH LOGFILE;

  備注:

  ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE;

  如果有缺失的歸檔日志文件,手工考背後,在備庫上:

  ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';

  FORCE 關鍵詞終止目標物理備數據庫上活動的RFS 進程,使得故障轉移能不用等待網絡連接超時而立即進

copyright © 萬盛學電腦網 all rights reserved