Oracle RAC 12.1.0.1 on the OEL6.5 OS
(VMware Workstation虚拟机)
目录
一、 安装前准备工作... 4
1. 网络配置... 4
2. 关闭sendmail服务... 4
3. 配置hosts. 5
4. YUM安装依赖包... 5
5. 修改内核... 7
6. 设置Oracle和Grid用户的SHELL限制... 8
7. 关闭防火墙... 8
8. 创建用户和组及相关目录... 9
9. 修改oracle和grid的环境变量... 10
10. 配置共享存储... 11
11. 配置SSH(用grid用户做示范,oracle用户同理)... 18
12. 修改shm. 19
13. 禁止NTP服务... 20
二、 安装grid. 20
三、 安装database软件... 36
四、 创建ASM磁盘... 42
五、 创建数据库... 43
六、 灾备库配置... 54
1. 网络配置... 54
2. 配置hosts. 54
3.YUM安装依赖包... 54
4.修改内核... 56
5.设置Oracle和Grid用户的SHELL限制... 57
6.关闭防火墙... 57
7.创建用户和组及相关目录... 58
8.修改oracle和grid的环境变量... 58
9.安装灾备的数据库软件... 59
10.主备库参数修改... 64
11.主备切换... 73
一、安装前准备工作
1.网络配置
(1) 两个节点分别需要两张网卡,即eth0和eth1
如下:
节点一(私有网卡不需要网关):
节点二(私有网卡不需要网关):
2.关闭sendmail服务
[[email protected] ~]# chkconfig sendmail off
[[email protected] ~]# chkconfig --list | grep sendmail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
3.配置hosts
vi /etc/hosts,将两个节点的实IP、虚IP、SCAN-IP、心跳网络都加上。示例如下:
#Host IP 192.168.31.240 rac1 192.168.31.241 rac2 #Virtual IP 192.168.31.242 vrac1 192.168.31.243 vrac2 #Scan Name 192.168.31.244 rac-scan #Heartbeat IP 192.168.1.240 prac1 192.168.1.241 prac2 |
4.YUM安装依赖包
(1)配置yum源
[root@rac1 ~]# mkdir –p /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# cp rhel-source.repo rhel-source.repo.bak
[[email protected] yum.repos.d]# vi rhel-source.repo
修改内容如下
[rhel6.5]
name=Red Hat 6.5
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
(2)安装rpm包
yum install binutils -y
yum install compat-libcap1 -y
yum install compat-libstdc++-33 -y
yum install compat-libstdc++-33.i686 -y
yum install gcc -y
yum install gcc-c++ -y
yum install glibc -y
yum install glibc.i686 -y
yum install glibc-devel -y
yum install glibc-devel.i686 -y
yum install ksh -y
yum install libgcc -y
yum install libgcc.i686 -y
yum install libstdc++ -y
yum install libstdc++.i686 -y
yum install libstdc++-devel -y
yum install libstdc++-devel.i686 -y
yum install libaio -y
yum install libaio.i686 -y
yum install libaio-devel -y
yum install libaio-devel.i686 -y
yum install libXext -y
yum install libXext.i686 -y
yum install libXtst -y
yum install libXtst.i686 -y
yum install libX11 -y
yum install libX11.i686 -y
yum install libXau -y
yum install libXau.i686 -y
yum install libxcb -y
yum install libxcb.i686 -y
yum install libXi -y
yum install libXi.i686 -y
yum install make -y
yum install sysstat -y
yum install unixODBC -y
yum install unixODBC-devel -y
5.修改内核
vi /etc/sysctl.conf
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
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
kernel.shmmax = 4398046511104
kernel.shmall = 1073741824
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
kernel.panic_on_oops= 1
/sbin/sysctl -p 生效参数
6.设置Oracle和Grid用户的SHELL限制
[[email protected] ~]# vi /etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
grid soft nproc 16384
grid hard nproc 16384
grid soft nofile 65536
grid hard nofile 65536
grid soft stack 10240
grid hard stack 10240
7.关闭防火墙
[email protected] ~]#service iptables stop
[[email protected] ~]#chkconfig iptables off
[[email protected] ~]#service ip6tables stop
[[email protected] ~]#chkconfig ip6tables off
有时候,远程节点会关闭SSH的连接,为了防止这种情况发生,需要修改配置文件sshd_config
vi/etc/ssh/sshd_config
LoginGraceTime 0
“LoginGraceTime”设置如果用户不能成功登录,在切断连接之前服务器需要等待的时间(以秒为单位)
[[email protected] ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
8.创建用户和组及相关目录
groupadd -g 1000oinstall
groupadd -g 1001dba
groupadd -g 1002oper
groupadd -g 1003backupdba
groupadd -g 1004dgdba
groupadd -g 1005 kmdba
groupadd -g 1006 asmdba
groupadd -g 1007 asmoper
groupadd -g 1008 asmadmin
useradd -u1101 -g oinstall -G dba,asmadmin,asmdba,asmoper grid
useradd -u 1100 -g oinstall -G dba,oper,backupdba,dgdba,kmdba,asmdba,asmadmin oracle
passwd grid
passwd oracle
mkdir -p /u01/app/12.1.0.1/grid
mkdir -p /u01/app/gridbase
mkdir -p /u01/app/oracle/product/12.1.0.1/db_1
chown -R grid:oinstall /u01
chmod -R 775 /u01/
chown -R oracle:oinstall /u01/app/oracle
9.修改oracle和grid的环境变量
Oracle用户的profile内容如下,注意红色SID字段需要修改,一般和节点的主机名一致即可:
export ORACLE_SID=rac1 #export ORACLE_SID=rac2 export ORACLE_UNQNAME=rac export ORACLE_HOSTNAME=rac1 export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/12.1.0.1/db_1 export ORACLE_TERM=xterm export PATH=/usr/sbin:$PATH export PATH=$ORACLE_HOME/bin:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib ulimit -u 16384 -n 65536 umask 022 |
grid用户的profile内容如下,注意红色SID字段需要修改,一般节点1是+ASM1,节点2是+ASM2:
export ORACLE_SID=+ASM1 #export ORACLE_SID=+ASM2 export ORACLE_BASE=/u01/app/gridbase export ORACLE_HOME=/u01/app/grid/12.1.0.1/ PATH=$PATH:$HOME/bin export PATH=/usr/sbin:$PATH:$ORACLE_HOME/bin:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib export TEMP=/tmp export TMP=/tmp export TMPDIR=/tmp umask 022 export ORACLE_HOSTNAME=rac1 |
10.配置共享存储
(1)在 cmd 中进入 WMwareWorkstation 安装目录,执行命令创建磁盘:
cdC:\Program Files (x86)\VMware\VMware Workstation
C:\Program Files(x86)\VMware\VMware Workstation>vmware-vdiskmanager.exe-c -s 7g -a lsilogic -t 2 "E:\My VirtualMachines\rac\sharedisk\ocr_vote.vmdk"
VixDiskLib:Invalid configuration file parameter. Failed to read configuration file.
Creating disk‘E:\My Virtual Machines\rac\sharedisk\ocr_vote.vmdk‘
Create: 100% done.
Virtual diskcreation successful.
C:\Program Files(x86)\VMware\VMware Workstation>vmware-vdiskmanager.exe-c -s 5g -a lsilogic -t 2 "E:\My VirtualMachines\rac\sharedisk\data.vmdk"
VixDiskLib:Invalid configuration file parameter. Failed to read configuration file.
Creating disk‘E:\My Virtual Machines\rac\sharedisk\data.vmdk‘
Create: 100% done.
Virtual diskcreation successful.
C:\Program Files(x86)\VMware\VMware Workstation>vmware-vdiskmanager.exe-c -s 5g -a lsilogic -t 2 "E:\My VirtualMachines\rac\sharedisk\fra.vmdk"
VixDiskLib:Invalid configuration file parameter. Failed to read configuration file.
Creating disk‘E:\My Virtual Machines\rac\sharedisk\fra.vmdk‘
Create: 100% done.
Virtual diskcreation successful.
C:\Program Files(x86)\VMware\VMware Workstation>
(2)
关闭两台虚拟机,用记事本打开虚拟机名字.wmx,即打开配置文件,2个节点都需要修改 例如: D:\rhela\rhela.vmx
添加以下内容,红色字体修改为自己的共享虚拟机磁盘文件路径,当然如果在上一步中如果是通过界面来创建的那么需要把下边的缺失的部分添加进去即可:
#shared disksconfigure
disk.EnableUUID="TRUE"
disk.locking ="FALSE"
scsi1.shared ="TRUE"
diskLib.dataCacheMaxSize= "0"
diskLib.dataCacheMaxReadAheadSize= "0"
diskLib.dataCacheMinReadAheadSize= "0"
diskLib.dataCachePageSize="4096"
diskLib.maxUnsyncedWrites= "0"
scsi1.present ="TRUE"
scsi1.virtualDev ="lsilogic"
scsil.sharedBus ="VIRTUAL"
scsi1:0.present ="TRUE"
scsi1:0.mode ="independent-persistent"
scsi1:0.fileName= "E:\share\ocr_vote.vmdk"
scsi1:0.deviceType= "disk"
scsi1:0.redo =""
scsi1:1.present ="TRUE"
scsi1:1.mode ="independent-persistent"
scsi1:1.fileName= "E:\share\data.vmdk"
scsi1:1.deviceType= "disk"
scsi1:1.redo =""
scsi1:2.present ="TRUE"
scsi1:2.mode ="independent-persistent"
scsi1:2.fileName= "E:\share\fra.vmdk"
scsi1:2.deviceType= "disk"
scsi1:2.redo =""
(3)
关闭VMware Workstation 软件重新打开,此时看到共享磁盘正确加载则配置正确
(4) 配置 udev 绑定的 scsi_id
不同的操作系统,scsi_id 命令的位置不同。
[[email protected]~]# cat /etc/issue
Oracle LinuxServer release 6.5
Kernel \r on an \m
注意:rhel 6 之后只支持 --whitelisted --replace-whitespace 参数,之前的 -g -u -s 参数已经不支持了。
[[email protected]~]# which scsi_id
/sbin/scsi_id
[[email protected]~]#
vi /etc/scsi_id.config文件,如果该文件不存在,则创建该文件并添加如下行:
[[email protected]~]# vi /etc/scsi_id.config
options=--whitelisted--replace-whitespace
[[email protected]~]#
如果是使用VMware 虚拟机,直接输入 scsi_id 命令可能无法获取 id,需修改 VMware 文件参数。
D:\VMs\OracleDatabase 11gR2\Oracle Database 11gR2.vmx
使用文本编辑器编辑该文件,在尾部新增一行参数:
disk.EnableUUID="TRUE"
保存文件,重新启动虚拟机。这里注意修改文件的时候一定要在关机的状态下修改,或者 scsi_id -g -u /dev/sdc 来获得uuid,-g -u参数在rhel6以后已经不用了
[[email protected]]# scsi_id --whitelisted --replace-whitespace --device=/dev/sdb
36000c2900b7d702663c8e271a52cd0f4
[[email protected]]# scsi_id --whitelisted --replace-whitespace --device=/dev/sdc
36000c290ab86fbd3430f3d2ef712e019
[[email protected]]# scsi_id --whitelisted --replace-whitespace --device=/dev/sdd
36000c295b0e0d470155ea906e546cf7c
创建并配置 udev rules 文件
[[email protected]~]# vi /etc/udev/rules.d/99-oracle-asmdevices.rules
KERNEL=="sd*",BUS=="scsi",PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace--device=/dev/$name",RESULT=="36000c2900b7d702663c8e271a52cd0f4",NAME="asm-data", OWNER="grid",GROUP="asmadmin",MODE="0660"
KERNEL=="sd*",BUS=="scsi",PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name",RESULT=="36000c290ab86fbd3430f3d2ef712e019",NAME="asm-fra", OWNER="grid",GROUP="asmadmin",MODE="0660"
KERNEL=="sd*",BUS=="scsi",PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace--device=/dev/$name",RESULT=="36000c295b0e0d470155ea906e546cf7c",NAME="asm-ocr2", OWNER="grid",GROUP="asmadmin",MODE="0660"
发送到rac2
scp/etc/udev/rules.d/99-oracle-asmdevices.rules rac2:/etc/udev/rules.d
添加完成后,重启 udev,不同 Linux 发行版本重启方式不一样。
该步骤慢一点,大约可能需要30秒左右吧,等等等等。。。。。。
[[email protected]~]# start_udev
Startingudev: [ OK ]
查看绑定的 asm,如果此时还是看不到 asmdisk,请重启操作系统后再查看。
[[email protected] ~]# ll /dev/asm*
brw-rw---- 1 gridasmadmin 8, 17 Jul 27 14:58 /dev/asm-data
brw-rw---- 1 gridasmadmin 8, 33 Jul 27 14:58 /dev/asm-fra
brw-rw---- 1 gridasmadmin 8, 49 Jul 27 14:58 /dev/asm-ocr2
对共享盘分区,已/dev/sdb为例,因为是共享存储,只需在其中一个节点上执行
[[email protected] ~]# fdisk/dev/sdb
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044,default 1044):
Using default value 1044
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
11.配置SSH(用grid用户做示范,oracle用户同理)
节点一:
[[email protected] ~]$ mkdir .ssh
[[email protected] ~]$ chmod 700 .ssh
[[email protected] ~]$ cd .ssh
[[email protected] .ssh]$ /usr/bin/ssh-keygen -t rsa
[[email protected] .ssh]$ /usr/bin/ssh-keygen -t dsa
节点二:
[[email protected] ~]$ mkdir .ssh
[[email protected] ~]$ chmod 700 .ssh
[[email protected] ~]$ cd .ssh
[[email protected] .ssh]$ /usr/bin/ssh-keygen -t dsa
[[email protected] .ssh]$ /usr/bin/ssh-keygen -t dsa
[[email protected] ~]cd~/.ssh
[[email protected] .ssh]cat/home/oracle/.ssh/id_rsa.pub >> authorized_keys
[[email protected] .ssh]cat/home/oracle/.ssh/id_dsa.pub >> authorized_keys
[[email protected] .ssh]sshrac1 cat /home/oracle/.ssh/id_rsa.pub >> authorized_keys
[[email protected] .ssh]sshrac1 cat /home/oracle/.ssh/id_dsa.pub >> authorized_keys
[[email protected] .ssh]scpauthorized_keys rac1:/home/oracle/.ssh/
以下为两个节点执行
ssh rac1 date
ssh rac2 date
ssh prac1 date
ssh prac2 date
12.修改shm
[[email protected] ~]#grep MemTotal/proc/meminfo
MemTotal: 2225780 kB
查看内存文件系统
[[email protected] ~]# df-h
Filesystem Size Used Avail Use%Mounted on
/dev/mapper/VolGroup00-LogVol00
5.8G 3.8G 1.7G 70% /
/dev/sda1 99M 13M 81M 14% /boot
tmpfs 1.1G 0 1.1G 0% /dev/shm
/dev/sdb1 16G 173M 15G 2%/taryartar/12c
[[email protected] ~]# vi /etc/fstab
tmpfs /dev/shm tmpfs defaults,size=2G 0 0
13.禁止NTP服务
[[email protected] ~]#/sbin/service ntpd stop
Shutting downntpd: [ OK ]
[[email protected] ~]#chkconfig ntpd off
[[email protected] ~]# mv/etc/ntp.conf /etc/ntp.conf.original
[[email protected] ~]#chkconfig ntpd --list
ntpd 0:off 1:off2:off 3:off 4:off 5:off 6:off
[[email protected] ~]#/sbin/service ntpd stop
Shutting downntpd: [ OK ]
[[email protected] ~]#chkconfig ntpd off
[[email protected] ~]# mv/etc/ntp.conf/etc/ntp.conf.original
[[email protected] ~]#chkconfig ntpd --list
ntpd 0:off 1:off 2:off3:off 4:off 5:off 6:off
二、安装grid
[[email protected] grid]# unzip linuxamd64_12101_grid_1of2.zip
[[email protected] grid]# unzip linuxamd64_12101_grid_2of2.zip
[[email protected] rpm]# rpm -ivh cvuqdisk-1.0.9-1.rpm
[[email protected] rpm]# rpm -ivh cvuqdisk-1.0.9-1.rpm
[[email protected] Linux_12.1.0.1]# xhost +
[[email protected] grid]$ ./runInstaller
此步骤可以自动配置SSH
根据自己设定的公网和私网IP来选择
因为是测试机器内存只给了2G,ORACLE最低要求4G。将其两个忽略。(如果有DNS报错也忽略,因为可能没有配置DNS的问题)
执行脚本:
[[email protected] ~]# /u01/app/oraInventory/orainstRoot.sh
Changingpermissions of /u01/app/oraInventory.
Adding read,writepermissions for group.
Removingread,write,execute permissions for world.
Changing groupnameof /u01/app/oraInventory to oinstall.
The execution ofthe script is complete.
[[email protected] ~]# /u01/app/oraInventory/orainstRoot.sh
Changingpermissions of /u01/app/oraInventory.
Adding read,writepermissions for group.
Removingread,write,execute permissions for world.
Changing groupnameof /u01/app/oraInventory to oinstall.
The execution ofthe script is complete.
[[email protected] ~]# /u01/app/grid/12.1.0.2/root.sh
Performing rootuser operation for Oracle 12c
The followingenvironment variables are set as:
ORACLE_OWNER= grid
ORACLE_HOME= /u01/app/grid/12.1.0.2
Enter the fullpathname of the local bin directory: [/usr/local/bin]:
The file"dbhome" already exists in /usr/local/bin. Overwrite it? (y/n)
[n]:
The file"oraenv" already exists in /usr/local/bin. Overwrite it? (y/n)
[n]:
The file "coraenv"already exists in /usr/local/bin. Overwrite it? (y/n)
[n]:
…….
…….
CRS-2672:Attempting to start ‘ora.asm‘ on ‘rac1‘
CRS-2676: Start of‘ora.asm‘ on ‘rac1‘ succeeded
CRS-2672:Attempting to start ‘ora.OCR.dg‘ on ‘rac1‘
CRS-2676: Start of‘ora.OCR.dg‘ on ‘rac1‘ succeeded
2015/07/2717:10:28 CLSRSC-325: Configure Oracle Grid Infrastructure for a Cluster ...succeeded
[[email protected] ~]# /u01/app/grid/12.1.0.2/root.sh
Performing rootuser operation for Oracle 12c
The followingenvironment variables are set as:
ORACLE_OWNER= grid
ORACLE_HOME= /u01/app/grid/12.1.0.2
Enter the fullpathname of the local bin directory: [/usr/local/bin]:
The file"dbhome" already exists in /usr/local/bin. Overwrite it? (y/n)
[n]:
The file"oraenv" already exists in /usr/local/bin. Overwrite it? (y/n)
[n]:
The file"coraenv" already exists in /usr/local/bin. Overwrite it? (y/n)
[n]:
………
………
CRS-2676: Start of‘ora.crsd‘ on ‘rac2‘ succeeded
CRS-6017:Processing resource auto-start for servers: rac2
CRS-2672:Attempting to start ‘ora.ons‘ on ‘rac2‘
CRS-2676: Start of‘ora.ons‘ on ‘rac2‘ succeeded
CRS-6016: Resourceauto-start has completed for server rac2
CRS-6024:Completed start of Oracle Cluster Ready Services-managed resources
CRS-4123: OracleHigh Availability Services has been started.
2015/07/2717:17:18 CLSRSC-343: Successfully started Oracle clusterware stack
2015/07/2717:17:40 CLSRSC-325: Configure Oracle Grid Infrastructure for a Cluster ...succeeded
跑完脚本后点OK。
因为DNS的问题,这里会报错,可以查看日志。
点击OK。
查看crs状态
[[email protected] ~]$crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....ER.lsnrora....er.type ONLINE ONLINE rac1
ora....N1.lsnrora....er.type ONLINE ONLINE rac1
ora.MGMTLSNR ora....nr.type ONLINE ONLINE rac1
ora.OCR.dg ora....up.type ONLINE ONLINE rac1
ora.asm ora.asm.type ONLINE ONLINE rac1
ora.cvu ora.cvu.type ONLINE ONLINE rac1
ora.mgmtdb ora....db.type ONLINE ONLINE rac1
ora....networkora....rk.type ONLINE ONLINE rac1
ora.oc4j ora.oc4j.type ONLINE ONLINE rac1
ora.ons ora.ons.type ONLINE ONLINE rac1
ora....SM1.asmapplication ONLINE ONLINE rac1
ora....C1.lsnrapplication ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip ora....t1.type ONLINE ONLINE rac1
ora....SM2.asmapplication ONLINE ONLINE rac2
ora....C2.lsnrapplication ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip ora....t1.type ONLINE ONLINE rac2
ora.scan1.vip ora....ip.type ONLINE ONLINE rac1
三、安装database软件
[[email protected] ~]# su – oracle
[[email protected] database]$ ./runInstaller
这里选择只安装数据库软件,数据库的创建等安装完软件。
因为没有配置DNS的问题,这个可以忽略。
两个节点分别跑脚本
四、创建ASM磁盘
[[email protected] Desktop]# su - grid
[[email protected] ~]$ asmca
Fra的创建方法一样,这里我们用DATA放数据文件,fra放归档和备份文件。
五、创建数据库
这里根据自己需求来选择
这里根据自己需要SGA和PGA来进行分配
块大小和进程数的设置
字符集的选择,可以自己选择自己所需的字符集。
连接模式,需用独占还是共享。
这里可以修改控制文件参数,数据文件参数,日志文件参数。
如果有报错要解决后才开始创建。
安装完毕点击close
[[email protected] Desktop]# su - oracle
[[email protected] ~]$ echo $ORACLE_SID
rac1
[[email protected] ~]$ sqlplus / as sysdba
SQL> select status from gv$instance;
STATUS
------------
OPEN
OPEN
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 36
Next log sequence to archive 37
Current log sequence 37
SQL>
[[email protected] ~]# su - grid
[[email protected] ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.DATA.dg ora....up.type ONLINE ONLINE rac1
ora.FRA.dg ora....up.type ONLINE ONLINE rac1
ora....ER.lsnr ora....er.type ONLINE ONLINE rac1
ora....N1.lsnr ora....er.type ONLINE ONLINE rac1
ora.MGMTLSNR ora....nr.type ONLINE ONLINE rac1
ora.OCR.dg ora....up.type ONLINE ONLINE rac1
ora.asm ora.asm.type ONLINE ONLINE rac1
ora.cvu ora.cvu.type ONLINE ONLINE rac1
ora.mgmtdb ora....db.type ONLINE ONLINE rac1
ora....network ora....rk.type ONLINE ONLINE rac1
ora.oc4j ora.oc4j.type ONLINE ONLINE rac1
ora.ons ora.ons.type ONLINE ONLINE rac1
ora.rac.db ora....se.type ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip ora....t1.type ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip ora....t1.type ONLINE ONLINE rac2
ora.scan1.vip ora....ip.type ONLINE ONLINE rac1
六、灾备库配置
1.网络配置
2.配置hosts
[[email protected] ~]# vi /etc/hosts
- 168.31.245 dg
-
3.YUM安装依赖包
(1)配置yum源
[root@rac1 ~]# mkdir –p /mnt/cdrom
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vi rhel-source.repo
修改内容如下
[rhel6.5]
name=Red Hat 6.5
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
(2)安装rpm包
yum install binutils -y
yum install compat-libcap1 -y
yum install compat-libstdc++-33 -y
yum install compat-libstdc++-33.i686 -y
yum install gcc -y
yum install gcc-c++ -y
yum install glibc -y
yum install glibc.i686 -y
yum install glibc-devel -y
yum install glibc-devel.i686 -y
yum install ksh -y
yum install libgcc -y
yum install libgcc.i686 -y
yum install libstdc++ -y
yum install libstdc++.i686 -y
yum install libstdc++-devel -y
yum install libstdc++-devel.i686 -y
yum install libaio -y
yum install libaio.i686 -y
yum install libaio-devel -y
yum install libaio-devel.i686 -y
yum install libXext -y
yum install libXext.i686 -y
yum install libXtst -y
yum install libXtst.i686 -y
yum install libX11 -y
yum install libX11.i686 -y
yum install libXau -y
yum install libXau.i686 -y
yum install libxcb -y
yum install libxcb.i686 -y
yum install libXi -y
yum install libXi.i686 -y
yum install make -y
yum install sysstat -y
yum install unixODBC -y
yum install unixODBC-devel -y
4.修改内核
vi /etc/sysctl.conf
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
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
kernel.shmmax = 4398046511104
kernel.shmall = 1073741824
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
kernel.panic_on_oops= 1
5.设置Oracle和Grid用户的SHELL限制
[[email protected] ~]# vi /etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
6.关闭防火墙
[email protected] ~]#service iptables stop
[[email protected] ~]#chkconfig iptables off
[[email protected] ~]#service ip6tables stop
[[email protected] ~]#chkconfig ip6tables off
有时候,远程节点会关闭SSH的连接,为了防止这种情况发生,需要修改配置文件sshd_config
vi/etc/ssh/sshd_config
LoginGraceTime 0
“LoginGraceTime”设置如果用户不能成功登录,在切断连接之前服务器需要等待的时间(以秒为单位)
[[email protected] ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
7.创建用户和组及相关目录
groupadd -g 1000oinstall
groupadd -g 1001dba
groupadd -g 1002oper
groupadd -g 1003backupdba
groupadd -g 1004dgdba
groupadd -g1005 kmdba
groupadd -g1006 asmdba
groupadd -g1007 asmoper
groupadd -g1008 asmadmin
useradd -u1100 -g oinstall -G dba,oper,backupdba,dgdba,kmdba,asmdba,asmadmin oracle
passwd oracle
mkdir -p /u01/app/oracle/product/12.1.0.1/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01/
8.修改oracle和grid的环境变量
Oracle用户的profile内容如下,注意红色SID字段需要修改,一般和节点的主机名一致即可:
export ORACLE_SID=rac1 #export ORACLE_SID=rac2 export ORACLE_UNQNAME=rac export ORACLE_HOSTNAME=rac1 export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/12.1.0.1/db_1 export ORACLE_TERM=xterm export PATH=/usr/sbin:$PATH export PATH=$ORACLE_HOME/bin:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib ulimit -u 16384 -n 65536 umask 022 |
9.安装灾备的数据库软件
[[email protected] ~]# su – oracle
[[email protected] database]$ ./runInstaller
这里选择只安装数据库软件,数据库的创建等安装完软件。
跑脚本~
10.主备库参数修改
主库:
ip:192.168.31.240 hostname:rac1 sid: rac1
ip:192.168.31.241 hostname:rac2 sid: rac2
备库
ip:192.168.31.245 hostname:dg sid: cai
主库(RAC):
SQL> create pfile=‘/tmp/pfile.ora‘ fromspfile;
[[email protected] dbs]$ vi /tmp/pfile.ora
rman target /
backup as compressed backup database;
ALTER DATABASE CREATE STANDBY CONTROLFILEAS ‘/tmp/control01.ctl‘;
vi /tmp/pfile.ora
增加以下内容
DB_UNIQUE_NAME=rac
LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(rac,cai)‘
LOG_ARCHIVE_DEST_1=
‘LOCATION=USE_DB_RECOVERY_FILE_DEST
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=rac‘
LOG_ARCHIVE_DEST_2=
‘SERVICE=cai LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=cai‘
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
FAL_SERVER=cai
DB_FILE_NAME_CONVERT=‘/u01/app/oracle/oradata/cai‘,‘+DATA/RAC/DATAFILE‘
LOG_FILE_NAME_CONVERT=‘/u01/app/oracle/oradata/cai‘,‘+DATA/RAC/DATAFILE‘
STANDBY_FILE_MANAGEMENT=AUTO
create spfile=‘+DATA/rac/spfilerac.ora‘from pfile=‘/tmp/pfile.ora‘
shutdown immediate
startup
cd $ORACLE_HOME/network/admin
vi tnsnames.ora
增加以下内容
rac1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.240)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
(INSTANCE_NAME = rac1)
)
)
rac2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.241)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
(INSTANCE_NAME = rac2)
)
)
cai =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.245)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cai)
)
)
主库增加standbylog
alter database add standby logfile thread 1group 7 (‘+data/rac/ONLINELOG/standby7.log‘) size 50m,
group 8(‘+data/rac/ONLINELOG/standby8.log‘) size 50m,
group 9(‘+data/rac/ONLINELOG/standby9.log‘) size 50m,
group 10(‘+data/rac/ONLINELOG/standby10.log‘) size 50m,
group 11(‘+data/rac/ONLINELOG/standby11.log‘) size 50m,
group 12(‘+data/rac/ONLINELOG/standby12.log‘) size 50m;
alter database add standby logfile thread 2group 13 (‘+data/rac/ONLINELOG/standby13.log‘) size 50m,
group 14(‘+data/rac/ONLINELOG/standby14.log‘) size 50m,
group 15(‘+data/rac/ONLINELOG/standby15.log‘) size 50m,
group 16(‘+data/rac/ONLINELOG/standby16.log‘) size 50m,
group 17 (‘+data/rac/ONLINELOG/standby17.log‘)size 50m,
group 18(‘+data/rac/ONLINELOG/standby18.log‘) size 50m;
SQL> select GROUP#,TYPE,MEMBER fromv$logfile;
GROUP# TYPE MEMBER
------ ------- --------------------------------------------------
1 ONLINE +DATA/RAC/ONLINELOG/group_1.258.886338827
7 STANDBY +DATA/rac/ONLINELOG/standby7.log
2 ONLINE +DATA/RAC/ONLINELOG/group_2.259.886338831
8 STANDBY +DATA/rac/ONLINELOG/standby8.log
3 ONLINE +DATA/RAC/ONLINELOG/group_3.266.886342575
9 STANDBY +DATA/rac/ONLINELOG/standby9.log
4 ONLINE +DATA/RAC/ONLINELOG/group_4.267.886342583
10 STANDBY +DATA/rac/ONLINELOG/standby10.log
11 STANDBY +DATA/rac/ONLINELOG/standby11.log
12 STANDBY +DATA/rac/ONLINELOG/standby12.log
13 STANDBY +DATA/rac/ONLINELOG/standby13.log
GROUP# TYPE MEMBER
------ ------- --------------------------------------------------
14 STANDBY +DATA/rac/ONLINELOG/standby14.log
15 STANDBY +DATA/rac/ONLINELOG/standby15.log
16 STANDBY +DATA/rac/ONLINELOG/standby16.log
17 STANDBY +DATA/rac/ONLINELOG/standby17.log
18 STANDBY +DATA/rac/ONLINELOG/standby18.log
select FILE#,name from v$datafile;
FILE# NAME
----------------------------------------------------------------------
1 +DATA/RAC/DATAFILE/system.260.886338839
2 +DATA/RAC/DATAFILE/sysaux.261.886338865
3 +DATA/RAC/DATAFILE/undotbs2.262.886338879
4 +DATA/RAC/DATAFILE/undotbs1.264.886338927
5 +DATA/RAC/DATAFILE/users.265.886338931
SQL> select FILE#,name from v$tempfile;
FILE# NAME
----------------------------------------------------------------------
1 +DATA/RAC/TEMPFILE/temp.263.886338883
备库:
cd $ORACLE_HOME/network/admin
vi listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = cai)
(ORACLE_HOME = /u01/app/oracle/12.1.0.1/db_1)
(SID_NAME = cai)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.245)(PORT = 1521))
)
cd $ORACLE_HOME/network/admin
vi tnsnames.ora
增加以下内容
rac1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.240)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
(INSTANCE_NAME = rac1)
)
)
rac2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.241)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
(INSTANCE_NAME = rac2)
)
)
cai =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.31.245)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cai)
)
)
修改备库的pfile
vi pfile.ora
#rac2.__data_transfer_cache_size=0
#rac1.__data_transfer_cache_size=0
*.__data_transfer_cache_size=0
#rac2.__db_cache_size=197132288
#rac1.__db_cache_size=121634816
*.__db_cache_size=121634816
#rac2.__java_pool_size=4194304
#rac1.__java_pool_size=4194304
*.__java_pool_size=4194304
#rac1.__large_pool_size=8388608
#rac2.__large_pool_size=8388608
*.__large_pool_size=8388608
#rac1.__oracle_base=‘/u01/app/oracle‘#ORACLE_BASEset from environment
#rac2.__oracle_base=‘/u01/app/oracle‘#ORACLE_BASEset from environment
*.__oracle_base=‘/u01/app/oracle‘
#rac2.__pga_aggregate_target=360710144
#rac1.__pga_aggregate_target=440401920
*.__pga_aggregate_target=440401920
#rac2.__sga_target=436207616
#rac1.__sga_target=356515840
*.__sga_target=356515840
#rac2.__shared_io_pool_size=8388608
#rac1.__shared_io_pool_size=12582912
*.__shared_io_pool_size=12582912
#rac1.__shared_pool_size=201326592
#rac2.__shared_pool_size=209715200
*.__shared_pool_size=209715200
#rac2.__streams_pool_size=0
#rac1.__streams_pool_size=0
*.__streams_pool_size=0
*.audit_file_dest=‘/u01/app/oracle/admin/cai/adump‘
*.audit_trail=‘db‘
#*.cluster_database=true
*.compatible=‘12.1.0.0.0‘
*.control_files=‘/u01/app/oracle/oradata/cai/control01.ctl‘
*.db_block_size=8192
*.db_domain=‘‘
*.db_name=‘rac‘
*.db_recovery_file_dest=‘/u01/app/oracle/flash‘
*.db_recovery_file_dest_size=5000m
*.diagnostic_dest=‘/u01/app/oracle‘
#rac1.instance_number=1
#rac2.instance_number=2
*.log_archive_format=‘%t_%s_%r.dbf‘
*.memory_target=760m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile=‘exclusive‘
#rac2.thread=2
#rac1.thread=1
#rac2.undo_tablespace=‘UNDOTBS1‘
#rac1.undo_tablespace=‘UNDOTBS2‘
*.undo_tablespace=‘UNDOTBS1‘
DB_UNIQUE_NAME=cai
LOG_ARCHIVE_CONFIG=‘DG_CONFIG=(rac,cai)‘
LOG_ARCHIVE_DEST_1=
‘LOCATION=USE_DB_RECOVERY_FILE_DEST
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=cai‘
LOG_ARCHIVE_DEST_2=
‘SERVICE=rac1 LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=rac‘
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
FAL_SERVER=‘rac1‘,‘rac2‘
DB_FILE_NAME_CONVERT=‘+DATA/RAC/DATAFILE‘,‘/u01/app/oracle/oradata/cai‘
LOG_FILE_NAME_CONVERT=‘+DATA/RAC/ONLINELOG‘,‘/u01/app/oracle/oradata/cai‘
STANDBY_FILE_MANAGEMENT=AUTO
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/cai/system.260.886338839
/u01/app/oracle/oradata/cai/sysaux.261.886338865
/u01/app/oracle/oradata/cai/undotbs2.262.886338879
/u01/app/oracle/oradata/cai/undotbs1.264.886338927
/u01/app/oracle/oradata/cai/users.265.886338931
rman恢复备库
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
set newname for datafile 1 to ‘/u01/app/oracle/oradata/cai/system.dbf‘;
set newname for datafile 2 to ‘/u01/app/oracle/oradata/cai/sysaux.dbf‘;
set newname for datafile 3 to ‘/u01/app/oracle/oradata/cai/undotbs2.dbf‘;
set newname for datafile 4 to ‘/u01/app/oracle/oradata/cai/undotbs1.dbf‘;
set newname for datafile 5 to ‘/u01/app/oracle/oradata/cai/users.dbf‘;
set newname for tempfile 1 to ‘/u01/app/oracle/oradata/cai/temp.dbf‘;
restore database;
switch datafile all;
switch tempfile all;
release channel c1;
release channel c2;
}
创建standby log(如果主库在创建standby logfile后,创建了standby controlfile则不需要此步骤) (standby redo log日志组数量=(n+1)*thread n:为生产日志组数量)
alter database add standby logfile thread 1group 7 (‘/u01/app/oracle/oradata/cai/standby7.log‘) size 50m,
group 8(‘/u01/app/oracle/oradata/cai/standby8.log‘) size 50m,
group 9(‘/u01/app/oracle/oradata/cai/standby9.log‘) size 50m,
group 10(‘/u01/app/oracle/oradata/cai/standby10.log‘) size 50m,
group 11(‘/u01/app/oracle/oradata/cai/standby11.log‘) size 50m,
group 12(‘/u01/app/oracle/oradata/cai/standby12.log‘) size 50m;
alter database add standby logfile thread 2group 13 (‘/u01/app/oracle/oradata/cai/standby13.log‘) size 50m,
group 14 (‘/u01/app/oracle/oradata/cai/standby14.log‘)size 50m,
group 15(‘/u01/app/oracle/oradata/cai/standby15.log‘) size 50m,
group 16(‘/u01/app/oracle/oradata/cai/standby16.log‘) size 50m,
group 17(‘/u01/app/oracle/oradata/cai/standby17.log‘) size 50m,
group 18 (‘/u01/app/oracle/oradata/cai/standby18.log‘)size 50m;
--查看日志组
select * from v$logfile;
--取消应用日志
alter database recover managed standbydatabase cancel;
--应用日志,active dataguard
alter database recover managed standbydatabase using current logfile disconnect from session;
--备库查看没有应用的日志
select THREAD#,SEQUENCE#,APPLIED from v$archived_log where APPLIED=‘NO‘;
--查看数据库状态
selectOPEN_MODE,PROTECTION_MODE,DATABASE_ROLE from v$database;
--查看FRA使用率
select * from V$RECOVERY_FILE_DEST;
--查看FRA使用率
select * from v$flash_recovery_area_usage;
11.主备切换
主库:
ip:192.168.31.240 hostname:rac1 sid: rac1
ip:192.168.31.241 hostname:rac2 sid: rac2
备库
ip:192.168.31.245 hostname:dg sid: cai
主库状态
SQL> show parameter fal_server
NAME TYPE VALUE
----------------------------------------------- ------------------------------
fal_server string cai
SQL> select protection_mode,database_role,force_logging,open_mode,switchover_statusfrom gv$database;
PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
-------------------- ---------------- ------------------------ --------------------
MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY
MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY
SQL> show parameter db_file_name_convert
NAME TYPE VALUE
----------------------------------------------- ------------------------------
db_file_name_convert string /u01/app/oracle/oradata/cai, +
DATA/RAC/DATAFILE
pdb_file_name_convert string
SQL> show parameterlog_file_name_convert
NAME TYPE VALUE
----------------------------------------------- ------------------------------
log_file_name_convert string /u01/app/oracle/oradata/cai, +DATA/RAC/DATAFILE
备库状态
SQL> show parameter fal_server
NAME TYPE VALUE
----------------------------------------------- ------------------------------
fal_server string rac1, rac2
PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
-------------------- ---------------- ------------------------ --------------------
MAXIMUM PERFORMANCE PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED
SQL> show parameter db_file_name_convert
NAME TYPE VALUE
----------------------------------------------- ------------------------------
db_file_name_convert string +DATA/RAC/DATAFILE, /u01/app/o
racle/oradata/cai
pdb_file_name_convert string
SQL> show parameterlog_file_name_convert
NAME TYPE VALUE
----------------------------------------------- ------------------------------
log_file_name_convert string +DATA/RAC/ONLINELOG, /u01/app/
oracle/oradata/cai
SQL> selectprotection_mode,database_role,force_logging,open_mode,switchover_status fromv$database;
PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
-------------------- ---------------- ------------------------ --------------------
MAXIMUM PERFORMANCE PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED
停止RAC节点二
SQL> show parameter instance_name
NAME TYPE VALUE
----------------------------------------------- ------------------------------
instance_name string rac2
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
-- 如果不关闭切换时会报错
ALTER DATABASE COMMIT TO SWITCHOVER TOSTANDBY *
ORA-01105: mount is incompatible withmounts by other instances
再次看RAC主库的状态
--切换角色前
SQL> selectprotection_mode,database_role,force_logging,open_mode,switchover_status fromgv$database;
PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
-------------------- ---------------- ------------------------ --------------------
MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY
--切换成备库
SQL> show parameter instance_name
NAME TYPE VALUE
----------------------------------------------- ------------------------------
instance_name string rac1
SQL> alter database commit to switchoverto physical standby with session shutdown;
Database altered.
--将RAC两个库mount起来(原主库,现在备库)
SQL> startup mount
ORACLE instance started.
Total System Global Area 793350144 bytes
Fixed Size 2293392 bytes
Variable Size 704643440 bytes
Database Buffers 83886080 bytes
Redo Buffers 2527232 bytes
Database mounted.
--切换角色后
SQL> selectprotection_mode,database_role,force_logging,open_mode,switchover_status fromgv$database;
PROTECTION_MODE DATABASE_ROLE FORCE_LOGGING OPEN_MODE SWITCHOVER_STATUS
-------------------- ------------------------------------------------------- ----------------------------------------
MAXIMUM PERFORMANCE PHYSICAL STANDBY YES MOUNTED RECOVERYNEEDED
MAXIMUM PERFORMANCE PHYSICAL STANDBY YES MOUNTED RECOVERYNEEDED
cai库(原备库,现在主库)
--切换角色前
SQL> select protection_mode,database_role,force_logging,open_mode,switchover_statusfrom v$database;
PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
-------------------- ---------------- ------------------------ --------------------
MAXIMUM PERFORMANCE PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
Database altered
--切换角色后
SQL> selectprotection_mode,database_role,force_logging,open_mode,switchover_status fromv$database;
PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
-------------------- ---------------- ------------------------ --------------------
MAXIMUM PERFORMANCE PRIMARY YES MOUNTED NOT ALLOWED
SQL> alter database open;
Database altered.
RAC库(原主库,现备库)
--两个节点都要OPEN
SQL> alter database open;
Database altered.
SQL> alter database recover managedstandby database using current logfile disconnect from session;
Database altered.
SQL> alter database recover managedstandby database cancel;
Database altered.
SQL> alter database recover managedstandby database using current logfile disconnect from session;
Database altered.
SQL> select OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE from gv$database;
OPEN_MODE PROTECTION_MODE DATABASE_ROLE
-------------------- ------------------------------------
READ ONLY WITH APPLY MAXIMUMPERFORMANCE PHYSICAL STANDBY
READ ONLY WITH APPLY MAXIMUMPERFORMANCE PHYSICAL STANDBY
--测试下
cai库(原备库,现主库)
SQL> create table zhi(namevarchar2(10),sal int);
Table created.
SQL> insert into zhi values (‘cai‘,9000);
1 row created.
SQL> insert into zhi values (‘zhi‘,9002);
1 row created.
SQL> commit;
Commit complete.
RAC库(原主库,现备库)
SQL> select * from zhi;
NAME SAL
----- ----------
cai 9000
zhi 9002