熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

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

2022-06-13   來源: Oracle 

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

  主庫orcl

  備庫stby

   檢查偵聽是否啟動

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

  sqlplus "/as sysdba"

  create pfile=/home/oracle/initprimora from spfile;

  cp /home/oracle/initprimora /home/oracle/initstbyora

  vi /home/oracle/initprimora

  orcl__db_cache_size=

  orcl__java_pool_size=

  orcl__large_pool_size=

  orcl__oracle_base=/oracle#ORACLE_BASE set from environment

  orcl__pga_aggregate_target=

  orcl__sga_target=

  orcl__shared_io_pool_size=

  orcl__shared_pool_size=

  orcl__streams_pool_size=

  *audit_file_dest=/oracle/admin/orcl/adump

  *audit_trail=db

  *compatible=

  *control_files=/oradata/orcl/controlctl/oradata/flash_recovery_area/orcl/controlctl

  *db_block_size=

  *db_domain=

  *db_name=orcl

  *db_recovery_file_dest=/oradata/flash_recovery_area

  *db_recovery_file_dest_size=

  *diagnostic_dest=/oracle

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

  *memory_target=

  *open_cursors=

  *processes=

  *remote_login_passwordfile=EXCLUSIVE

  *undo_tablespace=UNDOTBS

  *fal_client=prim

  *fal_server=stby

  *standby_file_management=auto

  *log_archive_dest_=location=/oradata/arch/orcl valid_for=(all_logfilesall_roles) db_unique_name=prim

  *log_archive_dest_=service=stby valid_for=(online_logfilesprimary_role) db_unique_name=stby

  *DB_UNIQUE_NAME=prim

  *log_archive_config=dg_config=(primstby)

  編輯備庫的參數文件

  vi /home/oracle/initstbyora

  stby__db_cache_size=

  stby__java_pool_size=

  stby__large_pool_size=

  stby__oracle_base=/oracle#ORACLE_BASE set from environment

  stby__pga_aggregate_target=

  stby__sga_target=

  stby__shared_io_pool_size=

  stby__shared_pool_size=

  stby__streams_pool_size=

  *audit_file_dest=/oracle/admin/stby/adump

  *audit_trail=db

  *compatible=

  *control_files=/oradata/stby/controlctl/oradata/flash_recovery_area/stby/controlctl

  *db_block_size=

  *db_domain=

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

  *db_recovery_file_dest=/oradata/flash_recovery_area

  *db_recovery_file_dest_size=

  *diagnostic_dest=/oracle

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

  *memory_target=

  *open_cursors=

  *processes=

  *remote_login_passwordfile=EXCLUSIVE

  *undo_tablespace=UNDOTBS

  *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_=location=/oradata/arch/stby valid_for=(all_logfilesall_roles) db_unique_name=stby

  *log_archive_dest_=service=prim valid_for=(online_logfilesprimary_role) db_unique_name=prim

  *DB_UNIQUE_NAME=stby

  *log_archive_config=dg_config=(primstby)

  備份主庫

  rman target /

  backup database format /u/oradata/dbfull%U;

  創建備庫控制文件

  export ORACLE_SID=orcl

  sqlplus "/as sysdba"

  alter database create standby controlfile as /oradata/stby/stbycontrolctl;

  cp /oradata/stby/stbycontrolctl /oradata/stby/controlctl

  cp /oradata/stby/stbycontrolctl /oradata/flash_recovery_area/stby/controlctl

  處理備庫

  export ORACLE_SID=stby

  orapwd file=/oracle/product//db_/dbs/orapwstby password=oracle entries= 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/initprimora

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

  orcl =

  (DESCRIPTION =

  (ADDRESS_LIST =

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

  )

  (CONNECT_DATA =

  (SID = orcl)

  (SERVER = DEDICATED)

  )

  )

  stby =

  (DESCRIPTION =

  (ADDRESS_LIST =

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

  )

  (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 ; 查看歸檔日志序列號

  主備庫角色切換

  角色切換

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

  SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

  SWITCHOVER_STATUS

  

  TO STANDBY

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

  SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

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

  SQL> SHUTDOWN IMMEDIATE

  SQL> STARTUP MOUNT

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

  SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

  SWITCHOVER_STATUS

  

  TO_PRIMARY

  步驟切換備庫到主庫角色

  SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

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

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

  SQL> ALTER DATABASE OPEN;

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

  SQL> SHUTDOWN IMMEDIATE;

  SQL> STARTUP;

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

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

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

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

  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 filespec;

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

  ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;


From:http://tw.wingwit.com/Article/program/Oracle/201311/19074.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.