oel7.9 搭建oracle 11.2.0.4 Data Guard—主库单实例

文档课题:oel7.9 搭建oracle 11.2.0.4 Data Guard—主库单实例
创建时间:2021/11/30
1、主备库规划

2、磁盘处理
2.1、划分磁盘空间
[root@bigdata ~]#fdisk /dev/sdb
为meddoc备库划分磁盘空间30g.
[root@bigdata ~]# partprobe
[root@bigdata ~]# lsblk -p
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
/dev/sdb 8:16 0 100G 0 disk
├─/dev/sdb2 8:18 0 30G 0 part
└─/dev/sdb1 8:17 0 50G 0 part
└─/dev/mapper/hisorcldg-hisorcldg 252:2 0 50G 0 lvm /hisorcldg
/dev/sr0 11:0 1 4.5G 0 rom
/dev/sda 8:0 0 100G 0 disk
├─/dev/sda2 8:2 0 98G 0 part
│ ├─/dev/mapper/ol-swap 252:1 0 16G 0 lvm [SWAP]
│ └─/dev/mapper/ol-root 252:0 0 82G 0 lvm /
└─/dev/sda1 8:1 0 2G 0 part /boot
[root@bigdata ~]# pvcreate /dev/sdb2 #创建pv
[root@bigdata ~]# vgcreate -s 4M meddocdg /dev/sdb2 #创建名为meddocdg的vg
[root@bigdata ~]# lvcreate -l 100%vg -n meddocdg meddocdg #创建名为meddocdg的lv
[root@bigdata ~]# mkfs -t xfs /dev/meddocdg /meddocdg

2.2、挂载
创建挂载点:
[root@bigdata ~]# mkdir /meddocdg
[root@bigdata ~]# chown -R oracle:oinstall /meddocdg
[root@bigdata ~]# blkid
/dev/mapper/ol-root: UUID="246e5309-f28c-479a-9584-36d0b8e62cb9" TYPE="xfs"
/dev/sda2: UUID="iMSfIj-HabE-8jgF-VDxJ-DJAu-mRWe-QFPefy" TYPE="LVM2_member"
/dev/sda1: UUID="d35e9e9d-0347-4c0e-993e-54062332e6a8" TYPE="xfs"
/dev/sdb1: UUID="YdUXdz-132F-yFY8-QKsK-1Kli-yHG9-YXuMjd" TYPE="LVM2_member"
/dev/sdb2: UUID="Vkoh6O-nlvj-bs4g-DMLX-PBU1-2UdW-nQwVYA" TYPE="LVM2_member"
/dev/sr0: UUID="2020-10-05-20-58-48-00" LABEL="OL-7.9 Server.x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/ol-swap: UUID="dcea927e-3e24-4ab8-a8b1-c3c5f79ed226" TYPE="swap"
/dev/mapper/hisorcldg-hisorcldg: UUID="4c9771b2-a415-4380-9f00-f8921c606b0c" TYPE="xfs"

[root@bigdata ~]# vim /etc/fstab
添加以下:
UUID=" a1bd18f9-35a7-4ac3-99d9-21e12b62b273" /meddocdg xfs defaults 0 0

[root@bigdata ~]# mount –a 自动挂载

3、主库配置
3.1、数据库归档
查看数据库是否运行在归档模式:
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 5
Current log sequence 7
备注:如果数据库已经开启归档,下面的操作可以忽略.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 3206836224 bytes
Fixed Size 2257520 bytes
Variable Size 1811942800 bytes
Database Buffers 1375731712 bytes
Redo Buffers 16904192 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.
#设置归档路径
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/ORCL/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=ORCL' scope=spfile;

System altered.

SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 8
Next log sequence to archive 10
Current log sequence 10
3.2、设置数据库强制归档
检查数据库是否开启强制归档:
SQL> select force_logging from v$database;

FORCE_
------
NO
备注:如果数据库已经开启强制归档,下面的操作可以忽略.
#开启强制归档
SQL> select force_logging from v$database;

FORCE_
------
NO

SQL> alter database force logging;

Database altered.

SQL> select force_logging from v$database;

FORCE_
------
YES
3.3、创建 STANDBY 日志文件
查询主库当前 redo logfile 的大小和组数:
SQL> select thread#,group#,members,bytes/1024/1024 as M from v$log;

THREAD# GROUP# MEMBERS M
---------- ---------- ---------- ----------
1 1 1 50
1 2 1 50
1 3 1 50
查询备库 standby 日志的大小和组数:
SQL> select group#,bytes/1024/1024 as M from v$standby_log;

no rows selected

SQL> alter database add standby logfile group 11 ('/u01/app/oracle/oradata/orcl/redo11_standby.log') size 50M;

Database altered.

SQL> alter database add standby logfile group 12 ('/u01/app/oracle/oradata/orcl/redo12_standby.log') size 50M;

Database altered.

SQL> alter database add standby logfile group 13 ('/u01/app/oracle/oradata/orcl/redo13_standby.log') size 50M;

Database altered.

SQL> alter database add standby logfile group 14 ('/u01/app/oracle/oradata/orcl/redo14_standby.log') size 50M;

Database altered.

SQL> select group#,bytes/1024/1024 as M from v$standby_log;

GROUP# M
---------- ----------
11 50
12 50
13 50
14 50

Database altered.
3.4、修改参数文件
#设置主库唯一名字
SQL> alter system set db_unique_name=orcl scope=spfile;

System altered.
#设置 log_archive_config
SQL> alter system set log_archive_config='dg_config=(orcl,meddocdg)' scope=spfile;

System altered.
#设置备库归档目的地
SQL> alter system set log_archive_dest_2='service=MEDDOCDG lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=meddocdg';

System altered.
#设置 standby 库从哪个数据库获取归档日志
SQL> alter system set fal_server=meddocdg;

System altered.

SQL> alter system set fal_client=orcl;

System altered.

#启用设置的日志路径
SQL> alter system set log_archive_dest_state_1='enable';

System altered.

SQL> alter system set log_archive_dest_state_2='enable';

System altered.
#如果主备库文件的存放路径不同,还需要设置以下两个参数
SQL> alter system set db_file_name_convert='/meddocdg/oradata/meddocdg/','/u01/app/oracle/oradata/orcl/' scope=spfile;

System altered.

SQL> alter system set log_file_name_convert='/meddocdg/oradata/onlinelog/', '/u01/app/oracle/oradata/orcl/','/meddocdg/oradata/meddocdg/controlfile/','/u01/app/oracle/fast_recovery_area/orcl/' scope=spfile;

System altered.

#设置文件管理模式,此项设置为自动,不然在主库创建数据文件后,备库不会自动创建
SQL> alter system set standby_file_management=auto;

System altered.
3.5、拷贝参数文件
用 spfile 文件创建 pfile 文件:
SQL> create pfile from spfile;

File created.
使用 scp 命令:
[oracle@meddoc orcl]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs/
[oracle@meddoc dbs]$ ll
total 28
-rw-rw---- 1 oracle oinstall 1544 Nov 30 13:38 hc_orcl.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r--r-- 1 oracle oinstall 1659 Nov 30 14:12 initorcl.ora
-rw-r----- 1 oracle oinstall 24 Nov 29 14:59 lkORCL
-rw-r----- 1 oracle oinstall 1536 Nov 29 15:08 orapworcl
-rw-r----- 1 oracle oinstall 4608 Nov 30 14:12 spfileorcl.ora
[oracle@meddoc dbs]$ scp initorcl.ora oracle@192.168.133.226:/u01/app/oracle/product/11.2.0/db_1/dbs/
3.6、拷贝密码文件
[oracle@meddoc dbs]$ scp orapworcl oracle@192.168.133.226:/u01/app/oracle/product/11.2.0/db_1/dbs/
3.7、修改监听配置文件
[oracle@meddoc dbs]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin
[oracle@meddoc admin]$ ll
total 12
-rw-r--r-- 1 oracle oinstall 367 Nov 29 14:41 listener.ora
drwxr-xr-x 2 oracle oinstall 64 Nov 29 14:32 samples
-rw-r--r-- 1 oracle oinstall 381 Dec 17 2012 shrept.lst
-rw-r----- 1 oracle oinstall 321 Nov 29 15:04 tnsnames.ora
[oracle@meddoc admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = meddoc)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /u01/app/oracle
备注:如果主库上的监听已经配置,这里可以忽略.
3.8、修改 TNS 配置文件
[oracle@meddoc admin]$ vi tnsnames.ora
[oracle@meddoc admin]$ cat 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.

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.133.225)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

MEDDOCDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.133.226)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = meddocdg)
)
)

#蓝色为修改部分
3.9、重启监听服务
$ lsnrctl stop
$ lsnrctl start

4、备库配置
4.1、添加实例名
[oracle@bigdata ~]$ vi /etc/oratab
添加以下:
meddocdg:/u01/app/oracle/product/11.2.0/db_1:N

[oracle@bigdata ~]$ export ORACLE_SID=meddocdg

4.2、重命名文件
[oracle@bigdata dbs]$ ll
total 36
-rw-rw---- 1 oracle oinstall 1544 Nov 30 12:18 hc_hisorcldg.dat
-rw-r--r-- 1 oracle oinstall 1744 Nov 29 22:16 inithisorcldg.ora
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r--r-- 1 oracle oinstall 1659 Nov 30 14:18 initorcl.ora
-rw-r----- 1 oracle oinstall 24 Nov 30 00:15 lkHISORCLDG
-rw-r----- 1 oracle oinstall 1536 Nov 30 00:15 orapwhisorcldg
-rw-r----- 1 oracle oinstall 1536 Nov 30 14:20 orapworcl
-rw-r----- 1 oracle oinstall 5632 Nov 30 12:17 spfilehisorcldg.ora
[oracle@bigdata dbs]$ mv initorcl.ora initmeddocdg.ora
[oracle@bigdata dbs]$ mv orapworcl orapwmeddocdg
4.3、修改参数文件
修改重命名后的参数文件:
[oracle@bigdata dbs]$ cat initmeddocdg.ora
orcl.__db_cache_size=1845493760
orcl.__java_pool_size=16777216
orcl.__large_pool_size=33554432
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=805306368
orcl.__sga_target=2415919104
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=486539264
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/meddocdg/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/meddocdg/control01.ctl','/u01/app/oracle/fast_recovery_area/meddocdg/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='/u01/app/oracle/oradata/orcl/','/meddocdg/oradata/meddocdg/'
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.db_unique_name='MEDDOCDG'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.fal_client='MEDDOCDG'
*.fal_server='ORCL'
*.log_archive_config='dg_config=(meddocdg,orcl)'
*.log_archive_dest_1='location=/u01/app/oracle/oradata/MEDDOCDG/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=MEDDOCDG'
*.log_archive_dest_2='service=ORCL lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcl'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_file_name_convert='/u01/app/oracle/oradata/orcl/','/meddocdg/oradata/onlinelog/','/u01/app/oracle/fast_recovery_area/orcl/','/meddocdg/oradata/meddocdg/controlfile/'
*.open_cursors=300
*.pga_aggregate_target=804257792
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=2412773376
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'

#红色为修改过内容
4.4、创建目录
[oracle@bigdata dbs]$ mkdir -p /u01/app/oracle/admin/meddocdg/adump
[oracle@bigdata dbs]$ mkdir -p /u01/app/oracle/oradata/meddocdg/
[oracle@bigdata dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/meddocdg/
[oracle@bigdata dbs]$ mkdir -p /meddocdg/oradata/meddocdg/
[oracle@bigdata dbs]$ mkdir -p /u01/app/oracle/oradata/MEDDOCDG/archivelog
[oracle@bigdata dbs]$ mkdir -p /meddocdg/oradata/onlinelog/
[oracle@bigdata dbs]$ mkdir -p /meddocdg/oradata/meddocdg/controlfile/
4.5、修改监听配置文件
修改监听配置文件:
[oracle@bigdata admin]$ vi listener.ora
[oracle@bigdata admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = hisorcldg)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = hisorcldg)
)
(SID_DESC =
(GLOBAL_DBNAME = meddocdg)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = meddocdg)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.133.226)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_LISTENER = /u01/app/oracle

#蓝色为修改部分
4.6、修改 TNS 配置文件
[oracle@bigdata admin]$ vi tnsnames.ora
[oracle@bigdata admin]$ cat 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.

HISORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.133.227)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisorcl)
)
)

HISORCLDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.133.226)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisorcldg)
)
)

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.133.225)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

MEDDOCDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.133.226)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = meddocdg)
)
)

备注:蓝色为修改部分
4.7、重启监听服务
[oracle@bigdata admin]$ lsnrctl stop
[oracle@bigdata admin]$ lsnrctl start

4.8、启动备库到 nomount 状态
[oracle@bigdata admin]$ echo $ORACLE_SID
meddocdg
[oracle@bigdata admin]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Nov 30 15:03:56 2021

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

Connected to an idle instance.

SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initmeddocdg.ora';
ORACLE instance started.

Total System Global Area 2405122048 bytes
Fixed Size 2255592 bytes
Variable Size 603981080 bytes
Database Buffers 1778384896 bytes
Redo Buffers 20500480 bytes
SQL> create spfile from pfile;

File created.
SQL> shutdown immediate;#关闭数据库
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 -
64bit Production
With the Partitioning, OLAP, Data Miningand Real ApplicationTesting options
[oracle@bigdata admin]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Nov 30 15:05:47 2021

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

Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2405122048 bytes
Fixed Size 2255592 bytes
Variable Size 603981080 bytes
Database Buffers 1778384896 bytes
Redo Buffers 20500480 bytes
SQL> select status from v$instance; #查看备库状态
STATUS
------------
STARTED
5、验证监听和 TNS 配置
主库:
ping 192.168.133.226
tnsping meddocdg
备库:
ping 192.168.133.225
tnsping orcl
测试OK后,主备库正常连接,如下所示:

5.1、主库验证
$ sqlplus sys/oracle_4U@192.168.133.225:1521/orcl as sysdba
> show parameter db_unique_name;
$ sqlplus sys/oracle_4U@192.168.133.226:1521/meddocdg as sysdba
5.2、备库验证
$ export ORACLE_SID=meddocdg
$ sqlplus sys/oracle_4U@192.168.133.226:1521/meddocdg as sysdba
> show parameter db_unique_name
$ sqlplus sys/oracle_4U@192.168.133.225:1521/orcl as sysdba
备注:在主备库上都能测试通过的条件下才能执行下面步骤
6、恢复数据库
6.1、恢复数据库
先将备库启动到nomount状态
SQL> startup nomount
ORACLE instance started.

Total System Global Area 2405122048 bytes
Fixed Size 2255592 bytes
Variable Size 603981080 bytes
Database Buffers 1778384896 bytes
Redo Buffers 20500480 bytes
然后执行以下:
$ rman target sys/oracle_4U@orcl auxiliary sys/oracle_4U@meddocdg

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Nov 30 15:15:29 2021

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

connected to target database: ORCL (DBID=1617684375)
connected to auxiliary database: ORCL (not mounted)

RMAN> duplicate target database for standby from active database;

Starting Duplicate Db at 30-NOV-21
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=193 device type=DISK

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

Starting backup at 30-NOV-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=201 device type=DISK
Finished backup at 30-NOV-21

contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/meddocdg/control01.ctl';
restore clone controlfile to '/u01/app/oracle/fast_recovery_area/meddocdg/control02.ctl' from
'/u01/app/oracle/oradata/meddocdg/control01.ctl';
}
executing Memory Script

Starting backup at 30-NOV-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.f tag=TAG20211130T151616 RECID=2 STAMP=1089990977
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 30-NOV-21

Starting restore at 30-NOV-21
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 30-NOV-21

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 tempfile 1 to
"/meddocdg/oradata/meddocdg/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/meddocdg/oradata/meddocdg/system01.dbf";
set newname for datafile 2 to
"/meddocdg/oradata/meddocdg/sysaux01.dbf";
set newname for datafile 3 to
"/meddocdg/oradata/meddocdg/undotbs01.dbf";
set newname for datafile 4 to
"/meddocdg/oradata/meddocdg/users01.dbf";
set newname for datafile 5 to
"/meddocdg/oradata/meddocdg/example01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/meddocdg/oradata/meddocdg/system01.dbf" datafile
2 auxiliary format
"/meddocdg/oradata/meddocdg/sysaux01.dbf" datafile
3 auxiliary format
"/meddocdg/oradata/meddocdg/undotbs01.dbf" datafile
4 auxiliary format
"/meddocdg/oradata/meddocdg/users01.dbf" datafile
5 auxiliary format
"/meddocdg/oradata/meddocdg/example01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /meddocdg/oradata/meddocdg/temp01.dbf 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 30-NOV-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
output file name=/meddocdg/oradata/meddocdg/system01.dbf tag=TAG20211130T151627
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:37
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
output file name=/meddocdg/oradata/meddocdg/sysaux01.dbf tag=TAG20211130T151627
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:28
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
output file name=/meddocdg/oradata/meddocdg/example01.dbf tag=TAG20211130T151627
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
output file name=/meddocdg/oradata/meddocdg/undotbs01.dbf tag=TAG20211130T151627
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:22
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
output file name=/meddocdg/oradata/meddocdg/users01.dbf tag=TAG20211130T151627
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 30-NOV-21

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=2 STAMP=1089991231 file name=/meddocdg/oradata/meddocdg/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=1089991231 file name=/meddocdg/oradata/meddocdg/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=1089991231 file name=/meddocdg/oradata/meddocdg/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=1089991231 file name=/meddocdg/oradata/meddocdg/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=1089991231 file name=/meddocdg/oradata/meddocdg/example01.dbf
Finished Duplicate Db at 30-NOV-21


6.2、开启实时同步
#open 数据库
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-10458: standby database requires recovery
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/meddocdg/oradata/meddocdg/system01.dbf'

主库执行
SQL> alter system set log_archive_config='dg_config=(orcl,meddocdg)';

System altered.

备库执行:
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.
SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database open;

Database altered.

#查看备库状态
SQL> select status from v$instance;

STATUS
------------------------
OPEN
#查看备库状态
SQL> select open_mode from v$database;

OPEN_MODE
----------------------------------------
READ ONLY
#开启实时同步
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

7、验证 DG 同步
7.1、查询主库最大归档序号
主库执行:
SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
17
备库验证:
SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
17
7.2、日志切换
主库执行:
SQL> alter system archive log current;

System altered.

SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
18
备库验证:
SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
18
7.3、查看主备库状态
主库执行:
SQL> select switchover_status,database_role from v$database;

SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
TO STANDBY PRIMARY
备库执行:
SQL> select switchover_status,database_role from v$database;

SWITCHOVER_STATUS DATABASE_ROLE
---------------------------------------- --------------------------------
NOT ALLOWED PHYSICAL STANDBY
7.4、创建一个table 测试
主库执行:
#创建 dg 表
SQL> create table dg(id number);

Table created.
#插入数据
SQL> insert into dg values(1);

1 row created.
#提交事务
SQL> commit;

Commit complete.
#主库查询 dg 表
SQL> select * from dg;

ID
----------
1
备库验证:
#备库查询 dg 表
SQL> select * from dg;

ID
----------
1
DG 同步,DG搭建结束.