浅谈DataGuard主从安装及测试
DataGuard:
primary : 192.168.0.111; db_name=orcl; db_unique_name=orcl
standby : 192.168.0.113; db_name=orcl; db_unique_name=aux1
在主库执行的操作:
1.主库要运行在归档模式
archive log list
shutdown immediate
startup mount
alter database archivelog;
alter database open;
archive log list
-
SQL> archive log list
-
Database log mode Archive Mode
-
Automatic archival Enabled
-
Archive destination /home/oracle/arc_orcl_dest1/
-
Oldest online log sequence 36
-
Next log sequence to archive 38
-
Current log sequence 38
2.主库要打开force logging
select force_logging from v$database;
NO/YES
alter database force logging;
-
SQL> select force_logging from v$database;
-
-
FOR
-
---
-
YES
-
-
Elapsed: 00:00:00.01
3.主库要打开dataguard开关
alter system set log_archive_config='dg_config=(主库的唯一名,从库的唯一名)';
alter system set log_archive_config='dg_config=(orcl,aux1)';
4.修改主库本地归档参数
mkdir -p /home/oracle/arc_orcl_dest1/
alter system set log_archive_dest_1='location=/home/oracle/arc_orcl_dest1/ valid_for=(日志类型,数据库角色) db_unique_name=orcl';
alter system set log_archive_dest_1='location=/home/oracle/arc_orcl_dest1/ valid_for=(online_logfiles,primary_role) db_unique_name=orcl';
5.主库启用远程归档参数
alter system set log_archive_dest_2='service=连接从库的服务命名 valid_for=(日志类型,数据库角色) db_unique_name=aux1';
alter system set log_archive_dest_2='service=aux1srv valid_for=(online_logfiles,primary_role) db_unique_name=aux1';
6.在主库为从库拷贝口令文件
scp $ORACLE_HOME/dbs/orapw$ORACLE_SID oracle@192.168.0.113:$ORACLE_HOME/dbs/orapwaux1
7.为从库准备参数文件:使用主库的参数文件修改
SQL> create pfile from spfile;
scp $ORACLE_HOME/dbs/init$ORACLE_SID.ora oracle@192.168.0.113:$ORACLE_HOME/dbs/initaux1.ora
-----------------------------------------------------------------------------------------
*.audit_file_dest='/u01/app/oracle/admin/aux1/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/aux1/control01.ctl'
*.db_block_size=8192
*.db_domain='example.com'
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_config='dg_config=(orcl,aux1)'
*.memory_target=843055104
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
db_unique_name='aux1'
log_archive_dest_3='location=/home/oracle/arc_aux1_dest3/ valid_for=(standby_logfiles,standby_role) db_unique_name=aux1'
standby_file_management=auto
db_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/aux1/'
log_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/aux1/'
-----------------------------------------------------------------------------------------
备注:db_file_name_convert及log_file_name_convert路径通过下面命令查看得出的,这里为
-
SQL> select name from v$datafile;
-
-
NAME
-
----------------------------------------------------------------------------------------------------
-
/u01/app/oracle/oradata/orcl/system01.dbf
-
/u01/app/oracle/oradata/orcl/sysaux01.dbf
-
/u01/app/oracle/oradata/orcl/undotbs01.dbf
-
/u01/app/oracle/oradata/orcl/users01.dbf
-
SQL> select member from v$logfile;
-
-
MEMBER
-
----------------------------------------------------------------------------------------------------
-
/u01/app/oracle/oradata/orcl/redo03.log
-
/u01/app/oracle/oradata/orcl/redo02.log
-
/u01/app/oracle/oradata/orcl/redo01.log
8.为从库准备相关目录
mkdir -p /u01/app/oracle/admin/aux1/adump
mkdir -p /u01/app/oracle/oradata/aux1/
mkdir -p /u01/app/oracle/fast_recovery_area
mkdir -p /home/oracle/arc_aux1_dest3/
9.修改从库环境变量,创建spfile,启动实例到nomount
export ORACLE_SID=aux1 #(当前会话有限,要是想永久生效,修改环境变量)类似如下:
[oracle@slave ~]$ vim .bashrc
-
export ORACLE_BASE=/u01/app/oracle
-
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
-
export PATH=$ORACLE_HOME/bin:$PATH
-
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
-
#export ORACLE_SID=orcl
-
export ORACLE_SID=aux1 #standby
-
export ORACLE_OWNER=oracle
-
export ORACLE_TERM=vt100
-
export THREADS_FLAG=native
-
export LANG=en_US
sqlplus / as sysdba
create spfile from pfile;
startup nomount
10.在从库配置并启动监听程序
vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
-
SID_LIST_LISTENER =
-
(SID_LIST =
-
(SID_DESC =
-
(GLOBAL_DBNAME = aux1.example.com)
-
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
-
(SID_NAME = aux1)
-
)
-
)
-
-
LISTENER =
-
(DESCRIPTION_LIST =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.113)(PORT = 1521))
-
)
-
)
备注:上面GLOBAL_DBNAME是通过show parameter name命令得出的
service_names string aux1.example.com
lsnrctl stop
lsnrctl start
11.在主库配置服务命名
vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
-----------------------------------------------------------------------------------------
aux1srv =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.111)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = aux1.example.com)
)
)
-----------------------------------------------------------------------------------------
12.在主库使用网络连接从库
sqlplus sys/oracle@aux1srv as sysdba
13.在主库启动rman复制从库
rman target / auxiliary sys/oracle@aux1srv
RMAN> duplicate target database for standby from active database;
14.在从库增加standby log(和主库的online log必须一样大小)
select bytes from v$log;
-
SQL> select bytes from v$log;
-
-
BYTES
-
----------
-
52428800
-
52428800
-
52428800
-
-
Elapsed: 00:00:00.02
select member from v$logfile;
-
SQL> select member from v$logfile;
-
-
MEMBER
-
----------------------------------------------------------------------------------------------------
-
/u01/app/oracle/oradata/orcl/redo03.log
-
/u01/app/oracle/oradata/orcl/redo02.log
-
/u01/app/oracle/oradata/orcl/redo01.log
alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo04.log' size 52428800;
alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo05.log' size 52428800;
alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo06.log' size 52428800;
alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo07.log' size 52428800;
alter database add standby logfile '/u01/app/oracle/oradata/aux1/redo08.log' size 52428800;
15.打开从库
SQL> alter database open;
16.在从库启用日志应用
alter database recover managed standby database using current logfile disconnect from session;
17.在主库切换日志
select GROUP#,THREAD#,SEQUENCE#,STATUS from v$log;
SQL> alter system switch logfile;
-
SQL> select GROUP#,THREAD#,SEQUENCE#,STATUS from v$log;
-
-
GROUP# THREAD# SEQUENCE# STATUS
-
---------- ---------- ---------- ----------------
-
1 1 37 INACTIVE
-
2 1 38 CURRENT
-
3 1 36 INACTIVE
-
-
Elapsed: 00:00:00.00
18.在从库查看日志应用情况
SQL> select sequence#,applied from v$archived_log;
-
SQL> select sequence#,applied from v$archived_log;
-
-
SEQUENCE# APPLIED
-
---------- ---------
-
30 YES
-
32 YES
-
29 YES
-
31 YES
-
33 YES
-
34 YES
-
36 YES
-
37 IN-MEMORY
-
35 YES
-
-
9 rows selected.
-
-
Elapsed: 00:00:00.01
19.在主库做数据修改,提交之后在从库看数据变化
主库:
SQL> select sal from scott.emp;
SQL> update scott.emp set sal=sal+1;
SQL> commit;
SQL> select sal from scott.emp;
-
SQL> select sal from scott.emp;
-
-
SAL
-
----------
-
812
-
1612
-
1262
-
2987
-
1262
-
2862
-
2462
-
3012
-
5012
-
1512
-
1112
-
962
-
3012
-
1312
-
-
14 rows selected.
从库:
SQL> select sal from scott.emp;
-
SQL> select sal from scott.emp;
-
-
SAL
-
----------
-
812
-
1612
-
1262
-
2987
-
1262
-
2862
-
2462
-
3012
-
5012
-
1512
-
1112
-
962
-
3012
-
1312
-
-
14 rows selected.
-
-
Elapsed: 00:00:00.00
可以看成主从数据已经同步了!
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31403979/viewspace-2126918/
,如需转载,请注明出处,否则将追究法律责任。