标签:fetch group by clu 重做日志 lines top tab 是否一致 alias
生产环境谨慎使用,建议生产环境采用RMAN备份恢复的方式。
本演示案例所用环境:
|
primary |
standby |
OS Hostname |
pry |
std |
OS Version |
RHEL6.5 |
RHEL6.5 |
DB Version |
11.2.0.4 |
11.2.0.4 |
db_name |
stephen |
stephen |
db_unique_name |
stephen |
standby |
service_names |
stephen |
standby |
instance_name |
stephen |
standby |
SQL> select force_logging from v$database;
SQL> alter database force logging;
(1) tnsnames.ora
STEPHEN =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = pry)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = stephen)
)
)
STANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standby)
(UR = A)
)
)
(2) tnsping命令解析网络服务名,命令须返回OK.
此时,standby端未配置监听,无法解析,可以standby配置后再测试。
$ tnsping standby
(3) 密码文件
若无密码文件,则创建密码文件。格式:orapw<ORACLE_SID>
cd $ORACLE_HOME/dbs
orapwd file=orapwstephen password=oracle ignorecase=y force=y
添加standby logfile 的要求:
(1) 确保主和备数据库上的日志文件大小是相同的
(2) 确定备库重做日志文件组的适当数目
Standby logfile数 = (每个线程的logfile数+1)* 线程数
(3) 检查create database时指定的MAXLOGFILES和MAXLOGMEMBERS参数,可以通过trace controlfile出来查看
(4) RAC环境创建standby logfile,指定thread#创建
每个thread的standby logfile数 = 每个thread的logfile数 + 1
检查当前环境的logfile:
set lines 200 pages 300
col member for a60
select a.thread#,a.group#,b.member,b.type,a.bytes/1024/1024 MB from v$log a,v$logfile b where a.group#=b.group#
union all
select a.thread#,a.group#,b.member,b.type,a.bytes/1024/1024 MB from v$standby_log a,v$logfile b where a.group#=b.group#;
根据查询的logfile 信息上文添加standby logfile的要求,添加合理的standby logfile,然后用上面的sql再次查看当前环境的logfile:
SQL> alter database add standby logfile
group 4 ‘/u01/oradata/stephen/redo04.log‘ size 50M,
group 5 ‘/u01/oradata/stephen/redo05.log‘ size 50M,
group 6 ‘/u01/oradata/stephen/redo06.log‘ size 50M,
group 7 ‘/u01/oradata/stephen/redo07.log‘ size 50M;
备份spfile:
create pfile=‘/tmp/pfile.bak‘ from spfile;
修改以下参数,其中stephen,standby分别为primary,standby的db_unqiue_name/TNS-Alias,详见参数详解部分:
alter system set log_archive_config=‘dg_config=(stephen,standby)‘;
alter system set log_archive_dest_1=‘location=/oradata/arch valid_for=(all_logfiles,all_roles) db_unique_name=stephen‘;
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_max_processes=30; #根据需求调整个数
--确认以下参数,若不为默认值则修改:
alter system set remote_login_passwordfile=exclusive scope=spfile;
# remote_login_passwordfile=exclusive/shared
alter system set log_archive_dest_state_1=enable;
alter system set log_archive_dest_state_2=enable;
--可修改归档日志格式,与datafile区分:
alter system set log_archive_format=‘%t_%s_%r.arc‘ scope=spfile;
--备角色参数:
alter system set fal_server=standby;
alter system set standby_file_management=auto;
alter system set db_file_name_convert=‘/oradata/standby‘,‘/oradata/stephen‘ scope=spfile;
alter system set log_file_name_convert=‘/oradata/standby‘,‘/oradata/stephen‘ scope=spfile;
注:以上参数,指定spfile修改的,在实例重启后生效。
首先确认当前数据库是否是归档模式,如果不是,则打开归档模式。
archive log list;
shutdown immediate;
startup mount;
alter database archivelog;
archive log list;
alter database open;
export ORACLE_BASE=/oracle/app/oracle
export ORACLE_HOME=/oracle/app/oracle/product/11.2.0/db_1
export ORACLE_SID=standby
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib #不同平台变量名不一样
(1) listener.ora
配置静态监听:
LISTENER =
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=std)(PORT=1521))
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=standby)
(SID_NAME=standby)
(ORACLE_HOME=/oracle/app/oracle/product/11.2.0/db_1)
)
)
启用监听:
lsnrctl start
lsnrctl status
(2) tnsnames.ora
STEPHEN =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = pry)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = stephen)
)
)
STANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = std)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = standby)
(UR = A)
)
)
(2) tnsping命令解析网络服务名,命令须返回OK.
$ tnsping stephen
(3) 密码文件
使用主库的密码文件:
scp pry:$ORACLE_HOME/dbs/orapwstephen $ORACLE_HOME/dbs/orapwstandby
mkdir -p $ORACLE_BASE/admin/standby/{adump,dpdump,pfile}
mkdir -p /oradata/{standby,arch}
只需要设置一个参数:db_name
echo ‘*.db_name=standby’>$ORACLE_HOME/dbs/initstandby.ora
启动数据库到nomount阶段:
startup nomount;
在primary端执行以下SQL进行 RMAN duplicate创建ADG,Oracle自动mount standby db:
$ rman target / auxiliary sys/oracle@standby
RMAN> run {allocate channel pry1 type disk;
allocate channel pry2 type disk;
allocate channel pry3 type disk;
allocate channel pry4 type disk;
allocate auxiliary channel stby type disk;
duplicate target database for standby from active database
spfile
parameter_value_convert ‘stephen‘,‘standby‘
set db_unique_name=‘standby‘
set instance_name=‘standby‘
set service_names=‘standby‘
set db_file_name_convert=‘/oradata/stephen‘,‘/oradata/standby‘
set log_file_name_convert=‘/oradata/stephen‘,‘/oradata/standby‘
set control_files=‘/oradata/standby/control01.ctl‘
set log_archive_max_processes=‘4‘
set fal_server=‘stephen‘
set standby_file_management=‘AUTO‘
set log_archive_config=‘dg_config=(stephen,standby)‘
set log_archive_dest_2=‘service=stephen lgwr async valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=stephen‘
;
}
如果打开standby db至read only时,报以下错误:
SQL> alter database open read only;
alter database open read only
*
ERROR at line 1:
ORA-10458: standby database requires recovery
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: ‘/oradata/standby/system01.dbf‘
只需要在mount阶段,执行归档日志应用,Fetch Archive Gap即可,primary端切换几次日志,确保standby一致后再打开standby db至read only:
SQL> recover managed standby database disconnect from session;
打开standby至read only模式,实时应用日志:
alter database open read only;
recover managed standby database using current logfile disconnect;
跟踪primary,standby database的alert log,观察是否有错误发生,也可以看到应用日志的相关信息。
确认standby是否应用日志:
--primary端多切几次日志,观察alert log信息。
alter system switch logfile;
alter system switch logfile;
--观察主备库日志序列号
archive log list;
--primary端查询v$archived_log视图,确认日志是否被应用:
set lines 300 pages 300
col name for a20
select name,dest_id,thread#,sequence#,standby_dest,applied,registrar,completion_time from v$archived_log
where standby_dest=‘YES‘
order by thread#,sequence#;
--primary端查询primary,standby的最大日志序列号是否一致:
select ‘Primary :‘ "DB Role",thread#,max(sequence#)
from v$archived_log
where standby_dest=‘NO‘
group by thread#
union
select ‘Standby :‘ "DB Role",thread#,max(sequence#)
from v$archived_log
where standby_dest=‘YES‘ and applied=‘YES‘
group by thread#
order by thread#;
标签:fetch group by clu 重做日志 lines top tab 是否一致 alias
原文地址:http://www.cnblogs.com/liang545621/p/7529048.html