RAC+DG | RAM:4G ,OS:CENTOS7.5 |
HOSTNAME:RAC1: | PUBLIC IP:162.168.145.244,PRIV IP:192.168.89.219,VIP:192.168.145.144,scanip:192.168.145.140 |
HOSTNAME:RAC2: | PUBLIC IP:162.168.145.245,PRIV IP:192.168.89.220,VIP:192.168.145.145,scanip:192.168.145.140 |
备库(hostname:racdg): | ip:192.168.145.247 |
rac DB | DB_NAME=oem db_unique_Name=oem |
备库 | DB_NAME=oem db_unique_name=oem_dg |
sql> alter database force loggin
如果数据库未开启归档,通过以下的方式进行开启
查看数据库是否运行在归档模式:
sql>archive log list;
如上所示未开启归档,可按下面方法开启数据库归档
SQL> shutdown immediate #关闭数据库
SQL> startup mount; #启动到mount状态
SQL> alter database archivelog; #开启归档
SQL> alterdatabase open; #open数据库
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(oem,oem_dg)' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=oem' scope=both sid='*';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=oem_dg LGWR AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=oem_dg' scope=both sid='*';
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
alter system set log_archive_max_processes=4 scope=both sid='*';
alter system set fal_server=oem_dg scope=both sid='*';
alter system set DB_FILE_NAME_CONVERT='/oradata/oem_dg/datafile/','+DATADG/oem/datafile/' scope=spfile sid='*';
alter system set LOG_FILE_NAME_CONVERT='/oradata/oem_dg/','+DATADG/oem/' scope=spfile sid='*';
alter system set standby_file_management=AUTO scope=both sid='*';
查看每个实例的最大日志:
select inst_id,count(1),max(bytes) from gv$log group by inst_id;
每个实例有四组log,最大50M,每个实例需要建立count+1个strandby日志,大小为最大日志大小,也就是5组50M大小的standby日志:
ASMCMD> pwd
+DATADG/OEM
ASMCMD> mkdir STANDBYLOG
alter system set standby_file_management=manual scope=both sid='*';
alter database add standby logfile thread 1 group 9 '+datadg/oem/standbylog/standby_group_01.log' size 52428800;
alter database add standby logfile thread 1 group 10 '+datadg/oem/standbylog/standby_group_02.log' size 52428800;
alter database add standby logfile thread 1 group 11 '+datadg/oem/standbylog/standby_group_03.log' size 52428800;
alter database add standby logfile thread 1 group 12 '+datadg/oem/standbylog/standby_group_04.log' size 52428800;
alter database add standby logfile thread 1 group 13 '+datadg/oem/standbylog/standby_group_05.log' size 52428800;
alter system set standby_file_management=auto scope=both sid='*';
select count(*) from v$standby_log;
oracle用户下执行 rman target /进入rman,然后执行下面的命令备份
run
{
sql "alter system switch logfile";
allocate channel ch1 type disk format '/u01/app/oracle/backup/Primary_for_DG_%U';
backup database;
backup current controlfile for standby;
sql "alter system archive log current";
}
scp /u01/app/oracle/backup/* 192.168.145.247:/u01/app/oracle/backup/
create pfile='/u01/app/oracle/standby_pfile.ora' from spfile;
*.audit_file_dest='/u01/app/oracle/admin/oem_dg/adump'
*.audit_trail='db'
*.cluster_database=false
*.compatible='11.2.0.4.0'
*.control_files='/oradata/oem_dg/controlfile/control01.ctl','/oradata/oem_dg/controlfile/control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='/oradata'
*.db_domain=''
*.db_file_name_convert='+DATADG/oem/datafile/','/oradata/oem_dg/datafile/'
*.db_name='oem'
*.db_unique_name='oem_dg'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=oemXDB)'
*.fal_server='OEM'
*.job_queue_processes=100
*.log_archive_config='DG_CONFIG=(oem,oem_dg)'
*.log_archive_dest_1='LOCATION=/backup/oem VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=oem_dg'
*.log_archive_dest_2='SERVICE=oem LGWR AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=oem'
*.log_archive_format='%t_%s_%r.arc'
*.log_archive_max_processes=4
*.log_buffer=10485760
*.log_file_name_convert='+DATADG/oem/','/oradata/oem_dg/'
*.memory_target=1581252608
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='exclusive'
*.session_cached_cursors=300
*.sessions=800
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
修改了之后,传递给备库
scp /u01/app/oracle/standby_pfile.ora 192.168.145.247:/u01/app/oracle/
#这里主库的ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
#从库的ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
#主库的ORACLE_SID=oem
#从库的ORACLE_SID=oem
#主库执行
scp $ORACLE_HOME/dbs/orapw$ORACLE_SID 192.168.145.247:/
#从库执行
#从库将复制过来的文件放在$ORACLE_HOME/dbs/下
mv $ORACLE_HOME/dbs/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID.bak
#接下来将传过来的orapwoem1复制到$ORACLE_HOME/dbs/目录下并更名为orapwoem,和从库的sid保持一致,即是替换掉了原来的密码,现在使用主库的密码
#如果更换密码不成功,后面在做日志传输的时候会报错
OEM =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = scanip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem)
)
)
OEM_DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.145.247)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem_dg)
(SID=oem)
(UR=A)
)
)
OEM1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.145.244)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem)
(SID=oem1)
)
)
OEM2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.145.245)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem)
(SID=oem2)
)
)
#oracle用户下:
mkdir -p /app/oracle/admin/oem_dg/adump
mkdir -p /app/oracle/diag/rdbms/oem_dg/oem/trace/cdump
#root用户下:
#用于spfile中的.log_archive_dest_1
mkdir /backup
chown oracle:oinstall /backup
#创建oradata相关的目录,这里对应着RAC的ASM磁盘上的储存文件
mkdir -p /oradata/oem_dg/
cd /oradata/oem_dg/
mkdir controlfile
mkdir datafile
mkdir onlinelog
mkdir standbylog
chown oracle:oinstall /oradata
chown oracle:oinstall /oradata/*
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration to
OEM =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.145.140)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem)
)
)
OEM_DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.145.247)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem_dg)
(SID=oem)
)
)
OEM1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.145.244)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem)
(SID=oem1)
)
)
OEM2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.145.245)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oem)
(SID=oem2)
)
)
~
export ORACLE_SID=oem
sqlplus sys as sysdba
startup nomount pfile='/u01/app/oracle/standby_pfile.ora';
rman target / auxiliary sys/111111@oem_dg
#111111是密码
#rman下执行
DUPLICATE TARGET DATABASE FOR STANDBY NOFILENAMECHECK;
create spfile from pfile='/u01/app/oracle/standby_pfile.ora';
#关闭
shutdown immediate
#开启并挂载
startup mount
alter database set standby database to maximize availability;
alter database recover managed standby database disconnect from session;
主库创建表
create table testdg as select * from user_tables;
alter system switch logfile;
备库查看相关的日志输出
tail -f /u01/app/oracle/diag/rdbms/oem_dg/oem/trace/alert_oem.log
SELECT a.th, a.seq transfered, b.seq archived
FROM (SELECT local.thread# th, MAX (local.sequence#) seq
FROM (SELECT thread#, sequence#
FROM v$archived_log
WHERE dest_id = 1) local
WHERE local.sequence# IN
(SELECT sequence#
FROM v$archived_log
WHERE dest_id = 2 AND thread# = local.thread#)
GROUP BY local.thread#) a,
(SELECT thread# th, MAX (sequence#) seq
FROM v$archived_log
WHERE dest_id = 1
GROUP BY thread#) b
WHERE a.th = b.th
ORDER BY 1;