两台主机的地址都放入hosts文件
两台都关闭iptables
DB
DG
DG只安装软件,不安装数据库
select status from v$instance;
查看是否为归档模式
select log_mode from v$database;
shutdown immediate;
startup mount
alter database archivelog;
alter database open;
archive log list
select log_mode from v$database;
强制日志模式,就是所有的操作都会记入日志
select force_logging from v$database;
alter database force logging;
select force_logging from v$database;
show parameter db_name
show parameter db_unique_name
alter system set log_archive_config=‘DG_CONFIG=(orcl,std)’;
export LANG=EN_us
netmgr
192.168.0.104
lsnrctl start
alter system set log_archive_dest_2='service=std valid_for=(online_logfiles,primary_role) db_unique_name=std';
alter system set log_archive_dest_state_2=enable;
alter system set remote_login_passwordfile=exclusive scope=spfile;
show parameter remote_login
alter system set fal_server=std;
ALTER SYSTEM SET DB_FILE_NAME_CONVERT=‘std’,‘orcl’scope=spfile;
ALTER SYSTEM SET LOG_FILE_NAME_CONVERT=‘std’,‘orcl’scope=spfile;
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
rman target=/
backup database plus archivelog;
ALTER DATABASE CREATE STANDBY CONTROLFILE AS ‘/tmp/stdcontrol.ctl’;
CREATE PFILE=’/tmp/initstd.ora’ from spfile;
查看创建的控制文件和PFILE
ls -lt /tmp/
vim /tmp/initstd.ora
把orcl修改成std
上面是原始内容,下面是修改的内容
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_file_dest='/u01/app/oracle/admin/std/adump'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/flash_recovery_area/orcl/control02.ctl'
*.control_files='/u01/app/oracle/oradata/std/control01.ctl','/u01/app/oracle/flash_recovery_area/std/control02.ctl'
*.db_file_name_convert='std','orcl'
*.db_file_name_convert='orcl','std'
增加一行
*.db_unique_name='std'
*.fal_server='STD'
*.fal_ser ver='ORCL'
*.log_archive_dest_2='service=std valid_for=(online_logfiles,primary_role) db_unique_name=std'
*.log_archive_dest_2='service=orcl valid_for=(online_logfiles,primary_role) db_unique_name=orcl'
*.log_file_name_convert='std','orcl'
*.log_file_name_convert='orcl','std'
连接到DG
ssh oracle@192.168.0.104
创建initstd.ora文件里所需要的目录,有audit_file_dest的目录和control_files里的目录
audit_file_dest=’/u01/app/oracle/admin/std/adump’
mkdir -p /u01/app/oracle/admin/std/adump
control_files=’/u01/app/oracle/oradata/std/control01.ctl’,’/u01/app/oracle/flash_recovery_area/std/control02.ctl’
mkdir -p /u01/app/oracle/oradata/std/
mkdir -p /u01/app/oracle/flash_recovery_area/std/
传送控制文件到control_files=’/u01/app/oracle/oradata/std/control01.ctl
scp /tmp/stdcontrol.ctl oracle@192.168.0.104:/u01/app/oracle/oradata/std/control01.ctl
查看传送的文件,位置必须是control_files=的位置
复至control01.ctl到/u01/app/oracle/flash_recovery_area/std/目录下,并重命名control02.ctl
cp control01.ctl /u01/app/oracle/flash_recovery_area/std/control02.ctl
查看创建的control02.ctl
ll /u01/app/oracle/flash_recovery_area/std/control02.ctl
传送ORCL目录
ll /u01/app/oracle/flash_recovery_area/ 查看目录
传送ORCL目录到/u01/app/oracle/flash_recovery_area/目录下
scp -r /u01/app/oracle/flash_recovery_area/ORCL oracle@192.168.0.104:/u01/app/oracle/flash_recovery_area/
查看传送的目录ll /u01/app/oracle/flash_recovery_area/
传送initstd.ora文件
scp /tmp/initstd.ora oracle@192.168.0.104:/tmp/initstd.ora
查看传送过去的文件ls -lt /tmp/
传送orapworcl文件
ll /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl 查看文件所在的位置
scp /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl oracle@192.168.0.104:/u01
/app/oracle/product/11.2.0/db_1/dbs/
查看传送过来的文件
cd /u01/app/oracle/product/11.2.0/db_1/dbs/
重命名文件mv orapworcl orapwstd
在DG创建
export LANG=EN_us
创建STD
lsnrctl start
两边能ping通
查看DB上的文件
tail -1 /etc/oratab
写入到DG里,前面改成std
在DG上面的操作
. oraenv
sqlplus / as sysdba
create spfile from pfile=’/tmp/initstd.ora’;
rman target=/
startup mount
DB上查看,DG创建
alter database add standby logfile(’/u01/app/oracle/oradata/std/standby_redo01.log’) size 50M;
alter database add standby logfile(’/u01/app/oracle/oradata/std/standby_redo02.log’) size 50M;
alter database add standby logfile(’/u01/app/oracle/oradata/std/standby_redo03.log’) size 50M;
alter database add standby logfile(’/u01/app/oracle/oradata/std/standby_redo04.log’) size 50M;
select GROUP#,MEMBER from v$logfile;
在DB上创建日志
alter database add standby logfile (’/u01/app/oracle/oradata/orcl/standby_redo01.log’) size 50M;
alter database add standby logfile (’/u01/app/oracle/oradata/orcl/standby_redo02.log’) size 50M;
alter database add standby logfile (’/u01/app/oracle/oradata/orcl/standby_redo03.log’) size 50M;
alter database add standby logfile (’/u01/app/oracle/oradata/orcl/standby_redo04.log’) size 50M;
DB查看创建日志
在DG执行
tail -f /u01/app/oracle/diag/rdbms/std/std/trace/alert_std.log
alter database recover managed standby database disconnect from session;
tail -f /u01/app/oracle/diag/rdbms/std/std/trace/alert_std.log里面写的内容
DB上执行
alter session set nls_date_format=‘DD-MON-YYYY HH24:MI:SS’;
select sequence#,first_time,next_time from v$archived_log ORDER BY sequence#;
alter system switch logfile;
select sequence#,first_time,next_time from v$archived_log ORDER BY sequence#;
在DG执行
alter session set nls_date_format=‘DD-MON-YYYY HH24:MI:SS’;
select sequence#,first_time,next_time,applied from v$archived_log ORDER BY sequence#;
在次切换日志
alter system switch logfile;
select sequence#,first_time,next_time,applied from v$archived_log ORDER BY sequence#;
select name,open_mode,database_role,db_unique_name,protection_mode from v$database;
DB上查看
shutdown immediate;
startup mount
alter database open read only;
select name,open_mode,database_role, protection_mode from v$database;