Oracle data guard 10g 搭建
Posted 春困秋乏夏打盹
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle data guard 10g 搭建相关的知识,希望对你有一定的参考价值。
Oracle data guard 10g 搭建
1系统常规参数检查
硬盘
[[email protected] ~]# df -h
内核
[[email protected] ~]# uname -a
[[email protected] grs]# uname -a
版本
[[email protected] ~]# cat /etc/redhat-release
物理内存
[[email protected] ~]# grep MemTotal /proc/meminfo
虚拟内存
[[email protected] ~]# grep SwapTotal /proc/meminfo
主机名
[[email protected] ~]# hostname
ip地址
[[email protected] ~]# ifconfig
2.关闭防火墙服务iptables&SELinux安全策略&邮件服务 sendmail&时间同步服务 NTP
关闭防火墙服务
[[email protected] ~]# service iptables status
防火墙服务2345级别开机都启动
[[email protected] ~]# chkconfig --list iptables
iptables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
chkconfig iptables off 关闭防火墙服务
关闭 SELinux安全策略
[[email protected] ~]# getenforce
a 永久关闭方法 – 需要重启服务器
修改/etc/selinux/config文件中设置 SELINUX=disabled ,然后重启服务器
[[email protected] ~]# vi /etc/selinux/config
6 SELINUX=disabled
b 临时关闭方法 – 设置系统参数
使用命令 setenforce 0
setenforce 1 设置 SELinux 成为enforcing模式
setenforce 0 设置 SELinux 成为 permissive模式
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce
Permissive
关闭邮件服务sendmail
[[email protected] ~]# service sendmail stop
service sendmail stop
chkconfig sendmail off
关闭 NTP时间同步服务
[[email protected] ~]# service ntpd status
ntpd is stopped
service ntpd stop
chkconfig --list ntpd
主库: ip:10.0.1.103
数据库sid:grs
Db_unique_name:grs
数据库安装路径:/u01/app/oracle/product/10.2.0/db_1
数据文件路径:/u01/app/oracle/oradata/grs/
本地归档路径:/u01/app/oracle/archivelog/
备库: ip:192.168.2.188
数据库sid:grsdg
Db_unique_name:grsdg
数据库安装路径:/mountdisk2/oracle/product/10.2.0/db_1
数据文件路径:/mountdisk2/oracle/oradata/grsdg/-----
/mountdisk2/oracle/oradata/grsdg
本地归档路径:/mountdisk2/oracle/archivelog/
2 准备工作
2.1 设置主库的force logging模式
SQL> conn /as sysdba
Connected.
SQL> select force_logging from v$database;
FOR
---
NO
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FOR
---
YES
alter database no force logging
2.2确认主库的归档模式
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archivelog/
Oldest online log sequence 253
Next log sequence to archive 255
Current log sequence 255
如果是disable,需要启动到mount,
然后SQL> alter database archivelog;/noarchivelog
2.3创建主库密码文件(如果不存在的话)
[[email protected] ~]# cd /u01/app/oracle/product/10.2.0/db_1/dbs/
[[email protected] dbs]# ll
-rw-r----- 1 oracle oinstall 1536 03-24 15:55 orapwgrs
不存在就创建
$ orapwd file=orapwgrs password="987064" entries=10 force=y;
2.4配置主库standby redo log,并验证结果
SQL> alter database add standby logfile group 4 (‘/u01/app/oracle/oradata/grs/redo04.log‘) size 100m;
Database altered.
--删除该日志组
SQL> alter database drop standby logfile group 4;
Database altered.
SQL> alter database add standby logfile group 4 (‘/u01/app/oracle/oradata/grs/redo04.log‘) size 50m;
alter database add standby logfile group 4 (‘/u01/app/oracle/oradata/grs/redo04.log‘) size 50m
*
ERROR at line 1:
ORA-00301: error in adding log file ‘/u01/app/oracle/oradata/grs/redo04.log‘ -
file cannot be created
ORA-27038: created file already exists
Additional information: 1
--需要物理删除
----保证主库与备库的日志大小一样,
SQL> alter database add standby logfile group 4 (‘/u01/app/oracle/oradata/grs/redo04.log‘) size 50m;
Database altered.
SQL> alter database add standby logfile group 5 (‘/u01/app/oracle/oradata/grs/redo05.log‘) size 50m;
Database altered.
SQL> select group#, thread#, sequence#, archived, status from v$standby_log;
GROUP# THREAD# SEQUENCE# ARCHIV STATUS
---------- ---------- ---------- ------ --------------------
4 0 0 YES UNASSIGNED
5 0 0 YES UNASSIGNED
SQL> select group#,type,member from v$logfile;
GROUP# TYPE
---------- -------
MEMBER
--------------------------------------------------------------------------------
3 ONLINE
/u01/app/oracle/oradata/grs/redo03.log
2 ONLINE
/u01/app/oracle/oradata/grs/redo02.log
1 ONLINE
/u01/app/oracle/oradata/grs/redo01.log
GROUP# TYPE
---------- -------
MEMBER
--------------------------------------------------------------------------------
4 STANDBY
/u01/app/oracle/oradata/grs/redo04.log
2.5配置主库初始化参数文件
SQL> create pfile =‘/u01/app/oracle/pfile_20140504‘ from spfile;
File created.
[[email protected] oracle]# cat pfile_20140506
j2grs.__db_cache_size=1509949440
grs.__db_cache_size=1644167168
grs.__java_pool_size=16777216
grs.__large_pool_size=16777216
grs.__shared_pool_size=452984832
grs.__streams_pool_size=0
*.audit_file_dest=‘/u01/app/oracle/admin/grs/adump‘
*.background_dump_dest=‘/u01/app/oracle/admin/grs/bdump‘
*.compatible=‘10.2.0.1.0‘
*.control_files=‘/u01/app/oracle/oradata/grs/control01.ctl‘,‘/u01/app/oracle/oradata/grs/control02.ctl‘,‘/u01/app/oracle/oradata/grs/control03.ctl‘
*.core_dump_dest=‘/u01/app/oracle/admin/grs/cdump‘
*.db_domain=‘‘
*.DB_FILE_NAME_CONVERT=‘/mountdisk2/oracle/oradata/grsdg‘,‘/u01/app/oradata/grs‘
*.db_name=‘grs‘
*.db_recovery_file_dest=‘/u01/app/oracle/flash_recovery_area‘
*.db_recovery_file_dest_size=2147483648
*.DB_UNIQUE_NAME=‘grs‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=grsXDB)‘
*.FAL_CLIENT=‘grs‘
*.FAL_SERVER=‘grsdg‘
*.job_queue_processes=10
*.LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(grs,grsdg)‘
*.LOG_ARCHIVE_DEST_1=‘LOCATION=/u01/app/oracle/archivelog/ arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=grs‘
*.LOG_ARCHIVE_DEST_2=‘SERVICE=grsdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=grsdg‘
*.LOG_ARCHIVE_DEST_STATE_1=‘ENABLE‘
*.log_archive_dest_state_2=‘DEFER‘
*.LOG_ARCHIVE_FORMAT=‘%t_%s_%r.arc‘
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.LOG_FILE_NAME_CONVERT=‘/mountdisk2/oracle/oradata/grsdg‘,‘/u01/app/oradata/grs‘
*.open_cursors=300
*.pga_aggregate_target=1073741824
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.sga_target=2147483648
*.STANDBY_FILE_MANAGEMENT=‘AUTO‘
*.undo_management=‘AUTO‘
*.undo_tablespace=‘UNDOTBS1‘
*.user_dump_dest=‘/u01/app/oracle/admin/grs/udump‘
Arch只支持最高性能模式,
如果standby数据库处于其他模式,就必须使用lgwr默认来传输redo数据
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile=‘/u01/app/oracle/pfile_20140504‘;
File created.
SQL> startup;
3 创建主库相关文件的备份
3.1创建主库数据文件的物理备份(这里采用tar方式)
建立目录
/u02/app/oracle/oradata/grs2
[[email protected] oradata]$ tar -cvf grs.tar grs/
grs/
3.2为备库创建控制文件
SQL> startup mount;
ORACLE instance started.
Total System Global Area 2147483648 bytes
Fixed Size 2022144 bytes
Variable Size 486540544 bytes
Database Buffers 1644167168 bytes
Redo Buffers 14753792 bytes
Database mounted.
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS ‘/u01/app/oracle/control01.ctl‘;
Database altered.
3.3为备库创建初始化参数文件
SQL> CREATE PFILE=‘/u01/oracle/backup/initgrs2.ora‘ FROM SPFILE;
File created.
3.4 将tar包以及主库控制文件和参数文件cp到备库
[[email protected] oradata]# scp -r /u01/app/oracle/oradata/grs [email protected]:/mountdisk2/oracle/oradata/
[[email protected] ~]# scp -r /u01/app/oracle/control01.ctl [email protected]:/mountdisk2/oracle/oradata/
4 设置备库
4.1解压主库数据文件到备库相应位置
[[email protected] oracle]$ tar -xvf grs.tar
grs/
grs/yhq_temp.dbf
grs/cmask01.dbf
grs/undotbs01.dbf
grs/exit
grs/backup
grs/rman_test.dbf
grs/redo04.log
grs/control_backup/
grs/control_backup/control01.ctl
grs/control_backup/control02.ctl
grs/control_backup/control03.ctl
grs/rman_catalog.dbf
[[email protected] ~]$ cd /mountdisk2/oracle/oradata/
[[email protected] oradata]$ ll
总计 6912
-rw-r----- 1 oracle oinstall 7061504 05-04 15:36 control01.ctl
drwxr-x--- 2 oracle oinstall 4096 05-04 14:31 grsdg
[[email protected] oradata]$ cp control01.ctl /mountdisk2/oracle/oradata/grsdg/control01.ctl
[[email protected] oradata]$ cd grsdg/
[[email protected] ~]# scp -r /u01/app/oracle/pfile_20140504 [email protected]:/mountdisk2/oracle/oradata/
[email protected]‘s password:
4.2创建相关没有的目录
[[email protected] oracle]$ mkdir -p archivelog/archivelog
[[email protected] oracle]$ mkdir -p /u02/app/oracle/flash_recovery_area/grs/onlinelog
[[email protected] oracle]$
[[email protected] oracle]$ pwd
/u02/app/oracle
QL> startup nomount;
ORA-09925: Unable to create audit trail file
Linux Error: 2: No such file or directory
Additional information: 9925
SQL> startup mount;
ORA-09925: Unable to create audit trail file
Linux Error: 2: No such file or directory
Additional information: 9925
SQL> show parameter audit_file_dest
ORA-01034: ORACLE not available
[[email protected] oracle]$ mkdir admin
[[email protected] oracle]$ cd admin/
[[email protected] admin]$ mkdir grs2
[[email protected] admin]$ cd grs2/
[[email protected] grs2]$ mkdir adump bdump cdump udump
4.3 修改备库的参数文件
[[email protected] oradata]$ cp pfile_20140504 /u01/app/oracle/product/10.2.0/db_1/dbs
[[email protected] oradata]# cat pfile_20140506
j2grsdg.__db_cache_size=1509949440
grsdg.__db_cache_size=1644167168
grsdg.__java_pool_size=16777216
grsdg.__large_pool_size=16777216
grsdg.__shared_pool_size=452984832
grsdg.__streams_pool_size=0
*.audit_file_dest=‘/mountdisk2/oracle/admin/grsdg/adump‘
*.background_dump_dest=‘/mountdisk2/oracle/admin/grsdg/bdump‘
*.compatible=‘10.2.0.1.0‘
*.control_files=‘/mountdisk2/oracle/oradata/grsdg/grsdgcontrol01.ctl‘,‘/mountdisk2/oracle/oradata/grsdg/grsdgcontrol02.ctl‘,‘/mountdisk2/oracle/oradata/grsdg/grsdgcontrol03.ctl‘
*.core_dump_dest=‘/mountdisk2/oracle/admin/grsdg/cdump‘
*.db_domain=‘‘
*.DB_FILE_NAME_CONVERT=‘/u01/app/oradata/grs‘,‘/mountdisk2/oracle/oradata/grsdg‘
*.db_name=‘grs‘
*.db_recovery_file_dest=‘/mountdisk2/oracle/flash_recovery_area‘
*.db_recovery_file_dest_size=2147483648
*.DB_UNIQUE_NAME=‘grsdg‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=grsXDB)‘
*.FAL_CLIENT=‘grsdg‘
*.FAL_SERVER=‘grs‘
*.job_queue_processes=10
*.LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(grs,grsdg)‘
*.LOG_ARCHIVE_DEST_1=‘LOCATION=/mountdisk2/oracle/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=grsdg‘
*.LOG_ARCHIVE_DEST_2=‘SERVICE=grs LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=grs‘
*.LOG_ARCHIVE_DEST_STATE_1=‘ENABLE‘
*.log_archive_dest_state_2=‘DEFER‘
*.LOG_ARCHIVE_FORMAT=‘%t_%s_%r.arc‘
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.LOG_FILE_NAME_CONVERT=‘/u01/app/oradata/grs‘,‘/mountdisk2/oracle/oradata/grsdg‘
*.open_cursors=300
*.pga_aggregate_target=1073741824
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.sga_target=2147483648
*.STANDBY_FILE_MANAGEMENT=‘AUTO‘
*.undo_management=‘AUTO‘
*.undo_tablespace=‘UNDOTBS1‘
*.user_dump_dest=‘/mountdisk2/oracle/admin/grsdg/udump‘
[[email protected] oradata]#
4.4创建备库密码文件
[[email protected] ~]# scp -r /u01/app/oracle/product/10.2.0/db_1/dbs/orapwgrs [email protected]:/mountdisk2/oracle/oradata/
复制密码文件到备库
[[email protected] oradata]$ mv orapwgrs /u01/app/oracle/product/10.2.0/db_1/dbs/orapwgrsdg
[[email protected] grs2]$ orapwd file=/u02/app/oracle/product/10.2.0/db_1/dbs/orapwgrs2 password="987064" entries=10 force=y;
5创建主备库监听及tnsnames文件
5.1创建文件
[[email protected] admin]$ cp -p /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora /u02/app/oracle/product/10.2.0/db_1/network/admin/
[[email protected] admin]$ cp -p /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora /u02/app/oracle/product/10.2.0/db_1/network/admin/
修改监听文件
[[email protected] admin]$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u02/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = Oracle8)
(ORACLE_HOME = /u02/app/oracle/product/10.2.0/db_1)
(SID_NAME = grs2)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.185)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
[[email protected] admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
GRS2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.185)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = grs2)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
主库
[[email protected] ~]$ tnsping 192.168.2.188
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 04-MAY-2014 15:57:47
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
Used HOSTNAME adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=192.168.2.188))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.2.188)(PORT=1521)))
OK (40 msec)
[[email protected] ~]$ tnsping grsdg
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 04-MAY-2014 17:49:16
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.188)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = grsdg)))
OK (10 msec)
备库
[[email protected] admin]$ tnsping 10.0.1.103
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 04-MAY-2014 15:56:57
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora
Used HOSTNAME adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=10.0.1.103))(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.1.103)(PORT=1521)))
OK (0 msec)
[[email protected] dbs]$ tnsping grs
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 04-MAY-2014 17:53:47
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora
TNS-03505: Failed to resolve name
[[email protected] admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
GRS =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.1.103)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = grs)
)
)
GRS2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.188)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = grsdg)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
5.2分别启动主备库监听
为什么要先启动备库再启动主库呢?
DG 原理:主库启动后会主动探测备库,如果此时备库没有启动那么主库探测不到备库的存在,就会等待若干分钟之后再次探测,你会在 alert 日志中看到大量 ORA 报错引起恐慌,为了避免这种情况发生。可以先启动备库,此时备库会等待来自主库的日志,当备库启动之后主库再启动会在第一时间探测到备库存在,就不会看到大量报错信息了。
为什么在操作primary standby 库时建议始终打开alert日志 这样可以实时监控数据库启动 关闭 切换 操作的状态,查看到日志是否应用,角色是否切换完毕,数据库是否read only 打开等,主要是为了方便我们监控主备库同步状态。
启动备库
备库的启动
[[email protected] admin]$ export ORACLE_SID=grsdg
[[email protected] dbs]$ cp initgrs2.ora /u01/app/oracle/product/10.2.0/db_1/dbs/initgrs2.ora
[[email protected] dbs]$ sqlplsu /nolog
-bash: sqlplsu: command not found
[[email protected] dbs]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 31 17:16:24 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> create spfile from pfile=‘/mountdisk2/oracle/oradata/pfile_20140504‘;
File created.
SQL> startup nomount;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file ‘/u01/app/oracle/product/10.2.0/db_1/dbs/initgrsdg.ora‘
[[email protected] dbs]$ cp pfile_20140504 initgrsdg.ora
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 92276304 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
SQL> alter database mount standby database;
Database altered.
SQL> show parameter convert;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string /mountdisk2/oracle/oradata/grs
dg, /u01/app/oradata/grs
log_file_name_convert string /mountdisk2/oracle/oradata/grs
dg, /u01/app/oradata/grs
SQL> set linesize 1000
SQL> set pagesize 1000
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/grs/system01.dbf
/u01/app/oracle/oradata/grs/undotbs01.dbf
/u01/app/oracle/oradata/grs/sysaux01.dbf
/u01/app/oracle/oradata/grs/users01.dbf
/u01/app/oracle/oradata/grs/example01.dbf
/u01/app/oracle/oradata/grs/yyhhqq.dbf
/u01/app/oracle/oradata/grs/grsv501.dbf
/u01/app/oracle/oradata/grs/starhub.dbf
/u01/app/oracle/oradata/grs/starhub01.dbf
/u01/app/oracle/oradata/grs/starhub02.dbf
/u01/app/oracle/oradata/grs/starhub03.dbf
/u01/app/oracle/oradata/grs/starhub04.dbf
/u01/app/oracle/oradata/grs/starhub05.dbf
/u01/app/oracle/oradata/grs/cmask01.dbf
/u01/app/oracle/oradata/grs/ais01.dbf
/u01/app/oracle/oradata/grs/ais02.dbf
/u01/app/oracle/oradata/grs/ipfingo02.dbf
/u01/app/oracle/oradata/grs/ipfiingo01.dbf
/u01/app/oracle/oradata/grs/ipfingo03.dbf
/u01/app/oracle/oradata/grs/SPICEI2I02.dbf
切换到主库
SQL> alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
System altered --开始打开远程的归档
--SQL> alter database recover managed standby database disconnect from session;
Database altered.
6.主备库状态检查
1 主库
select db_unique_name,open_mode,database_role,switchover_status,
dataguard_broker,protection_mode,remote_archive,guard_status from
v$database;
grs READ WRITE PRIMARY SESSIONS ACTIVE DISABLED MAXIMUM PERFORMANCE ENABLED NONE
主库:可读写 没有启动broker 主库角色
主库:
SQL> select group#,bytes,status from v$standby_log;
GROUP# BYTES STATUS
---------- ---------- --------------------
4 52428800 UNASSIGNED
5 52428800 UNASSIGNED
主库的 standby_log没有使用
SQL> select * from v$archive_gap;
no rows selected
主库没有遗漏
SQL> col standby_dest for a12
SQL> col archived for a10
SQL> col applied for a10
SQL> col status for a10
SQL> select sequence#,standby_dest,archived,applied,status from v$archived_log;
SEQUENCE# STANDBY_DEST ARCHIVED APPLIED STATUS
---------- ------------ ---------- ---------- ----------
245 NO YES NO X
246 NO YES NO X
247 NO YES NO X
248 NO YES NO X
249 NO YES NO A
250 NO YES NO A
251 NO YES NO A
252 NO YES NO A
253 NO YES NO A
254 NO YES NO A
255 NO YES NO A
SEQUENCE# STANDBY_DEST ARCHIVED APPLIED STATUS
---------- ------------ ---------- ---------- ----------
256 NO YES NO A
257 NO YES NO A
257 YES YES NO A
258 NO YES NO A
258 YES YES NO A
260 NO YES NO A
261 NO YES NO A
262 NO YES NO A
262 YES YES NO A
20 rows selected.
一共有20个归档日志, 257 257 262 传输到standby
全部归档,全部未应用,状态A
A - Available
D - Deleted
U - Unavailable
X - Expired
select dest_name,database_mode,recovery_mode,archived_seq#,applied_seq# from
v$archive_dest_status;
LOG_ARCHIVE_DEST_1 OPEN IDLE 262 0
LOG_ARCHIVE_DEST_2 UNKNOWN UNKNOWN 262 261
LOG_ARCHIVE_DEST_3 OPEN IDLE 0 0
SQL> select process,status,sequence#,delay_mins from v$managed_standby;
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
LNS WRITING 263 0
备库状态
SQL> conn /as sysdba
Connected.
SQL> select db_unique_name,open_mode,database_role,switchover_status,
2 dataguard_broker,protection_mode,remote_archive,guard_status from
3 v$database;
DB_UNIQUE_NAME
------------------------------------------------------------
OPEN_MODE DATABASE_ROLE
-------------------- --------------------------------
SWITCHOVER_STATUS DATAGUARD_BROKER
---------------------------------------- ----------------
PROTECTION_MODE REMOTE_ARCHIVE GUARD_STATUS
---------------------------------------- ---------------- --------------
grsdg
MOUNTED PHYSICAL STANDBY
RECOVERY NEEDED DISABLED
MAXIMUM PERFORMANCE ENABLED NONE
SQL> select group#,bytes,status from v$standby_log;
no rows selected
SQL> select * from v$archive_gap;
no rows selected
SQL> col standby_dest for a12
SQL> col archived for a10
SQL> col applied for a10
SQL> col status for a10
SQL> select sequence#,standby_dest,archived,applied,status from v$archived_log;
SEQUENCE# STANDBY_DEST ARCHIVED APPLIED STATUS
---------- ------------ ---------- ---------- ----------
262 NO YES NO A
select dest_name,database_mode,recovery_mode,archived_seq#,applied_seq# from v$archive_dest_status;
SQL> select process,status,sequence#,delay_mins from v$managed_standby;
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
ARCH CONNECTED 0 0
RFS IDLE 263 0
RFS IDLE 0 0
7 .日志应用与切换
7 验证归档文件的情况
1 通过数据字典视图验证
--主库执行
[[email protected] ~]$ export ORACLE_SID=grs
[[email protected] ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 31 17:07:31 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 96470608 bytes
Database Buffers 184549376 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 100664912 bytes
Database Buffers 180355072 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> select sequence#, first_time, next_time, applied, fal from v$archived_log order by sequence#;
SEQUENCE# FIRST_TIME NEXT_TIME APP FAL
---------- ------------------ ------------------ --- ---
1 25-MAR-14 25-MAR-14 NO NO
1 25-MAR-14 25-MAR-14 NO YES
2 25-MAR-14 26-MAR-14 NO NO
2 25-MAR-14 26-MAR-14 NO YES
3 26-MAR-14 26-MAR-14 NO YES
3 26-MAR-14 26-MAR-14 NO NO
4 26-MAR-14 27-MAR-14 NO NO
4 26-MAR-14 27-MAR-14 NO YES
5 27-MAR-14 27-MAR-14 NO NO
5 27-MAR-14 27-MAR-14 NO YES
6 27-MAR-14 27-MAR-14 NO NO
SEQUENCE# FIRST_TIME NEXT_TIME APP FAL
---------- ------------------ ------------------ --- ---
6 27-MAR-14 27-MAR-14 NO YES
6 24-MAR-14 24-MAR-14 NO NO
7 27-MAR-14 27-MAR-14 NO YES
7 27-MAR-14 27-MAR-14 NO NO
7 24-MAR-14 24-MAR-14 NO NO
7 24-MAR-14 24-MAR-14 NO NO
8 24-MAR-14 25-MAR-14 NO NO
8 27-MAR-14 28-MAR-14 NO NO
8 27-MAR-14 28-MAR-14 NO YES
9 28-MAR-14 31-MAR-14 NO NO
9 25-MAR-14 25-MAR-14 NO NO
SEQUENCE# FIRST_TIME NEXT_TIME APP FAL
---------- ------------------ ------------------ --- ---
9 28-MAR-14 31-MAR-14 YES YES
10 31-MAR-14 31-MAR-14 NO NO
10 25-MAR-14 25-MAR-14 NO NO
10 31-MAR-14 31-MAR-14 NO YES
11 31-MAR-14 31-MAR-14 NO YES
11 25-MAR-14 25-MAR-14 NO NO
11 31-MAR-14 31-MAR-14 NO NO
12 31-MAR-14 31-MAR-14 NO NO
12 31-MAR-14 31-MAR-14 NO YES
12 25-MAR-14 25-MAR-14 NO NO
32 rows selected.
2 查看告警日志文件
--备库上有类似的信息
[[email protected] bdump]$ tail -f -n 100 /u02/app/oracle/admin/grs2/bdump/alert_grs2.log
Errors in file /u02/app/oracle/admin/grs2/bdump/grs2_mrp0_25231.trc:
ORA-01110: data file 1: ‘/u01/app/oracle/oradata/grs/system01.dbf‘
Errors in file /u02/app/oracle/admin/grs2/bdump/grs2_mrp0_25231.trc:
ORA-01110: data file 1: ‘/u01/app/oracle/oradata/grs/system01.dbf‘
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: ‘/u01/app/oracle/oradata/grs/system01.dbf‘
Mon Mar 31 17:17:35 2014
MRP0: Background Media Recovery process shutdown (grs2)
Mon Mar 31 17:17:36 2014
Completed: alter database recover managed standby database disconnect from session
Mon Mar 31 17:18:14 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[3]: Assigned to RFS process 25253
RFS[3]: Identified database type as ‘physical standby‘
Mon Mar 31 17:18:17 2014
Redo Shipping Client Connected as PUBLIC
主库
1 主库上建测试表
SQL> conn
Enter user-name: scott
Enter password:
Connected.
SQL> create table randy (id number);
Table created.
SQL> insert into randy values(1);
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> commit;
Commit complete.
SQL> select * from randy;
ID
----------
1
1
1
1
2 主库上模拟日志切换
SQL> alter system archive log current;
备库上的日志
db_recovery_file_dest_size of 2048 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Mon Mar 31 17:43:20 2014
RFS[2]: Possible network disconnect with primary database
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[15]: Assigned to RFS process 26201
RFS[15]: Identified database type as ‘physical standby‘
Primary database is in MAXIMUM PERFORMANCE mode
Primary database is in MAXIMUM PERFORMANCE mode
RFS[15]: Successfully opened standby log 4: ‘/u01/app/oracle/oradata/grs/redo04.log‘
Mon Mar 31 17:43:39 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[16]: Assigned to RFS process 26211
RFS[16]: Identified database type as ‘physical standby‘
RFS[16]: No standby redo logfiles of size 6761 blocks available
RFS[16]: Archived Log: ‘/u02/app/oracle/archivelog/archivelog/1_13_843150133.arc‘
以只读模式打开备库,验证数据
SQL> alter database recover managed standby database cancel;
同一台机器上进行dg
主库的参数文件
[[email protected] backup]$ vi initgrs.ora
grs.__db_cache_size=184549376
grs.__java_pool_size=4194304
grs.__large_pool_size=4194304
grs.__shared_pool_size=83886080
grs.__streams_pool_size=4194304
*.audit_file_dest=‘/u01/app/oracle/admin/grs/adump‘
*.background_dump_dest=‘/u01/app/oracle/admin/grs/bdump‘
*.compatible=‘10.2.0.1.0‘
*.control_files=‘/u01/app/oracle/oradata/grs/control01.ctl‘,‘/u01/app/oracle/oradata/grs/control02.ctl‘,‘/u01/app/oracle/oradata/grs/control03.ctl‘
*.core_dump_dest=‘/u01/app/oracle/admin/grs/cdump‘
*.db_block_size=8192
*.db_domain=‘‘
*.db_file_multiblock_read_count=16
*.DB_FILE_NAME_CONVERT=‘/u01/app/oracle/oradata/grs‘,‘/u02/app/oracle/oradata/grs2‘
*.db_name=‘grs‘
*.db_recovery_file_dest=‘/u01/app/oracle/flash_recovery_area‘
*.db_recovery_file_dest_size=2147483648
*.DB_UNIQUE_NAME=‘grs‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=grsXDB)‘
*.FAL_CLIENT=‘grs2‘
*.FAL_SERVER=‘grs‘
*.job_queue_processes=10
*.LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(grs,grs2)‘
*.LOG_ARCHIVE_DEST_1=‘LOCATION=/u01/app/oracle/archivelog/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=grs‘
*.LOG_ARCHIVE_DEST_2=‘SERVICE=grs2 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=grs2‘
*.LOG_ARCHIVE_DEST_STATE_1=‘ENABLE‘
*.LOG_ARCHIVE_DEST_STATE_2=‘ENABLE‘
*.LOG_ARCHIVE_FORMAT=‘%t_%s_%r.arc‘
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.LOG_FILE_NAME_CONVERT=‘/u01/app/oracle/oradata/grs‘,‘/u02/app/oracle/oradata/grs2‘
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.sga_target=285212672
*.STANDBY_FILE_MANAGEMENT=‘AUTO‘
*.undo_management=‘AUTO‘
*.undo_tablespace=‘UNDOTBS1‘
*.user_dump_dest=‘/u01/app/oracle/admin/grs/udump‘
备库的参数文件
[[email protected] dbs]$ vi initgrs2.ora
grs.__db_cache_size=184549376
grs.__java_pool_size=4194304
grs.__large_pool_size=4194304
grs.__shared_pool_size=83886080
grs.__streams_pool_size=4194304
*.audit_file_dest=‘/u02/app/oracle/admin/grs2/adump‘
*.background_dump_dest=‘/u02/app/oracle/admin/grs2/bdump‘
*.compatible=‘10.2.0.1.0‘
*.control_files=‘/u02/app/oracle/oradata/grs2/control01.ctl‘,‘/u02/app/oracle/oradata/grs2/control02.ctl‘,‘/u02/app/oracle/oradata/grs2/control03.ctl‘
*.core_dump_dest=‘/u02/app/oracle/admin/grs2/cdump‘
*.db_block_size=8192
*.db_domain=‘‘
*.db_file_multiblock_read_count=16
*.DB_FILE_NAME_CONVERT=‘/u02/app/oracle/oradata/grs2‘,‘/u01/app/oracle/oradata/grs‘
*.db_name=‘grs‘
*.db_recovery_file_dest=‘/u02/app/oracle/flash_recovery_area‘
*.db_recovery_file_dest_size=2147483648
*.DB_UNIQUE_NAME=‘grs2‘
*.dispatchers=‘(PROTOCOL=TCP) (SERVICE=grsXDB)‘
*.FAL_CLIENT=‘grs‘
*.FAL_SERVER=‘grs2‘
*.job_queue_processes=10
*.LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(grs,grs2)‘
*.LOG_ARCHIVE_DEST_1=‘LOCATION=/u02/app/oracle/archivelog/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=grs2‘
*.LOG_ARCHIVE_DEST_2=‘SERVICE=grs LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=grs‘
*.LOG_ARCHIVE_DEST_STATE_1=‘ENABLE‘
*.LOG_ARCHIVE_DEST_STATE_2=‘ENABLE‘
*.LOG_ARCHIVE_FORMAT=‘%t_%s_%r.arc‘
*.LOG_ARCHIVE_MAX_PROCESSES=30
*.LOG_FILE_NAME_CONVERT=‘/u02/app/oracle/oradata/grs2‘,‘/u01/app/oracle/oradata/grs‘
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_login_passwordfile=‘EXCLUSIVE‘
*.sga_target=285212672
*.STANDBY_FILE_MANAGEMENT=‘AUTO‘
*.undo_management=‘AUTO‘
*.undo_tablespace=‘UNDOTBS1‘
*.user_dump_dest=‘/u02/app/oracle/admin/grs2/udump‘
以上是关于Oracle data guard 10g 搭建的主要内容,如果未能解决你的问题,请参考以下文章
Oracle11g Active Data Guard搭建管理
Oracle Data Guard系列:单机环境基于拷贝文件方式搭建DG
Oracle 12C R2 on Linux 7.X Data Guard 搭建文档