1. 程式人生 > >dataguard搭建-rac到單機

dataguard搭建-rac到單機

dataguard rac到單機

一 檢查源端,打開歸檔

SQL>archive log list;
#如果未打開,關閉數據庫
Shutdown immediate;
#啟動至mount狀態
Startup mount
#開啟歸檔
SQL> alter database archivelog ; 
Database altered. 
#打開強制日誌,不打開,使nologging選項時,備庫的表會報錯
SQL> alter database force logging;
 Database altered.
SQL> alter database open; 
Database altered.
#檢查
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /data/arch
Oldest online log sequence     12
Next log sequence to archive   14
Current log sequence           14
SQL> select force_logging from v$database;
FORCE
---
YES

二 更改參數

alter system set log_archive_config=‘DG_CONFIG=(db,standby)‘ scope=both;
alter system set log_archive_dest=‘‘ scope=both;
alter system set log_archive_dest_1=‘location=/data/arch‘ scope=spfile;
--用歸檔傳輸
alter system set log_archive_dest_2=‘service=standby arch valid_for=(online_logfiles,primary_role) db_unique_name=standby‘ scope=spfile;
--首選在線日誌傳輸,實時應用
alter system set log_archive_dest_2=‘service=standby lgwr sync affirm valid_for=(online_logfiles,primary_role) db_unique_name=standby‘ scope=both;
SQL> alter system set log_archive_max_processes=4 scope=both;
SQL> alter system set fal_server=standby scope=both;
SQL> alter system set fal_client=db scope=both;
SQL> alter system set standby_file_management=auto scope=both;
SQL> alter system set db_file_name_convert=‘+data‘,‘/data‘ scope=spfile;
SQL> alter system set log_file_name_convert=‘+data‘,‘/data‘ scope=spfile;
Sql>alter system set db_unique_name=db scope=spfile;
#先不啟用
SQL>alter system set log_archive_dest_state_2=defer;

三 配置tnsnames

服務端$ORACLE_HOME/network/admin/tnsnames.ora

standby =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.84.17)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = standby)
    )
  )

四 備份主庫:

rman "target / nocatalog"
run{
configure default device type to disk;
configure device type disk parallelism 1;
backup as compressed backupset database format ‘/home/oracle/full_%s_%p_%T.bak‘ TAG fullbak_fordg;
}

五 創建standby controlfile:

創建standby controlfile:

SQL> alter database create standby controlfile as ‘/home/oracle/standby.ctl‘;

六 創建pfile

create pfile=‘/data/backup/pfile.ora‘ from spfile;

主要修改db_unique_name

Fal_server

Fal_client

參考如下:

*.audit_file_dest=‘/opt/db/adump‘
*.audit_trail=‘none‘
*.cluster_database=false
*.compatible=‘11.2.0.4.0‘
*.db_file_name_convert=‘+DATA‘,‘/data‘
*.log_file_name_convert=‘+DATA‘,‘/data‘
*.control_files=‘/u01/data/ctl_01.ctl‘
*.log_archive_config=‘DG_CONFIG=(db,standby)‘
*.db_block_size=8192
*.db_create_file_dest=‘/data‘
*.db_domain=‘‘
*.db_files=200
*.db_name=‘db‘
*.db_unique_name=‘standby‘
*.db_recovery_file_dest_size=53477376000
*.db_recovery_file_dest=‘‘
*.deferred_segment_creation=FALSE
*.diagnostic_dest=‘/u01/app/oracle‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=TCIS30XDB)‘
*.log_archive_dest_1=‘location=/data/arch valid_for=(all_logfiles,all_roles) db_unique_name=standby‘
*.open_cursors=100
*.pga_aggregate_target=50MB
*.processes=100
*.remote_login_passwordfile=‘exclusive‘
*.sessions=150
*.sga_target=100MB
*.undo_tablespace=‘UNDOTBS1‘
*.fal_server=db

七 創建密鑰文件

orapwd file=orapw$ORACLE_SID password=oracle

八 創建備庫 listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /opt/product/11.2)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = standby)
      (ORACLE_HOME = /opt/product/11.2)
      (SID_NAME = sid_name)
    )
  )

9 備機創建目錄

mkdir /data/arch

mkdir /data/dg1

mkdir –p /u01/app/oracle/admin/standby/adump

更改~/.bash_profile

Export ORACLE_SID=standby

10啟動及恢復

cp standby.ctl /data/standby/ctl01.ctl
SQL> startup nomount;
SQL> alter database mount standby database;
rman target /
catalog start with ‘/home/oracle/backup‘;
Restore database;
SQL>recover managed standby database disconnect from session;

11 備庫添加standby log file;

alter database recover managed standby database cancel
alter database add standby logfile thread 1 group 10 ‘+data(flashfile)‘ size 50m;
alter database add standby logfile thread 1 group 11 ‘+data(flashfile)‘ size 50m;
alter database add standby logfile thread 2 group 12 ‘+data(flashfile)‘ size 50m;
alter database add standby logfile thread 2 group 13 ‘+data(flashfile)‘ size 50m;
alter database add standby logfile group 14 ‘/u01/data/standbyredo09.log‘ size 50m;

#主庫啟用日誌傳送

SQL>alter system set log_archive_dest_state_2=enabled;

#模式為最大可用

SQL>alter database set standby database to maximize availability;
alter database recover managed standby database cancel;
alter database open;
alter database recover managed standby database using current logfile disconnect from session;

12 檢查

select process,client_process,sequence#,status from v$managed_standby;
col  current_scn for 999999999999;
select protection_mode,database_role,open_mode,current_scn from v$database
col name for a50 ;
col sequence# for 9999999;
select name,sequence#,to_char(completion_time,‘yyyy-mm-dd hh24:mi:ss‘) from v$archived_log order by 2;
SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;
--主庫查詢
 select sequence#,status from v$Log;
 col value for a30;
 col name for a13;
 col unit for a30;
 select name,value,unit,time_computed from v$dataguard_stats;
SELECT * FROM V$STANDBY_EVENT_HISTOGRAM WHERE NAME = ‘apply lag‘ AND COUNT > 0;
 col checkpoint_change# for 99999999999999;
 select name,checkpoint_change# from v$datafile;
 select name,checkpoint_change# from v$datafile_header;
 
 SELECT DBID,
       NAME,
       TO_CHAR(CREATED, ‘DD-MON-YYYY HH24:MI:SS‘) CREATED,
       OPEN_MODE,
       LOG_MODE,
       TO_CHAR(CHECKPOINT_CHANGE#, ‘999999999999999‘) AS CHECKPOINT_CHANGE#,
       CONTROLFILE_TYPE,
       TO_CHAR(CONTROLFILE_CHANGE#, ‘999999999999999‘) AS CONTROLFILE_CHANGE#,
       TO_CHAR(CONTROLFILE_TIME, ‘DD-MON-YYYY HH24:MI:SS‘) CONTROLFILE_TIME,
       TO_CHAR(RESETLOGS_CHANGE#, ‘999999999999999‘) AS RESETLOGS_CHANGE#,
       TO_CHAR(RESETLOGS_TIME, ‘DD-MON-YYYY HH24:MI:SS‘) RESETLOGS_TIME
  FROM V$DATABASE;
--sofar 單位為KB
select * from v$recovery_progress;
--檢查歸檔應用情況
col name for a50 ;
col sequence# for 9999999;
select name,sequence#,to_char(completion_time,‘yyyy-mm-dd hh24:mi:ss‘) from v$archived_log order by 2;
SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;
select thread#,max(sequence#) maxseq from gv$archived_log group by thread# order by thread#;
select * from v$archive_gap;
--檢查net_timeout的適當值
select frequency,duration from v$redo_dest_resp_histogram where dest_id=2 and frequency>1;
select recovery_mode from v$archive_dest_status where dest_id=2;


本文出自 “snowhill” 博客,請務必保留此出處http://snowhill.blog.51cto.com/339421/1923591

dataguard搭建-rac到單機