*此處安裝ORACLE DATAGUARD是利用ORACLE RMAN DUPLICATE方式安裝。
*能夠搭建好ORACLE DG再來impdp生產數據,也能夠先導入主庫數據再來作DG
*注意看下面的配置文件,此處LISTENER TNSNAMES裏的SID_NAME我都是用的db_name的ora,沒有測試其它的
*TNSNAMES的起名orcl_pd orcl_sd我都用用和db_unique_name同樣的java
*版本CENTOS6.5 ORACLE11.2.0.4sql
一、兩臺服務器上分別安裝數據庫軟件,只安裝軟件不安裝實例,爲了減小複雜度,全部目錄都同樣
安裝請參考其餘文檔
二、在主庫上安裝數據庫實例ORA
DBCA安裝
修改日誌文件大小
內存分配好
三、在主庫上建立與舊庫同樣的用戶名錶空間數據庫
create tablespace ekp datafile '/u01/app/oracle/oradata/ora/ora01.dbf' size 10240M autoextend on next 512M extent management local; create temporary tablespace ora_temp tempfile'/u01/app/oracle/oradata/ora/ora_temp.dbf' size 10240m autoextend on next 512m extent management local; create user ora identified by abcABC123 default tablespace ekp temporary tablespace ora_temp; grant connect,resource,dba to ora;
四、中止應用,到舊庫上導出用戶數據服務器
expdp ora/abcABC123 DIRECTORY=oa_databackup dumpfile=oadb1010.dmp logfile=oadbf111.log schemas=ora compression=all
五、把備份文件拷貝到主庫上,建立directory,而後導入數據IMPDP
session
mkdir -p /u01/app/oracle/bakdump create or replace directory oa_databackup as '/u01/app/oracle/bakdump';
六、主庫參數修改
1)開啓歸檔oracle
shutdown immediate; startup mount; alter database archivelog; archive log list; alter database open;
2)強制寫日誌app
alter database force logging;
3)增長備庫日誌dom
ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/app/oracle/oradata/ora/redo04.log') size 50M; ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/u01/app/oracle/oradata/ora/redo05.log') size 50M; ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 ('/u01/app/oracle/oradata/ora/redo06.log') size 50M; ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 ('/u01/app/oracle/oradata/ora/redo07.log') size 50M;
4)監聽ide
--主庫測試
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ora) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) (SID_NAME = ora) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.13.3.28)(PORT = 1521)) ) ADR_BASE_LISTENER = /u01/app/oracle
--從庫
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = ora) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) (SID_NAME = ora) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.13.3.29)(PORT = 1521)) ) ADR_BASE_LISTENER = /u01/app/oracle
5)tnsname
--主庫從庫同樣
orcl_pd = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.13.3.28)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ora) ) ) orcl_sd = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.13.3.29)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ora) ) )
6)參數文件
主庫參數
ora.__db_cache_size=61874372608 ora.__java_pool_size=939524096 ora.__large_pool_size=536870912 ora.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment ora.__pga_aggregate_target=39325794304 ora.__sga_target=68719476736 ora.__shared_io_pool_size=0 ora.__shared_pool_size=4831838208 ora.__streams_pool_size=134217728 *.audit_file_dest='/u01/app/oracle/admin/ora/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/u01/app/oracle/oradata/ora/control01.ctl','/u01/app/oracle/fast_recovery_area/ora/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='ora' *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' *.db_recovery_file_dest_size=4385144832 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=oraXDB)' *.open_cursors=300 *.pga_aggregate_target=39267074048 *.processes=1000 *.remote_login_passwordfile='EXCLUSIVE' *.sessions=1105 *.sga_target=68719476736 *.undo_tablespace='UNDOTBS1' DB_UNIQUE_NAME=orcl_pd LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_sd)' LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_pd' LOG_ARCHIVE_DEST_2='SERVICE=orcl_sd ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_sd' LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE LOG_ARCHIVE_FORMAT=%t_%s_%r.arc FAL_SERVER=orcl_sd STANDBY_FILE_MANAGEMENT=AUTO
從庫參數
ora.__db_cache_size=61874372608 ora.__java_pool_size=939524096 ora.__large_pool_size=536870912 ora.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment ora.__pga_aggregate_target=39325794304 ora.__sga_target=68719476736 ora.__shared_io_pool_size=0 ora.__shared_pool_size=4831838208 ora.__streams_pool_size=134217728 *.audit_file_dest='/u01/app/oracle/admin/ora/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/u01/app/oracle/oradata/ora/control01.ctl','/u01/app/oracle/fast_recovery_area/ora/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='ora' *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' *.db_recovery_file_dest_size=4385144832 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=oraXDB)' *.open_cursors=300 *.pga_aggregate_target=39267074048 *.processes=1000 *.remote_login_passwordfile='EXCLUSIVE' *.sessions=1105 *.sga_target=68719476736 *.undo_tablespace='UNDOTBS1' DB_UNIQUE_NAME=orcl_sd LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl_pd,orcl_sd)' LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_sd' LOG_ARCHIVE_DEST_2='SERVICE=orcl_pd ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_pd' LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE LOG_ARCHIVE_FORMAT=%t_%s_%r.arc FAL_SERVER=orcl_pd STANDBY_FILE_MANAGEMENT=AUTO
7) impdp 舊數據
impdp ora/abcABC123 DIRECTORY=oa_databackup DUMPFILE=oadb1010.dmp SCHEMAS=ora
七、 備庫操做
從主課拷貝密碼文件initoracle_sid listener.ora tnsname.ora 到從庫對應位置,注意修改相對應的內容,如initora.ora修改上面從庫增長的內容,listener.ora修改IP。其它同樣
並在從庫新建相關目錄:
cd /u01/app/oracle mkdir archivelog mkdir -p oradata/ora mkdir -p fast_recovery_area/ora mkdir -p /u01/app/oracle/admin/ora/adump mkdir -p /u01/app/oracle/bakdump mkdir -p /u01/app/oracle/admin/ora/adump
注意修改etc/hosts
八、備庫duplicate
備庫利用拷貝過來的參數文件啓動到nomount
sqlplus / as sysdba startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initora.ora'
另開窗口rman duplicate複製
rman target sys/oracleadmin@orcl_pd auxiliary sys/oracleadmin@orcl_sd nocatalog duplicate target database for standby nofilenamecheck from active database;
九、打開備庫數據庫並開啓主從複製
sqlplus / as sysdba
alter database open;
alter database recover managed standby database using current logfile disconnect from session;
十、檢查狀態
正常狀況下主庫OPEN_MODE 是WIRITE READ 從庫是READ ONLY WITH APPLY
SELECT OPEN_MODE,DATABASE_ROLE,DB_UNIQUE_NAME,SWITCHOVER_STATUS FROM V$DATABASE;
主備庫查詢下面語句,看看日誌是否一致
SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG;
不一致時,主庫切換一下日誌在查看
ALTER SYSTEM SWITCH LOGFILE;
十一、角色切換SWITCHOVER
1)主庫上 select switchover_status from v$database; 若是狀態爲SESSION ACTIVE則執行下面 alter database commit to switchover to physical standby with session shutdown; 若是狀態爲TO_STANDBY則執行下面 alter database commit to switchover to physical standby (若是切換失敗後要重啓一下庫) 不然要切換一下日誌看看alter system switch logfile; 2)備庫上 select switchover_status from v$database switchover_status 爲NOT ALLOWED alter database commit to switchover to primary; 3)原來主庫上 shutdown immediate startup alter database recover managed standby database using current logfile disconnect from session; (上面是開啓日誌傳輸,這個是關閉alter database recover managed standby database cancel;) 4)原來備庫上 shutdown immediate startup
十二、failover災難切換
假設物理主庫宕機,沒法啓動,緊急啓用備庫
直接在備庫上操做,將備庫轉換爲主庫角色
備庫上執行下面四條命令便可
SQL > alter database recover managed standby database finish; SQL > alter database commit to switchover to primary; SQL > shutdown immediate; SQL > startup;