Dataguard配置总结
Dataguard配置总结
本例情形
在主库存在运行的情况下,增加配置dataguard备库,实现双机热备,高可用性。
主库要求,归档模式,强制归档。
主库idty
备库idty_st
1、密码文件
为备库制作密码文件、参数文件。密码文件直接使用主库文件,参数文件需要修改。
cp orapwidty ~/
scp orapwidty 132.108.200.133:/home/oracle
2、参数文件
create pfile='/home/oracle/pfileidty_st.ora' from spfile
scp pfileidty_st.ora 132.108.200.133:/home/oracle
3、参数文件修改
--------------以下修改作为参考
*.log_archive_config='dg_config=(idty,idty_st)'
*.DB_UNIQUE_NAME=idty_st
*.LOG_ARCHIVE_DEST_2='SERVICE=idty ARCH VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=idty'
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER=idty
*.FAL_CLIENT=idty_st
*.STANDBY_FILE_MANAGEMENT=AUTO
*.standby_archive_dest='/home/oracle/app/oracle/stlog/idty'
修改备课日志目录,如果不改默认在dbs目录。如果存在多个备库,则日志数据不便于区分。
alter system set standby_archive_dest='/home/oracle/app/oracle/stlog/idty' scope=both;
4、备库创建数据文件目录、回闪区日志文件目录
日志目录/oradat/idty /fast_recovery_area/idty
接收日志目录 /stlog/idty
5、启动备库数据库 ,启动到nomount
export ORACLE_SID=idty
产生spfile
create spfile from pfile='/home/oracle/pfileidty_st.ora';
startup nomount
修改备课日志目录,如果不改默认在dbs目录。如果存在多个备库,则日志数据不便于区分。
alter system set standby_archive_dest='/home/oracle/app/oracle/stlog/idty' scope=both;
sqlplus "/as sysdba"
select name from v$database;
6、配置tnsnames listener
主库/备库配置tnsnames
IDTY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 132.108.120.179)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = idty)
)
)
IDTY_ST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 132.108.200.133)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = idty_st)
)
)
备库配置监听
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=idty_st)
(ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome1)
(SID_NAME=idty))
)
重启监听
7、rman duplicate复制主库创建备库
在备库,rman登录主库
rman target sys/xxxxxx@idty auxiliary sys/xxxxxx@idty_st
开始复制
DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER (适用与主、备库oracle_home路径不同,设置了目录转换的情形。)
如果目录不同,需要修改pfile,增加目录转换。本例目录相同就没有设置目录转换。
DB_FILE_NAME_CONVERT='/home/app/oracle/oradata/ljydb','/home/oracle/app/oracle/oradata/ljydb'
LOG_FILE_NAME_CONVERT='/home/app/oracle/oradata/ljydb','/home/oracle/app/oracle/oradata/ljydb','/home/app/oracle/fast_recovery_area/ljydb','/home/oracle/app/oracle/fast_recovery_area/ljydb'
如果和主库路径相同,则要加NOFILENAMECHECK参数。否则报RMAN-05001,conflicts with a file used by the target database。
DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;
8、主库配置
保证主库要求,归档模式,强制归档。
ALTER DATABASE FORCE LOGGING;
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
修改参数:
alter system set log_archive_config='dg_config=(idty,idty_st)' scope=both;
alter system set log_archive_dest_2='service=idty_st async valid_for=(online_logfiles,primary_role) db_unique_name=idty_st' scope=both;
alter system set log_archive_dest_state_2=enable;
建议先关闭日志传输,等备库配置好后在启动传输。
alter system set log_archive_dest_state_2=defer;
show parameter log_archive_config;
show parameter log_archive_config;
9、备库应用日志
应用日志
alter database recover managed standby database disconnect from session;
暂停日志应用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
10、主库启动日志传输
启动日志传输
alter system set log_archive_dest_state_2=enable;
建议先关闭日志传输,等备库配置好后在启动传输。
--测试下 产生归档文件
alter system switch logfile;
11、多个实例监听静态配置方法
listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cvm-dbsrv02)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=ljydb_st)
(ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome1)
(SID_NAME=ljydb))
(SID_DESC=
(GLOBAL_DBNAME=idty_st)
(ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome1)
(SID_NAME=idty))
)
12、问题及解决方法
ORA-17628:问题解决,原因是备库缺少日志目录、数据文件目录,创建相应的目录,即可解决问题。
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 10/26/2017 16:56:20
RMAN-05501: aborting duplication of target database
RMAN-03015: error occurred in stored script Memory Script
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/26/2017 16:56:20
ORA-17628: Oracle error 19505 returned by remote Oracle server
没有创建日志目录/oradat/idty /fast_recovery_area/idty
ORA-32004:问题原因,pfile增加了参数设置,改变了默认值则出现提示,不影响数据库启动。本例子设置了参数standby_archive_dest
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
!!!!!!!!!----------------------
SQL> startup nomount
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.
看日志:
Deprecated system parameters with specified values:
standby_archive_dest
##### ---------------------
RMAN-05001,主备库oracle目录相同的情况下,如果没有nofilenamecheck参数,则复制库的时候会报这个错。
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 10/27/2017 10:40:46
RMAN-05501: aborting duplication of target database
RMAN-05001: auxiliary file name /home/oracle/app/oracle/oradata/idty/ts_data03.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name /home/oracle/app/oracle/oradata/idty/ts_data02.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name /home/oracle/app/oracle/oradata/idty/ts_data01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name /home/oracle/app/oracle/oradata/idty/users01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name /home/oracle/app/oracle/oradata/idty/undotbs01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name /home/oracle/app/oracle/oradata/idty/sysaux01.dbf conflicts with a file used by the target database
RMAN-05001: auxiliary file name /home/oracle/app/oracle/oradata/idty/system01.dbf conflicts with a file used by the target database
!!!!!!!!!------以下原因描述来源网络:
nofilenamecheck如果副本数据库与目标库不在同一台机器上,并且副本数据库的在线日志文件路径与目标库相同,
则运行duplicate命令时必须指定NOFILENAMECHECK参数以避免冲突提示。
晕了吧,异机操作路径相同还必需指定NOFILENAMECHECK。此处oracle表现的很傻,
它不知道你要恢复的路径是在另一台机器上,它只是认为要恢复到的路径怎么跟目标数据库表现的一样呢?
会不会是要覆盖目标数据库啊,为了避免这种情形,于是它就报错。所以一旦异机恢复,并且路径相同,
那么你必须通过指定NOFILENAMECHECK来避免oracle的自动识别。
13、常用sql语句
查看日志目录
select *From v$archive_dest;
查看数据库是否归档模式
select log_mode,force_logging from v$database
select * from V$DATAGUARD_CONFIG ;
查数据库
select *From v$archive_dest_status
select open_mode from v$database;
select *from v$session;
查看日志应用传输清单
SELECT SEQUENCE#,name , FIRST_TIME, NEXT_TIME ,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE# desc;
查看备库日志传输、应用进程状态、日志
SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;
SELECT * FROM V$DATAGUARD_STATUS order by timestamp desc;
1、扩大恢复目录空间大小
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE=10G SCOPE=BOTH;
14、dataguard方案的局限性思考
因为dataguard的原理是通过网络传输归档日志到备库,然后在备库应用日志,实现双机热备。
那么对于日志量生成速度太快的数据库,临界情况是主库日志产生的速度大于网络传输数据的速度,将导致备库永远追不上主库,主库未传输的日志占用空间将不断扩张,而且因为未传输完成也不能清除。
因此,dataguard方案不适合分析型数据库。
从经验人士获知的dataguard可适应的极限日志量为400G-500G/每天。(未实验验证)