1.oracle 12C dataguard搭建环境(主从库相同,从库只装软件不建库)
OS:
[oracle@oracle-two ~]$ more /etc/redhat-release
CentOS release 6.5 (Final)
ORACLE:
SQL> SELECT * FROM V$VERSION;
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
PL/SQL Release 12.2.0.1.0 - Production 0
CORE 12.2.0.1.0 Production 0
TNS for Linux: Version 12.2.0.1.0 - Production 0
NLSRTL Version 12.2.0.1.0 - Production 0
2.dataguard主库参数配置
2.1检查主库状态,pdb是否为open,
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 CDB READ WRITE NO
2.2检查主库是否开启force_logging,否则要执行以下命令
SQL> select force_logging from v$database;
FORCE_LOGGING
---------------------------------------
YES
SQL> alter database force logging;
Database altered.
2.3检查主库归档模式开启情况
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled(未开启归档模式)
Archive destination /u01/app/oracle/oradata/arch
Oldest online log sequence 51
Current log sequence 53
执行名利开启归档
SQL> alter database archivelog;
Database altered.
再次查看,归档模式开启情况
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled(归档模式开启)
Archive destination /u01/app/oracle/oradata/arch
Oldest online log sequence 51
Next log sequence to archive 53
Current log sequence 53
2.4检查在线日志redolog,确认member和group#,根据在线日志添加standby logfile(以下操作均在CBD下操作)
SQL> select group#, members, bytes from v$log;
GROUP# MEMBERS BYTES
---------- ---------- ----------
1 2 209715200
3 2 209715200
2 2 209715200
添加standby logfile(3+1)
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/ORCL/onlinelog/stdredo01.log' size 50M;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/ORCL/onlinelog/stdredo02.log' size 50M;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/ORCL/onlinelog/stdredo03.log' size 50M;
ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/ORCL/onlinelog/stdredo04.log' size 50M;
3.配置两个数据库的网络参数文件tnsname.ora和listener.ora
primary和Standby上的tnsnames.ora相同。
3.1配置tnsnames.ora参数文件
#primary database
porcl =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle-one)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.12.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
#standby database
sorcl=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.12.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
(UR=A)
)
)
#pluggable database
cdb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle-one)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.12.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = cdb)
)
)
3.2配置监听文件
# listener.ora Network Configuration File: /u01/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/12.2.0/dbhome_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle-one)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
LISTENERD =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle-one)(PORT = 1521))
)
)
4.配置数据库参数文件
注意:数据库参数文件的调整时注意PDB和CDB的切换运行,否则会报如下错误
ORA-65040: operation not allowed from within a pluggable database
4.1主库配置完后参数文件:如下(如果是从pfile指定文件启动,启动完成后要创建spfile文件)
orcl.__data_transfer_cache_size=0
orcl.__db_cache_size=234881024
orcl.__inmemory_ext_roarea=0
orcl.__inmemory_ext_rwarea=0
orcl.__java_pool_size=4194304
orcl.__large_pool_size=8388608
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=272629760
orcl.__sga_target=507510784
orcl.__shared_io_pool_size=20971520
orcl.__shared_pool_size=222298112
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='12.2.0'
*.control_files='/u01/app/oracle/oradata/ORCL/controlfile/o1_mf_dqflr6xp_.ctl','/u01/app/oracle/fast_recovery_area/orcl/ORCL/controlfile/o1_mf_dqflr78t_.ctl'
*.db_block_size=8192
*.db_create_file_dest='/u01/app/oracle/oradata'
*.db_file_name_convert='/u01/app/oracle/oradata/ORCL/datafile/','/u01/app/oracle/oradata/ORCL/datafile/'
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area/orcl'
*.db_recovery_file_dest_size=8016m
*.db_unique_name='porcl'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.enable_pluggable_database=true
*.fal_client='PORCL'
*.fal_server='SORCL'
*.log_archive_config='DG_CONFIG=(porcl,sorcl)'
*.log_archive_dest_1='location=/u01/app/oracle/oradata/arch db_unique_name=porcl'
*.log_archive_dest_2='service=sorcl LGWR ASYNC noaffirm reopen=60 valid_for=(online_logfiles,primary_role) db_unique_name=sorcl'
*.log_archive_dest_state_2='enable'
*.log_file_name_convert='/u01/app/oracle/oradata/ORCL/onlinelog/','/u01/app/oracle/oradata/ORCL/onlinelog/','/u01/app/oracle/fast_recovery_area/orcl/ORCL/onlinelog/','
/u01/app/oracle/fast_recovery_area/orcl/ORCL/onlinelog/'
*.memory_target=744m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='ORCL'
*.standby_file_management='auto'
*.undo_tablespace='UNDOTBS1'
4.2将主库修改后的参数文件传送到备库
4.3修改从库数据库参数文件并使用该参数文件从pfile启动。
*.db_unique_name=
*.log_archive_config=
*.log_file_name_convert=
*.db_file_name_convert=
*.log_archive_dest_1=
*.log_archive_dest_2=
*.standby_file_management=
*.fal_server=
*.fal_client=
4.4主库密码文件传送到备库
[oracle@oracle-one dbs]$ scp orapworcl orcle-one:/dbs/
5.启动standby database到nomount状态
5.1检查tns连接名是否正常(主备库均需要检查)
tnsping porcl
tnsping sorcl
lsnrctl
5.2启动备库
startup pfile='/home/oracle/standbypfile.ora' nomount
启动后创建spfile
create spfile from pfile='/home/oracle/standbypfile.ora'
6.恢复备库
[oracle@oracle-one dbs]$rman target sys/oracle@porcl auxiliary sys/oracle@sorcl
RMAN> duplicate target database for standby nofilenamecheck from active database;
Finished Duplicate Db at 2016:04:0109:26:00
完成备库的克隆。
6.1查看备库状态是否正常
show pdbs
select log_mode,open_mode ,database_role from v$database;
6.2手工同步
手工启动同步
alter database recover managed standby database using current logfile disconnect from session;
取消手动同步
alter database recover managed standby database cancel
6.3验证数据同步
主库插入数据
SQL> conn so/ziqiyuan@cdb
Connected.
SQL> insert into t_padd values(0,'dh');
SQL> commit;
主库切换在线日志
SQL> alter system switch logfile;
备库查看那表内数据的同步情况
SQL> select * from so.t_padd;
ID NAME
---------- ------------
1 cag
8 haha
2 zfg
3 zfeg
0 dh
数据同步完成。
7.配置过程中报错及处理方法
安装过程中出现错误以及处理方法
报错一、[ora12c@dave network-scripts]$ rman target sys/ziqiyuan@cdb auxiliary sys/ziqiyuan@scdb;
ERROR:
ORA-12528: TNS:listener: all appropriate instances are blocking new connections
处理方法:添加(UR=A)
# tnsnames.ora Network Configuration File: D:\oracle\product\10.1.0\db_1
\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
sorcl=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.12.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
(UR=A)
)
)
报错二、RMAN-07536: command not allowed when connected to a Pluggable Database
处理方法:修改target后面tns连接名,服务名执行cdb而非pdb
报错三、
Starting backup at 2018:03:3122:58:42
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/31/2018 22:58:44
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 03/31/2018 22:58:44
ORA-17627: ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3701
Additional information: 1724833639
ORA-17629: Cannot connect to the remote database server
本案例处理方法:主备服务器的tnsnames.ora修改为一致,切记漏改
报错三:
contents of Memory Script:
{
sql clone "create spfile from memory";
shutdown clone immediate;( 修改完后一定得改成spfile启动,负责会报错)
startup clone nomount;
restore clone from service 'cdb' standby controlfile;
}
executing Memory Script
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/31/2018 23:20:35
RMAN-05501: aborting duplication of target database
RMAN-03015: error occurred in stored script Memory Script
RMAN-04006: error from auxiliary database: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
处理方法:实例从pfile启动后没有改成spfile启动,修改后再次复制成功