Oracle ADG环境搭建

别等时光非礼了梦想. 提交于 2019-12-03 10:49:18

部署

环境介绍

 

 

1,软件安装前基础部署

(两台做同样操作)

1.1,关闭selinux和防火墙

 

因为centos7里面没有/etc/sysconfig/iptables这个配置文件所以我们首先用yum安装建立一个

[root@adg ~]# yum install -y iptables && \

yum -y install iptables-services

然后在iptables里加上一条防火墙规则,到后面的tnsping会用的到,不加的话可能会tnsping不通

在最后加上-A INPUT -m state --state NEW -m tcp -p tcp --dport 1521-j ACCEPT

 [root@adg ~]# cat /etc/sysconfig/iptables ​ *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibiteda -A INPUT -m state --state NEW -m tcp -p tcp --dport 1521-j ACCEPT COMMIT

关闭selinux和防火墙

 [root@adg ~]# setenforce 0 && \ ​ sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config && \ iptables -F && \ systemctl stop iptables.services && \ chkconfig iptables off setenforce: SELinux is disabled

1.2,修改时区,否则可能会主备不同步

查看当前时区

 [root@adg ~]# date Wed Oct 30 22:17:35 EDT 2019

执行tzselect命令按提示更换时区,依次选择5-Asia,9-China,1-Beijing Time.

 [root@adg ~]# tzselect  Please identify a location so that time zone rules can be set correctly. Please select a continent or ocean.  1) Africa  2) Americas  3) Antarctica  4) Arctic Ocean  5) Asia  6) Atlantic Ocean  7) Australia  8) Europe  9) Indian Ocean 10) Pacific Ocean 11) none - I want to specify the time zone using the Posix TZ format. #? 5 Please select a country.  1) Afghanistan       18) Israel            35) Palestine  2) Armenia       19) Japan         36) Philippines  3) Azerbaijan        20) Jordan            37) Qatar  4) Bahrain       21) Kazakhstan        38) Russia  5) Bangladesh        22) Korea (North)     39) Saudi Arabia  6) Bhutan        23) Korea (South)     40) Singapore  7) Brunei        24) Kuwait            41) Sri Lanka  8) Cambodia          25) Kyrgyzstan        42) Syria  9) China         26) Laos          43) Taiwan 10) Cyprus        27) Lebanon           44) Tajikistan 11) East Timor        28) Macau         45) Thailand 12) Georgia       29) Malaysia          46) Turkmenistan 13) Hong Kong         30) Mongolia          47) United Arab Emirates 14) India         31) Myanmar (Burma)       48) Uzbekistan 15) Indonesia         32) Nepal         49) Vietnam 16) Iran          33) Oman          50) Yemen 17) Iraq          34) Pakistan #? 9 Please select one of the following time zone regions. 1) Beijing Time 2) Xinjiang Time #? 1 ​ The following information has been given: ​     China     Beijing Time ​ Therefore TZ='Asia/Shanghai' will be used. Local time is now:  Thu Oct 31 10:19:14 CST 2019. Universal Time is now:  Thu Oct 31 02:19:14 UTC 2019. Is the above information OK? 1) Yes 2) No #? 1 ​ You can make this change permanent for yourself by appending the line     TZ='Asia/Shanghai'; export TZ to the file '.profile' in your home directory; then log out and log in again. ​ Here is that TZ value again, this time on standard output so that you can use the /bin/tzselect command in shell scripts: Asia/Shanghai

配置全局环境变量,添加export TZ=‘Asia/Shanghai’

 [root@adg ~]# vim /etc/profile export TZ='Asia/Shanghai' [root@adg ~]# source /etc/profile [root@adg ~]# date Thu Oct 31 10:22:03 CST 2019

 

1.3,配置yum源

设置163和epel的yum源

 [root@adg ~]# setenforce 0 > /dev/null 2>&1 [root@adg ~]# cp /etc/sysconfig/iptables /etc/sysconfig/iptables`date +%F_%T` [root@adg ~]# cp /etc/yum.conf /etc/yum.confbak`date +%F_%T` [root@adg ~]# echo 'exclude=kernel* exclude=centos-release*' >> /etc/yum.conf && grep exclude /etc/yum.conf  && mkdir -p /tmp/repobak && rm -rf /tmp/repobak/* && cd /etc/yum.repos.d/ && mv -f * /tmp/repobak/ > /dev/null 2>&1 [root@adg ~]# curl -o /etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo [root@adg ~]# mv -f /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup > /dev/null 2>&1 [root@adg ~]# mv -f /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup > /dev/null 2>&1 [root@adg ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo [root@adg ~]# rpm --import /etc/pki/rpm-gpg/RPM* &&  yum clean all &&  yum makecache &&  yum groupinfo 'Development tools' &&  yum groupinstall -y 'Development tools' &&  yum install wget vim man rsync openssh-clients openssl -y && ls -l && cd ~

1.4,安装依赖包

 [root@adg ~]# yum install binutils  compat-libstdc* elfutils-libelf elfutils-libelf-devel  gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel  libgcc  libstdc++ libstdc++-devel  libgomp make numactl numactl-devel sysstat -y [root@adg ~]# yum install unixODBC unixODBC-devel -y pdksh需要使用rpm安装,把包放到/tmp目录下 [root@adg ~]# yum -y install lrzsz [root@adg ~]# rpm -ivh pdksh-5.2.14-1.i386.rpm --nodeps

1.5,配置主机名(HOST解析)

主:

 [root@adg ~]# cat /etc/hosts 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.25.44 adg 192.168.25.45 dg

备:

 [root@dg ~]# cat /etc/hosts 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.25.45 dg 192.168.25.44 adg

1.6,配置内核参数

 [root@adg ~]# cp /etc/sysctl.conf /etc/sysctl.conf.bak [root@adg ~]# echo 'net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 8589934591 kernel.shmall = 2097152 fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576' > /etc/sysctl.conf 执行/sbin/sysctl -p使之生效 [root@adg ~]# /sbin/sysctl -p ​ ---如果有下列报错 sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-arptables: No such file or directory ---执行下面命令(没有报错请忽略(下面解决方法适用于centos7版本,centos6我试过不行,解决不了)) [root@adg ~]# modprobe br_netfilter [root@adg ~]# ls /proc/sys/net/bridge/ bridge-nf-call-arptables  bridge-nf-call-iptables        bridge-nf-filter-vlan-tagged bridge-nf-call-ip6tables  bridge-nf-filter-pppoe-tagged  bridge-nf-pass-vlan-input-dev [root@adg ~]# /sbin/sysctl -p net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 8589934591 kernel.shmall = 2097152 fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576 [root@adg ~]# egrep -v '^#|^$' /etc/sysctl.conf | wc -l 22

参数说明

 kernel.shmmax: 64位linux系统:可取的最大值为物理内存值-1byte,建议值为多于物理内存的一半,一般取值大于SGA_MAX_SIZE即可,可以取物理内存-1byte。例如,如果为12GB物理内存,可取128*1024*1024*1024-1=12884901887,SGA肯定会包含在单个共享内存段中。128GB对应的是137438953471。 kernel.shmall: 该参数控制可以使用的共享内存的总页数。Linux共享内存页大小为4KB,共享内存段的大小都是共享内存页大小的整数倍。一个共享内存段的最大大小是16G,那么需要共享内存页数是16GB/4KB=16777216KB /4KB=4194304(页)。 即16GB对应4194304,8GB对应2097152,128GB对应33554432 net.ipv4.ip_forward = 0 #不变  net.ipv4.conf.default.rp_filter = 1 #不变 net.ipv4.conf.default.accept_source_route = 0   #不变 kernel.sysrq = 0    #不变 kernel.core_uses_pid = 1    #不变 net.ipv4.tcp_syncookies = 1 #不变 net.bridge.bridge-nf-call-ip6tables = 0  #不变 net.bridge.bridge-nf-call-iptables = 0   #不变 net.bridge.bridge-nf-call-arptables = 0  #不变 kernel.msgmnb = 65536   #不变 kernel.msgmax = 65536   #不变 kernel.shmmax = 4294967295  #变 note:4*1024*1024*1024-1=4294967295 共享内存段的最大尺寸,需要小于SGA MAX SIZE,大小为shmall*页大小(4K); kernel.shmall = 2097152     #变note:4*1024*1024/4K*2=2097152,两倍, 1倍实际不够,控制共享内存页数 fs.aio-max-nr = 1048576 #新增 异步I/O请求数目 fs.file-max = 6815744   #新增 一个进程可以打开的文件句柄的最大数量 kernel.shmmni = 4096    #新增 共享内存段的最大数量,ipcs -sa kernel.sem = 250 32000 100 128  #新增 设置的信号量 net.ipv4.ip_local_port_range = 9000 65500   #新增 专用服务器模式下与用户进程通信时分配给用户的端口区间 net.core.rmem_default = 262144  #新增 默认接收缓冲区大小 net.core.rmem_max = 4194304 #新增 接收缓冲区最大值 net.core.wmem_default = 262144  #新增 默认发送缓冲区大小 net.core.wmem_max = 1048586 #新增 默认发送缓冲区大小

1.7,配置资源限制

soft是指当前系统设置生效的值,而hard表明系统中所能设定的最大值,nofile是指文件句柄数,nproc是指进程数,

 [root@adg ~]# cp /etc/security/limits.conf /etc/security/limits.conf.bak [root@adg ~]# sed -i.bak 's/1024/102400/' /etc/security/limits.d/20-nproc.conf  [root@adg ~]# ulimit -u 102400 [root@adg ~]# echo 'session    required     pam_limits.so' >> /etc/pam.d/login [root@adg ~]# echo ' oracle  soft    nproc   16000 oracle  hard    nproc   16384 oracle  soft    nofile  60000 oracle  hard    nofile  65536 oracle  soft    stack   20480 oracle  hard    stack   20480 *   soft    memlock unlimited *   hard    memlock unlimited' >> /etc/security/limits.conf

参数说明

 ​ oracle              soft    nproc   16000   #oracle要求最小为2047 oracle              hard    nproc   16384       #--进程的最大数目,对oracle用户生效 oracle              soft    nofile  60000       #oracle要求最小为1024 oracle              hard    nofile  65536       #--打开文件的最大数目,对oracle用户生效 oracle              soft    stack   10240 oracle              hard    stack   10240 * soft  memlock     unlimited * hard  memlock     unlimited               #--最大锁定内存地址空间,对所有用户生效

1.8,创建用户和组,并创建密码

 [root@adg ~]# groupadd oinstall [root@adg ~]# groupadd dba [root@adg ~]# useradd -g oinstall -G dba oracle [root@adg ~]# id oracle uid=1000(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba) [root@adg ~]# echo "oracle" | passwd --stdin oracle Changing password for user oracle. passwd: all authentication tokens updated successfully.

1.9,创建安装oracle软件所需要的安装目录

 [root@adg ~]# mkdir -p /data/app/oracle  [root@adg ~]# mkdir -p /data/app/oraInventory [root@adg ~]# chown -R oracle:oinstall /data/  [root@adg ~]# chmod -R 775 /data/

1.10,配置root和oracle的环境变量

root用户:

 [root@adg ~]# cat >> /root/.bash_profile  << EOF export ORACLE_BASE=/data/app/oracle export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0.4/db_1 export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:$GGS_HOME export TNS_ADMIN=\$ORACLE_HOME/network/admin/ EOF [root@adg ~]# cat /root/.bash_profile  .bash_profile Get the aliases and functions if [ -f ~/.bashrc ]; then     . ~/.bashrc fi User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH export ORACLE_BASE=/data/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/db_1 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib: export TNS_ADMIN=$ORACLE_HOME/network/admin/ [root@adg ~]# source /root/.bash_profile && echo $ORACLE_HOME  /data/app/oracle/product/11.2.0.4/db_1

Oracle用户:

 [oracle@adg ~]$ cat >> /home/oracle/.bash_profile << EOF export ORACLE_BASE=/data/app/oracle export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0.4/db_1 export ORACLE_SID=orcl export ORALCE_OWNER=oracle PATH=\$PATH:\$HOME/bin:\$ORACLE_HOME/bin:\$ORACLE_HOME/OPatch:\$ORACLE_HOME/jdk/bin:/usr/bin:/usr/sbin:/sbin:/bin:/usr/local/bin:/usr/local/sbin export PATH export LANG="en_US.UTF-8" export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:$GGS_HOME alias sqlplus='rlwrap sqlplus' alias rman='rlwrap rman' alias scp='scp -o StrictHostKeyChecking=no' alias ssh='ssh -o StrictHostKeyChecking=no' EOF [oracle@adg ~]$ source /home/oracle/.bash_profile && echo $ORACLE_HOME && echo $ORACLE_BASE && env | grep ORA /data/app/oracle/product/11.2.0.4/db_1 /data/app/oracle ORALCE_OWNER=oracle ORACLE_SID=orcl ORACLE_BASE=/data/app/oracle ORACLE_HOME=/data/app/oracle/product/11.2.0.4/db_1

1.11,上传oracle安装包和rlwrap软件包并解压

oracle用户上传,上传至/tmp目录

 [root@adg ~]# su - oracle Last login: Tue Oct 29 22:58:03 EDT 2019 on pts/0 [oracle@adg ~]$ cd /tmp/ [oracle@adg tmp]$ ls p13390677_112040_Linux-x86-64_1of7.zip p13390677_112040_Linux-x86-64_2of7.zip pdksh-5.2.14-1.i386.rpm rlwrap-0.42.tar.gz [oracle@adg database]$ unzip p13390677_112040_Linux-x86-64_1of7.zip && \ unzip p13390677_112040_Linux-x86-64_2of7.zip && \ chown -R oracle:oinstall /tmp/database/ && \ chmod -R 775 /tmp/database/ && \ cd /tmp/database && \ ll 。。。。。。。。。。。。。。。。。。。。。。。 。。。。。。。。。。。。。。。。。。。。。。。。 total 44 drwxrwxr-x  4 oracle oinstall   248 Aug 27  2013 install -rwxrwxr-x  1 oracle oinstall 30016 Aug 27  2013 readme.html drwxrwxr-x  2 oracle oinstall    61 Aug 27  2013 response drwxrwxr-x  2 oracle oinstall    34 Aug 27  2013 rpm -rwxrwxr-x  1 oracle oinstall  3267 Aug 27  2013 runInstaller drwxrwxr-x  2 oracle oinstall    29 Aug 27  2013 sshsetup drwxrwxr-x 14 oracle oinstall  4096 Aug 27  2013 stage -rwxrwxr-x  1 oracle oinstall   500 Aug 27  2013 welcome.html

root用户安装rlwrap

 [root@adg ~]# cd /tmp/ [root@adg tmp]# yum -y install readline* && \ tar -zxvf rlwrap-0.42.tar.gz && \ cd rlwrap-0.42 && \ ./configure && \ make && make install

2,使用静默方式安装oracle

安装包解压后在/database/response目录下有三个rsp文件,用来作为静默安装时的应答文件

三个文件的作用分别是:

db_install.rsp:安装应答

dbca.rsp:创建数据库应答

netca.rsp:建立监听、本地服务名等网络设置的应答

2.1,配置db_install.rsp

注意这里主备不同的是要修改自己得主机名:ORACLE_HOSTNAME=XXX

主备的SID都是orcl

 [root@adg ~]# su - oracle Last login: Wed Oct 30 02:41:56 EDT 2019 on pts/0 [oracle@adg ~]$ cd /tmp/database/response/ [oracle@adg response]$ cp db_install.rsp db_install.rsp.bak cat > /tmp/database/response/db_install.rsp << EOF oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 oracle.install.option=INSTALL_DB_SWONLY ORACLE_HOSTNAME=adg UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/data/app/oraInventory SELECTED_LANGUAGES=en,zh_CN,th,zh_TW ORACLE_HOME=/data/app/oracle/product/11.2.0.4/db_1 ORACLE_BASE=/data/app/oracle oracle.install.db.InstallEdition=EE oracle.install.db.EEOptionsSelection=true oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0 oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=oinstall oracle.install.db.CLUSTER_NODES= oracle.install.db.isRACOneInstall= oracle.install.db.racOneServiceName= oracle.install.db.config.starterdb.type=GENERAL_PURPOSE oracle.install.db.config.starterdb.globalDBName=orcl oracle.install.db.config.starterdb.SID=orcl oracle.install.db.config.starterdb.characterSet=AL32UTF8 oracle.install.db.config.starterdb.memoryOption=true oracle.install.db.config.starterdb.memoryLimit= oracle.install.db.config.starterdb.installExampleSchemas=false oracle.install.db.config.starterdb.enableSecuritySettings=true oracle.install.db.config.starterdb.password.ALL=oracle oracle.install.db.config.starterdb.password.SYS=oracle oracle.install.db.config.starterdb.password.SYSTEM=oracle oracle.install.db.config.starterdb.password.SYSMAN=oracle oracle.install.db.config.starterdb.password.DBSNMP= oracle.install.db.config.starterdb.control=DB_CONTROL oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL= oracle.install.db.config.starterdb.automatedBackup.enable=false oracle.install.db.config.starterdb.automatedBackup.osuid= oracle.install.db.config.starterdb.automatedBackup.ospwd= oracle.install.db.config.starterdb.storageType= oracle.install.db.config.starterdb.fileSystemStorage.dataLocation= oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation= oracle.install.db.config.asm.diskGroup= oracle.install.db.config.asm.ASMSNMPPassword= MYORACLESUPPORT_USERNAME= MYORACLESUPPORT_PASSWORD= SECURITY_UPDATES_VIA_MYORACLESUPPORT= DECLINE_SECURITY_UPDATES=true PROXY_HOST= PROXY_PORT= PROXY_USER= PROXY_PWD= PROXY_REALM= COLLECTOR_SUPPORTHUB_URL= oracle.installer.autoupdates.option=SKIP_UPDATES oracle.installer.autoupdates.downloadUpdatesLoc= AUTOUPDATES_MYORACLESUPPORT_USERNAME= AUTOUPDATES_MYORACLESUPPORT_PASSWORD= EOF

配置说明:

 oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0//标注响应文件版本 oracle.install.option=INSTALL_DB_SWONLY//.只装数据库软件 ORACLE_HOSTNAME=主机名 UNIX_GROUP_NAME=oinstall//指定oracle inventory目录的所有者 INVENTORY_LOCATION=/u01/app/oraInventory指定产品清单oracle inventory目录的路径 SELECTED_LANGUAGES=en,zh_CN//指定语言 ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_home1//设置ORALCE_HOME的路径 ORACLE_BASE=/u01/app/oracle//指定ORALCE_BASE的路径 oracle.install.db.InstallEdition=EE//安装数据库软件的版本,企业版 oracle.install.db.EEOptionsSelection=true//手动指定企业安装组件 选true对安装大小影响不大所以选true oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0//如果上面选true,这些就是手动指定的组件 oracle.install.db.DBA_GROUP=dba//指定拥有DBA用户组,通常会是dba组 oracle.install.db.OPER_GROUP=oper//指定oper用户组 oracle.install.db.CLUSTER_NODES=//指定所有的节点 oracle.install.db.isRACOneInstall=false//是否是RACO方式安装 oracle.install.db.racOneServiceName= oracle.install.db.config.starterdb.type=//选择数据库的用途,一般用途/事物处理,数据仓库 oracle.install.db.config.starterdb.globalDBName=指定GlobalName oracle.install.db.config.starterdb.SID=//你指定的SID oracle.install.db.config.starterdb.characterSet=AL32UTF8//设置数据库编码 oracle.install.db.config.starterdb.memoryOption=true//11g的新特性自动内存管理,也就是SGA_TARGET和PAG_AGGREGATE_TARGET都,不用设置了,Oracle会自动调配两部分大小,这个要选true oracle.install.db.config.starterdb.memoryLimit=上面是true的情况下,指定Oracle自动管理内存的大小,这里不用填或者填写物理内存的40%左右等等自定义; oracle.install.db.config.starterdb.installExampleSchemas=false是否载入模板示例 oracle.install.db.config.starterdb.enableSecuritySettings=true  是否启用安全设置 oracle.install.db.config.starterdb.password.ALL=123456所有用户名的密码 oracle.install.db.config.starterdb.password.SYS= oracle.install.db.config.starterdb.password.SYSTEM= oracle.install.db.config.starterdb.password.SYSMAN= oracle.install.db.config.starterdb.password.DBSNMP= oracle.install.db.config.starterdb.control=DB_CONTROL数据库本地管理工具DB_CONTROL,远程集中管理工具GRID_CONTROL oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=GRID_CONTROL需要设定grid control的远程路径URL oracle.install.db.config.starterdb.automatedBackup.enable=false设置自动备份 oracle.install.db.config.starterdb.automatedBackup.osuid=.自动备份会启动一个job,指定启动JOB的系统用户ID oracle.install.db.config.starterdb.automatedBackup.ospwd=自动备份会开启一个job,需要指定OSUser的密码 oracle.install.db.config.starterdb.storageType=要求指定使用的文件系统存放数据库文件还是ASM oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=使用文件系统存放数据库文件才需要指定数据文件、控制文件、Redo log的存放目录 oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=使用文件系统存放数据库文件才需要指定备份恢复目录 oracle.install.db.config.asm.diskGroup=使用ASM存放数据库文件才需要指定存放的磁盘组 oracle.install.db.config.asm.ASMSNMPPassword=使用ASM存放数据库文件才需要指定ASM实例密码 MYORACLESUPPORT_USERNAME=指定metalink账户用户名 MYORACLESUPPORT_PASSWORD=指定metalink账户密码 SECURITY_UPDATES_VIA_MYORACLESUPPORT=用户是否可以设置metalink密码 DECLINE_SECURITY_UPDATES=true是否设置安全更新, PROXY_HOST=代理服务器名 PROXY_PORT=代理服务器端口 PROXY_USER=代理服务器用户名 PROXY_PWD=代理服务器密码 PROXY_REALM= COLLECTOR_SUPPORTHUB_URL= oracle.installer.autoupdates.option=SKIP_UPDATES 自动更新 oracle.installer.autoupdates.downloadUpdatesLoc=自动更新下载目录 AUTOUPDATES_MYORACLESUPPORT_USERNAME=自动更新的用户名 AUTOUPDATES_MYORACLESUPPORT_PASSWORD=自动更新的密码

2.2,执行db_install.rsp

oracle用户开始执行安装

 [oracle@adg response]$ ls dbca.rsp  db_install.rsp  db_install.rsp.bak  netca.rsp [oracle@adg response]$ unset LANG LANGUAGE;unset DISPLAY; [oracle@adg response]$ /tmp/database/runInstaller -silent -force -ignoreSysPrereqs -ignorePrereq -showprogress -responseFile /tmp/database/response/db_install.rsp 。。。。。。。。。。。。。。。。。。。。。。 Prepare in progress. ..................................................   9% Done. ​ Prepare successful. ​ 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 ​ 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 ​ Execute Root Scripts in progress. ​ As a root user, execute the following script(s):     1. /data/app/oraInventory/orainstRoot.sh     2. /data/app/oracle/product/11.2.0.4/db_1/root.sh ​ ..................................................   100% Done. ​ Execute Root Scripts successful. Successfully Setup Software.

漫长的等待,在等待的过程中最好不要中断xshell,也不要打开新的窗口

2.3,执行脚本

root用户执行下面两个脚本

 [oracle@adg response]$ su - root Password:  Last login: Wed Oct 30 02:59:26 EDT 2019 on pts/0 ​ [root@adg ~]# sh /data/app/oraInventory/orainstRoot.sh  Changing permissions of /data/app/oraInventory. Adding read,write permissions for group. Removing read,write,execute permissions for world. Changing groupname of /data/app/oraInventory to oinstall. The execution of the script is complete. ​ [root@adg ~]# sh /data/app/oracle/product/11.2.0.4/db_1/root.sh  Check /data/app/oracle/product/11.2.0.4/db_1/install/root_adg_2019-10-30_04-36-14.log for the output of root script

3,配置静态监听

HSOT要根据实际的主机名进行修改

3.1,配置监听文件

主:

 [root@adg ~]# su - oracle Last login: Wed Oct 30 04:04:07 EDT 2019 on pts/0 [oracle@adg ~]$ cd $ORACLE_HOME/network/admin  [oracle@adg admin]$ ll total 4 drwxr-xr-x 2 oracle oinstall  64 Oct 30 04:24 samples -rw-r--r-- 1 oracle oinstall 381 Dec 17  2012 shrept.lst [oracle@adg admin]$ echo ' SID_LIST_LISTENER = (SID_LIST =  (SID_DESC =    (GLOBAL_DBNAME = orcl)    (ORACLE_HOME = /data/app/oracle/product/11.2.0.4/db_1)    (SID_NAME = orcl)  ) ) ​ LISTENER = (DESCRIPTION_LIST =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))  )  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))  ) ) ADR_BASE_LISTENER = /data/app/oracle' > listener.ora

备:

 [root@adg ~]# su - oracle Last login: Wed Oct 30 04:04:07 EDT 2019 on pts/0 [oracle@adg ~]$ cd $ORACLE_HOME/network/admin  [oracle@dg admin]$ echo ' SID_LIST_LISTENER = (SID_LIST =  (SID_DESC =    (GLOBAL_DBNAME = orcl)    (ORACLE_HOME = /data/app/oracle/product/11.2.0.4/db_1)    (SID_NAME = orcl)  ) ) LISTENER = (DESCRIPTION_LIST =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))  )  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))  ) ) ADR_BASE_LISTENER = /data/app/oracle' > listener.ora

3.2,配置网络服务名文件

主备配置一样,只需要修改一下主机名就行

主:

 [oracle@adg admin]$ echo ' ORCL = (DESCRIPTION =  (ADDRESS_LIST =    (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))  )  (CONNECT_DATA =    (SERVICE_NAME = orcl)    (SERVER = DEDICATED)  ) ) ' > tnsnames.ora

备:

 [oracle@dg admin]$ echo ' ORCL = (DESCRIPTION =  (ADDRESS_LIST =    (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))  )  (CONNECT_DATA =    (SERVICE_NAME = orcl)    (SERVER = DEDICATED)  ) ) ' > tnsnames.ora

启动监听程序

 [oracle@adg admin]$ lsnrctl start && lsnrctl reload && tnsping orcl && lsnrctl status ​ Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl) (SERVER = DEDICATED))) OK (0 msec) ​ LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 30-OCT-2019 21:49:37 ​ Copyright (c) 1991, 2013, Oracle.  All rights reserved. ​ Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) ​ STATUS of the LISTENER ​ Alias                     LISTENER Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date                30-OCT-2019 21:49:36 Uptime                    0 days 0 hr. 0 min. 1 sec Trace Level               off Security                  ON: Local OS Authentication SNMP                      OFF Listener Parameter File   /data/app/oracle/product/11.2.0.4/db_1/network/admin/listener.ora Listener Log File         /data/app/oracle/diag/tnslsnr/adg/listener/alert/log.xml Listening Endpoints Summary...   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=adg)(PORT=1521))) Services Summary... Service "orcl" has 1 instance(s).   Instance "orcl", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully

3.3,查看监听程序是否启动

 [oracle@adg admin]$ netstat -luntp | grep tnslsnr (Not all processes could be identified, non-owned process info  will not be shown, you would have to be root to see it all.) tcp6       0      0 :::1521                 :::*                    LISTEN      6594/tnslsnr     

4,静默安装数据库(创建实例)

这里只需主库创建库(实例),备库不要创建,备库开启监听就行

4.1,配置响应文件dbca.rsp

 [oracle@adg ~]$ mkdir -p /data/app/oracle/oradata  [oracle@adg ~]$ mkdir -p /data/app/oracle/flash_recovery_area [oracle@adg ~]$ cd /tmp/database/response/ [oracle@adg response]$ cp dbca.rsp dbca.rsp.bak [oracle@adg response]$ cat > /tmp/database/response/dbca.rsp << EOF [GENERAL] RESPONSEFILE_VERSION = "11.2.0" OPERATION_TYPE = "createDatabase" [CREATEDATABASE] GDBNAME = "orcl" SID = "orcl" TEMPLATENAME = "General_Purpose.dbc" SYSPASSWORD = "oracle" SYSTEMPASSWORD = "oracle" DATAFILEDESTINATION = /data/app/oracle/oradata RECOVERYAREADESTINATION=/data/app/oracle/flash_recovery_area CHARACTERSET = "AL32UTF8" [CONFIGUREDATABASE] SYSDBAUSERNAME = "sys" EOF

dbca.rsp文件参数说明:

 RESPONSEFILE_VERSION = "11.2.0"      #不能更改 OPERATION_TYPE = "createDatabase"    #不变 默认即可 GDBNAME = "orcl"        #数据库的名字,随便怎么改,不影响,自定义 比如"oracle11g.com" SID = "orcl"            #对应的实例名字instance_name,随便怎么改,不影响,自定义 比如"oracle11g.com" TEMPLATENAME = "General_Purpose.dbc" #不变 默认即可 建库用的模板文件  SYSPASSWORD = "oracle"   #SYS管理员密码 自定义 SYSTEMPASSWORD = "oracle"  #SYSTEM管理员密码 自定义 DATAFILEDESTINATION = /data/app/oracle/oradata   #数据文件存放目录 可自定义如/data目录但用户和组要是oracle:oinstall即mkdir /data ; chown -R oracle:oinstall /data ; chmod -R 775 /data; 当然此项默认是$ORACLE_BASE/oradata 此项本来是注释掉的,而$ORACLE_BASE/oradata就是/data/app/oracle/oradata,故此项可不用动,即保持注释掉即也可; RECOVERYAREADESTINATION=/data/app/oracle/flash_recovery_area #恢复数据存放目录 闪回区 可自定义 CHARACTERSET = "AL32UTF8"   #字符集,重要!!! 建库后一般不能更改,所以建库前要确定清楚,选AL32UTF8比较合适; NATIONALCHARACTERSET= "AL16UTF16" #最好还是保持默认的"AL16UTF16",这里我选的UTF8可能出现了后面的PLSQL中文乱码; #MEMORYPERCENTAGE = "40"       #服务器物理内存分配给oracle的内存比例,这里先不选 #TOTALMEMORY = "3500"    # //物理内存的60%左右,分配给oracle的总内存3500MB,可自行设定 或者注释不选因为oracle会自行管理; #-----------------------*** End of CREATEDATABASE section ***------------------------ SOURCEDB = "myhost:1521:orcl"     #End of CREATEDATABASE sectio后面的很多没有注释掉的选项不用管。

4.2,执行响应文件dbca.rsp

oracle用户执行,使用-responseFile参数后面必须跟绝对路径

 [oracle@adg response]$  dbca -silent -responseFile /tmp/database/response/dbca.rsp Copying database files 1% complete ​ 。。。。。。 ​ 。。。。。。 ​ 100% complete Look at the log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details. [oracle@adg response]$ 

4.3,查看oracle进程

 [oracle@adg ~]$ ps -ef | grep ora_| grep -v grep |wc -l 36 [oracle@adg ~]$ ps -ef | grep ora_| grep -v grep  oracle    6654     1  0 22:00 ?        00:00:00 ora_pmon_DBUA0030506 oracle    6656     1  0 22:00 ?        00:00:00 ora_psp0_DBUA0030506 oracle    6658     1  0 22:00 ?        00:00:02 ora_vktm_DBUA0030506 oracle    6662     1  0 22:00 ?        00:00:00 ora_gen0_DBUA0030506 oracle    6664     1  0 22:00 ?        00:00:00 ora_diag_DBUA0030506 oracle    6666     1  0 22:00 ?        00:00:00 ora_dbrm_DBUA0030506 oracle    6668     1  0 22:00 ?        00:00:00 ora_dia0_DBUA0030506 oracle    6670     1  0 22:00 ?        00:00:00 ora_mman_DBUA0030506 oracle    6672     1  0 22:00 ?        00:00:00 ora_dbw0_DBUA0030506 oracle    6674     1  0 22:00 ?        00:00:00 ora_lgwr_DBUA0030506 oracle    6676     1  0 22:00 ?        00:00:00 ora_ckpt_DBUA0030506 oracle    6678     1  0 22:00 ?        00:00:00 ora_smon_DBUA0030506 oracle    6680     1  0 22:00 ?        00:00:00 ora_reco_DBUA0030506 oracle    6682     1  0 22:00 ?        00:00:00 ora_mmon_DBUA0030506 oracle    6684     1  0 22:00 ?        00:00:00 ora_mmnl_DBUA0030506 oracle    7013     1  0 22:04 ?        00:00:00 ora_pmon_orcl oracle    7015     1  0 22:04 ?        00:00:00 ora_psp0_orcl oracle    7017     1  0 22:04 ?        00:00:01 ora_vktm_orcl oracle    7021     1  0 22:04 ?        00:00:00 ora_gen0_orcl oracle    7023     1  0 22:04 ?        00:00:00 ora_diag_orcl oracle    7025     1  0 22:04 ?        00:00:00 ora_dbrm_orcl oracle    7027     1  0 22:04 ?        00:00:00 ora_dia0_orcl oracle    7029     1  0 22:04 ?        00:00:00 ora_mman_orcl oracle    7031     1  0 22:04 ?        00:00:00 ora_dbw0_orcl oracle    7033     1  0 22:04 ?        00:00:00 ora_lgwr_orcl oracle    7035     1  0 22:04 ?        00:00:00 ora_ckpt_orcl oracle    7037     1  0 22:04 ?        00:00:00 ora_smon_orcl oracle    7039     1  0 22:04 ?        00:00:00 ora_reco_orcl oracle    7041     1  0 22:04 ?        00:00:00 ora_mmon_orcl oracle    7043     1  0 22:04 ?        00:00:00 ora_mmnl_orcl oracle    7045     1  0 22:04 ?        00:00:00 ora_d000_orcl oracle    7047     1  0 22:04 ?        00:00:00 ora_s000_orcl oracle    7055     1  0 22:04 ?        00:00:00 ora_qmnc_orcl oracle    7073     1  0 22:04 ?        00:00:00 ora_cjq0_orcl oracle    7075     1  0 22:05 ?        00:00:00 ora_q000_orcl oracle    7077     1  0 22:05 ?        00:00:00 ora_q001_orcl

把oracle配置文件最后一行改为yes,/etc/oratab

 [oracle@adg ~]$ cat /etc/oratab  .......................... orcl:/data/app/oracle/product/11.2.0.4/db_1:Y

5,开始搭建配置ADG

5.1,编辑修改网络服务名配置文件tnsnames.ora,

编辑修改网络服务名配置文件tnsnames.ora,要保证主库和备库的tnsnames.ora文件中的内容完全相同,可以修改后直接传给备库。

注意:配置文件中的oraclpri和orclsty一定要等于pfile文件中的dbuniquename,否则可能会无法同步

主:

 [oracle@adg ~]$ cp $ORACLE_HOME/network/admin/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora.bak`date +%F` [oracle@adg ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora  # tnsnames.ora Network Configuration File: /data/app/oracle/product/11.2.0.4/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. ​ ORCL =   (DESCRIPTION =     (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))     (CONNECT_DATA =       (SERVER = DEDICATED)       (SERVICE_NAME = orcl)     )   ) ​ orcl_pri =   (DESCRIPTION =     (ADDRESS_LIST =       (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))     )     (CONNECT_DATA =       (SERVICE_NAME = orcl)       (SERVER = DEDICATED)     ) ) ​ orcl_sty =   (DESCRIPTION =     (ADDRESS_LIST =       (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))     )     (CONNECT_DATA =       (SERVICE_NAME = orcl)         (SERVER = DEDICATED)     ) )

备:

 [oracle@dg ~]$ cp $ORACLE_HOME/network/admin/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora.bak`date +%F` [oracle@dg ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora  ORCL =   (DESCRIPTION =     (ADDRESS_LIST =       (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))     )     (CONNECT_DATA =       (SERVICE_NAME = orcl)       (SERVER = DEDICATED)     ) ) ​ orcl_pri =   (DESCRIPTION =     (ADDRESS_LIST =       (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))     )     (CONNECT_DATA =       (SERVICE_NAME = orcl)       (SERVER = DEDICATED)     ) ) ​ orcl_sty =   (DESCRIPTION =     (ADDRESS_LIST =       (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))     )     (CONNECT_DATA =       (SERVICE_NAME = orcl)         (SERVER = DEDICATED)     ) )

5.2,主备都要重启监听

 [oracle@adg ~]$ lsnrctl stop ; lsnrctl start ; lsnrctl reload [oracle@dg ~]$ lsnrctl stop ; lsnrctl start ; lsnrctl reload

5.3,配置完后,确保任意一端都可以tnsping通自己和对方

主:

 [oracle@adg ~]$ tnsping orcl_pri ​ TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2019 03:50:06 ​ Copyright (c) 1997, 2013, Oracle.  All rights reserved. ​ Used parameter files: ​ ​ Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl) (SERVER = DEDICATED))) OK (0 msec) [oracle@adg ~]$ tnsping orcl_sty ​ TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2019 03:50:09 ​ Copyright (c) 1997, 2013, Oracle.  All rights reserved. ​ Used parameter files: ​ ​ Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl) (SERVER = DEDICATED))) OK (0 msec) [oracle@adg ~]$ tnsping $HOSTNAME ​ TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2019 03:50:20 ​ Copyright (c) 1997, 2013, Oracle.  All rights reserved. ​ Used parameter files: ​ Used HOSTNAME adapter to resolve the alias Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.25.44)(PORT=1521))) OK (0 msec)

备:

 oracle@dg ~]$ tnsping orcl_pri ​ TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2019 03:50:52 ​ Copyright (c) 1997, 2013, Oracle.  All rights reserved. ​ Used parameter files: ​ ​ Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = adg)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl) (SERVER = DEDICATED))) OK (0 msec) [oracle@dg ~]$ tnsping orcl_sty ​ TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2019 03:50:54 ​ Copyright (c) 1997, 2013, Oracle.  All rights reserved. ​ Used parameter files: ​ ​ Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl) (SERVER = DEDICATED))) OK (0 msec) [oracle@dg ~]$ tnsping $HOSTNAME ​ TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2019 03:51:00 ​ Copyright (c) 1997, 2013, Oracle.  All rights reserved. ​ Used parameter files: ​ Used HOSTNAME adapter to resolve the alias Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.25.45)(PORT=1521))) OK (0 msec)

5.4,如果tnsping不通

如果tnsping不通,报如下错误

 TNS-12543: TNS:destination host unreachable

报错原因是1521的端口没有开放

解决方法:

(不确定是否都可以解决,但是我确实用这个解决了)

在/etc/sysconfig/iptables 这个配置文件里添加一条开放1521端口的策略

-A INPUT -m state --state NEW -m tcp -p tcp --dport 1521-j ACCEPT

在进目录的时候会发现,centos7里并没有这个文件目录,所以我们需要安装iptables,iptables-services

执行下面命令

 [root@adg ~]#  systemctl stop firewalld [root@adg ~]#  systemctl mask firewalld Created symlink from /etc/systemd/system/firewalld.service to /dev/null. [root@adg ~]#  yum install -y iptables && yum -y install iptables-services

然后再添加下面的策略

用root用户添加

 -A INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT 添加完成之后,重启防火墙 [root@adg ~]# cat /etc/sysconfig/iptables # sample configuration for iptables service # you can edit this manually or use system-config-firewall # please do not ask us to add additional ports/services to this default configuration *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibiteda -A INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT COMMIT [root@adg ~]# systemctl restart iptables 重启之后还是tnsping不通那就关闭一下防火墙 [root@adg ~]# systemctl stop iptables.service

6,主库配置

6.1,启用归档模式

6.1.1,启动主库startup
[oracle@adg ~]$ sqlplus / as sysdba
SQL> startup
SQL> set linesize 3000 pagesize 300;
---查看数据库状态
SQL> select NAME,OPEN_MODE,LOG_MODE,PROTECTION_MODE,ACTIVATION#,SWITCHOVER#,SWITCHOVER_STATUS,database_role from v$database;

NAME	  OPEN_MODE	       LOG_MODE     PROTECTION_MODE	 ACTIVATION# SWITCHOVER# SWITCHOVER_STATUS    DATABASE_ROLE
--------- -------------------- ------------ -------------------- ----------- ----------- -------------------- ----------------
ORCL	  READ WRITE	       NOARCHIVELOG MAXIMUM PERFORMANCE   1550559822  1550559822 NOT ALLOWED	      PRIMARY

SQL> select status from v$instance;

STATUS
------------
OPEN

6.1.2,开启强制日志
SQL> set pagesize 50
SQL> set linesize 300
---查看归档是否开启,是否为强制日志,LOG_MODE为NOARCHIVELOG说明没有开启归档,FOR为YES说明为FORCE强制
SQL> select name,log_mode,force_logging from v$database;

NAME	  LOG_MODE     FOR
--------- ------------ ---
ORCL	  NOARCHIVELOG NO
---开启日志,修改数据库为强制日志,这是必须的操作,主库的每一步操作都得记录到日志中去。
--安装时开启过了,如果没有开启强制日志,则:
SQL> alter database force logging;

Database altered.

SQL> select name,log_mode,force_logging from v$database;

NAME	  LOG_MODE     FOR
--------- ------------ ---
ORCL	  NOARCHIVELOG YES
---如果取消force logging 命令则:
SQL> alter database no force logging;
6.1.3,开启归档

存放主库的归档日志文件的目录会和其他数据文件等等一起拷贝到备库。

---查看归档日志路径
SQL> show parameter recover;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest		     string	 /data/app/oracle/fast_recovery
						 _area
db_recovery_file_dest_size	     big integer 4182M
db_unrecoverable_scn_tracking	     boolean	 TRUE
recovery_parallelism		     integer	 0
---如果没有归档路径或者想换个归档路径,则可以用下面的命令,路径自定义
SQL> !mkdir /data/app/oracle/fast_recovery_area;
SQL> alter system set db_recovery_file_dest='/data/app/oracle/fast_recovery_area' scope=both;
--查看归档是否开启,是否为强制日志,LOG_MODE为NOARCHIVELOG说明没有开启归档,FOR为YES说明为FORCE强制
SQL> select log_mode,force_logging from v$database;
LOG_MODE     FOR
------------ ---
NOARCHIVELOG YES
---设归档大小
SQL> alter system set db_recovery_file_dest_size=50G scope=both;

System altered.

---关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

---重启至mount状态,挂载数据库
SQL> startup mount;
ORACLE instance started.

Total System Global Area 2455228416 bytes
Fixed Size		    2255712 bytes
Variable Size		  620758176 bytes
Database Buffers	 1811939328 bytes
Redo Buffers		   20275200 bytes
Database mounted.
--启用归档--修改数据库为归档模式,因为dg是通过传送归档日志到备库然后应用来保证主备库一致的。
--在Oracle 11g,开启archive log模式时,默认归档目录为db_recovery_file_dest指定。
SQL> alter database archivelog;

Database altered.
---打开数据库
SQL> alter database open;

Database altered.

---再次查看归档配置是否生效
SQL> select name,log_mode,force_logging from v$database;

NAME	  LOG_MODE     FOR
--------- ------------ ---
ORCL	  ARCHIVELOG   YES

SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     3
Next log sequence to archive   5
Current log sequence	       5
---此处注意要切一次归档日志,然后用archive log list;看一下,新的目录会立即投入到当前环境
SQL> alter system switch logfile;

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     4
Next log sequence to archive   6
Current log sequence	       6

---此时验证新的归档日志有没有在目标目录生成
SQL> !ls /data/app/oracle/fast_recovery_area/ORCL/archivelog/2019_10_28/o1_mf_1_5_gvf8flgr_.arc
/data/app/oracle/fast_recovery_area/ORCL/archivelog/2019_10_28/o1_mf_1_5_gvf8flgr_.arc

6.2,创建standby redo log

主库添加 standby redo log:大小和 online redo 相同,比 online redo group 多一组的备份文件

---查看现有的备份文件
SQL> set lin 8000 pages 3000;
SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER							       IS_
---------- ------- ------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---
	 3	   ONLINE  /data/app/oracle/oradata/orcl/redo03.log			       NO
	 2	   ONLINE  /data/app/oracle/oradata/orcl/redo02.log			       NO
	 1	   ONLINE  /data/app/oracle/oradata/orcl/redo01.log			       NO
	 
---查看当前日志组状态
SQL> select group#,sequence#,members,bytes/1024/1024,status from v$log order by GROUP#;

    GROUP#  SEQUENCE#	 MEMBERS BYTES/1024/1024 STATUS
---------- ---------- ---------- --------------- ----------------
	 1	    4	       1	      50 INACTIVE
	 2	    5	       1	      50 INACTIVE
	 3	    6	       1	      50 CURRENT
--主库添加 standby redo log:大小和 online redo 相同,比 online redo group 多一组。注意GROUP X 要增加,redoX.log也要增加,我犯过一次错误是只改了GROUP 4,GROUP 5,GROUP 6,GROUP 7,即没有/data/app/oracle/oradata/orcl/redo04.log中的redo04.log,都是redo04.log,而应该是redo04.log,redo05.log,redo06.log,redo07.log,
SQL> alter database add standby logfile group 4 ('/data/app/oracle/oradata/orcl/redo04.log') size 50M;

Database altered.

SQL> alter database add standby logfile group 5 ('/data/app/oracle/oradata/orcl/redo05.log') size 50M;

Database altered.

SQL> alter database add standby logfile group 6 ('/data/app/oracle/oradata/orcl/redo06.log') size 50M;

Database altered.

SQL> alter database add standby logfile group 7 ('/data/app/oracle/oradata/orcl/redo07.log') size 50M;

Database altered.


再次查看:
SQL> select * from v$logfile order by group#;

    GROUP# STATUS  TYPE    MEMBER							       IS_
---------- ------- ------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---
	 1	   ONLINE  /data/app/oracle/oradata/orcl/redo01.log			       NO
	 2	   ONLINE  /data/app/oracle/oradata/orcl/redo02.log			       NO
	 3	   ONLINE  /data/app/oracle/oradata/orcl/redo03.log			       NO
	 4	   STANDBY /data/app/oracle/oradata/orcl/redo04.log			       NO
	 5	   STANDBY /data/app/oracle/oradata/orcl/redo05.log			       NO
	 6	   STANDBY /data/app/oracle/oradata/orcl/redo06.log			       NO
	 7	   STANDBY /data/app/oracle/oradata/orcl/redo07.log			       NO

7 rows selected.

SQL> select group#,sequence#,members,bytes/1024/1024,status from v$log;

    GROUP#  SEQUENCE#	 MEMBERS BYTES/1024/1024 STATUS
---------- ---------- ---------- --------------- ----------------
	 1	    4	       1	      50 INACTIVE
	 2	    5	       1	      50 INACTIVE
	 3	    6	       1	      50 CURRENT
--查看备机日志生成方式,此处MANUAL为手工方式,建议改为自动方式
SQL> show parameter standby;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
standby_archive_dest		     string	 ?/dbs/arch
standby_file_management 	     string	 MANUAL
SQL> alter system set standby_file_management=auto scope=both;

System altered.

SQL> show parameter standby;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
standby_archive_dest		     string	 ?/dbs/arch
standby_file_management 	     string	 AUTO

查看刚刚添加的数据文件是否在内
SQL> select * from v$logfile order by group#;

    GROUP# STATUS  TYPE    MEMBER							       IS_
---------- ------- ------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---
	 1	   ONLINE  /data/app/oracle/oradata/orcl/redo01.log			       NO
	 2	   ONLINE  /data/app/oracle/oradata/orcl/redo02.log			       NO
	 3	   ONLINE  /data/app/oracle/oradata/orcl/redo03.log			       NO
	 4	   STANDBY /data/app/oracle/oradata/orcl/redo04.log			       NO
	 5	   STANDBY /data/app/oracle/oradata/orcl/redo05.log			       NO
	 6	   STANDBY /data/app/oracle/oradata/orcl/redo06.log			       NO
	 7	   STANDBY /data/app/oracle/oradata/orcl/redo07.log			       NO

7 rows selected.
--查看standby 日志组的信息:
SQL> select group#,sequence#,status,bytes/1024/1024 from v$standby_log;

    GROUP#  SEQUENCE# STATUS	 BYTES/1024/1024
---------- ---------- ---------- ---------------
	 4	    0 UNASSIGNED	      50
	 5	    0 UNASSIGNED	      50
	 6	    0 UNASSIGNED	      50
	 7	    0 UNASSIGNED	      50

6.3,拷贝密码文件

在Primary上创建密码文件(此步骤只在主库上做) ,注意如果主库的sys用户的密码更改了则密码文件也就会跟着变了则此时需要重启拷贝密码文件到备库的$ORACLE_HOME/dbs/目录才行。

注:经实测此步不用做也可以,因为密码文件本来就是有的,就是$ORACLE_HOME/dbs/orapworcl文件,而我们在拷贝参数文件到备库时会把整个$ORACLE_HOME/dbs/*拷贝到备库。

注意:主备库分别创建自己的密码文件好像有问题,备库的密码文件需要跟主库保持一致,否则导致日志传输不到备库。我最后是将主库的密码文件直接copy到备库的$ORACLE_HOME/dbs/目录即可,有的说拷贝到备库后把这个密码文件进行重命名后使用而实际不用重命名也可以。

主备库的密码文件要相同
[oracle@adg dbs]$ mkdir -p /data/app/rman_backup
[oracle@adg dbs]$ pwd
/data/app/oracle/product/11.2.0.4/db_1/dbs
[oracle@adg dbs]$ cp orapworcl /data/app/rman_backup/


#正常都是有的,没有的话则创建一个密码文件即可,要保持主备密码文件名相同,否则同步可能出现错误
[oracle@adg ~]$ cd $ORACLE_HOME/dbs/
[oracle@adg ~]$ orapwd file=orapworcl password=oracle force=y

6.4,修改参数文件

6.4.1,生成pfile
SQL> sqlplus / as sysdba
SQL> select status from v$instance;

STATUS
------------
OPEN
----这里创建pfile是为了做一些主库参数的配置,并且还得拷贝到备库再次修改成备库的配置。
SQL>  select open_mode,database_role,db_unique_name from v$database;

OPEN_MODE	     DATABASE_ROLE    DB_UNIQUE_NAME
-------------------- ---------------- ------------------------------
READ WRITE	     PRIMARY	      orcl

在主库上通过 SQL> select  name from v$datafile; 查看对应的路径目录,用于*.db_file_name_convert
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/data/app/oracle/oradata/orcl/system01.dbf
/data/app/oracle/oradata/orcl/sysaux01.dbf
/data/app/oracle/oradata/orcl/undotbs01.dbf
/data/app/oracle/oradata/orcl/users01.dbf
---在主库上通过 SQL> select * from v$logfile; 查看对应的路径目录;用于*.log_file_name_convert
SQL> select * from v$logfile;
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

6.4.2 ,修改pfile

什么是pfile文件:初始化参数文件(Initialization Parameters Files),Oracle 9i之前,ORACLE一直采用PFILE方式存储初始化参数,该文件为文本文件。

什么是sfile文件:服务器参数文件(Server Parameter Files),从Oracle 9i开始,Oracle引入了SPFILE文件,该文件为二进制格式,不能通过手工修改。

区别:PFILE是文本文件的,而SPFILE是二进制格式的。PFILE文件可以用文本编辑器打开手工配置、而SPFILE不行,只能通过SQL命令在线修改。从操作系统上可以看到这两者的区别,初始化参数文件为ASCII文本文件,SPFILE为数据文件。

[oracle@adg dbs]$ cat initorcl.ora
orcl.__db_cache_size=6006243328
orcl.__java_pool_size=100663296
orcl.__large_pool_size=117440512
orcl.__oracle_base='/data/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=2466250752
orcl.__sga_target=7381975040
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=1107296256
orcl.__streams_pool_size=0
*.audit_file_dest='/data/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
#指定控制文件路径
*.control_files='/data/app/oracle/oradata/orcl/control01.ctl','/data/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_files=2000
*.db_name='orcl'
*.db_recovery_file_dest='/data/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=53687091200
*.diagnostic_dest='/data/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.open_cursors=300
*.pga_aggregate_target=2459959296
*.processes=1500
#启用本地密码,默认即可
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=1500
*.sga_target=7379877888
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
在最后添加如下内容
*.db_unique_name='orcl_pri'
#主节点
*.fal_server='orcl_sty'
#当前节点
*.fal_client='orcl_pri'
#dbf文件路径转换
*.db_file_name_convert='/data/app/oracle/oradata/orcl/','/data/app/oracle/oradata/orcl/' 
#日志文件路径转换
*.log_file_name_convert='/data/app/oracle/oradata/orcl/','/data/app/oracle/oradata/orcl/'
#归档配置
*.log_archive_config='dg_config=(orcl_pri,orcl_sty)'
#本地归档
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=orcl_pri'
#远程归档
*.log_archive_dest_2='service=orcl_sty LGWR ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=orcl_sty'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'

参数说明:

*.db_unique_name='orcl_pri'	--这里是主库的标识名称,如果是备库则要改为orcl_sty

*.fal_server='orcl_sty'	--这里是在主库上,要填写备份数据库的SID,自己是client,远端是server

*.fal_client='orcl_pri'	--这里是在主库上,要填写主数据库的SID,自己是client,远端是server

*.standby_file_management=auto

*.remote_login_passwordfile='EXCLUSIVE'	--# 启用本地密码,默认即可


*.db_file_name_convert='/data/app/oracle/oradata/orcl/','/data/app/oracle/oradata/orcl/' 
【注1】:db_file_name_convert 主数据库和备用数据库的数据文件转换目录对映(如果两数据库的目录结构不一样),如果有多个对映,逐一指明对映关系。一对一映射设定
*.db_file_name_convert='/opt/oracle/oraInventory/oradata/oracle','/opt/oracle/oraInventory/oradata/standby';多对多映射设定
*.db_file_name_convert='/opt/oracle/oraInventory/oradata/oracle','/home/ldai/testdb','/opt/oracle/oraInventory/oradata/standby','/home/ldai/testdb/standby'
【注2】:在主库上通过 SQL> select  name from v$datafile; 查看对应的路径目录;
【注3】:在主库pfile配置文件中,第一个路径是备库的路径,第二个路径是主库的路径,这点是比较特别的,和常规的情况是相反的;在备库pfile配置文件中,第一个路径是主库的路径,第二个路径是备库的路径,这点是比较特别的,和常规的情况是相反的;
【注4】:这个转换目录可以不相同,比如主库为/data/app/oracle/oradata/orcl_pri,备库为/data/app/oracle/oradata/orcl_sty。
【注5】:格式应保持一致,比如"*.db_file_name_convert='+DG1/db/datafile','+DATAGRP/db/datafile/' ”,路径少了一个"/”,将导致standby apply失败。

*.log_file_name_convert='/data/app/oracle/oradata/orcl/','/data/app/oracle/oradata/orcl/'
【注1】:在线联机redo onlinelog日志文件转换目录,特别注意是是在线联机重做onlinelog日志,不是archivelog日志;
【注2】:在主库上通过 SQL> select * from v$logfile; 查看对应的路径目录;
【注3】:在主库pfile配置文件中,第一个路径是备库的路径,第二个路径是主库的路径,这点是比较特别的,和常规的情况是相反的;在备库pfile配置文件中,第一个路径是主库的路径,第二个路径是备库的路径,这点是比较特别的,和常规的情况是相反的;
【注4】:这个转换目录可以不相同,比如主库为/data/app/oracle/oradata/orcl_pri,备库为/data/app/oracle/oradata/orcl_sty。
【注5】:格式应保持一致,比如"*.log_file_name_convert='+DG1/db/datafile','+DATAGRP/db/datafile/' ”,路径少了一个"/”,将导致standby apply失败。

*.log_archive_config='dg_config=(orcl_pri,orcl_sty)'	--主备库配置是一样的,pri主数据库SID,std备份数据库SID

*.log_archive_dest_1='location=/data/app/oracle/oradata/orcl valid_for=(all_logfiles,all_roles) db_unique_name=orcl_pri'	--主数据库的归档日志路径和SID,主库归档本地位置

*.log_archive_dest_2='service=orcl_sty LGWR ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=orcl_sty'	--备份数据库的SID,主库归档远程位置,如果是最大性能模式则写成LGWR ASYNC,如果是最大可用模式则写成LGWR SYNC AFFIRM;下面有详细说明。

*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'

具体说明之dbname和dbunique_name:
DG主库和备库的dbname必须一致,dbunique_name不一致。下面是查询的SQL语句,查询的结果主库为orcl,这里不用专门修改,通过上面的pfile文件进行定义就可以啦,
具体说明之falserver和falclient:
FAL_CLIENT和FAL_SERVER是配置dataguard用到的两个参数,FAL指获取归档日志(Fetch Archived Log)

在一定的条件下,或者因为网络失败,或者因为资源紧张,会在primary和standby之间产生裂隙,也就是有些归档日志没有及时的传输并应用到standby库。因为MRP(managed recovery process)/LSP(logical standby process)没有与primary直接通讯的能力来获取丢失的归档日志。因此这些gaps通过FAL客户和服务器来解决,由初始化参数定义FAL_CLIENT和FAL_SERVER。

FAL_SERVER指定一个Oracle Net service name,standby数据库使用这个参数连接到FAL server,这个参数适用于standby站点。比如,FAL_SERVER = PrimaryDB,此处PrimaryDB是一个TNS name,指向primary库。

FAL_CLIENT指定一个FAL客户端的名字,以便FAL Server可以引用standby库,这也是一个TNS name,primary库必须适当配置此TNS name指向stanby库。这个参数也是在standby库端设置。比如,FAL_CLIENT = StandbyDB,StandbyDB是standby库的TNS name。

FAL_CLIENT和FAL_SERVER应该成对设置或改变。

这两个参数只需在standby库设置,但也可以在primary库设置这两个参数,以方便switchover或failover时primary库转变为standby角色。

fal_client也是设置本身,
fal_server是对方

FAL_SERVER:用来指定出现GAP的时候重哪里取归档日志。 
FAL_CLENT:用来制动把GAP发送到哪里。

关于*.logarchivedest_2的LGWR SYNC(同步)或ASYNC(异步):
LGWR还分为LGWR ASYNC(异步)和LGWR SYNC(同步)两种。
 最大保护最大可用最大性能
进程 LGWR LGWR LGWR或ARCH
网络传输模式 SYNC SYNC LGWR时设置ASYNC
磁盘写操作 AFFIRM AFFIRM NOAFFIRM
备用日志 YES 物理备用需要 LGWR和物理备用时需要
备用库类型 物理Standby 物理或逻辑 物理或逻辑

最大保护(maximize protection):最高级别的保护模式。primay上的事务在commit前必须确认redo已经传递到至少一个standby上,如果所有standby不可用,则primary会挂起。该模式能保证零数据丢失。对于最大保护和最高可用性模式,Standby数据库必须配置standby redo log,并且oracle推荐所有数据库都使用LGWR ASYNC模式传输。

如果是最大性能模式则写成LGWR ASYNC,如果是最大可用模式则写成LGWR SYNC AFFIRM;

 

6.4.3,生成spfile

什么是pfile文件:初始化参数文件(Initialization Parameters Files),Oracle 9i之前,ORACLE一直采用PFILE方式存储初始化参数,该文件为文本文件。

什么是sfile文件:服务器参数文件(Server Parameter Files),从Oracle 9i开始,Oracle引入了SPFILE文件,该文件为二进制格式,不能通过手工修改。

区别:PFILE是文本文件的,而SPFILE是二进制格式的。PFILE文件可以用文本编辑器打开手工配置、而SPFILE不行,只能通过SQL命令在线修改。从操作系统上可以看到这两者的区别,初始化参数文件为ASCII文本文件,SPFILE为数据文件。

--用pfile启动主库,并创建spfile
SQL> startup nomount pfile='/data/app/oracle/product/11.2.0.4/db_1/dbs/initorcl.ora'
ORACLE instance started.

Total System Global Area 7349010432 bytes
Fixed Size		    2267464 bytes
Variable Size		 1728054968 bytes
Database Buffers	 5603590144 bytes
Redo Buffers		   15097856 bytes

SQL> create spfile from pfile;

File created.

SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 7349010432 bytes
Fixed Size		    2267464 bytes
Variable Size		 1728054968 bytes
Database Buffers	 5603590144 bytes
Redo Buffers		   15097856 bytes
Database mounted.
Database opened.
---查看当前数据库是否使用spfile启动,(如下,若有路径则证明数据库是使用spfile启动的,若没有值,则说明是用pfile启动的)
SQL> show parameter spfile;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
spfile				     string	 /data/app/oracle/product/11.2.
						 0.4/db_1/dbs/spfileorcl.ora

---两确认数据库已经启用归档模式和强制日志模式;
SQL> select name,log_mode,force_logging from v$database;

NAME	  LOG_MODE     FOR
--------- ------------ ---
ORCL	  ARCHIVELOG   YES

---复制一份到/data/app/rman_backup/目录用于后面拷贝到备库
SQL> create pfile='/data/app/rman_backup/initphydb1.ora' from spfile;

File created.

6.5,配置最大性能模式

SQL> startup
ORACLE instance started
---查看数据库的保护模式
SQL> select database_role,protection_mode,protection_level,open_mode from v$database;

DATABASE_ROLE	 PROTECTION_MODE      PROTECTION_LEVEL	   OPEN_MODE
---------------- -------------------- -------------------- --------------------
PRIMARY 	 MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  READ WRITE

---如果不是最大性能模式,则:(目前不需要修改)
SQL> alter database set standby database to MAXIMIZE PERFORMANCE; 
Database altered.

SQL> exit

说明如下:

DataGuard的三种数据保护模式:

(1)MAXIMIZE PROTECTION(最大保护模式): alter database set standby database to MAXIMIZE PROTECTION; 最大数据保护与无数据分歧,LGWR将同时传送到备用节点,在主节点事务确认之前,备用节点也必须完全收到日志数据。如果网络不好,引起LGWR不能传送数据,将引起严重的性能问题,导致主节点DOWN机。如果出现了什么故障导致 standby数据库不可用的话,primary 数据库会被shutdown。不适合在生产环境种应用。

(2)MAXIMIZE AVAILABILITY(最大可用模式): alter database set standby database to maximize availability; 无数据丢失模式,允许数据分歧,允许异步传送。正常情况下运行在最大保护模式,在主节点与备用节点的网络断开或连接不正常时,自动切换到最大性能模式,主节点的操作还是可以继续的。在网络不好的情况下有较大的性能影响。对数据库性能有影响,数据丢失相对最大性能模式要小。 不受备库影响。

(3)MAXIMIZE PERFORMANCE(最大性能模式): alter database set standby database to MAXIMIZE PERFORMANCE; 最大性能模式是默认的保护模式。这种模式应当可以说是从8i继承过来的备用服务器模式,异步传送,无数据同步检查,可能丢失数据,但是能获得主节点的最大性能。在主数据库出现故障的情况下,可能有一些在主数据库上提交了的事务没有传输到备用数据库中。Primary不受影响备库影响。

6.6,创建standby的控制文件

在Primary上创建Standby Database的控制文件(此步骤只在主库上做) ,生成控制文件的保存位置官方文档中是在/tmp目录,

注:经实测此步不用创建也可以,因为后面我们用rman恢复备库的时候也直接会把控制文件给恢复过去的。

[oracle@adg ~]$ sqlplus / as sysdba
SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> alter database create standby controlfile as '/data/app/rman_backup/standby.ctl';

Database altered.
SQL> ! ls -l /data/app/rman_backup/standby.ctl
-rw-r----- 1 oracle oinstall 9748480 Oct 28 21:49 /data/app/rman_backup/standby.ctl
SQL> ! du -sh /data/app/rman_backup/standby.ctl
9.3M	/data/app/rman_backup/standby.ctl

6.7,RMAN 备份数据库

6.7.1,使用rman对database和archive log进行备份

注意:备份的时候一定要注意空间的大小,rman备份的数据非常的大,

[oracle@adg ~]$ rman target /
RMAN> run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
backup database format '/data/app/rman_backup/FULL_%U.bak';
backup archivelog all format '/data/app/rman_backup/ARC_%U.bak';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
12> }
released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=1146 device type=DISK

allocated channel: c2
channel c2: SID=1718 device type=DISK

allocated channel: c3
channel c3: SID=579 device type=DISK

allocated channel: c4
channel c4: SID=1714 device type=DISK

Starting backup at 2019-10-28 22:27:10
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/data/app/oracle/oradata/orcl/system01.dbf
channel c1: starting piece 1 at 2019-10-28 22:27:10
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00002 name=/data/app/oracle/oradata/orcl/sysaux01.dbf
channel c2: starting piece 1 at 2019-10-28 22:27:10
channel c3: starting full datafile backup set
channel c3: specifying datafile(s) in backup set
input datafile file number=00003 name=/data/app/oracle/oradata/orcl/undotbs01.dbf
channel c3: starting piece 1 at 2019-10-28 22:27:10
channel c4: starting full datafile backup set
channel c4: specifying datafile(s) in backup set
channel c3: finished piece 1 at 2019-10-28 22:27:11
piece handle=/data/app/rman_backup/FULL_06uffu5u_1_1.bak tag=TAG20191028T222710 comment=NONE
channel c3: backup set complete, elapsed time: 00:00:01
channel c3: starting full datafile backup set
channel c3: specifying datafile(s) in backup set
input datafile file number=00004 name=/data/app/oracle/oradata/orcl/users01.dbf
channel c3: starting piece 1 at 2019-10-28 22:27:49
including current control file in backup set
channel c4: starting piece 1 at 2019-10-28 22:27:49
channel c2: finished piece 1 at 2019-10-28 22:27:49
piece handle=/data/app/rman_backup/FULL_05uffu5u_1_1.bak tag=TAG20191028T222710 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:39
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
including current SPFILE in backup set
channel c2: starting piece 1 at 2019-10-28 22:27:49
channel c1: finished piece 1 at 2019-10-28 22:27:50
piece handle=/data/app/rman_backup/FULL_04uffu5u_1_1.bak tag=TAG20191028T222710 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:40
channel c2: finished piece 1 at 2019-10-28 22:27:50
piece handle=/data/app/rman_backup/FULL_09uffu75_1_1.bak tag=TAG20191028T222710 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:01
channel c3: finished piece 1 at 2019-10-28 22:27:50
piece handle=/data/app/rman_backup/FULL_08uffu70_1_1.bak tag=TAG20191028T222710 comment=NONE
channel c3: backup set complete, elapsed time: 00:00:01
channel c4: finished piece 1 at 2019-10-28 22:27:50
piece handle=/data/app/rman_backup/FULL_07uffu5u_1_1.bak tag=TAG20191028T222710 comment=NONE
channel c4: backup set complete, elapsed time: 00:00:01
Finished backup at 2019-10-28 22:27:50

Starting backup at 2019-10-28 22:27:50
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=1 STAMP=1022818035
input archived log thread=1 sequence=6 RECID=2 STAMP=1022821489
channel c1: starting piece 1 at 2019-10-28 22:27:51
channel c2: starting archived log backup set
channel c2: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=3 STAMP=1022821495
input archived log thread=1 sequence=8 RECID=4 STAMP=1022850054
channel c2: starting piece 1 at 2019-10-28 22:27:51
channel c3: starting archived log backup set
channel c3: specifying archived log(s) in backup set
input archived log thread=1 sequence=9 RECID=5 STAMP=1022882412
channel c3: starting piece 1 at 2019-10-28 22:27:51
channel c4: starting archived log backup set
channel c4: specifying archived log(s) in backup set
input archived log thread=1 sequence=10 RECID=6 STAMP=1022882421
input archived log thread=1 sequence=11 RECID=7 STAMP=1022883971
channel c4: starting piece 1 at 2019-10-28 22:27:51
channel c1: finished piece 1 at 2019-10-28 22:27:51
piece handle=/data/app/rman_backup/ARC_0auffu77_1_1.bak tag=TAG20191028T222751 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:00
channel c1: starting archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12 RECID=8 STAMP=1022884071
channel c1: starting piece 1 at 2019-10-28 22:27:51
channel c2: finished piece 1 at 2019-10-28 22:27:51
piece handle=/data/app/rman_backup/ARC_0buffu77_1_1.bak tag=TAG20191028T222751 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:00
channel c1: finished piece 1 at 2019-10-28 22:27:52
piece handle=/data/app/rman_backup/ARC_0euffu77_1_1.bak tag=TAG20191028T222751 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c3: finished piece 1 at 2019-10-28 22:27:52
piece handle=/data/app/rman_backup/ARC_0cuffu77_1_1.bak tag=TAG20191028T222751 comment=NONE
channel c3: backup set complete, elapsed time: 00:00:01
channel c4: finished piece 1 at 2019-10-28 22:27:52
piece handle=/data/app/rman_backup/ARC_0duffu77_1_1.bak tag=TAG20191028T222751 comment=NONE
channel c4: backup set complete, elapsed time: 00:00:01
Finished backup at 2019-10-28 22:27:52

released channel: c1

released channel: c2

released channel: c3

released channel: c4
 #说明:
备份数据库全备份--》backup database format '/data/app/rman_backup/FULL_%U.bak'; 
备份所有归档文件--》backup archivelog all format '/data/app/rman_backup/ARC_%U.bak';
6.7.2,验证备份:
[oracle@adg ~]$ cd /data/app/rman_backup/ && du -sh
2.4G	.
[oracle@adg rman_backup]$ cd /data/app/rman_backup/
[oracle@adg rman_backup]$ du -sh *
127M	ARC_03uffu43_1_1.bak
22M	ARC_0auffu77_1_1.bak
32M	ARC_0buffu77_1_1.bak
41M	ARC_0cuffu77_1_1.bak
33M	ARC_0duffu77_1_1.bak
36K	ARC_0euffu77_1_1.bak
1.1G	FULL_01uffu2i_1_1.bak
9.4M	FULL_02uffu3v_1_1.bak
636M	FULL_04uffu5u_1_1.bak
387M	FULL_05uffu5u_1_1.bak
22M	FULL_06uffu5u_1_1.bak
9.4M	FULL_07uffu5u_1_1.bak
1.4M	FULL_08uffu70_1_1.bak
96K	FULL_09uffu75_1_1.bak
4.0K	initphydb1.ora
4.0K	orapworcl
9.3M	standby.ctl
6.7.3,打包压缩

由于rman备份的数据太大,我们用tar进行打包压缩

[oracle@adg rman_backup]$ tar -czvf rmanbak20191029.tgz ./ARC_*.bak ./FULL_*.bak
./ARC_03uffu43_1_1.bak
./ARC_0auffu77_1_1.bak
./ARC_0buffu77_1_1.bak
./ARC_0cuffu77_1_1.bak
./ARC_0duffu77_1_1.bak
./ARC_0euffu77_1_1.bak
./FULL_01uffu2i_1_1.bak
./FULL_02uffu3v_1_1.bak
./FULL_04uffu5u_1_1.bak
./FULL_05uffu5u_1_1.bak
./FULL_06uffu5u_1_1.bak
./FULL_07uffu5u_1_1.bak
./FULL_08uffu70_1_1.bak
./FULL_09uffu75_1_1.bak

6.8,拷贝所有备份文件到备库

拷贝控制文件,密码文件,参数文件,监听文件,rman备份文件等到备库上,

注意:主库rman的备份复制到备库时,复制到的目录一定要和主库rman备份的目录相同。

---在备库建立相应的目录
[oracle@dg ~]$ mkdir -p /data/app/rman_backup 

---在主库把备份文件拷到备库上
[oracle@adg rman_backup]$ scp -p 12525 -l 100000 initphydb1.ora orapworcl standby.ctl rmanbak20191029.tgz oracle@dg:/data/app/rman_backup/
Warning: Permanently added 'dg,192.168.25.45' (ECDSA) to the list of known hosts.
oracle@dg's password: 
100000: No such file or directory
initphydb1.ora                                           100% 1626   186.5KB/s   00:00    
orapworcl                                                100% 1536   134.3KB/s   00:00    
standby.ctl                                              100% 9520KB  16.1MB/s   00:00    
rmanbak20191029.tgz                                      100%  543MB  14.7MB/s   00:37 

---备库看一下
[oracle@dg rman_backup]$ pwd
/data/app/rman_backup
[oracle@dg rman_backup]$ ll
total 565224
-rw-r--r-- 1 oracle oinstall      1626 Oct 28 05:11 initphydb1.ora
-rw-r----- 1 oracle oinstall      1536 Oct 28 04:26 orapworcl
-rw-r--r-- 1 oracle oinstall 569031597 Oct 28 22:41 rmanbak20191029.tgz
-rw-r----- 1 oracle oinstall   9748480 Oct 28 21:49 standby.ctl

7,对备库进行配置

7.1,建立相应的文件目录

(因为备库没有创建实例,所以是没有相关的目录的,我们需要参考主库的位置来创建。包括dump文件目录,闪回区,数据文件目录,通过show parameter dest 命令查看且pfile参数文件里涉及到的目录都要在备库创建)

---备库创建相应的目录:
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/admin/orcl/adump
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/admin/orcl/dpdump
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/admin/orcl/cdump
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/diag/rdbms/orcl_pri/orcl/trace
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/admin/orcl_sty/adump
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/admin/orcl_sty/dpdump
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/admin/orcl_sty/cdump
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/diag/rdbms/orcl_sty/orcl_sty/trace
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/diag/rdbms/orcl_sty/orcl/trace

---在主库通过SQL> show parameter db_recovery_file_dest;查看,然后在备库中创建相同的目录
SQL> show parameter db_recovery_file_dest;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest		     string	 /data/app/oracle/fast_recovery
						 _area
db_recovery_file_dest_size	     big integer 50G
SQL> show parameter db_file_name_convert

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert		     string	 /data/app/oracle/oradata/orcl/
						 , /data/app/oracle/oradata/orc
						 l/
SQL> show parameter log_file_name_convert;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
log_file_name_convert		     string	 /data/app/oracle/oradata/orcl/
						 , /data/app/oracle/oradata/orc
						 l/

---备库:
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/fast_recovery_area/
[oracle@dg ~]$ mkdir -p $ORACLE_BASE/oradata/orcl

文件目录说明:

adump --> audit_file_dest

dpdump --> 是存放一些登录信息的

trace -->  background_dump_dest 警告日志:也就是alert log,在系统初始化参数文件设置的show  parameter background_dump_dest对应的就是它的位置。

cdump --> 记录核心dump的目录,如果oracle核心进程应为BUG等原因崩溃,会做内存的dump,dump文件保存在该目录下。

fast_recovery_area --> 闪回区

oradata/orcl --> log_archive_dest_1和db_file_name_convert,即日志和数据文件目录,由pfile文件中定义的。

7.2,生成密码文件信息

正常的应该是和主库的密码文件内容保持相同,名称也要保持相同一样。

[oracle@dg ~]$ cp /data/app/rman_backup/orapworcl $ORACLE_HOME/dbs/
[oracle@dg ~]$ ll $ORACLE_HOME/dbs/
total 8
-rw-r--r-- 1 oracle oinstall 2851 May 15  2009 init.ora
-rw-r----- 1 oracle oinstall 1536 Oct 29 01:16 orapworcl

7.3,存放控制文件

---首先看一下主库的地址
主:
SQL> show parameter control_file;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time	     integer	 7
control_files			     string	 /data/app/oracle/oradata/orcl/
						 control01.ctl, /data/app/oracl
						 e/fast_recovery_area/orcl/cont
						 rol02.ctl
						 
---指定实际dg的控制文件路径,此路径可自定义,与pfile文件保持一致,
备:
[oracle@dg ~]$ mkdir -p /data/app/oracle/fast_recovery_area/orcl/
[oracle@dg ~]$ cp /data/app/rman_backup/standby.ctl /data/app/oracle/oradata/orcl/control01.ctl
[oracle@dg ~]$ cp /data/app/rman_backup/standby.ctl /data/app/oracle/fast_recovery_area/orcl/control02.ctl
[oracle@dg ~]$ ll /data/app/oracle/oradata/orcl/control01.ctl 
-rw-r----- 1 oracle oinstall 9748480 Oct 29 01:22 /data/app/oracle/oradata/orcl/control01.ctl
[oracle@dg ~]$ ll /data/app/oracle/fast_recovery_area/orcl/control02.ctl 
-rw-r----- 1 oracle oinstall 9748480 Oct 29 01:22 /data/app/oracle/fast_recovery_area/orcl/control02.ctl

7.4,修改pfile参数文件

首先再查看一下主库上的数据文件,临时文件,日志文件存放路径

主库:
---查看数据文件路径
SQL> set line 2000 pages 200;
SQL> col file_name for a50;
SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME 	       FILE_NAME
------------------------------ --------------------------------------------------
USERS			       /data/app/oracle/oradata/orcl/users01.dbf
UNDOTBS1		       /data/app/oracle/oradata/orcl/undotbs01.dbf
SYSAUX			       /data/app/oracle/oradata/orcl/sysaux01.dbf
SYSTEM			       /data/app/oracle/oradata/orcl/system01.dbf
---查看临时文件存放路径
SQL> col name for a50
SQL> select name from v$tempfile;

NAME
--------------------------------------------------
/data/app/oracle/oradata/orcl/temp01.dbf

---查看主库日志文件的路径
SQL> select group#,member from v$logfile;

    GROUP# MEMBER
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	 3 /data/app/oracle/oradata/orcl/redo03.log
	 2 /data/app/oracle/oradata/orcl/redo02.log
	 1 /data/app/oracle/oradata/orcl/redo01.log
	 4 /data/app/oracle/oradata/orcl/redo04.log
	 5 /data/app/oracle/oradata/orcl/redo05.log
	 6 /data/app/oracle/oradata/orcl/redo06.log
	 7 /data/app/oracle/oradata/orcl/redo07.log

7 rows selected.
备库:
---查看未修改之前的从主库传过来的原始pfile文件,
[oracle@dg ~]$ cd $ORACLE_HOME
[oracle@dg db_1]$ cd dbs/
[oracle@dg dbs]$ ll
total 8
-rw-r--r-- 1 oracle oinstall 2851 May 15  2009 init.ora
-rw-r----- 1 oracle oinstall 1536 Oct 29 01:16 orapworcl
[oracle@dg dbs]$ cp /data/app/rman_backup/initphydb1.ora $ORACLE_HOME/dbs/ 
[oracle@dg dbs]$ ll
total 12
-rw-r--r-- 1 oracle oinstall 2851 May 15  2009 init.ora
-rw-r--r-- 1 oracle oinstall 1626 Oct 29 01:36 initphydb1.ora
-rw-r----- 1 oracle oinstall 1536 Oct 29 01:16 orapworcl

[oracle@dg dbs]$ sed -i.ori 's/^orcl/orcl_sty/g' $ORACLE_HOME/dbs/initphydb1.ora && \
> mv $ORACLE_HOME/dbs/initphydb1.ora $ORACLE_HOME/dbs/initorcl_sty.ora

---修改后的内容如下[oracle@dg dbs]$ cat initorcl_sty.ora 
orcl_sty.__db_cache_size=6174015488
orcl_sty.__java_pool_size=16777216
orcl_sty.__large_pool_size=33554432
orcl_sty.__oracle_base='/data/app/oracle'#ORACLE_BASE set from environment
orcl_sty.__pga_aggregate_target=2466250752
orcl_sty.__sga_target=7381975040
orcl_sty.__shared_io_pool_size=0
orcl_sty.__shared_pool_size=1107296256
orcl_sty.__streams_pool_size=0
*.audit_file_dest='/data/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/data/app/oracle/oradata/orcl/control01.ctl','/data/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='/data/app/oracle/oradata/orcl/','/data/app/oracle/oradata/orcl/'
*.db_files=2000
*.db_name='orcl'
*.db_recovery_file_dest='/data/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=53687091200
*.db_unique_name='orcl_sty'
*.diagnostic_dest='/data/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.fal_client='orcl_sty'
*.fal_server='orcl_pri'
*.log_archive_config='dg_config=(orcl_pri,orcl_sty)'
*.log_archive_dest_1='LOCATION=/data/app/oracle/fast_recovery_area valid_for=(all_logfiles,all_roles) db_unique_name=orcl_sty'
*.log_archive_dest_2='service=orcl_pri LGWR ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=orcl_pri'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_file_name_convert='/data/app/oracle/oradata/orcl/','/data/app/oracle/oradata/orcl/'
*.open_cursors=300
*.pga_aggregate_target=2459959296
*.processes=1500
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=1500
*.sga_target=7379877888
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'

(大致修改以下内容)
*.db_unique_name='orcl_sty'
*.fal_client='orcl_sty'
*.fal_server='orcl_pri'
*.log_archive_dest_1='LOCATION=/data/app/oracle/fast_recovery_area valid_for=(all_logfiles,all_roles) db_unique_name=orcl_sty'
*.log_archive_dest_2='service=orcl_pri LGWR ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=orcl_pri'

7.5,启动备库到nomount状态

使用修改后的初始化文件启动备库到nomount状态

备库:
[oracle@dg dbs]$ sqlplus / as sysdba
SQL> startup pfile='/data/app/oracle/product/11.2.0.4/db_1/dbs/initorcl_sty.ora' nomount;
ORACLE instance started.

Total System Global Area 7349010432 bytes
Fixed Size		    2267464 bytes
Variable Size		 1728054968 bytes
Database Buffers	 5603590144 bytes
Redo Buffers		   15097856 bytes

SQL> create spfile from pfile='/data/app/oracle/product/11.2.0.4/db_1/dbs/initorcl_sty.ora';

File created.

7.6,备库恢复控制文件

备:
[oracle@dg ~]$ rman target /
RMAN> restore controlfile from '/data/app/oracle/oradata/orcl/control01.ctl';

Starting restore at 2019-10-29 02:00:56
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=572 device type=DISK

channel ORA_DISK_1: copied control file copy
output file name=/data/app/oracle/oradata/orcl/control01.ctl
output file name=/data/app/oracle/fast_recovery_area/orcl/control02.ctl
Finished restore at 2019-10-29 02:00:57

RMAN> exit
Recovery Manager complete.

7.7,切换备库到mount状态

备:
[oracle@dg ~]$ sqlplus / as sysdba
SQL> alter database mount;

Database altered.

SQL> select status from v$instance;

STATUS
------------
MOUNTED

7.8,rman将主库数据恢复到备库

解压rman备份的文件

备:
[oracle@dg ~]$ cd /data/app/rman_backup/
[oracle@dg rman_backup]$ tar -zxf rmanbak20191029.tgz 
[oracle@dg rman_backup]$ du -sh *
127M	ARC_03uffu43_1_1.bak
22M	ARC_0auffu77_1_1.bak
32M	ARC_0buffu77_1_1.bak
41M	ARC_0cuffu77_1_1.bak
33M	ARC_0duffu77_1_1.bak
36K	ARC_0euffu77_1_1.bak
1.1G	FULL_01uffu2i_1_1.bak
9.4M	FULL_02uffu3v_1_1.bak
636M	FULL_04uffu5u_1_1.bak
387M	FULL_05uffu5u_1_1.bak
22M	FULL_06uffu5u_1_1.bak
9.4M	FULL_07uffu5u_1_1.bak
1.4M	FULL_08uffu70_1_1.bak
96K	FULL_09uffu75_1_1.bak
4.0K	initphydb1.ora
4.0K	orapworcl
543M	rmanbak20191029.tgz
9.3M	standby.ctl
[oracle@dg rman_backup]$ mv standby.ctl rmanbak20191029.tgz orapworcl initphydb1.ora /tmp/

---恢复备库,特别注意catalog start with '/data/app/rman_backup/';非常重要
备:
[oracle@dg ~]$ cd /data/app/rman_backup/
[oracle@dg rman_backup]$ rman target /
RMAN> catalog start with '/data/app/rman_backup/';

Starting implicit crosscheck backup at 2019-10-29 02:07:19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=575 device type=DISK
Finished implicit crosscheck backup at 2019-10-29 02:07:19

Starting implicit crosscheck copy at 2019-10-29 02:07:19
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2019-10-29 02:07:19

searching for all files in the recovery area
cataloging files...
no files cataloged

searching for all files that match the pattern /data/app/rman_backup/

List of Files Unknown to the Database
=====================================
File Name: /data/app/rman_backup/ARC_03uffu43_1_1.bak
File Name: /data/app/rman_backup/ARC_0auffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0buffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0cuffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0duffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0euffu77_1_1.bak
File Name: /data/app/rman_backup/FULL_01uffu2i_1_1.bak
File Name: /data/app/rman_backup/FULL_02uffu3v_1_1.bak
File Name: /data/app/rman_backup/FULL_04uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_05uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_06uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_07uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_08uffu70_1_1.bak
File Name: /data/app/rman_backup/FULL_09uffu75_1_1.bak

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /data/app/rman_backup/ARC_03uffu43_1_1.bak
File Name: /data/app/rman_backup/ARC_0auffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0buffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0cuffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0duffu77_1_1.bak
File Name: /data/app/rman_backup/ARC_0euffu77_1_1.bak
File Name: /data/app/rman_backup/FULL_01uffu2i_1_1.bak
File Name: /data/app/rman_backup/FULL_02uffu3v_1_1.bak
File Name: /data/app/rman_backup/FULL_04uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_05uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_06uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_07uffu5u_1_1.bak
File Name: /data/app/rman_backup/FULL_08uffu70_1_1.bak
File Name: /data/app/rman_backup/FULL_09uffu75_1_1.bak

RMAN> run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
restore database ;
release channel c1;
release channel c2;
release channel c3;
10> release channel c4;
11> }

released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=575 device type=DISK

allocated channel: c2
channel c2: SID=1144 device type=DISK

allocated channel: c3
channel c3: SID=1714 device type=DISK

allocated channel: c4
channel c4: SID=9 device type=DISK

Starting restore at 2019-10-29 02:08:06

channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00001 to /data/app/oracle/oradata/orcl/system01.dbf
channel c1: reading from backup piece /data/app/rman_backup/FULL_04uffu5u_1_1.bak
channel c2: starting datafile backup set restore
channel c2: specifying datafile(s) to restore from backup set
channel c2: restoring datafile 00002 to /data/app/oracle/oradata/orcl/sysaux01.dbf
channel c2: reading from backup piece /data/app/rman_backup/FULL_05uffu5u_1_1.bak
channel c3: starting datafile backup set restore
channel c3: specifying datafile(s) to restore from backup set
channel c3: restoring datafile 00003 to /data/app/oracle/oradata/orcl/undotbs01.dbf
channel c3: reading from backup piece /data/app/rman_backup/FULL_06uffu5u_1_1.bak
channel c4: starting datafile backup set restore
channel c4: specifying datafile(s) to restore from backup set
channel c4: restoring datafile 00004 to /data/app/oracle/oradata/orcl/users01.dbf
channel c4: reading from backup piece /data/app/rman_backup/FULL_08uffu70_1_1.bak
channel c3: piece handle=/data/app/rman_backup/FULL_06uffu5u_1_1.bak tag=TAG20191028T222710
channel c3: restored backup piece 1
channel c3: restore complete, elapsed time: 00:00:07
channel c4: piece handle=/data/app/rman_backup/FULL_08uffu70_1_1.bak tag=TAG20191028T222710
channel c4: restored backup piece 1
channel c4: restore complete, elapsed time: 00:00:07
channel c1: piece handle=/data/app/rman_backup/FULL_04uffu5u_1_1.bak tag=TAG20191028T222710
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:55
channel c2: piece handle=/data/app/rman_backup/FULL_05uffu5u_1_1.bak tag=TAG20191028T222710
channel c2: restored backup piece 1
channel c2: restore complete, elapsed time: 00:00:55
Finished restore at 2019-10-29 02:09:02

released channel: c1

released channel: c2

released channel: c3

released channel: c4

RMAN> exit
Recovery Manager complete.

7.9,启动备库

重启启动备库

[oracle@dg ~]$ sqlplus / as sysdba
SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 7349010432 bytes
Fixed Size		    2267464 bytes
Variable Size		 1728054968 bytes
Database Buffers	 5603590144 bytes
Redo Buffers		   15097856 bytes

---启动standby数据库到mount状态
SQL> alter database mount standby database;

Database altered.

---查看当前数据库是否使用spfile启动,如下可以看到spfile路径,则证明数据库是使用spfile启动的,若没有值,则说明是用pfile启动的。
SQL> show parameter spfile;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
spfile				     string	 /data/app/oracle/product/11.2.
						 0.4/db_1/dbs/spfileorcl.ora
                         添加日志备份日志组
SQL> alter database add standby logfile;

Database altered.

---开启备库应用日志:standby端开启实时日志应用,会启动MRP0日志应用进程
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

---查看实例状态
SQL> select status from v$instance;

STATUS
------------
MOUNTED

8.验证主备库同步

8.1,dg状态下进行验证

验证过程中如果出现问题看主库和备库的
$ORACLE_BASE/diag/rdbms/orcl_pri/orcl/trace/和
$ORACLE_BASE/diag/rdbms/phydb3/orcl/trace目录中的trace文件。
8.1.1,备库查看RFS接收日志进程和MRP应用日志进程,以及同步主库情况
备库:
SQL> set lin 3000 pages 3000;
SQL> select process,sequence#,status,delay_mins from v$managed_standby;

PROCESS    SEQUENCE# STATUS	  DELAY_MINS
--------- ---------- ------------ ----------
ARCH		   0 CONNECTED		   0
ARCH		   0 CONNECTED		   0
ARCH		  14 CLOSING		   0
ARCH		   0 CONNECTED		   0
RFS		   0 IDLE		   0
RFS		  15 IDLE		   0
RFS		   0 IDLE		   0
MRP0		  15 APPLYING_LOG	   0

8 rows selected.

如上所示,有RFS接收日志进程,有MRP0 进程且MRP0 进程状态正常,则表示DG运行正常。

其中:ARCH是归档进程,RFS是归档传输进程,MRP0是日志应用进程

8.1.2,查看archive log list序列是否一致

在主库上,如果最后一行数字相同说明配置成功。

主:
[oracle@adg ~]$ sqlplus / as sysdba
SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     13
Next log sequence to archive   15
Current log sequence	       15

在备库上如果最后一行数字相同说明配置成功

备:
[oracle@dg ~]$ sqlplus / as sysdba
SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       /data/app/oracle/fast_recovery_area
Oldest online log sequence     0
Next log sequence to archive   0
Current log sequence	       15
8.1.3,切日志

在主库上执行alter system switch logfile;再去查看archive log list 查看主备库的current log sequence 是否一致。如果一致,这是正确的配置。

主:
SQL> alter system switch logfile;

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     14
Next log sequence to archive   16
Current log sequence	       16

备:
SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       /data/app/oracle/fast_recovery_area
Oldest online log sequence     15
Next log sequence to archive   0
Current log sequence	       16
8.1.4,查看有没有gap
主:
SQL> select status,gap_status from v$archive_dest_status where dest_id=2;

STATUS	  GAP_STATUS
--------- ------------------------
VALID	  NO GAP

SQL> select * from v$archive_dest_status where dest_id=2;

备:
SQL> select status,gap_status from v$archive_dest_status where dest_id=2;

STATUS	  GAP_STATUS
--------- ------------------------
VALID

说明DG正常
8.1.5,查看日志应用进度
主:
SQL> set lin 3000 pages 300;
SQL> select REGISTRAR,CREATOR,THREAD#,APPLIED,sequence#,first_change#,next_change#,COMPLETION_TIME from v$archived_log;

REGISTR CREATOR    THREAD# APPLIED    SEQUENCE# FIRST_CHANGE# NEXT_CHANGE# COMPLETION_TIME
------- ------- ---------- --------- ---------- ------------- ------------ -------------------
ARCH	ARCH		 1 NO		      5        958075	    965960 2019-10-28 04:07:15
ARCH	ARCH		 1 NO		      6        965960	    966741 2019-10-28 05:04:49
ARCH	ARCH		 1 NO		      7        966741	    967042 2019-10-28 05:04:55
ARCH	ARCH		 1 NO		      8        967042	   1000644 2019-10-28 13:00:54
ARCH	ARCH		 1 NO		      9       1000644	   1038611 2019-10-28 22:00:12
ARCH	ARCH		 1 NO		     10       1038611	   1039148 2019-10-28 22:00:21
FGRD	FGRD		 1 NO		     11       1039148	   1040868 2019-10-28 22:26:11
FGRD	FGRD		 1 NO		     12       1040868	   1041001 2019-10-28 22:27:51
ARCH	ARCH		 1 YES		     11       1039148	   1040868 2019-10-29 02:02:19
ARCH	ARCH		 1 YES		     10       1038611	   1039148 2019-10-29 02:02:19
ARCH	ARCH		 1 YES		      9       1000644	   1038611 2019-10-29 02:02:19
ARCH	ARCH		 1 NO		     13       1041001	   1055050 2019-10-29 02:02:19
ARCH	ARCH		 1 YES		     12       1040868	   1041001 2019-10-29 02:02:24
ARCH	ARCH		 1 YES		     13       1041001	   1055050 2019-10-29 02:02:24
ARCH	ARCH		 1 NO		     14       1055050	   1057191 2019-10-29 02:34:52
ARCH	ARCH		 1 YES		     14       1055050	   1057191 2019-10-29 02:34:53
ARCH	ARCH		 1 NO		     15       1057191	   1058128 2019-10-29 02:50:05
LGWR	LGWR		 1 NO		     15       1057191	   1058128 2019-10-29 02:50:05

18 rows selected.

备;
SQL> set lin 300 pages 300;
SQL> select REGISTRAR,CREATOR,THREAD#,APPLIED,sequence#,first_change#,next_change#, COMPLETION_TIME from v$archived_log;

REGISTR CREATOR    THREAD# APPLIED    SEQUENCE# FIRST_CHANGE# NEXT_CHANGE# COMPLETION_TIME
------- ------- ---------- --------- ---------- ------------- ------------ -------------------
RFS	ARCH		 1 YES		     11       1039148	   1040868 2019-10-29 02:02:19
RFS	ARCH		 1 YES		     10       1038611	   1039148 2019-10-29 02:02:19
RFS	ARCH		 1 YES		      9       1000644	   1038611 2019-10-29 02:02:19
RFS	ARCH		 1 YES		     12       1040868	   1041001 2019-10-29 02:02:24
RFS	ARCH		 1 YES		     13       1041001	   1055050 2019-10-29 02:02:27
RFS	ARCH		 1 YES		     14       1055050	   1057191 2019-10-29 02:34:53
RFS	ARCH		 1 IN-MEMORY	     15       1057191	   1058128 2019-10-29 02:50:05

7 rows selected.
8.1.6,查询数据库模式是否正常
主:
SQL> set lin 3000 pages 300;
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

      DBID NAME      OPEN_MODE		  CURRENT_SCN PROTECTION_MODE	   DATABASE_ROLE    FOR OPEN_MODE	     SWITCHOVER_STATUS
---------- --------- -------------------- ----------- -------------------- ---------------- --- -------------------- --------------------
1550594382 ORCL      READ WRITE 	      1058731 MAXIMUM PERFORMANCE  PRIMARY	    YES READ WRITE	     TO STANDBY

备:
SQL> set lin 3000 pages 300;
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

      DBID NAME      OPEN_MODE		  CURRENT_SCN PROTECTION_MODE	   DATABASE_ROLE    FOR OPEN_MODE	     SWITCHOVER_STATUS
---------- --------- -------------------- ----------- -------------------- ---------------- --- -------------------- --------------------
1550594382 ORCL      MOUNTED		      1057190 MAXIMUM PERFORMANCE  PHYSICAL STANDBY YES MOUNTED 	     NOT ALLOWED

8.2,开启备库ADG状态进行验证

8.2.1,开启备库的ADG
备:
取消日志应用
SQL> alter database recover managed standby database cancel;

Database altered.

以open模式打开数据库
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> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

查询数据库模式是否正常
SQL> set lin 3000 pages 300;
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

      DBID NAME      OPEN_MODE		  CURRENT_SCN PROTECTION_MODE	   DATABASE_ROLE    FOR OPEN_MODE	     SWITCHOVER_STATUS
---------- --------- -------------------- ----------- -------------------- ---------------- --- -------------------- --------------------
1550594382 ORCL      READ ONLY WITH APPLY     1059251 MAXIMUM PERFORMANCE  PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED
8.2.2,再次验证主备状态

再次检查DG2状态是否正常

查看archive log list 序列是否一致

---在主库上, 如果最后一行数字相同, 如果相同说明配置成功
主:
SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     14
Next log sequence to archive   16
Current log sequence	       16

备:
---在备库上,如果最后一行数字相同, 如果相同说明配置成功
SQL> select status from v$instance;

STATUS
------------
OPEN

SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       /data/app/oracle/fast_recovery_area
Oldest online log sequence     15
Next log sequence to archive   0
Current log sequence	       16

切日志

---在主库上执行alter system switch logfile;再去查看archive log list 查看主备库的current log sequence 是否一致。如果一致,这是正确的配置
主:
SQL> alter system switch logfile;

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     15
Next log sequence to archive   17
Current log sequence	       17

备:
SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       /data/app/oracle/fast_recovery_area
Oldest online log sequence     15
Next log sequence to archive   0
Current log sequence	       17

查看有没有gap

主;
SQL> select status,gap_status from v$archive_dest_status where dest_id=2;

STATUS	  GAP_STATUS
--------- ------------------------
VALID	  NO GAP

SQL> select * from v$archive_dest_status where dest_id=2;

   DEST_ID DEST_NAME									      STATUS    TYPE	     DATABASE_MODE   RECOVERY_MODE	     PROTECTION_MODE	  DESTINATION										     STANDBY_LOGFILE_COUNT STANDBY_LOGFILE_ACTIVE ARCHIVED_THREAD# ARCHIVED_SEQ# APPLIED_THREAD# APPLIED_SEQ# ERROR							      SRL DB_UNIQUE_NAME		 SYNCHRONIZATION_STATUS SYN GAP_STATUS
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------- -------------- --------------- ----------------------- -------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------- ---------------------- ---------------- ------------- --------------- ------------ ----------------------------------------------------------------- --- ------------------------------ ---------------------- --- ------------------------
	 2 LOG_ARCHIVE_DEST_2								      VALID     PHYSICAL	     OPEN_READ-ONLY  MANAGED REAL TIME APPLY MAXIMUM PERFORMANCE  orcl_sty											         5		      1 	       1	    16		     1		 15	        YES orcl_sty			 CHECK CONFIGURATION	NO  NO GAP

备:
SQL> select status,gap_status from v$archive_dest_status where dest_id=2;

STATUS	  GAP_STATUS
--------- ------------------------
VALID	  NO GAP

说明DG1正常

备库查看RFS接收日志和MRP应用日志同步主库情况

备:
SQL> set lin 3000 pages 300;
SQL> select process, sequence#,status,delay_mins from v$managed_standby;

PROCESS    SEQUENCE# STATUS	  DELAY_MINS
--------- ---------- ------------ ----------
ARCH		   0 CONNECTED		   0
ARCH		   0 CONNECTED		   0
ARCH		  16 CLOSING		   0
ARCH		   0 CONNECTED		   0
RFS		   0 IDLE		   0
RFS		  17 IDLE		   0
RFS		   0 IDLE		   0
MRP0		  17 APPLYING_LOG	   0

8 rows selected.
如上面所示,有RFS接收日志进程,有MRP0 进程且MRP0 进程状态正常,则表示DG运行正常。 
其中:ARCH是归档进程,RFS是归档传输进程,MRP0是日志应用进程 

查看日志应用进度,

主:
SQL> set lin 3000 pages 300;
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

      DBID NAME      OPEN_MODE		  CURRENT_SCN PROTECTION_MODE	   DATABASE_ROLE    FOR OPEN_MODE	     SWITCHOVER_STATUS
---------- --------- -------------------- ----------- -------------------- ---------------- --- -------------------- --------------------
1550594382 ORCL      READ WRITE 	      1060210 MAXIMUM PERFORMANCE  PRIMARY	    YES READ WRITE	     TO STANDBY


备:
SQL> set lin 3000 pages 300;
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

      DBID NAME      OPEN_MODE		  CURRENT_SCN PROTECTION_MODE	   DATABASE_ROLE    FOR OPEN_MODE	     SWITCHOVER_STATUS
---------- --------- -------------------- ----------- -------------------- ---------------- --- -------------------- --------------------
1550594382 ORCL      READ ONLY WITH APPLY     1060254 MAXIMUM PERFORMANCE  PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED

查询数据库模式是否正常

主:
SQL> set lin 3000 pages 300;
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

      DBID NAME      OPEN_MODE      CURRENT_SCN PROTECTION_MODE    DATABASE_ROLE    FOR OPEN_MODE      SWITCHOVER_STATUS
---------- --------- -------------------- ----------- -------------------- ---------------- --- -------------------- --------------------
1550594382 ORCL      READ WRITE         1235867 MAXIMUM PERFORMANCE  PRIMARY      YES READ WRITE       TO STANDBY

备:
SQL> set lin 3000 pages 300;
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database;

      DBID NAME      OPEN_MODE      CURRENT_SCN PROTECTION_MODE    DATABASE_ROLE    FOR OPEN_MODE      SWITCHOVER_STATUS
---------- --------- -------------------- ----------- -------------------- ---------------- --- -------------------- --------------------
1550594382 ORCL      READ ONLY          1234481 MAXIMUM PERFORMANCE  PHYSICAL STANDBY YES READ ONLY      NOT ALLOWED

8.3,数据测试

主:
SQL> alter system switch logfile;

System altered.

SQL> create table test as select * from dba_objects;

Table created.

SQL> insert into test select * from test;

86259 rows created.

SQL> insert into test select * from test;

172518 rows created.

SQL> commit;

Commit complete.

SQL> insert into test select * from test;

345036 rows created.

SQL> commit;

Commit complete.

SQL> insert into test select * from test;

690072 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

  COUNT(*)
----------
   1380144
   
   
   
备:
备库上查询
SQL> select count(*) from test;

  COUNT(*)
----------
   1380144


主库再次执行
主:
SQL> drop table test;

Table dropped.

SQL> select cout(*) from test;
select cout(*) from test
            *
ERROR at line 1:
ORA-00936: missing expression


备:
再次查询
SQL> select count(*) from test;

  COUNT(*)
----------
   1380144

SQL> select count(*) from test;
select count(*) from test
                     *
ERROR at line 1:
ORA-00942: table or view does not exist

oracle搭建ADG 到此结束-----------------------------------------------------------------

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!