Bootstrap

oracle adg dup 一拖一拖一(一主两备)(dup)

oracle adg dup 一拖一拖一(一主两备)

1.配置Public IP

ora1
nmcli connection modify ens33 ipv4.addresses 192.168.134.249/24 ipv4.gateway 192.168.134.2 ipv4.method manual autoconnect yes
nmcli connection up ens33
nmcli connection show
orastd1
节点二
nmcli connection modify ens33 ipv4.addresses 192.168.134.250/24 ipv4.gateway 192.168.134.2 ipv4.method manual autoconnect yes
nmcli connection up ens33
nmcli connection show
orastd2
节点三
nmcli connection modify ens33 ipv4.addresses 192.168.134.251/24 ipv4.gateway 192.168.134.2 ipv4.method manual autoconnect yes
nmcli connection up ens33
nmcli connection show
ora1
cat <<EOF>> /etc/sysconfig/network-scripts/ifcfg-ens33
PEERDNS=no            
DNS1=114.114.114.114        
DNS2=8.8.8.8  
EOF
重启网络 
systemctl restart NetworkManager

orastd1
cat <<EOF>> /etc/sysconfig/network-scripts/ifcfg-ens33
PEERDNS=no            
DNS1=114.114.114.114        
DNS2=8.8.8.8  
EOF
重启网络 
systemctl restart NetworkManager

orastd2
cat <<EOF>> /etc/sysconfig/network-scripts/ifcfg-ens33
PEERDNS=no            
DNS1=114.114.114.114        
DNS2=8.8.8.8  
EOF
重启网络 
systemctl restart NetworkManager
关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
getenforce

3.关闭防火墙

  1. 使用root权限登录到Red Hat系统的终端。

  2. 停止当前运行的防火墙服务。可以使用以下命令:

    systemctl stop firewalld
    
  3. 禁止防火墙服务在系统启动时自动启动。可以使用以下命令:

    systemctl disable firewalld
    
  4. 确认防火墙服务已停止并禁用。可以使用以下命令验证:

    systemctl status firewalld
    

    如果输出显示 “inactive”,则表示防火墙服务已成功停止并禁用。

  5. 重新启动系统,以使更改生效。

配置yum源

#### 1.配置网络yum源

1.删除redhat7.0系统自带的yum软件包;

rpm -qa|grep yum >oldyum.pkg  备份原信息

rpm -qa|grep yum|xargs rpm -e --nodeps  不检查依赖,直接删除rpm包

2.自行下载所需要的软件包。包名会更新,根据当前最新的下载。如有有依赖问题,下载依赖包进行安装。

阿里云网络源地址:https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/

网易163网络源地址:http://mirrors.163.com/ CentOS

网络源地址:http://centos.ustc.edu.cn/centos/

打开网页,ctrl+f 搜索相关yum包:http://mirrors.163.com/centos/7/os/x86_64/Packages/

wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-4.11.3-45.el7.x86_64.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

3.根据依赖项安装;

rpm -ivh --force rpm-4.11.3-45.el7.x86_64.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm python-urlgrabber-3.10-10.el7.noarch.rpm yum-3.4.3-168.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm  --force  

4.下载repo配置文件。

wget http://mirrors.aliyun.com/repo/Centos-7.repo
将文件中所有的$releasever**更换为**7,否则无法使用。
mv Centos-7.repo /etc/yum.repos.d/
vi /etc/yum.repos.d/Centos-7.repo
%s/$releasever/7/g 

5下载KEY文件:
[redhat@root ~]$ cd /etc/yum.repos.d/
mv redhat.repo redhat.repo.bak
关闭订阅插件提示
[redhat@root ~]$ vi /etc/yum.conf
    plugins=0
[redhat@root ~]$ vim /etc/yum/pluginconf.d/subscription-manager.conf
    [main]
    enabled=0 #将它禁用掉
6.清理yum缓存。将服务器软件包信息缓存至本地,提高搜索安装效率
yum -y clean all && yum -y makecache

安装相关软件

## 安装常用软件
yum install -y vim tree net-tools unzip
## 安装Oracle依赖包
yum install -y binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33.i686 glibc glibc.i686 glibc-devel glibc-devel.i686 ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libX11 libX11.i686 libXau libXau.i686 libXi libXi.i686 libXtst libXtst.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel libstdc++-devel.i686 libxcb libxcb.i686 make nfs-utils net-tools smartmontools sysstat unixODBC unixODBC-devel gcc gcc-c++ libXext libXext.i686 zlib-devel zlib-devel.i686

配置hosts


ora1
hostnamectl set-hostname ora1
orastd1
hostnamectl set-hostname orastd1
orastd2
hostnamectl set-hostname orastd2

主库备库都要添加进去
echo "192.168.134.249 ora1" >> /etc/hosts
echo "192.168.134.250 orastd1" >> /etc/hosts
echo "192.168.134.251 orastd2" >> /etc/hosts

主库安装数据库

配置目录

mkdir /opt/oracle
先把下载的包传到soft目录下
mkdir /soft
cd /soft
rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86 64.rpm
yum -y install compat-libcap1 ksh
yum -y install compat-libstdc++-33
yum -y install libaio-devel
yum -y install libstdc++-devel 

修改密码

passwd oracle

手工目录的授权

chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle

安装oracle-database-ee:

rpm -ivh oracle-database-ee-19c-1.0-1.x86_64.rpm

准备配置文件

cd /etc/sysconfig
cp oracledb_ORCLCDB-19c.conf oracledb_orcl-19c.conf
vi /etc/sysconfig/oracledb_orcl-19c.conf
不要修改

cd /etc/init.d
cp oracledb_ORCLCDB-19c oracledb_orcl-19c
vi /etc/init.d/oracledb_orcl-19c
下面是在vi里面执行
:%s/ORCLCDB/orcl/g	
:%s/ORCLPDB1/orclpdb/g
(为了全局替换)
然后在修改下面的内容:

创建数据库

/etc/init.d/oracledb_orcl-19c configure

检查环境:

su - oracle
ps -ef | grep smon
echo $ORACLE_HOME
lsnrctl status

测试停止、启动
/etc/init.d/oracledb itpuxdb-19c

Usage: /etc/init.d/oracledb_itpuxdb-19c {start|stoprestart|configure)

/etc/init.d/oracledb_orcl-19c stop

/etc/init.d/oracledb_orcl-19c start

环境变量配置

su - oracle
echo "export LANG=en_US" >>~/.bash_profile
echo "export ORACLE_BASE=/opt/oracle">>~/.bash_profile
echo "export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1">> ~/.bash_profile
echo "export ORACLE_UNQNAME=orcl">> ~/.bash_profile
echo "export ORACLE_SID=orcl">>~/.bash_profile
echo "NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;export NLS_LANG" >>~/.bash_profile
echo "export PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin" >> ~/.bash_profile

source ~/.bash_profile
env | grep ORACLE

这样主库就搭建成功啦

2.一级备库的搭建

(前面一点都差不多,但是没有了**准备配置文件:创建数据库)

配置hosts

主库备库都要添加进去
echo "192.168.134.249 ora1" >> /etc/hosts
echo "192.168.134.250 orastd1" >> /etc/hosts
echo "192.168.134.251 orastd2" >> /etc/hosts

关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

配置目录

mkdir /opt/oracle

这个是配置目录,如果有的话就不用创建啦

准备预先安装的包

先把下载的包传到soft目录下
mkdir /soft
rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm

注意:(这里会出现问题)
根据提示安装所需要的包:(如)

yum -y install compat-libcap1 ksh
yum -y install compat-libstdc++-33
yum -y install libaio-devel
yum -y install libstdc++-devel 

修改密码:

passwd oracle

手工目录的授权

chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle

安装oracle-database-ee:

rpm -ivh oracle-database-ee-19c-1.0-1.x86_64.rpm

检查环境:

su - oracle
ps -ef | grep smon
echo $ORACLE HOME
lsnrctl status(这个会出错误没关系,下面会配好)

环境变量配置

su - oracle
echo "export LANG=en_US">>~/.bash_profile
echo "export ORACLE_BASE=/opt/oracle">>~/.bash_profile
echo "export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1">> ~/.bash_profile
echo "export ORACLE_UNQNAME=orcldg">> ~/.bash_profile
echo "export ORACLE_SID=orcldg">>~/.bash_profile
echo "NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;export NLS_LANG">>~/.bash_profile
echo "export PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin">> ~/.bash_profile

source ~/.bash_profile
env |grep ORACLE

备库的数据库环境装好了。

二级备库的搭建

2.一级备库的搭建

(前面一点都差不多,但是没有了**准备配置文件:创建数据库)

配置hosts

主库备库都要添加进去
echo "192.168.134.249 ora1" >> /etc/hosts
echo "192.168.134.250 orastd1" >> /etc/hosts
echo "192.168.134.251 orastd2" >> /etc/hosts

关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

配置目录

mkdir /opt/oracle

这个是配置目录,如果有的话就不用创建啦

准备预先安装的包

先把下载的包传到soft目录下
mkdir /soft
rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm

注意:(这里会出现问题)
根据提示安装所需要的包:(如)

yum -y install compat-libcap1 ksh
yum -y install compat-libstdc++-33
yum -y install libaio-devel
yum -y install libstdc++-devel 

修改密码:

passwd oracle

手工目录的授权

chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle

安装oracle-database-ee:

rpm -ivh oracle-database-ee-19c-1.0-1.x86_64.rpm

检查环境:

su - oracle
ps -ef | grep smon
echo $ORACLE HOME
lsnrctl status(这个会出错误没关系,下面会配好)

环境变量配置

su - oracle
echo "export LANG=en_US">>~/.bash_profile
echo "export ORACLE_BASE=/opt/oracle">>~/.bash_profile
echo "export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1">> ~/.bash_profile
echo "export ORACLE_UNQNAME=orcldgs">> ~/.bash_profile
echo "export ORACLE_SID=orcldgs">>~/.bash_profile
echo "NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;export NLS_LANG">>~/.bash_profile
echo "export PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin">> ~/.bash_profile

source ~/.bash_profile
env |grep ORACLE

备库的数据库环境装好了。

三、主备库的实施配置

准备备库1监听配置

vi /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora

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

SID_LIST_LISTENER=
(SID_LIST=
	(SID_DESC=
		(GLOBAL_DBNAME=orcldg)
		(SID_NAME=orcldg)
		(ORACLE_HOME=/opt/oracle/product/19c/dbhome_1)
 )
)
:wq

然后检查监听是否配置成功
lsnrctl start
lsnrctl status

准备备库2监听配置

vi /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora

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

SID_LIST_LISTENER=
(SID_LIST=
	(SID_DESC=
		(GLOBAL_DBNAME=orcldgs)
		(SID_NAME=orcldgs)
		(ORACLE_HOME=/opt/oracle/product/19c/dbhome_1)
 )
)
:wq

然后检查监听是否配置成功
lsnrctl start
lsnrctl status

主库配置

1.打开强制日志

su - oracle 
sqlplus "/as sysdba"
alter database force logging;

2.设置为归档模式

alter system set db_recovery_file_dest_size=5g;
alter system set db_recovery_file_dest='/opt/oracle';
shutdown immediate
startup mount;
alter database archivelog;
alter database open;
alter system switch logfile;

可以出查看一下是否有归档文件
cd /opt/oracle/ITPUXDB/archivelog/

3.创建日志文件 如果主库有三个了(那就要创建四个)

select * from v$log;
select * from v$logfile;

alter database add standby logfile group 4 '/opt/oracle/oradata/ORCL/stredo04.10g' size 200m;
alter database add standby logfile group 5 '/opt/oracle/oradata/ORCL/stredo05.log' size 200m;
alter database add standby logfile group 6 '/opt/oracle/oradata/ORCL/stredo06.log' size 200m;
alter database add standby logfile group 7 '/opt/oracle/oradata/ORCL/stredo07.log' size 200m;

主备库监听tnsnames.ora:

vi /opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora


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

ORCLDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = orastd1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcldg)
    )
  )
  
ORCLDGS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = orastd2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcldgs)
    )
  )

(主库只要加ITPUXDG,备库全加上)

测试
tnsping ORCL
tnsping ORCLDG
tnsping ORCLDGS

准备数据库密码文件

主库:

orapwd file='opt/oracle/product/19c/dbhome_1/dbs/orapworcl' password=hsl-123456
orapwd file='./orapworcl' password=orcl-123

备库:

cd /opt/oracle/product/19c/dbhome_1/dbs
scp orapworcl 192.168.134.250:/opt/oracle/product/19c/dbhome_1/dbs/orapworcl
mv orapworcl orapworcldg
scp orapworcl 192.168.134.251:/opt/oracle/product/19c/dbhome_1/dbs/orapworcl
mv orapworcl orapworcldgs

登录

主库:
sqlplus "sys/123456@orcl as sysdba"

准备参数文件了。

主库:

create pfile='/opt/oracle/pfile.ora' from spfile;
(等会有改参数,这个是备份一份,然后传到备库里面在改参数)
然后在把pfile传给备库
scp /opt/oracle/pfile.ora 192.168.134.250:/opt/oracle/
scp /opt/oracle/pfile.ora 192.168.134.251:/opt/oracle/

主库参数(重启生效):

alter system set db_unique_name='orcl' scope=spfile;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(itpuxdb,itpuxdg)' scope=both;
alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=itpuxdb' scope=both; 
alter system set LOG_ARCHIVE_DEST_2='SERVICE=itpuxdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)  DB_UNIQUE_NAME=itpuxdg' scope=both;
alter system set fal_client='itpuxdb' scope=both;
alter system set FAL_SERVER='itpuxdg' scope=both;
alter system set DB_FILE_NAME_CONVERT='ITPUXDG','ITPUXDB'  scope=spfile;
alter system set LOG_FILE_NAME_CONVERT='ITPUXDG','ITPUXDB' scope=spfile;
alter system set standby_file_management=AUTO scope=both;

#重启生效:
shutdown immediate
startup
alter system set db_unique_name='orcl' scope=spfile;
alter system set log_archive_config = 'dg_config=(orcl,orcldg)' 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=orcl' scope=both; 
alter system set LOG_ARCHIVE_DEST_2='SERVICE=orcldg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)  DB_UNIQUE_NAME=orcldg' scope=both;
alter system set LOG_ARCHIVE_DEST_STATE_1='ENABLE' scope=both;
alter system set LOG_ARCHIVE_DEST_STATE_2='ENABLE' scope=both;
alter system set fal_server='ORCLDG' scope=both;
alter system set fal_client='ORCL' scope=both;
alter system set db_file_name_convert='ORCLDG','ORCL' scope=spfile;
alter system set log_file_name_convert='ORCLDG','ORCL' scope=spfile;
alter system set standby_file_management=auto scope=both;

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

备库参数:

cd /opt/oracle
vi pfile.ora    
#先把"*."前面的都删了,把itpuxdb改成itpuxdg,在添加下面的。
db_unique_name='itpuxdg'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(itpuxdg,itpuxdb)'
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=itpuxdg'
LOG_ARCHIVE_DEST_2='SERVICE=itpuxdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=itpuxdb' fal_client='itpuxdg'
FAL_SERVER='itpuxdb'
DB_FILE_NAME_CONVERT='ITPUXDB','ITPUXDG'
LOG_FILE_NAME_CONVERT='ITPUXDB','ITPUXDG'
standby_file_management=AUTO
db_unique_name='orcldg'
LOG_ARCHIVE_CONFIG='DG_CONFIG= orcl,orcldg,orcldgs)'
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcldg' 
LOG_ARCHIVE_DEST_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
LOG_ARCHIVE_DEST_3='SERVICE=orcldgs LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)  DB_UNIQUE_NAME=orcldgs'
fal_client='ORCLDG'
FAL_SERVER='ORCL','ORCLDGS'
DB_FILE_NAME_CONVERT='ORCL','ORCLDG'
LOG_FILE_NAME_CONVERT='ORCL','ORCLDG'
standby_file_management=AUTO

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

备库备库创建需要的目录:

mkdir -p /opt/oracle/admin/orcldgs/adump
mkdir -p /opt/oracle/oradata/ORCLDGS

二级备库参数:

cd /opt/oracle
vi pfile.ora    
db_unique_name='orcldgs'
LOG_ARCHIVE_CONFIG='DG_CONFIG= (orcl,orcldg,orcldgs)'
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcldgs' 
LOG_ARCHIVE_DEST_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
LOG_ARCHIVE_DEST_3='SERVICE=orcldgs LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)  DB_UNIQUE_NAME=orcldg'
fal_client='ORCLDGS'
FAL_SERVER='ORCL','ORCLDG'
DB_FILE_NAME_CONVERT='ORCLDG','ORCLDGS'
LOG_FILE_NAME_CONVERT='ORCLDG','ORCLDGS'
standby_file_management=AUTO

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

启动到nomunt(一级备库);

sqlplus "sys/123456@orcldg as sysdba"
startup pfile='/opt/oracle/pfile.ora' nomount;
create spfile from pfile='/opt/oracle/pfile.ora';
shutdown immediate;
startup nomount;

启动到nomunt(二级备库);

sqlplus "sys/123456@orcldgs as sysdba"
startup pfile='/opt/oracle/pfile.ora' nomount;
create spfile from pfile='/opt/oracle/pfile.ora';
shutdown immediate;
startup nomount;

打开时出现了

ORA-00845: MEMORY_TARGET not supported on this system

那就是 memory_target大于了/dev/shm,重新调整数据库参数MEMORY_TARGET的大小,要下于/dev/shm的大小
查看/dev/shm的大小
df -h | grep shm

使用创建dataguard数据库(主库备库都可以)

rman target sys/123456@orcl auxiliary sys/123456@orcldg
duplicate target database for standby from active database;

如果在传输过程中,出现网络中断,或者备库异常down机等突发情况导致的duplicate中断,那么后面可以尝试下面恢复手段:

1、备库重启至nomount状态

2、再次执行duplicate命令,此时如果已经传输过去的数据文件不会再次传输,会跳过接着继续传输进行后面步骤,非常简单。但是如果再次尝试还是有网络限制,可能就需要手动处理的方式。

RMAN> duplicate target database for standby from active database;

Starting Duplicate Db at 10-MAY-24
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=256 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   passwordfile auxiliary format  '/opt/oracle/product/19c/dbhome_1/dbs/orapworcldg'   ;
}
executing Memory Script

Starting backup at 10-MAY-24
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
Finished backup at 10-MAY-24

contents of Memory Script:
{
   restore clone from service  'orcl' standby controlfile;
}
executing Memory Script

Starting restore at 10-MAY-24
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/oradata/ORCLDG/control01.ctl
output file name=/opt/oracle/oradata/ORCLDG/control02.ctl
Finished restore at 10-MAY-24

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
 "/opt/oracle/oradata/ORCLDG/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/opt/oracle/oradata/ORCLDG/system01.dbf";
   set newname for datafile  3 to
 "/opt/oracle/oradata/ORCLDG/sysaux01.dbf";
   set newname for datafile  4 to
 "/opt/oracle/oradata/ORCLDG/undotbs01.dbf";
   set newname for datafile  7 to
 "/opt/oracle/oradata/ORCLDG/users01.dbf";
   restore
   from  nonsparse   from service
 'orcl'   clone database
   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /opt/oracle/oradata/ORCLDG/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 10-MAY-24
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /opt/oracle/oradata/ORCLDG/system01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00601: fatal error in recovery manager
RMAN-03004: fatal error during execution of command
RMAN-10041: Could not re-create polling channel context following failure.
RMAN-10024: error setting up for rpc polling
RMAN-10005: error opening cursor
RMAN-10002: Oracle error: ORA-03114: not connected to ORACLE

直接关闭数据库

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

b、下一步

此时将备库重启至nomount状态(使用原先的pfile即可)

sqlplus "sys/123456@orcldgs as sysdba"
startup pfile='/opt/oracle/pfile.ora' nomount;
create spfile from pfile='/opt/oracle/pfile.ora';
shutdown immediate;
startup nomount;

c、再次执行duplicate命令
rman target sys/123456@orcl auxiliary sys/123456@orcldg
duplicate target database for standby from active database dorecover;

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

可以看到成功连上了system01.dbf

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

四、检查测试:

查看dataguard状态:

select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;


启动dataguard数据同步:

sqlplus "/as sysdba"
alter database recover managed standby database disconnect from session; 开启同步

关闭dataguard数据同步:

alter database recover managed standby database cancel;

以上步骤知识了解,不要执行,从下开始再执行。

启动adg模式的备库:

上述备库的数据库是nomount状态,再执行完rman后
alter dataabse open;
alter database recover managed standby database disconnect from session; 

主库测试:

alter system switch logfile;

主备库检查dataguard状态:

select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;


dataguard数据同步测试

主库:

create tablespace xgedu66 datafile '/opt/oracle/oradata/ITPUXDB/xgedu66.dbf' size 10m autoextend off;
create user xgedu66 identified by xgedu66 default tablespace xgedu66;
grant dba to xgedu66;

conn xgedu66/xgedu66;
create table xgedu66.itpux01(c1 varchar2(10),c2 number);
insert into itpux01 values('itpux01','1');
insert into itpux01 values('itpux02','2');
commit;
select * from xgedu66.itpux01;
alter system switch logfile;


备库检查:

select * from xgedu66.itpux01;

查看dataguard状态:

select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;

检查dataguard日志

tail -100f /opt/oracle/diag/rdbms/itpuxdb/itpuxdb/trace/alert_itpuxdb.log
tail -100f /opt/oracle/diag/rdbms/itpuxdg/itpuxdg/trace/alert_itpuxdg.log

file;


主备库检查dataguard状态:

select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;




dataguard数据同步测试

主库:

create tablespace xgedu66 datafile ‘/opt/oracle/oradata/ITPUXDB/xgedu66.dbf’ size 10m autoextend off;
create user xgedu66 identified by xgedu66 default tablespace xgedu66;
grant dba to xgedu66;

conn xgedu66/xgedu66;
create table xgedu66.itpux01(c1 varchar2(10),c2 number);
insert into itpux01 values(‘itpux01’,‘1’);
insert into itpux01 values(‘itpux02’,‘2’);
commit;
select * from xgedu66.itpux01;
alter system switch logfile;


备库检查:

select * from xgedu66.itpux01;


查看dataguard状态:

select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;


检查dataguard日志

tail -100f /opt/oracle/diag/rdbms/itpuxdb/itpuxdb/trace/alert_itpuxdb.log
tail -100f /opt/oracle/diag/rdbms/itpuxdg/itpuxdg/trace/alert_itpuxdg.log








;