linux-oracle11g-dg搭建日誌

peng163fj發表於2015-04-13

rpm -ivh compat-libstdc++* elfutils* ksh* libaio-devel* unixODBC* unixODBC-devel* --nodeps



cp compat-libstdc++* /u01

cp elfutils* /u01

cp ksh* /u01

cp libaio-devel* /u01

cp unixODBC* /u01

cp package unixODBC-devel* /u01



rpm -q binutils compat-libstdc++ elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers kernel-headers ksh libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel 


#*               soft    core            0


oracle               soft    nproc            2047

oracle               hard    nproc            16384

oracle               soft    nofile            1024

oracle               hard    nofile            65536

oracle               soft    stack            10240




# For Oracle

export DISPLAY=:0.0

export TMP=/tmp;

export TMPDIR=$TMP;

export ORACLE_BASE=/u01/app/oracle;

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1;

export ORACLE_SID=sales;

export ORACLE_TERM=xterm;

export PATH=/usr/sbin:$PATH;

export PATH=$ORACLE_HOME/bin:$PATH;

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;




rpm -q binutils-2.20.51.0.2-5.11.el6.i686 compat-libcap1-1.10-1.i686 compat-libstdc++-33-3.2.3-69.el6.i686 gcc-4.4.4-13.el6.i686 gcc-c++-4.4.4-13.el6.i686 glibc-2.12-1.7.el6.i686 glibc-devel-2.12-1.7.el6.i686 ksh libgcc-4.4.4-13.el6.i686 libstdc++-4.4.4-13.el6.i686 libstdc++-devel-4.4.4-13.el6.i686 libaio-0.3.107-10.el6.i686 libaio-devel-0.3.107-10.el6.i686 make-3.81-19.el6.i686 sysstat-9.0.4-11.el6.i686 






rpm -ivh binutils*.rpm compat-libcap*.rpm compat-libstdc++*.rpm gcc*.rpm gcc-c++*.rpm glibc*.rpm glibc*.rpm ksh libgcc*.rpm libstdc++*.rpm libstdc++*.rpm libaio*.rpm libaio-devel*.rpm make*.rpm sysstat*.rpm --nodeps --force




#  

# atrpms  

# el6Server - i386 - ATrpms  

#  

[atrpms]  

name=el6Server - i386 - ATrpms  

baseurl=  

type=rpm-md 







export DISPLAY=172.16.254.4:0.0


prod.localdomain





scp orapwprod 192.168.17.247:/u01/app/oracle/product/11.2.0/db_1/dbs 

scp initprod.ora 192.168.17.247:/u01/app/oracle/product/11.2.0/db_1/dbs

scp /u01/app/standby.ctl 192.168.17.247:/u01/app




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

mkdir -p /u01/app/oracle/admin/standby/bdump

mkdir -p /u01/app/oracle/admin/standby/cdump

mkdir -p /u01/app/oracle/admin/standby/udump

mkdir -p /u01/app/oracle/admin/standby/dpdump

mkdir -p /u01/app/oracle/oradata/standby/archivelog 


ls -l /u01/app/oracle/admin/standby

ls -l /u01/app/oracle/oradata/standby


create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initstandby.ora';


startup nomount




alter  system  set log_archive_config='dg_config=(prod,standby)'; 

alter  system  set log_archive_dest_1='location=/u01/app/oracle/oradata/prod/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=prod'; 

alter  system  set  log_archive_dest_2='service=standby  lgwr 

async  valid_for=(online_logfiles,primary_role) 

db_unique_name=standby'; 

alter system set log_archive_dest_state_1=enable; 

alter system set log_archive_dest_state_2=enable; 

alter system set log_archive_max_processes=10; 

alter system set fal_server=standby; 

alter system set fal_client=prod; 

alter system set standby_file_management=auto;

alter system set db_unique_name='prod'scope=spfile; 

alter  system  set db_file_name_convert='/u01/app/oracle/oradata/standby','/u01/app/oracle/oradata/prod' scope=spfile; 

alter  system  set log_file_name_convert='/u01/app/oracle/oradata/standby','/u01/app/oracle/oradata/prod' scope=spfile;


mkdir -p /u01/backupset

chown -R oracle.oinstall /u01/backupset


run 

allocate channel d1 type disk format '/u01/backupset/%U'; 

backup database; 

release channel d1; 

}


scp -r /u01/backupset 192.168.17.247:/u01


rman target / auxiliary sys/redhat@standby


run

{

allocate auxiliary channel d1 type disk;

duplicate target database for standby nofilenamecheck;

release channel d1;

}


scp -r /u01/backupset 192.168.17.247:/u01



alter  database  add  standby  logfile ('/u01/app/oracle/oradata/standby/standby01.log') size 50m; 

alter  database  add  standby  logfile ('/u01/app/oracle/oradata/standby/standby02.log') size 50m; 

alter  database  add  standby  logfile ('/u01/app/oracle/oradata/standby/standby03.log') size 50m; 

alter  database  add  standby  logfile ('/u01/app/oracle/oradata/standby/standby04.log') size 50m;




alter  database  recover  managed  standby  database  using  current logfile disconnect from session;


select  sequence#,  applied  from  v$archived_log    where 

applied='YES' order by sequence#;



conn scott/tiger 

create table t(i int); 

insert into t values(1); 

commit; 

conn / as sysdba 

alter system switch logfile;





alter system switch logfile;



select switchover_status from v$database


alter database recover managed standby database cancel;



alter database open;


conn scott/tiger 

select * from t;


conn / as sysdba

select open_mode from v$database; 

alter  database  recover  managed  standby  database  using  current logfile disconnect from session; 



alter database commit to switchover to physical standby WITH SESSION SHUTDOWN; 


select switchover_status from v$database;

select open_mode from v$database; 

select status from v$instance;



---standby 在startup mount後

alter  database  recover  managed  standby  database  using  current logfile disconnect from session; 

alter database recover managed standby database cancel;

alter database open;


-- 切換失敗,注意殺掉殭屍程式

alter database commit to switchover to physical standby WITH SESSION SHUTDOWN; 

看筆記


--切換回備庫

startup nomount

alter databasemount standby database;

 


select  sequence#,  applied  from  v$archived_log    where 

applied='YES' order by sequence#;

select switchover_status from v$database;

alter database commit to switchover to primary;--把備庫切為主庫

alter database recover managed standby database disconnect from session;--報錯media need recover 的處理


---prod上,建立備日誌

alter  database  add  standby  logfile 

('/u01/app/oracle/oradata/prod/standby01.log') size 50m; 

alter  database  add  standby  logfile 

('/u01/app/oracle/oradata/prod/standby02.log') size 50m; 

alter  database  add  standby  logfile 

('/u01/app/oracle/oradata/prod/standby03.log') size 50m; 

alter  database  add  standby  logfile 

('/u01/app/oracle/oradata/prod/standby04.log') size 50m;

--執行同步語句

alter  database  recover  managed  standby  database  using  current logfile disconnect from session;

select  sequence#,  applied  from  v$archived_log    where 

applied='YES'order by sequence#;

--standby上執行

conn scott/tiger

insert into t values(2);

commit; 

conn / as sysdba 

alter system switch logfile;

--prod上執行

alter database recover managed standby database cancel; 

alter database open; 

conn scott/tiger 

select * from t;--物理DG切換成功


conn / as sysdba 

select open_mode from v$database;--現在是read only

alter  database  recover  managed  standby  database  using  current logfile disconnect from session; 

select open_mode from v$database;--切換回同步模式mount




--切換回原來的狀態

select switchover_status from v$database; 

alter database commit to switchover to physical standby;

shutdown immediate 

startup nomount 

alter database mount standby database;--standby標誌他為standby



---prod上

select  sequence#,  applied  from  v$archived_log    where 

applied='YES' order by sequence#;

select switchover_status from v$database; 

alter database commit to switchover to primary; 

select status from v$instance;--主庫標識為primary

shutdown immediate 

startup


--standby上

alter  database  recover  managed  standby  database  using  current logfile disconnect from session;


--prod上

conn scott/tiger 

insert into t values(3); 

commit; 

conn / as sysdba 

alter system switch logfile;


--standby上

alter database recover managed standby database cancel; 

alter database open; 

conn scott/tiger 

select * from t;


conn / as sysdba 

alter  database  recover  managed  standby  database  using  current logfile disconnect from session; 

select open_mode from v$database;





-----搭建虛擬備庫

--配置邏輯備庫

alter database recover managed standby database cancel;


--配置prod

exit 

mkdir -p /u01/app/oracle/oradata/prod/lgarchive 

ls -l /u01/app/oracle/oradata/prod/


sqlplus / as sysdba 

alter  system  set log_archive_dest_3='location=/u01/app/oracle/oradata/prod/lgarchive valid_for=(standby_logfiles,standby_role) db_unique_name=prod'; alter system set log_archive_dest_state_3=enable;

execute dbms_logstdby.build;


--配置standby

exit 

mkdir -p /u01/app/oracle/oradata/standby/lgarchive 

ls -l /u01/app/oracle/oradata/standby/


sqlplus / as sysdba 

alter  system  set log_archive_dest_3='location=/u01/app/oracle/oradata/standby/lgarchive  valid_for=(standby_logfiles,standby_role) db_unique_name=standby'; 

alter system set log_archive_dest_state_3=enable;

--physical standby轉換為logical standby

select * from v$tempfile

select status from v$instance;

select database_role from v$database;

startup mount force 

alter database recover to logical standby standby;

select status from v$instance; 

startup mount force 

select database_role from v$database;

alter database open resetlogs;

show parameter db_name

--prod環境

alter system switch logfile;

/

/

/


--standby

ls -l /u01/app/oracle/oradata/standby/archivelog

sqlplus / as sysdba 

alter database start logical standby apply immediate;


--驗證 prod庫

conn scott/tiger 

create table a(a varchar2(10)); 

insert into a values('a'); 

commit;



--驗證 standby庫

conn scott/tiger 

select * from a;




----切換邏輯備庫,prod與standby都執行

conn / as sysdba 

alter system set undo_retention=3600;


--prod執行

select switchover_status from v$database; 

alter database prepare to switchover to logical standby; 

select switchover_status from v$database;


--standby執行

select switchover_status from v$database; 

alter database prepare to switchover to primary; 

select switchover_status from v$database; 


--prod執行

select switchover_status from v$database;--返回結果to logical standby

取消轉換的命令為:alter  database  prepare  to  switchover  cancel;

alter database commit to switchover to logical standby;


--standby執行

select switchover_status from v$database; 

alter database commit to switchover to primary;


--prod執行

alter database start logical standby apply immediate; 


--standby執行

conn scott/tiger 

insert into a values('b'); 

commit; 

conn / as sysdba 


--prod執行

conn scott/tiger 

select * from a; 

conn / as sysdba 




alter database prepare to switchover to logical standby; 

alter database prepare to switchover to primary;

select switchover_status from v$database;

alter database commit to switchover to logical standby; 

alter database commit to switchover to primary;


alter database start logical standby apply immediate;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21302630/viewspace-1571799/,如需轉載,請註明出處,否則將追究法律責任。

相關文章