Oracle ADG RAC TO RAC

规划

保护模式:MAX Performance

传输进程:LNS ASYNC

环境规划信息 Primary Node RAC Standby Node RAC
主机名 11rac1,11rac2 racdg1,racdg2
Hosts文件 11rac1
11rac2
11rac1-vip
11rac2-vip
11rac1-priv
11rac2-priv
rac-scan
racdg1
racdb2
racdg1-vip
racdg2-vip
racdg1-priv
racdb2-priv
racdg-scan
DB_NAME racdb racdb
INTANCE_NAME racdb1,racdb2 racdb1,racdb2
DB_UNIQUE_NAME racdb_primary racdb_standby1
操作系统版本 CentOS7.9.2009 CentOS7.9.2009
Oracle数据库版本 11.2.0.4 11.2.0.4
归档位置 快速恢复区 快速恢复区域
快速恢复区域 +fra +fra
Service_name racdb_primary racdb_standby1
数据库软件 安装GI+数据库软件+创建监听+安装数据库 安装GI+数据库软件+创建监听(无需建库)

操作系统配置

Hosts文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 原RAC
[root@11rac1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# Public
10.10.10.171 11rac1
10.10.10.172 11rac2
# Private
172.16.1.171 11rac1-priv
172.16.1.172 11rac2-priv
# Virtual
10.10.10.173 11rac1-vip
10.10.10.174 11rac2-vip
# SCAN
10.10.10.175 rac-scan
10.10.10.176 rac-scan
10.10.10.177 rac-scan
[root@11rac1 ~]#


# 目标RAC
[root@racdg2 tmp]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

# Public
10.10.10.181 racdg1
10.10.10.182 racdg2
# Private
172.16.1.181 racdg1-priv
172.16.1.182 racdg2-priv
# Virtual
10.10.10.183 racdg1-vip
10.10.10.184 racdg2-vip
# SCAN
10.10.10.185 racdg-scan
[root@racdg2 tmp]#

安装数据库

在配置dataguard之前,主库已经安装了GI+数据库软件+创建了数据库,备库也已经安装了GI+数据库软件,==备库不需要使用dbca建库==。如果使用自动RAC部署脚本则备库会自动创建数据库,此时需要将其手动删除掉。

卸载RAC备库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 在备库RAC任意节点,以oracle用户身份执行dbca
1.选择RAC数据库
2.选择删除数据库
# 或者静默删除,如下
[oracle@racdg1 ~]$ dbca -silent -deleteDatabase -sourceDB racdb -sysDBAUserName sys -sysDBAPassword SysPassword1
Connecting to database
9% complete
14% complete
19% complete
23% complete
28% complete
33% complete
38% complete
47% complete
Updating network configuration files
48% complete
52% complete
Deleting instances and datafiles
66% complete
80% complete
95% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/racdb0.log" for further details.
[root@racdg1 rac1-scripts]# su - grid
Last login: Fri Mar 28 14:19:27 CST 2025 on pts/1
[grid@racdg1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.CRS.dg
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.DATA.dg
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.FRA.dg
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.LISTENER.lsnr
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.asm
ONLINE ONLINE racdg1 Started
ONLINE ONLINE racdg2 Started
ora.gsd
OFFLINE OFFLINE racdg1
OFFLINE OFFLINE racdg2
ora.net1.network
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.ons
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE racdg2
ora.LISTENER_SCAN2.lsnr
1 ONLINE ONLINE racdg1
ora.LISTENER_SCAN3.lsnr
1 ONLINE ONLINE racdg1
ora.cvu
1 ONLINE ONLINE racdg1
ora.oc4j
1 ONLINE ONLINE racdg1
ora.racdg1.vip
1 ONLINE ONLINE racdg1
ora.racdg2.vip
1 ONLINE ONLINE racdg2
ora.scan1.vip
1 ONLINE ONLINE racdg2
ora.scan2.vip
1 ONLINE ONLINE racdg1
ora.scan3.vip
1 ONLINE ONLINE racdg1

主RAC信息收集

查看主库数据库名

备库数据库名要和主库保持一致。

1
2
3
4
5
6
SQL> show parameter db_name;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string racdb
SQL>

数据文件路径

主库所有数据文件(包括临时表空间数据文件)都存放在+DATA/racdb/datafile 目录。DG 配置过程中需要配置参数 db_file_name_convert,来指定主库和备库数据文件的目录映射关系。如果主库、备库数据文件路径一致则不需要配置该参数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- 数据文件路径
SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/racdb/datafile/users.259.1170160479
+DATA/racdb/datafile/undotbs1.258.1170160479
+DATA/racdb/datafile/sysaux.257.1170160479
+DATA/racdb/datafile/system.256.1170160477
+DATA/racdb/datafile/undotbs2.264.1170160703
-- 临时数据文件路径
SQL> select file_name from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
+DATA/racdb/tempfile/temp.263.1170160605

在线重做日志文件

主库所有日志文件都存放在+DATA/racdb/onlinelog 目录。DG配置过程中需要配置参数 log_file_name_convert,来指定主库和备库日志文件的目录映射关系。如果主库、备库日志文件路径一致则不需要配置该参数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- online redo log文件路径和大小
SQL> select t1.group#,t1.thread#,member,bytes/1024/1024 from v$log t1,v$logfile t2 where t1.group# = t2.group#;

GROUP# THREAD# MEMBER BYTES/1024/1024
---------- ---------- -------------------------------------------------- ---------------
2 1 +DATA/racdb/onlinelog/group_2.262.1170160587 50
2 1 +FRA/racdb/onlinelog/group_2.258.1170160589 50
1 1 +DATA/racdb/onlinelog/group_1.261.1170160587 50
1 1 +FRA/racdb/onlinelog/group_1.257.1170160587 50
3 2 +DATA/racdb/onlinelog/group_3.265.1170161993 50
3 2 +FRA/racdb/onlinelog/group_3.259.1170161995 50
4 2 +DATA/racdb/onlinelog/group_4.266.1170161995 50
4 2 +FRA/racdb/onlinelog/group_4.260.1170161995 50

8 rows selected.

主库FRA目录

如果主库开启了 FRA 目录,默认归档日志和 Rman 备份片是要存放在 FRA 目录的,也可以设置log_archive_dest_1 参数来重新指定主库的归档日志目录。另外主库开启 FRA 目录,建议备库也要开启。

1
2
3
4
5
6
SQL> show parameter db_recovery;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string +FRA
db_recovery_file_dest_size big integer 4407M

主库是否可以sys远程访问

DG 要求主库 sys 用户必须能够远程密码登录。一般通过参数 remote_login_passwordfile 来控制。

1
2
3
4
5
6
SQL> select * from gv$pwfile_users;

INST_ID USERNAME SYSDB SYSOP SYSAS
---------- ------------------------------ ----- ----- -----
1 SYS TRUE TRUE FALSE
2 SYS TRUE TRUE FALSE

查看主库的审计目录

该目录在备库恢复之前需要提前创建。

1
2
3
4
5
6
7
8
9
SQL> show parameter audit

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest string /u01/app/oracle/admin/racdb/adump
audit_sys_operations boolean FALSE
audit_syslog_level string
audit_trail string DB
SQL>

配置RAC主库

主RAC启用归档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[oracle@11rac1 ~]$ srvctl stop database -d racdb                 # 关闭所有节点数据库
[oracle@11rac1 ~]$ srvctl status database -d racdb
Instance racdb1 is not running on node 11rac1
Instance racdb2 is not running on node 11rac2
[oracle@11rac1 ~]$ srvctl start database -d racdb -o mount # 启动所有节点数据库到mount
[oracle@11rac1 ~]$ srvctl status database -d racdb
Instance racdb1 is running on node 11rac1
Instance racdb2 is running on node 11rac2
[oracle@11rac1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 14:51:49 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> alter database archivelog; # 启用归档

Database altered.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@11rac1 ~]$ srvctl stop database -d racdb # 关闭所有节点数据库
[oracle@11rac1 ~]$ srvctl start database -d racdb # 启动所有节点数据库
[oracle@11rac1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 14:53:36 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 448
Next log sequence to archive 449
Current log sequence 449
SQL> show parameter USE_DB_RECOVERY_FILE_DEST;
SQL> show parameter recovery;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string +FRA
db_recovery_file_dest_size big integer 4407M
recovery_parallelism integer 0
SQL>

主RAC dg参数

Oracle RAC 因为有多个节点,并且多个节点可以配置不同的参数,因此需要用 sid 来指定该参数的生效节点,如果 sid=‘*’则代表全部节点。
本次因为主库和备库数据文件路径和日志文件路径存放位置一致,故没有配置 db_file_name_convert 参数和 log_file_name_convert 参数。

强制日志

1
2
select log_mode,force_logging from v$database;
ALTER DATABASE FORCE LOGGING;

Standbyredolog(RAC)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- Standbyredolog(RAC)
-- 如果主库是RAC数据库:standby redo log组数=(每线程的日志组数+1)
-- 如下,主RAC每个thread有2组,每组2个
SQL> select a."GROUP#",a."THREAD#",a."BYTES",a."MEMBERS" from v$log a,v$logfile b
2 where a."GROUP#" = b."GROUP#"
3 order by group#;

GROUP# THREAD# BYTES MEMBERS
---------- ---------- ---------- ----------
1 1 52428800 2
1 1 52428800 2
2 1 52428800 2
2 1 52428800 2
3 2 52428800 2
3 2 52428800 2
4 2 52428800 2
4 2 52428800 2

8 rows selected.
-- 因此需要为standby redolog创建每个thread 3组,每组一个成员日志即可
-- thread1
alter database add standby logfile thread 1 group 5 ('+DATA') size 50M;
alter database add standby logfile thread 1 group 6 ('+DATA') size 50M;
alter database add standby logfile thread 1 group 7 ('+DATA') size 50M;
alter database add standby logfile thread 1 group 5 size 50M ,group 6 size 50M ,group 7 size 50M; -- 默认位于+DATA中
-- thread2
alter database add standby logfile thread 2 group 8 ('+DATA') size 50M;
alter database add standby logfile thread 2 group 9 ('+DATA') size 50M;
alter database add standby logfile thread 2 group 10 ('+DATA') size 50M;
alter database add standby logfile thread 2 group 8 size 50M ,group 9 size 50M ,group 10 size 50M;
-- 查询standby redo log
SQL> select GROUP#,DBID,THREAD#,SEQUENCE#,BYTES,BLOCKSIZE,USED,ARCHIVED,STATUS from v$standby_log;
-- 查询所有redo log文件,如下所示,可以看到自动在+fra中也有一份standby redo log
SQL> select GROUP#,STATUS ,TYPE,MEMBER from v$logfile;

GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------
2 ONLINE +DATA/racdb/onlinelog/group_2.262.1170160587
2 ONLINE +FRA/racdb/onlinelog/group_2.258.1170160589
1 ONLINE +DATA/racdb/onlinelog/group_1.261.1170160587
1 ONLINE +FRA/racdb/onlinelog/group_1.257.1170160587
3 ONLINE +DATA/racdb/onlinelog/group_3.265.1170161993
3 ONLINE +FRA/racdb/onlinelog/group_3.259.1170161995
4 ONLINE +DATA/racdb/onlinelog/group_4.266.1170161995
4 ONLINE +FRA/racdb/onlinelog/group_4.260.1170161995
5 STANDBY +DATA/racdb/onlinelog/group_5.268.1196954537
5 STANDBY +FRA/racdb/onlinelog/group_5.261.1196954539
6 STANDBY +DATA/racdb/onlinelog/group_6.269.1196954539
6 STANDBY +FRA/racdb/onlinelog/group_6.262.1196954539
7 STANDBY +DATA/racdb/onlinelog/group_7.270.1196954541
7 STANDBY +FRA/racdb/onlinelog/group_7.263.1196954541
8 STANDBY +DATA/racdb/onlinelog/group_8.271.1196954553
8 STANDBY +FRA/racdb/onlinelog/group_8.264.1196954553
9 STANDBY +DATA/racdb/onlinelog/group_9.272.1196954553
9 STANDBY +FRA/racdb/onlinelog/group_9.265.1196954553
10 STANDBY +DATA/racdb/onlinelog/group_10.273.1196954553
10 STANDBY +FRA/racdb/onlinelog/group_10.266.1196954555

主要dg参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-- dg参数
ALTER SYSTEM SET DB_UNIQUE_NAME='racdb_primary' SCOPE=SPFILE SID='*';
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(racdb_primary,racdb_standby1)' SCOPE=BOTH SID='*';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=racdb_primary' SCOPE=SPFILE SID='*';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=racdb_standby1 LGWR ASYNC REOPEN=15 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdb_standby1' SCOPE=BOTH SID='*';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_1=enable SCOPE=BOTH SID='*';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=enable SCOPE=BOTH SID='*';
ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE SID='*';
ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4 SCOPE=BOTH SID='*';
ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE='exclusive' SCOPE=SPFILE SID='*';

-- Add below item when DB turn to standby role
-- alter system set db_file_name_convert='+DATA/testdbdg','+DATA/testdb' scope=spfile;
-- alter system set log_file_name_convert='+DATA/testdbdg','+DATA/testdb' scope=spfile;
ALTER SYSTEM SET FAL_SERVER='racdb_standby1' SCOPE=BOTH SID='*';
ALTER SYSTEM SET FAL_CLIENT='racdb_primary' SCOPE=BOTH SID='*';
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO SCOPE=BOTH SID='*';

重启主RAC

1
2
srvctl stop database -d racdb
srvctl start database -d racdb

主库TNSNAME

主RAC所有节点配置保持一致,HOST地址要写集群的 scan_ip SERVICE_NAME

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[oracle@11rac1 ~]$ cat /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

RACDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb)
)
)

racdb_primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.175)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_primary) # 这里需要注意
)
)

racdb_standby1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.185)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_standby1) # 这里需要注意
)
)
[oracle@11rac1 ~]$

此外,如果使用active duplicate方式来同步数据,则使用scan ip会出问题,因此我们还需要在TNSNAMES中额外配置一个名称用于使用RAC其中一个节点的 VIP 来进行同步。这里配置使用各自节点 1 的vip进行 rman的active duplicate。如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[oracle@11rac1 ~]$ cat /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

RACDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb)
)
)

racdb_primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.175)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_primary)
)
)

racdb_standby1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.185)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_standby1)
)
)

tar =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.173)(PORT = 1521)) # 主RAC节点1 VIP
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_primary)
)
)

aux =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.183)(PORT = 1521)) # 备RAC节点1 VIP
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_standby1)
)
)
[oracle@11rac1 ~]$

主库监听器检查

在sqlplus检查local_listenerremote_listener参数,local_listener要配置的host为各自节点的 VIP 地址,remote_listener 配置 scan_ip 名称和端口即可。

节点1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[oracle@11rac1 ~]$ cat /u01/app/11.2.0/grid/network/admin/listener.ora
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
LISTENER_SCAN3=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN3)))) # line added by Agent
LISTENER_SCAN2=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN2)))) # line added by Agent
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN2=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN3=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
[oracle@11rac1 ~]$

[oracle@11rac1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 16:15:36 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> show parameter listener;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
listener_networks string
local_listener string (ADDRESS=(PROTOCOL=TCP)(HOST=
10.10.10.173)(PORT=1521))
remote_listener string rac-scan:1521

[root@11rac1 ~]# su - grid
Last login: Fri Mar 28 15:41:22 CST 2025 on pts/0
[grid@11rac1 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-MAR-2025 16:17:14

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 27-MAR-2025 16:26:48
Uptime 0 days 23 hr. 50 min. 26 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/11rac1/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.10.10.171)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.10.10.173)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "racdbXDB" has 1 instance(s).
Instance "racdb1", status READY, has 1 handler(s) for this service...
Service "racdb_primary" has 1 instance(s). # 这里需要注意,直接监听了db_unique_name
Instance "racdb1", status READY, has 1 handler(s) for this service...
The command completed successfully

节点2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[oracle@11rac2 ~]$ cat /u01/app/11.2.0/grid/network/admin/listener.ora
LISTENER_SCAN2=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN2)))) # line added by Agent
LISTENER_SCAN3=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN3)))) # line added by Agent
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN3=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN2=ON # line added by Agent
[oracle@11rac2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 16:16:10 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> show parameter listener;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
listener_networks string
local_listener string (ADDRESS=(PROTOCOL=TCP)(HOST=
10.10.10.174)(PORT=1521))
remote_listener string rac-scan:1521
SQL>

[oracle@11rac2 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-MAR-2025 16:19:44

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 27-MAR-2025 16:28:05
Uptime 0 days 23 hr. 51 min. 39 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/11rac2/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.10.10.172)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.10.10.174)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "racdbXDB" has 1 instance(s).
Instance "racdb2", status READY, has 1 handler(s) for this service...
Service "racdb_primary" has 1 instance(s).
Instance "racdb2", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@11rac2 ~]$

配置RAC备库

创建必要的系统目录

注:实际环境中主库和备库的路径可能不一样,请按照备库实际路径创建。

1
2
3
4
5
6
7
8
# 备库节点1
[root@racdg1 rac1-scripts]# su - oracle
Last login: Fri Mar 28 14:20:27 CST 2025 on pts/1
[oracle@racdg1 ~]$ mkdir -p /u01/app/oracle/admin/racdb/adump
# 备库节点2
[root@racdg2 rac2-scripts]# su - oracle
Last login: Fri Mar 28 14:28:50 CST 2025 on pts/1
[oracle@racdg2 ~]$ mkdir -p /u01/app/oracle/admin/racdb/adump

如果使用基于RMAN的复制,则还需要创建以下目录:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@oracle01 ~]# mkdir -p /oradata/rmanbackup
[root@oracle01 ~]# chown -R oracle.oinstall /oradata/ ---创建备份片存放目录

[grid@oracle01 ~]$ asmcmd # grid 用户下,使用 asmcmd 命令创建以下目录
ASMCMD> ls
CRS/
DATA/
LOG/
ASMCMD> cd DATA
ASMCMD> ls
ASMCMD>
ASMCMD> mkdir RACDB
ASMCMD> cd racdb
ASMCMD> mkdir CONTROLFILE
ASMCMD> mkdir DATAFILE
ASMCMD> mkdir ONLINELOG
ASMCMD> mkdir PARAMETERFILE
ASMCMD> mkdir TEMPFILE
ASMCMD>

准备备库pfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- 1.主库中生成pfile
[oracle@11rac1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 17:15:20 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> create pfile='/tmp/init_racdb_stby.ora' from spfile;

File created.

SQL>

-- 2.将生成的pfile复制到备库节点1
[oracle@11rac1 ~]$ scp /tmp/init_racdb_stby.ora oracle@10.10.10.181:/tmp/init_racdb_stby.ora
The authenticity of host '10.10.10.181 (10.10.10.181)' can't be established.
ECDSA key fingerprint is SHA256:QgEFFzHMaak6UisXidzJFGADDG78qCCttyBGFVjXJFQ.
ECDSA key fingerprint is MD5:73:2b:2f:68:4b:b6:b4:2b:24:43:db:bb:11:5a:4c:9a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.181' (ECDSA) to the list of known hosts.
oracle@10.10.10.181's password:
init_racdb_stby.ora 100% 1916 611.2KB/s 00:00
[oracle@11rac1 ~]$

**编辑备库的pfile **

注:如果数据文件和日志文件路径异构需要配置以下参数:db_file_name_convert ; log_file_name_convert 指定主库到备库的文件映射关系。在路径同构的情况下,使用 db_create_file_dest 指定大致的路径即可,在 asm 中,只需指定磁盘组名称即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[oracle@racdg1 ~]$ cat /tmp/init_racdb_stby.ora 
racdb1.__db_cache_size=1124073472
racdb2.__db_cache_size=1124073472
racdb1.__java_pool_size=16777216
racdb2.__java_pool_size=16777216
racdb1.__large_pool_size=33554432
racdb2.__large_pool_size=33554432
racdb1.__pga_aggregate_target=536870912
racdb2.__pga_aggregate_target=536870912
racdb1.__sga_target=1610612736
racdb2.__sga_target=1610612736
racdb1.__shared_io_pool_size=0
racdb2.__shared_io_pool_size=0
racdb1.__shared_pool_size=419430400
racdb2.__shared_pool_size=419430400
racdb1.__streams_pool_size=0
racdb2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/racdb/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATA/racdb/controlfile/current.260.1170160581','+FRA/racdb/controlfile/current.256.1170160581' # 控制文件
*.db_block_size=8192
*.db_create_file_dest='+DATA' # 数据文件位置
*.db_domain=''
*.db_name='racdb' # 主备库一致
*.db_recovery_file_dest='+FRA' # 快速恢复区域位置
*.db_recovery_file_dest_size=4621074432 # 快速恢复区域大小
*.db_unique_name='racdb_standby1' # 备库unique名字
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racdbXDB)'
*.fal_client='racdb_standby1' # 主备库相反
*.fal_server='racdb_primary'
racdb1.instance_number=1
racdb2.instance_number=2
*.log_archive_config='DG_CONFIG=(racdb_primary,racdb_standby1)'
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=racdb_standby1' # 主备库相反
*.log_archive_dest_2='SERVICE=racdb_primary LGWR ASYNC REOPEN=15 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdb_primary' # 主备库相反
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s_%r.arc'
*.log_archive_max_processes=4
*.open_cursors=300
*.pga_aggregate_target=536870912
*.processes=150
*.remote_listener='racdg-scan:1521' # 备库scan名称
*.remote_login_passwordfile='exclusive'
*.sga_target=1610612736
*.standby_file_management='AUTO'
racdb2.thread=2
racdb1.thread=1
racdb1.undo_tablespace='UNDOTBS1'
racdb2.undo_tablespace='UNDOTBS2'
[oracle@racdg1 ~]$

备库密码文件

因为 RAC 是多个节点,每个节点都有一个密码文件,一般是内容一致,名称不同。主库的密码文件在$ORACLE_HOME/dbs 文件夹下,名称为:orapw+当前节点实例名

下面将主库节点1的密码文件复制到备库的所有节点:

1
2
3
4
5
6
7
8
9
[oracle@11rac1 ~]$ scp /u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwracdb1 oracle@10.10.10.181:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
oracle@10.10.10.181's password:
orapwracdb1 100% 1536 623.0KB/s 00:00
[oracle@11rac1 ~]$ scp /u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwracdb1 oracle@10.10.10.182:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwracdb2
oracle@10.10.10.182's password:
orapwracdb1 100% 1536 193.3KB/s 00:00
[oracle@11rac1 ~]$

[oracle@racdg2 ~]$ mv /u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwracdb1 /u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwracdb2

备库监听器配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 备库所有节点
# 节点1
[grid@racdg1 ~]$ cat /u01/app/11.2.0/grid/network/admin/listener.ora
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
LISTENER_SCAN3=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN3)))) # line added by Agent
LISTENER_SCAN2=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN2)))) # line added by Agent
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN2=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN3=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent

SID_LIST_listener =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = racdb_standby1)
(SID_NAME = racdb1)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
)
)
[grid@racdg1 ~]$
# 节点2
[grid@racdg2 ~]$ cat /u01/app/11.2.0/grid/network/admin/listener.ora
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent

SID_LIST_listener =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = racdb_standby1)
(SID_NAME = racdb2)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
)
)
[grid@racdg2 ~]$

重启监听

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
srvctl stop listener
srvctl start listener

# 节点1
[grid@racdg1 ~]$ lsnrctl reload

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-MAR-2025 20:20:56

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
The command completed successfully
[grid@racdg1 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-MAR-2025 20:21:01

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 28-MAR-2025 12:46:15
Uptime 0 days 7 hr. 34 min. 46 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/racdg1/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
Services Summary...
Service "racdb_standby1" has 1 instance(s).
Instance "racdb1", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[grid@racdg1 ~]$

备库TNSNAME

主备库相同:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 备库所有节点
[oracle@racdg1 ~]$ cat /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

RACDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = racdg-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb)
)
)

racdb_primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.175)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_primary)
)
)

racdb_standby1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.185)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_standby1)
)
)

tar =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.173)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_primary)
)
)

aux =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.183)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb_standby1)
)
)
[oracle@racdg1 ~]$

备库节点1启动到nomount

只需在一个节点上执行即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[oracle@racdg1 ~]$ echo $ORACLE_SID
racdb1
[oracle@racdg1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 20:42:02 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile='/tmp/init_racdb_stby.ora';
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 520096928 bytes
Database Buffers 1073741824 bytes
Redo Buffers 7319552 bytes
SQL>

测试主备库TNS连通性

在开始active duplicate前,先验证主库和备库的tns连通性,要确保新创建的aux、tar、racdb_primary、racdb_standby1 四个 tns 都要能在主备库的各个节点上互相能访问到。

1
2
3
4
5
6
7
8
9
10
11
12
13
tnsping racdb
tnsping racdb_primary
tnsping racdb_standby1
tnsping tar
tnsping aux

[oracle@racdg1 ~]$ sqlplus sys/SysPassword1@racdb_primary as sysdba

[oracle@racdg1 ~]$ sqlplus sys/SysPassword1@racdb_standby1 as sysdba # 这个测试是无法连接的,应该是跟用的scan地址有关

[oracle@racdg1 ~]$ sqlplus sys/SysPassword1@tar as sysdba

[oracle@racdg1 ~]$ sqlplus sys/SysPassword1@aux as sysdba

开始复制数据库Active duplicate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
[oracle@racdg1 ~]$ rman target sys/SysPassword1@tar auxiliary sys/SysPassword1@aux

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Mar 28 21:05:36 2025

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: RACDB (DBID=1167777349)
connected to auxiliary database: RACDB (not mounted)

RMAN> run {
2> allocate channel c1 type disk;
3> allocate channel c2 type disk;
4> allocate auxiliary channel c3 type disk;
5> allocate auxiliary channel c4 type disk;
6> duplicate target database for standby from active database nofilenamecheck;
7> release channel c1;
8> release channel c2;
9> release channel c3;
10> release channel c4;
11> }

using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=159 instance=racdb1 device type=DISK

allocated channel: c2
channel c2: SID=153 instance=racdb1 device type=DISK

allocated channel: c3
channel c3: SID=125 instance=racdb1 device type=DISK

allocated channel: c4
channel c4: SID=16 instance=racdb1 device type=DISK

Starting Duplicate Db at 2025-03-28 21:14:17

contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwracdb1' auxiliary format
'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwracdb1' ;
}
executing Memory Script

Starting backup at 2025-03-28 21:14:17
Finished backup at 2025-03-28 21:14:19

contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '+DATA/racdb_standby1/controlfile/current.267.1196975659';
restore clone controlfile to '+FRA/racdb_standby1/controlfile/current.256.1196975659' from
'+DATA/racdb_standby1/controlfile/current.267.1196975659';
sql clone "create spfile from memory";
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set control_files =
''+DATA/racdb_standby1/controlfile/current.267.1196975659'', ''+FRA/racdb_standby1/controlfile/current.256.1196975659'' comment=
''Set by RMAN'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script

Starting backup at 2025-03-28 21:14:19
channel c1: starting datafile copy
copying standby control file
output file name=+DATA/racdb_standby1/controlfile/current.267.1196975659 tag=TAG20250328T211419
channel c1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2025-03-28 21:14:22

Starting restore at 2025-03-28 21:14:22

channel c4: skipped, AUTOBACKUP already found
channel c3: copied control file copy
Finished restore at 2025-03-28 21:14:31

sql statement: create spfile from memory

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 1603411968 bytes

Fixed Size 2253664 bytes
Variable Size 536874144 bytes
Database Buffers 1056964608 bytes
Redo Buffers 7319552 bytes
allocated channel: c3
channel c3: SID=15 instance=racdb1 device type=DISK
allocated channel: c4
channel c4: SID=17 instance=racdb1 device type=DISK

sql statement: alter system set control_files = ''+DATA/racdb_standby1/controlfile/current.267.1196975659'', ''+FRA/racdb_standby1/controlfile/current.256.1196975659'' comment= ''Set by RMAN'' scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 1603411968 bytes

Fixed Size 2253664 bytes
Variable Size 536874144 bytes
Database Buffers 1056964608 bytes
Redo Buffers 7319552 bytes
allocated channel: c3
channel c3: SID=15 instance=racdb1 device type=DISK
allocated channel: c4
channel c4: SID=143 instance=racdb1 device type=DISK

contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:
{
set newname for clone tempfile 1 to new;
switch clone tempfile all;
set newname for clone datafile 1 to new;
set newname for clone datafile 2 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 5 to new;
backup as copy reuse
datafile 1 auxiliary format new
datafile 2 auxiliary format new
datafile 3 auxiliary format new
datafile 4 auxiliary format new
datafile 5 auxiliary format new
;
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to +DATA in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 2025-03-28 21:15:25
channel c1: starting datafile copy
input datafile file number=00002 name=+DATA/racdb/datafile/sysaux.257.1170160479
channel c2: starting datafile copy
input datafile file number=00001 name=+DATA/racdb/datafile/system.256.1170160477
output file name=+DATA/racdb_standby1/datafile/sysaux.260.1196975727 tag=TAG20250328T211526
channel c1: datafile copy complete, elapsed time: 00:00:25
channel c1: starting datafile copy
input datafile file number=00005 name=+DATA/racdb/datafile/undotbs2.264.1170160703
output file name=+DATA/racdb_standby1/datafile/system.263.1196975727 tag=TAG20250328T211526
channel c2: datafile copy complete, elapsed time: 00:00:26
channel c2: starting datafile copy
input datafile file number=00003 name=+DATA/racdb/datafile/undotbs1.258.1170160479
output file name=+DATA/racdb_standby1/datafile/undotbs2.266.1196975753 tag=TAG20250328T211526
channel c1: datafile copy complete, elapsed time: 00:00:16
channel c1: starting datafile copy
input datafile file number=00004 name=+DATA/racdb/datafile/users.259.1170160479
output file name=+DATA/racdb_standby1/datafile/undotbs1.265.1196975755 tag=TAG20250328T211526
channel c2: datafile copy complete, elapsed time: 00:00:15
output file name=+DATA/racdb_standby1/datafile/users.262.1196975769 tag=TAG20250328T211526
channel c1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2025-03-28 21:16:09

sql statement: alter system archive log current

contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=1196975774 file name=+DATA/racdb_standby1/datafile/system.263.1196975727
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=1196975774 file name=+DATA/racdb_standby1/datafile/sysaux.260.1196975727
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=1196975775 file name=+DATA/racdb_standby1/datafile/undotbs1.265.1196975755
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=1196975775 file name=+DATA/racdb_standby1/datafile/users.262.1196975769
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=1196975775 file name=+DATA/racdb_standby1/datafile/undotbs2.266.1196975753
Finished Duplicate Db at 2025-03-28 21:16:24

released channel: c1

released channel: c2

released channel: c3

released channel: c4

RMAN>

创建备库spfile

备库查询当前控制文件路径:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[oracle@racdg1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 21:22:30 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> show parameter control_files;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string +DATA/racdb_standby1/controlfi
le/current.267.1196975659, +FR
A/racdb_standby1/controlfile/c
urrent.256.1196975659
SQL>

将新的controlfile 位置,更新到备库启动的pfile 中:

1
2
3
[oracle@racdg1 ~]$ cat /tmp/init_racdb_stby.ora | grep control
*.control_files='+DATA/racdb_standby1/controlfile/current.267.1196975659','+FRA/racdb_standby1/controlfile/current.256.1196975659'
[oracle@racdg1 ~]$

关闭备库,使用修改后的pfile 启动备库:

1
2
3
4
5
6
7
8
9
10
11
12
13
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount pfile='/tmp/init_racdb_stby.ora';
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 520096928 bytes
Database Buffers 1073741824 bytes
Redo Buffers 7319552 bytes
SQL>

从静态参数文件创建动态参数文件:

1
2
3
SQL> create spfile='+DATA/racdb_standby1/spfileracdb.ora' from pfile='/tmp/init_racdb_stby.ora';

File created.

**创建各节点的静态参数文件指向共同的动态参数文件: **

1
2
3
4
# 备库节点1
[oracle@racdg1 ~]$ echo "SPFILE='+DATA/racdb_standby1/spfileracdb.ora'" > $ORACLE_HOME/dbs/initracdb1.ora
# 备库节点2
[oracle@racdg2 ~]$ echo "SPFILE='+DATA/racdb_standby1/spfileracdb.ora'" > $ORACLE_HOME/dbs/initracdb2.ora

删除节点1 本地active duplicate 时生成的spfile:

1
2
[oracle@racdg1 ~]$ rm -rf /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileracdb1.ora 
[oracle@racdg1 ~]$

使用共享spfile重新启动数据库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- 备库节点1
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 520096928 bytes
Database Buffers 1073741824 bytes
Redo Buffers 7319552 bytes
Database mounted.
SQL>

-- 备库节点2
[oracle@racdg2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 21:39:26 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 520096928 bytes
Database Buffers 1073741824 bytes
Redo Buffers 7319552 bytes
Database mounted.
SQL>

备库SRL

备库自动创建了SRL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
SQL> select GROUP#,STATUS ,TYPE,MEMBER from v$logfile;

GROUP# STATUS TYPE MEMBER
---------- ------- ------- ------------------------------------------------------------
2 ONLINE +DATA/racdb_standby1/onlinelog/group_2.264.1196975777
2 ONLINE +FRA/racdb_standby1/onlinelog/group_2.259.1196975777
1 ONLINE +DATA/racdb_standby1/onlinelog/group_1.261.1196975775
1 ONLINE +FRA/racdb_standby1/onlinelog/group_1.260.1196975777
3 ONLINE +DATA/racdb_standby1/onlinelog/group_3.259.1196975777
3 ONLINE +FRA/racdb_standby1/onlinelog/group_3.258.1196975777
4 ONLINE +DATA/racdb_standby1/onlinelog/group_4.258.1196975777
4 ONLINE +FRA/racdb_standby1/onlinelog/group_4.257.1196975779
5 STANDBY +DATA/racdb_standby1/onlinelog/group_5.257.1196975779
5 STANDBY +FRA/racdb_standby1/onlinelog/group_5.261.1196975779
6 STANDBY +DATA/racdb_standby1/onlinelog/group_6.256.1196975781
6 STANDBY +FRA/racdb_standby1/onlinelog/group_6.262.1196975781
7 STANDBY +DATA/racdb_standby1/onlinelog/group_7.268.1196975781
7 STANDBY +FRA/racdb_standby1/onlinelog/group_7.263.1196975781
8 STANDBY +DATA/racdb_standby1/onlinelog/group_8.269.1196975783
8 STANDBY +FRA/racdb_standby1/onlinelog/group_8.264.1196975783
9 STANDBY +DATA/racdb_standby1/onlinelog/group_9.270.1196975783
9 STANDBY +FRA/racdb_standby1/onlinelog/group_9.265.1196975783
10 STANDBY +DATA/racdb_standby1/onlinelog/group_10.271.1196975783
10 STANDBY +FRA/racdb_standby1/onlinelog/group_10.266.1196975783

20 rows selected.

将恢复的备库加入CRS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 查看当前
[grid@racdg1 ~]$ srvctl config database -v
No databases are configured
# 如果存在老的信息,则使用以下指令删除
srvctl remove database -d racdb_standby1

# 添加数据库,以oracle身份执行
[oracle@racdg1 ~]$ srvctl add database -d racdb_standby1 -n racdb -o /u01/app/oracle/product/11.2.0/dbhome_1 -p +DATA/racdb_standby1/spfileracdb.ora -r physical_standby -s 'READ ONLY'
[oracle@racdg1 ~]$
# 添加racdb1实例到CRS
[oracle@racdg1 ~]$ srvctl add instance -d racdb_standby1 -i racdb1 -n racdg1
# 添加racdb2实例到CRS
[oracle@racdg1 ~]$ srvctl add instance -d racdb_standby1 -i racdb2 -n racdg2

# 检查
[oracle@racdg1 ~]$ srvctl status database -d racdb_standby1
Instance racdb1 is not running on node racdg1
Instance racdb2 is not running on node racdg2
[oracle@racdg1 ~]$ srvctl config database -d racdb_standby1
Database unique name: racdb_standby1
Database name: racdb
Oracle home: /u01/app/oracle/product/11.2.0/dbhome_1
Oracle user: oracle
Spfile: +DATA/racdb_standby1/spfileracdb.ora
Domain:
Start options: read only
Stop options: immediate
Database role: PHYSICAL_STANDBY
Management policy: AUTOMATIC
Server pools: racdb_standby1
Database instances: racdb1,racdb2
Disk Groups:
Mount point paths:
Services:
Type: RAC
Database is administrator managed
[oracle@racdg1 ~]$

启动DG同步进程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[oracle@racdg1 ~]$ srvctl stop database -d racdb_standby1
[oracle@racdg1 ~]$ srvctl status database -d racdb_standby1
Instance racdb1 is not running on node racdg1
Instance racdb2 is not running on node racdg2
[oracle@racdg1 ~]$ srvctl start database -d racdb_standby1 -o 'READ ONLY'
[oracle@racdg1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 28 22:25:12 2025

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select open_mode from gv$database;

OPEN_MODE
--------------------
READ ONLY
READ ONLY

SQL>

# 启动实时应用
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

SQL>

DG状态检查:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
SQL> select switchover_status,database_role,open_mode,protection_mode,protection_level from v$database;

SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
-------------------- ---------------- -------------------- -------------------- --------------------
NOT ALLOWED PHYSICAL STANDBY READ ONLY WITH APPLY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE

SQL> select process,client_process,sequence#,status from v$managed_standby;

PROCESS CLIENT_P SEQUENCE# STATUS
--------- -------- ---------- ------------
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
MRP0 N/A 279 WAIT_FOR_LOG

SQL> select recovery_mode from v$archive_dest_status;

RECOVERY_MODE
-----------------------
MANAGED REAL TIME APPLY
IDLE
IDLE

[grid@racdg1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.CRS.dg
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.DATA.dg
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.FRA.dg
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.LISTENER.lsnr
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.asm
ONLINE ONLINE racdg1 Started
ONLINE ONLINE racdg2 Started
ora.gsd
OFFLINE OFFLINE racdg1
OFFLINE OFFLINE racdg2
ora.net1.network
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
ora.ons
ONLINE ONLINE racdg1
ONLINE ONLINE racdg2
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE racdg2
ora.LISTENER_SCAN2.lsnr
1 ONLINE ONLINE racdg1
ora.LISTENER_SCAN3.lsnr
1 ONLINE ONLINE racdg1
ora.cvu
1 ONLINE ONLINE racdg1
ora.oc4j
1 ONLINE ONLINE racdg1
ora.racdb_standby1.db
1 ONLINE ONLINE racdg1 Open
2 ONLINE ONLINE racdg2 Open
ora.racdg1.vip
1 ONLINE ONLINE racdg1
ora.racdg2.vip
1 ONLINE ONLINE racdg2
ora.scan1.vip
1 ONLINE ONLINE racdg2
ora.scan2.vip
1 ONLINE ONLINE racdg1
ora.scan3.vip
1 ONLINE ONLINE racdg1
[grid@racdg1 ~]$

主备库同步进度

打开备库 alert 日志,用 tail 命令跟进告警信息。

1
2
3
4
5
6
7
8
9
10
11
tail -200f /u01/app/oracle/diag/rdbms/racdb_standby1/racdb1/trace/alert_racdb1.log

Media Recovery Log +LOG/racdb_stby/archivelog/2018_06_07/thread_1_seq_399.267.978211171
Media Recovery Waiting for thread 2 sequence 159 (in transit)
Thu Jun 07 21:19:48 2018
RFS[7]: Selected log 8 for thread 2 sequence 160 dbid 971926187 branch 974309419
Thu Jun 07 21:19:48 2018
Archived Log entry 13 added for thread 2 sequence 159 ID 0x39eda8ab dest 1:
Thu Jun 07 21:19:49 2018
Media Recovery Log +LOG/racdb_stby/archivelog/2018_06_07/thread_2_seq_159.268.978211189
Media Recovery Waiting for thread 1 sequence 400 (in transit)

查询v$archived_log 视图确认DG 同步状态

动态性能视图 v$archived_log,可以查看主库和备库的日志同步情况和备库的日志应用情况。方法是在主库手动切换 redo log,在分别在主库和备库查看 v$archived_log视图中最大 sequence 的日志,看主备的最大 sequence 是否相同,如果主库和备库的 sequence 相同,说明日志已传输到备库;另外看备库中所有日志的应用状态(applied)是否为 YES,如果是YES 说明备库已经应用了主库传输的日志,由此两点也可说明 DG 同步正常。

1
2
3
4
5
6
-- 在Primary 库中查看
alter system switch logfile;
select * from (select sequence#,completion_time,applied from v$archived_log order by 1 desc) where rownum<10; -- 获取最大的归档日志编号

-- 在备库查看
select * from (select sequence# , completion_time , applied from v$archived_log order by 1 desc) where rownum<10; -- 获取最大的归档日志编号