rac dataguard搭建过程

这几天要为rac大家dataguard,但是实际上rac现在只有但节点运行,因为另一个节点服务器坏了需要维修。


如果某天节点1修好了,在起数据库之前务必先修改tnsname.ora,添加HNDG的部分。不然归档会缺失


sid都叫HNDB
备库监听名叫HNDG好了
db_unique_name 主库叫HNDB,备库叫HNDG






在备库tnsnames.ora添加


HNDB =
  (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = hn-db1-vip)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = hn-db2-vip)(PORT = 1521))
      (LOAD_BALANCE = yes)
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = HNDB)
      )
  )


HNDG =
  (DESCRIPTION =
     (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = hn-dg)(PORT = 1521))
     )
     (CONNECT_DATA =
        (SERVICE_NAME = HNDB)
     )
  )
  
HNDB2 =
  (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = hn-db2-vip)(PORT = 1521))
      (CONNECT_DATA =    
        (SERVER = DEDICATED)        
        (SERVICE_NAME = HNDB)              
        (INSTANCE_NAME = HNDB2)                    
      )
  )
  
HNDB1 =
  (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = hn-db1-vip)(PORT = 1521))
      (CONNECT_DATA =    
        (SERVER = DEDICATED)        
        (SERVICE_NAME = HNDB)              
        (INSTANCE_NAME = HNDB1)                    
      )
  )














在主库tnsnames.ora添加
HNDG =
  (DESCRIPTION =
     (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = hn-dg)(PORT = 1521))
     )
     (CONNECT_DATA =
        (SERVICE_NAME = HNDB)
     )
  )
  










原spfile
HNDB1.__db_cache_size=3724541952
HNDB2.__db_cache_size=3724541952
HNDB1.__java_pool_size=16777216
HNDB2.__java_pool_size=16777216
HNDB1.__large_pool_size=16777216
HNDB2.__large_pool_size=16777216
HNDB1.__shared_pool_size=520093696
HNDB2.__shared_pool_size=520093696
HNDB1.__streams_pool_size=0
HNDB2.__streams_pool_size=0
*.archive_lag_target=0
*.audit_file_dest='/oracle/app/admin/HNDB/adump'
*.background_dump_dest='/oracle/app/admin/HNDB/bdump'
*.cluster_database_instances=2
*.cluster_database=TRUE
*.compatible='10.2.0.3.0'
*.control_file_record_keep_time=10
*.control_files='+VGDATA/hndb/controlfile/current.256.715872251','+VGRECOVERY/hndb/controlfile/current.256.715872253'
*.core_dump_dest='/oracle/app/admin/HNDB/cdump'
*.cursor_sharing='FORCE'
*.db_block_size=8192
*.db_create_file_dest='+VGDATA'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='HNDB'
*.db_recovery_file_dest='+VGRECOVERY'
*.db_recovery_file_dest_size=107374182400
*.dispatchers='(PROTOCOL=TCP) (SERVICE=HNDBXDB)'
HNDB2.instance_number=2
HNDB1.instance_number=1
*.job_queue_processes=10
HNDB1.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 10.88.1.101)(PORT = 1521))'
HNDB2.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 10.88.1.103)(PORT = 1521))'
*.log_archive_dest_1='location=+VGRECOVERY'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=800
*.optimizer_index_caching=100
*.optimizer_index_cost_adj=20
*.pga_aggregate_target=734003200
*.processes=900
*.remote_listener='LISTENERS_HNDB'
*.remote_login_passwordfile='exclusive'
*.session_cached_cursors=100
*.sessions=995
*.sga_target=4294967296
HNDB2.thread=2
HNDB1.thread=1
*.undo_management='AUTO'
*.undo_retention=1800
*.undo_tablespace='UNDOTBS1'
HNDB1.undo_tablespace='UNDOTBS1'
HNDB2.undo_tablespace='UNDOTBS2'
*.user_dump_dest='/oracle/app/admin/HNDB/udump'


















主库的spfile
alter system set db_unique_name='HNDB' scope=spfile;
alter database force logging;
alter system set log_archive_config='DG_CONFIG=(HNDB,HNDG)' scope=spfile;
alter system set log_archive_dest_1='LOCATION=+VGRECOVERY valid_for=(all_logfiles,all_roles) db_unique_name=HNDB' scope=spfile;  
alter system set log_archive_dest_2='SERVICE=HNDG lgwr ASYNC valid_for=(online_logfile,primary_role) db_unique_name=HNDG' scope=spfile;
alter system set fal_client='HNDB1' sid='HNDB1';--不知道为毛加了 scope=spfile会报错,直接不加scope参数就可以;
alter system set fal_client='HNDB2' sid='HNDB2';--不知道为毛加了 scope=spfile会报错,直接不加scope参数就可以;
alter system set fal_server='HNDG' scope=spfile;
alter system set standby_file_management=auto 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 remote_login_passwordfile='exclusive' scope=spfile;
alter system set db_file_name_convert='/oracle/app/oradata/HNDB/datafile','+VGDATA/hndb/datafile','/oracle/app/oradata/HNDB/tempfile','+VGDATA/hndb/tempfile' SCOPE=SPFILE;
alter system set log_file_name_convert='/oracle/app/oradata/HNDB/VGDATA','+VGDATA/hndb/onlinelog','/oracle/app/oradata/HNDB/VGRECOVERY','+VGRECOVERY/hndb/onlinelog' SCOPE=SPFILE;






修改后


HNDB1.__db_cache_size=3724541952
HNDB2.__db_cache_size=3841982464
HNDB1.__java_pool_size=16777216
HNDB2.__java_pool_size=16777216
HNDB1.__large_pool_size=16777216
HNDB2.__large_pool_size=16777216
HNDB1.__shared_pool_size=520093696
HNDB2.__shared_pool_size=402653184
HNDB1.__streams_pool_size=0
HNDB2.__streams_pool_size=0
*.archive_lag_target=0
*.audit_file_dest='/oracle/app/admin/HNDB/adump'
*.background_dump_dest='/oracle/app/admin/HNDB/bdump'
*.cluster_database_instances=2
*.cluster_database=TRUE
*.compatible='10.2.0.3.0'
*.control_file_record_keep_time=10
*.control_files='+VGDATA/hndb/controlfile/current.256.715872251','+VGRECOVERY/hndb/controlfile/current.256.715872253'
*.core_dump_dest='/oracle/app/admin/HNDB/cdump'
*.cursor_sharing='FORCE'
*.db_block_size=8192
*.db_create_file_dest='+VGDATA'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='/oracle/app/oradata/HNDB/datafile','+VGDATA/hndb/datafile','/oracle/app/oradata/HNDB/tempfile','+VGDATA/hndb/tempfile'
*.db_name='HNDB'
*.db_recovery_file_dest='+VGRECOVERY'
*.db_recovery_file_dest_size=107374182400
*.db_unique_name='HNDB'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=HNDBXDB)'
HNDB1.fal_client='HNDB1'
HNDB2.fal_client='HNDB2'
*.fal_server='HNDG'
HNDB2.instance_number=2
HNDB1.instance_number=1
*.job_queue_processes=10
HNDB1.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 10.88.1.101)(PORT = 1521))'
HNDB2.local_listener='(ADDRESS = (PROTOCOL = TCP)(HOST = 10.88.1.103)(PORT = 1521))'
*.log_archive_config='DG_CONFIG=(HNDB,HNDG)'
*.log_archive_dest_1='LOCATION=+VGRECOVERY valid_for=(all_logfiles,all_roles) db_unique_name=HNDB'
*.log_archive_dest_2='SERVICE=HNDG lgwr async valid_for=(online_logfile,primary_role) db_unique_name=HNDG'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_format='%t_%s_%r.dbf'
*.log_file_name_convert='/oracle/app/oradata/HNDB/VGDATA','+VGDATA/hndb/onlinelog','/oracle/app/oradata/HNDB/VGRECOVERY','+VGRECOVERY/hndb/onlinelog'
*.open_cursors=800
*.optimizer_index_caching=100
*.optimizer_index_cost_adj=20
*.pga_aggregate_target=734003200
*.processes=900
*.remote_listener='LISTENERS_HNDB'
*.remote_login_passwordfile='exclusive'
*.session_cached_cursors=100
*.sessions=995
*.sga_target=4294967296
*.standby_file_management='AUTO'
HNDB2.thread=2
HNDB1.thread=1
*.undo_management='AUTO'
*.undo_retention=1800
*.undo_tablespace='UNDOTBS1'
HNDB1.undo_tablespace='UNDOTBS1'
HNDB2.undo_tablespace='UNDOTBS2'
*.user_dump_dest='/oracle/app/admin/HNDB/udump'














起来的时候
出现这个
ORA-03113: end-of-file on communication channel


alert显示
LGWR: Error 12541 verifying archivelog destination LOG_ARCHIVE_DEST_2
 
Error 12541 received logging on to the standby
Check whether the listener is up and running.


然后自己就直接shutdown了。。。。。。。。


没办法改成这个试试


alter system set log_archive_dest_2='SERVICE=HNDG lgwr SYNC valid_for=(online_logfile,primary_role) db_unique_name=HNDG' scope=spfile;
这个居然可以正常开机了。。


又改回async,这次没自动关机了,alert后台不断报12541而已
alter system set log_archive_dest_2='SERVICE=HNDG lgwr async valid_for=(online_logfile,primary_role) db_unique_name=HNDG' scope=both;


把spfile弄成pfile再拷过去备库




ps:可以用SELECT force_logging from v$database看看是不是强制写日志






















在备库添加standby log
如果要回切需要在主库也加




ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 11('+VGDATA/hndb/onlinelog/slog11a.ora','+VGRECOVERY/hndb/onlinelog/slog11b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 12('+VGDATA/hndb/onlinelog/slog12a.ora','+VGRECOVERY/hndb/onlinelog/slog12b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 13('+VGDATA/hndb/onlinelog/slog13a.ora','+VGRECOVERY/hndb/onlinelog/slog13b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 14('+VGDATA/hndb/onlinelog/slog14a.ora','+VGRECOVERY/hndb/onlinelog/slog14b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 15('+VGDATA/hndb/onlinelog/slog15a.ora','+VGRECOVERY/hndb/onlinelog/slog15b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 16('+VGDATA/hndb/onlinelog/slog16a.ora','+VGRECOVERY/hndb/onlinelog/slog16b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 17('+VGDATA/hndb/onlinelog/slog17a.ora','+VGRECOVERY/hndb/onlinelog/slog17b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 18('+VGDATA/hndb/onlinelog/slog18a.ora','+VGRECOVERY/hndb/onlinelog/slog18b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 19('+VGDATA/hndb/onlinelog/slog19a.ora','+VGRECOVERY/hndb/onlinelog/slog19b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 20('+VGDATA/hndb/onlinelog/slog20a.ora','+VGRECOVERY/hndb/onlinelog/slog20b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 21('+VGDATA/hndb/onlinelog/slog21a.ora','+VGRECOVERY/hndb/onlinelog/slog21b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 22('+VGDATA/hndb/onlinelog/slog22a.ora','+VGRECOVERY/hndb/onlinelog/slog22b.ora') SIZE 100m;










在主库上部署备份脚本










#bk.rcv
connect target sys/abc@HNDB2
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
set limit channel c1 kbytes 1800000;
set limit channel c2 kbytes 1800000;
backup full
tag 'dbfull'
format '/orabackup/backup/rman2/dataguard%n_%s_%p_%T'
database include current controlfile for standby;
sql 'alter system archive log current';
release channel c1;
release channel c2;
}










备库






把主库的pfile修改为








*.archive_lag_target=0
*.audit_file_dest='/oracle/app/admin/HNDB/adump'
*.background_dump_dest='/oracle/app/admin/HNDB/bdump'
*.compatible='10.2.0.3.0'
*.control_file_record_keep_time=10
*.control_files='/oracle/app/oradata/HNDB/control01.ctl','/oracle/app/oradata/HNDB/control02.ctl'
*.core_dump_dest='/oracle/app/admin/HNDB/cdump'
*.cursor_sharing='FORCE'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='+VGDATA/hndb/datafile','/oracle/app/oradata/HNDB/datafile','+VGDATA/hndb/tempfile','/oracle/app/oradata/HNDB/tempfile'
*.db_name='HNDB'
*.db_recovery_file_dest='/oracle/app/flash_recovery_area'
*.db_recovery_file_dest_size=6737418240
*.db_unique_name='HNDG'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=HNDBXDB)'
*.fal_client='HNDG'
*.fal_server='HNDB2','HNDB1'
*.job_queue_processes=10
*.log_archive_config='DG_CONFIG=(HNDB,HNDG)'
*.log_archive_dest_1='LOCATION=/oracle/app/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=HNDG'
*.log_archive_dest_2='SERVICE=HNDB lgwr async valid_for=(online_logfile,primary_role) db_unique_name=HNDB'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_format='%t_%s_%r.dbf'
*.log_file_name_convert='+VGDATA/hndb/onlinelog','/oracle/app/oradata/HNDB/VGDATA','+VGRECOVERY/hndb/onlinelog','/oracle/app/oradata/HNDB/VGRECOVERY'
*.open_cursors=800
*.optimizer_index_caching=100
*.optimizer_index_cost_adj=20
*.pga_aggregate_target=236870912
*.processes=900
*.remote_login_passwordfile='exclusive'
*.session_cached_cursors=100
*.sessions=995
*.sga_target=1648854016
*.standby_file_management='AUTO'
*.undo_management='AUTO'
*.undo_retention=1800
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/oracle/app/admin/HNDB/udump'




漏了删*.remote_listener='LISTENERS_HNDB'




startup nomount 
ok了






清空原数据文件


建好目录




$ mkdir datafile
$ mkdir tempfile
$ mkdir VGDATA
$ mkdir VGRECOVERY

$ ll
total 0
drwxrwxrwx   2 oracle     oinstall        96 Dec 19 15:02 VGDATA
drwxrwxrwx   2 oracle     oinstall        96 Dec 19 15:02 VGRECOVERY
drwxrwxrwx   2 oracle     oinstall        96 Dec 19 15:02 datafile
drwxrwxrwx   2 oracle     oinstall        96 Dec 19 15:02 tempfile
$ pwd
/oracle/app/oradata/HNDB








在备库的/etc/hosts添加










在这个目录下部署恢复脚本
/var/backup/script




run
{
allocate channel chan1 type disk;
allocate channel chan2 type disk;
allocate auxiliary channel aux1 type disk;
allocate auxiliary channel aux2 type disk;
duplicate target database for standby nofilenamecheck;
}




保证和主库的备份目录一致,做一个软连接
cd /orabackup/backup




ln -s /var/backup/rman /orabackup/backup/rman2


nohup rman target  sys/hndb123@HNDB2 auxiliary / @recover.rcv log recover.log &




看来要等很久,归档空间应该毫无压力。
修改备份脚本


主要去掉 delete input
添加
delete noprompt archivelog until time "to_date(to_char(sysdate-2,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd








connect target sys/abc@HNDB
run{
allocate channel c1 type disk connect sys/hndb123@HNDB2;
allocate channel c2 type disk connect sys/hndb123@HNDB2;
sql 'alter system archive log current';
backup tag 'full-archive-bk'
       filesperset 3
       format '/orabackup/backup/arch_bak1/arch%n_%s_%p_%T'
archivelog all;
delete noprompt archivelog until time "to_date(to_char(sysdate-2,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd
 hh24:mi:ss')";


release channel c1;
release channel c2;
}




shutdown immediate;  
startup nomount;
alter database  mount standby database;
alter database recover managed standby database disconnect from session;




不断出现
PING[ARC1]: Heartbeat failed to connect to standby 'HNDG'. Error is 16191


忘记替换密码文件




果然是这问题


看看正常不
select sequence#,applied,ARCHIVAL_THREAD# from v$archived_log order by sequence#;




把源库的脚本解注释


明天回来再搞备库的删归档脚本






百思不得其解。。。为毛主库建了standby_log之后,rman恢复备库没有standby_log?
印象中单机dg会有啊,难道是我记忆错乱还是双机不一样?


尝试一下在备库建吧。。修改一下路径


alter database recover managed standby database cancel;


ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 11('/oracle/app/oradata/HNDB/VGDATA/slog11a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog11b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 12('/oracle/app/oradata/HNDB/VGDATA/slog12a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog12b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 13('/oracle/app/oradata/HNDB/VGDATA/slog13a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog13b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 14('/oracle/app/oradata/HNDB/VGDATA/slog14a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog14b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 15('/oracle/app/oradata/HNDB/VGDATA/slog15a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog15b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 group 16('/oracle/app/oradata/HNDB/VGDATA/slog16a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog16b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 17('/oracle/app/oradata/HNDB/VGDATA/slog17a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog17b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 18('/oracle/app/oradata/HNDB/VGDATA/slog18a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog18b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 19('/oracle/app/oradata/HNDB/VGDATA/slog19a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog19b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 20('/oracle/app/oradata/HNDB/VGDATA/slog20a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog20b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 21('/oracle/app/oradata/HNDB/VGDATA/slog21a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog21b.ora') SIZE 100m;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 2 group 22('/oracle/app/oradata/HNDB/VGDATA/slog22a.ora','/oracle/app/oradata/HNDB/VGRECOVERY/slog22b.ora') SIZE 100m;




alter database recover managed standby database disconnect from session;






建了之后可以用了






RFS[2]: Successfully opened standby log 17: '/oracle/app/oradata/HNDB/VGDATA/slog17a.ora'
Fri Dec 20 10:35:08 2013
Media Recovery Waiting for thread 2 sequence 107094 (in transit)
Fri Dec 20 10:35:09 2013
Primary database is in MAXIMUM PERFORMANCE mode
RFS[2]: Successfully opened standby log 17: '/oracle/app/oradata/HNDB/VGDATA/slog17a.ora'
Fri Dec 20 10:35:13 2013
Media Recovery Log /oracle/app/archivelog/2_107094_715872248.dbf
Media Recovery Waiting for thread 2 sequence 107095 (in transit)
Fri Dec 20 11:05:05 2013
Primary database is in MAXIMUM PERFORMANCE mode
RFS[2]: Successfully opened standby log 18: '/oracle/app/oradata/HNDB/VGDATA/slog18a.ora'
Primary database is in MAXIMUM PERFORMANCE mode
Fri Dec 20 11:05:06 2013
Media Recovery Log /oracle/app/archivelog/2_107095_715872248.dbf
Fri Dec 20 11:05:06 2013
RFS[2]: Successfully opened standby log 17: '/oracle/app/oradata/HNDB/VGDATA/slog17a.ora'
Fri Dec 20 11:05:15 2013
Media Recovery Log /oracle/app/archivelog/2_107096_715872248.dbf
Media Recovery Waiting for thread 2 sequence 107097 (in transit)




每次都会说成功打开备用日志

你可能感兴趣的:(数据库,搭建,RAC,dataguard)