Oracle Dataguard(主库为 Oracle rac 集群)配置教程(03)—— 创建 dataguard 数据库之前的准备工作
Posted 睿思达DBA_WGX
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle Dataguard(主库为 Oracle rac 集群)配置教程(03)—— 创建 dataguard 数据库之前的准备工作相关的知识,希望对你有一定的参考价值。
Oracle Dataguard(主库为 Oracle rac 集群)配置教程(03)—— 创建 dataguard 数据库之前的准备工作
/
本专栏详细讲解 Oracle Dataguard(Oracle 版本为11g,主库为双节点 Oracle rac 集群)的配置过程。主要内容包括:
(1)dataguard 服务器 Oracle 软件的安装。
(2)Oracle RAC 主库与 Dataguard 服务器的配置。
(3)主从同步测试。
(4)主备库切换。
/
目录
- Oracle Dataguard(主库为 Oracle rac 集群)配置教程(03)—— 创建 dataguard 数据库之前的准备工作
一、从 Oracle RAC 主库复制所需的文件到 Dataguard 服务器
把 Oracle RAC 主库的备份文件、备库控制文件、备库参数文件复制至dataguard 服务器。
1、切换到 Oracle RAC 主库的节点1,复制文件到 Dataguard 服务器
# 查看文件
[oracle@rac1 rman_backup]$ ll
total 1097744
-rw-r----- 1 oracle asmadmin 2332160 Feb 10 16:30 ARC_0a1k5bh5_1_1.bak
-rw-r----- 1 oracle asmadmin 1490432 Feb 10 16:30 ARC_0b1k5bh6_1_1.bak
-rw-r----- 1 oracle asmadmin 665313280 Feb 10 16:27 Full_051k5ba1_1_1.bak
-rw-r----- 1 oracle asmadmin 409878528 Feb 10 16:28 Full_061k5ba2_1_1.bak
-rw-r----- 1 oracle asmadmin 6725632 Feb 10 16:29 Full_071k5ba2_1_1.bak
-rw-r----- 1 oracle asmadmin 18546688 Feb 10 16:29 Full_081k5bab_1_1.bak
-rw-r----- 1 oracle asmadmin 98304 Feb 10 16:29 Full_091k5beb_1_1.bak
-rw-r--r-- 1 oracle asmadmin 1392 Feb 10 16:40 inithisdg.ora
drwx------ 2 oracle oinstall 16384 Feb 10 16:02 lost+found
-rw-r----- 1 oracle asmadmin 18546688 Feb 10 16:36 standby_0c1k5bse_1_1.ctl
[oracle@rac1 rman_backup]$ scp ARC* 192.168.1.151:/rman_backup/
The authenticity of host '192.168.1.151 (192.168.1.151)' can't be established.
ECDSA key fingerprint is 99:44:64:04:3b:1b:0b:94:78:cf:ef:c8:db:42:ca:0c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.151' (ECDSA) to the list of known hosts.
oracle@192.168.1.151's password:
ARC_0a1k5bh5_1_1.bak 100% 2278KB 2.2MB/s 00:00
ARC_0b1k5bh6_1_1.bak 100% 1456KB 1.4MB/s 00:00
[oracle@rac1 rman_backup]$
[oracle@rac1 rman_backup]$ scp Full* 192.168.1.151:/rman_backup/
oracle@192.168.1.151's password:
Full_051k5ba1_1_1.bak 100% 634MB 28.8MB/s 00:22
Full_061k5ba2_1_1.bak 100% 391MB 35.5MB/s 00:11
Full_071k5ba2_1_1.bak 100% 6568KB 6.4MB/s 00:00
Full_081k5bab_1_1.bak 100% 18MB 17.7MB/s 00:00
Full_091k5beb_1_1.bak 100% 96KB 96.0KB/s 00:01
[oracle@rac1 rman_backup]$
[oracle@rac1 rman_backup]$ scp init* 192.168.1.151:/rman_backup/
oracle@192.168.1.151's password:
inithisdg.ora 100% 1392 1.4KB/s 00:00
[oracle@rac1 rman_backup]$ scp stand* 192.168.1.151:/rman_backup/
oracle@192.168.1.151's password:
standby_0c1k5bse_1_1.ctl 100% 18MB 17.7MB/s 00:01
2、在 dataguard 服务器查看文件
[root@hisdg ~]# cd /rman_backup/
[root@hisdg rman_backup]# ll
总用量 1097744
-rw-r-----. 1 oracle oinstall 2332160 2月 10 16:56 ARC_0a1k5bh5_1_1.bak
-rw-r-----. 1 oracle oinstall 1490432 2月 10 16:56 ARC_0b1k5bh6_1_1.bak
-rw-r-----. 1 oracle oinstall 665313280 2月 10 16:57 Full_051k5ba1_1_1.bak
-rw-r-----. 1 oracle oinstall 409878528 2月 10 16:57 Full_061k5ba2_1_1.bak
-rw-r-----. 1 oracle oinstall 6725632 2月 10 16:57 Full_071k5ba2_1_1.bak
-rw-r-----. 1 oracle oinstall 18546688 2月 10 16:57 Full_081k5bab_1_1.bak
-rw-r-----. 1 oracle oinstall 98304 2月 10 16:57 Full_091k5beb_1_1.bak
-rw-r--r--. 1 oracle oinstall 1392 2月 10 16:57 inithisdg.ora
drwx------. 2 oracle oinstall 16384 2月 10 16:12 lost+found
-rw-r-----. 1 oracle oinstall 18546688 2月 10 16:57 standby_0c1k5bse_1_1.ctl
二、在 dataguard 服务器创建口令文件
在 Oracle RAC 主库节点1执行以下操作:
[oracle@rac1 rman_backup]$ cd $ORACLE_HOME/dbs
[oracle@rac1 dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@rac1 dbs]$ ll
total 18084
-rw-rw---- 1 oracle asmadmin 1544 Feb 10 08:27 hc_false1.dat
-rw-rw---- 1 oracle asmadmin 1544 Feb 10 16:04 hc_hisdb1.dat
-rw-r----- 1 oracle oinstall 37 Feb 10 08:59 inithisdb1.ora
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r----- 1 oracle oinstall 1536 Feb 10 16:42 orapwhisdb1
-rw-r----- 1 oracle asmadmin 18497536 Feb 10 16:36 snapcf_hisdb1.f
[oracle@rac1 dbs]$ scp orapwhisdb1 192.168.1.151:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwhisdg
oracle@192.168.1.151's password:
orapwhisdb1 100% 1536 1.5KB/s 00:00
在 dataguard 服务器上查看口令文件信息:
[oracle@hisdg dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@hisdg dbs]$ ll
总用量 8
-rw-r--r--. 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r-----. 1 oracle oinstall 1536 2月 10 17:05 orapwhisdg
三、修改物理备库的初始化参数文件
1、把备份的初始化参数文件复制到 $ORACLE_HOME/dbs 目录下
[oracle@hisdg dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@hisdg dbs]$ ll
总用量 8
-rw-r--r--. 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r-----. 1 oracle oinstall 1536 2月 10 17:05 orapwhisdg
[oracle@hisdg dbs]$ cp /rman_backup/inithisdg.ora ./
[oracle@hisdg dbs]$ ll
总用量 12
-rw-r--r--. 1 oracle oinstall 1392 2月 11 00:39 inithisdg.ora
-rw-r--r--. 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r-----. 1 oracle oinstall 1536 2月 10 17:05 orapwhisdg
2、查看参数文件的内容
[oracle@hisdg dbs]$ cat inithisdg.ora
hisdb1.__db_cache_size=385875968
hisdb2.__db_cache_size=385875968
hisdb1.__java_pool_size=4194304
hisdb2.__java_pool_size=4194304
hisdb1.__large_pool_size=8388608
hisdb2.__large_pool_size=8388608
hisdb1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
hisdb1.__pga_aggregate_target=209715200
hisdb2.__pga_aggregate_target=209715200
hisdb1.__sga_target=629145600
hisdb2.__sga_target=629145600
hisdb1.__shared_io_pool_size=0
hisdb2.__shared_io_pool_size=0
hisdb1.__shared_pool_size=222298112
hisdb2.__shared_pool_size=222298112
hisdb1.__streams_pool_size=0
hisdb2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/hisdb/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATA/hisdb/controlfile/current.265.1128415467','+BAK/hisdb/controlfile/current.256.1128415469'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='hisdb'
*.db_recovery_file_dest='+BAK'
*.db_recovery_file_dest_size=4621074432
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=hisdbXDB)'
hisdb1.instance_number=1
hisdb2.instance_number=2
*.open_cursors=300
*.pga_aggregate_target=209715200
*.processes=150
*.remote_listener='rac-scan:1521'
*.remote_login_passwordfile='exclusive'
3、修改参数文件,修改之后的内容如下
*.audit_file_dest='/u01/app/oracle/admin/hisdg/adump'
*.audit_trail='db'
*.cluster_database=false
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oradata/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='/u01/app/oradata/'
*.db_domain=''
*.db_name='hisdb'
*.db_unique_name='hisdg'
*.db_file_name_convert=('+DATA/hisdb/datafile/','/u01/app/oradata/datafile/')
*.db_file_name_convert=('+DATA/hisdb/tempfile/','/u01/app/oradata/tempfile/')
*.log_file_name_convert=('+DATA/hisdb/onlinelog/','/u01/app/oradata/onlinelog/')
*.log_file_name_convert=('+BAK/hisdb/onlinelog/','/u01/app/oraInventory/onlinelog/')
*.db_recovery_file_dest='/u01/app/oraInventory/'
*.db_recovery_file_dest_size=4621074432
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=hisdgXDB)'
*.log_archive_format='ARC_%t_%S_%r.arc'
*.open_cursors=300
*.pga_aggregate_target=209715200
*.processes=150
*.remote_login_passwordfile='exclusive'
*.sga_target=629145600
*.thread=1
*.undo_tablespace='UNDOTBS1'
4、创建参数文件所需要的目录
mkdir -p /u01/app/oracle/admin/hisdg/adump
mkdir -p /u01/app/oradata/datafile
mkdir -p /u01/app/oradata/tempfile
mkdir -p /u01/app/oradata/onlinelog
mkdir -p /u01/app/oraInventory/onlinelog
[oracle@hisdg dbs]$ mkdir -p /u01/app/oracle/admin/hisdg/adump
[oracle@hisdg dbs]$ mkdir -p /u01/app/oradata/datafile
[oracle@hisdg dbs]$ mkdir -p /u01/app/oradata/tempfile
[oracle@hisdg dbs]$ mkdir -p /u01/app/oradata/onlinelog
[oracle@hisdg dbs]$ mkdir -p /u01/app/oraInventory/onlinelog
四、配置 Oracle RAC 主库的两个节点以及 dataguard 服务器的 tnsnames.ora 文件
1、配置 Oracle RAC 集群节点1的 tnsnames.ora 文件
[oracle@rac1 admin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/network/admin
[oracle@rac1 admin]$ ll
total 8
drwxr-xr-x 2 oracle oinstall 64 Feb 10 00:45 samples
-rw-r--r-- 1 oracle oinstall 381 Dec 17 2012 shrept.lst
-rw-r----- 1 oracle oinstall 325 Feb 10 08:54 tnsnames.ora
[oracle@rac1 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
HISDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
)
)
HISDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
(INSTANCE_NAME = hisdb1)
)
)
HISDB2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
(INSTANCE_NAME = hisdb2)
)
)
HISTDBDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.151)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = histdg)
)
)
2、配置 Oracle RAC 集群节点2的 tnsnames.ora 文件
[oracle@rac2 admin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/network/admin
[oracle@rac2 admin]$ ll
total 8
drwxr-xr-x 2 oracle oinstall 64 Feb 10 01:04 samples
-rw-r--r-- 1 oracle oinstall 381 Feb 10 01:04 shrept.lst
-rw-r----- 1 oracle oinstall 325 Feb 10 08:54 tnsnames.ora
[oracle@rac2 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
HISDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
)
)
HISDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
(INSTANCE_NAME = hisdb1)
)
)
HISDB2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
(INSTANCE_NAME = hisdb2)
)
)
HISTDBDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.151)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = histdg)
)
)
3、配置 dataguard 服务器的 tnsnames.ora 文件
[oracle@hisdg admin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/network/admin
[oracle@hisdg admin]$ ll
总用量 12
-rw-r--r--. 1 oracle oinstall 366 2月 10 14:48 listener.ora
drwxr-xr-x. 2 oracle oinstall 64 2月 10 14:22 samples
-rw-r--r--. 1 oracle oinstall 381 12月 17 2012 shrept.lst
-rw-r--r--. 1 oracle oinstall 219 2月 10 14:48 sqlnet.ora
[oracle@hisdg admin]$ vi tnsnames.ora
HISDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.201)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
)
)
HISDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
(INSTANCE_NAME = hisdb1)
)
)
HISDB2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
(INSTANCE_NAME = hisdb2)
)
)
HISTDBDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.151)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = histdg)
)
)
4、连接测试
-- Oracle RAC 主库的节点1
SQL> conn sys/oracle@hisdb as sysdba
Connected.
SQL> conn sys/oracle@hisdb1 as sysdba
Connected.
SQL> conn sys/oracle@hisdb2 as sysdba
Connected.
-- dataguard 没有数据库,因此无法连接
SQL> conn sys/oracle@hisdg as sysdba
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Warning: You are no longer connected to ORACLE.
-- Oracle RAC 主库的节点2
SQL> conn sys/oracle@hisdb as sysdba
Connected.
SQL> conn sys/oracle@hisdb1 as sysdba
Connected.
SQL> conn sys/oracle@hisdb2 as sysdba
Connected.
-- dataguard 没有数据库,因此无法连接
SQL> conn sys/oracle@hisdg as sysdba
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Warning: You are no longer connected to ORACLE.
-- dataguard 服务器
SQL> conn sys/oracle@hisdb as sysdba
Connected.
SQL> conn sys/oracle@hisdb1 as sysdba
Connected.
SQL> conn sys/oracle@hisdb2 as sysdba
Connected.
-- dataguard 没有数据库,因此无法连接
SQL> conn sys/oracle@hisdg as sysdba
ERROR:
ORA-12541: TNS:no listener
Warning: You are no longer connected to ORACLE.
Oracle dataguard 正常切换和应急切换
--------------------
SESSIONS ACTIVE
--------------------
TO PRIMARY
---------- ----------------
MOUNTED PHYSICAL STANDBY
select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE
alter database commit to switchover to primary;
重新启动数据库open
shutdown immediate
startup
select switchover_status
from v$database;
SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE
select
open_mode,database_role from v$database;
OPEN_MODE
DATABASE_ROLE
---------- ----------------
OPEN PRIMARY
至此原主库切换至备库,原备库切换至主库了
3)应急切换
(注:模拟主库由于故障无法正常switchover,需要执行failover,强制备库->pridb并接管业务)
1.备库:
由于是failover,所以理解主库这时候已经无法正常使用,只需备库切换至pridb
停止应用恢复模式
alter database recover managed standby database finish;
转换standbydb为primary db
alter database commit to switchover to primary;
重启数据库,恢复正常业务
shutdown immediate
startup
select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
OPEN PRIMARY
以上是关于Oracle Dataguard(主库为 Oracle rac 集群)配置教程(03)—— 创建 dataguard 数据库之前的准备工作的主要内容,如果未能解决你的问题,请参考以下文章