Oracle DG数据库升级(11.2.0.1-11.2.0.4)
Posted 杨新建的技术学习之路
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle DG数据库升级(11.2.0.1-11.2.0.4)相关的知识,希望对你有一定的参考价值。
数据库在使用一段时间后总是会面临需要升级的情况,DBA日常的工作中的一项工作就是负责数据库升级,以解决数据库的bug,还有就是提高性能。
Oracle DG 环境数据库升级有两种方案:(1) 从11.2.0.1 PHYSICAL STANDBY DATABAES 升级到11.2.0.4 PHYSICAL STANDBY DATABAES (2) 把PHYSICAL STANDBY 转临时的逻辑备库,升级逻辑备库后,切换,再升级原主库,这就是所说的滚动升级
在选择方案之前,需要了解Physical DG和Logical DG的区别:
Physical Standby使用的是Media Recovery 技术,在数据块级别进行恢复,这种方式没有数据类型的限制,可以保证两个数据库完全一致。 Physical Standby数据库只能以只读方式打开。
Logical Standby使用的是Logminer 技术,通过把日志内容还原成SQL 语句,然后SQL引擎执行这些语句,Logical Standby不支持所有数据类型,可以在视图DBA_LOGSTDBY_UNSUPPORTED 中查看不支持的数据类型,如果使用了被忽略的数据类型,则不能保证数据库完全一致,因为涉及到不支持的数据类型的相关操作会被忽略掉。
通过比较两种方案的区别,这里决定采用第一种方案,原因是数据库的表里有逻辑备库不支持的数据类型,为了避免相关操作被忽略掉,所以选用第一种方案。
升级思路如下:
① 主库备库安装新版本软件;
② 主库暂停归档传输;关闭主库
③ 主库升级数据库,完成后主库启用归档传输
④ 备库升级或者重做
⑤ 备库开启日志恢复后打开数据库
⑥ 主备库做切换来验证
升级方案的步骤如下:
当前环境是11.2.0.1.0版本的物理DG环境
2.将所需的数据库软件及补丁包上传到指定的目录/home/oracle/orasoft
3.创建新的ORACLE_HOME目录,更改.bash_profile文件,安装oracle软件,打补丁
这部分操作主备库都需要做,更改bash_profile文件
[oracle@oracle142 ~]$ mkdir -p /opt/app1/db11g
[oracle@oracle142 ~]$ vi .bash_profile
LANG='en_US.UTF-8'
TMP=/opt/app/tmp
TMPDIR=/opt/app/tmp
#ORACLE_BASE=/opt/app
ORACLE_BASE=/opt/app1
ORACLE_HOME=$ORACLE_BASE/db11g
ORACLE_SID=orcl
#ORACLE_HOME=$ORACLE_BASE/oracle
#ORACLE_SID=test12c
LD_LIBRARY_PATH=$ORACLE_HOME/lib
OGG_HOME=/opt/ogg11
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:$OGG_HOME/bin
export PATH ORACLE_BASE ORACLE_HOME ORACLE_SID LANG TMP TMPDIR OGG_HOME LD_LIBRARY_PATH
[oracle@oracle142 orasoft]$ unzip p13390677_112040_Linux-x86-64_1of7.zip
[oracle@oracle142 orasoft]$ unzip p13390677_112040_Linux-x86-64_2of7.zip
[oracle@oracle142 orasoft]$ cd database
[oracle@oracle142 database]$ ls
install readme.html response rpm runInstaller sshsetup stage welcome.html
[oracle@oracle142 database]$ ./runInstaller
安装过程(可启动图形化界面安装或者静默安装的方式都可以)
执行上图脚本
安装完成之后开始打补丁,打补丁需要首先把Opatch这个包先解压到ORACLE_HOME目录下,再解压补丁包打补丁。
4.安装完毕之后,准备开始做升级,升级之前需要做准备工作:
① 停止业务,暂停连接数据库主备库的应用服务器
② 备份主库数据库,数据大于一切,所以一定要备份
③ 如果数据库flashback开启着,那么可以创建一个 restore point
以上工作完成之后就可以开始升级了
4.1 主库暂停归档传输
SQL> alter system set log_archive_dest_state_2=defer ;
System altered.
SQL> show parameter log_archive_dest_state_2
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_2 string DEFER
4.2 关闭主库,关闭监听,修改环境变量
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@oracle142 ~]$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-MAY-2018 18:29:11
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.16.16.202)(PORT=1521)))
The command completed successfully
更改完成后,source使得profile生效
[oracle@oracle142 ~]$ source .bash_profile
[oracle@oracle142 ~]$ cat .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
LANG='en_US.UTF-8'
TMP=/opt/app/tmp
TMPDIR=/opt/app/tmp
#ORACLE_BASE=/opt/app
ORACLE_BASE=/opt/app1
ORACLE_HOME=$ORACLE_BASE/db11g
ORACLE_SID=orcl
LD_LIBRARY_PATH=$ORACLE_HOME/lib
OGG_HOME=/opt/ogg11
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:$OGG_HOME/bin
export PATH ORACLE_BASE ORACLE_HOME ORACLE_SID LANG TMP TMPDIR OGG_HOME LD_LIBRARY_PATH
4.3 主库将参数文件、密码文件、监听文件、解析文件都拷贝到相关的新目录
[oracle@oracle142 ~]$ cp /opt/app/db11g/dbs/* /opt/app1/db11g/dbs/
[oracle@oracle142 ~]$ cp -r /opt/app/db11g/network/admin/* /opt/app1/db11g/network/admin/
[oracle@oracle142 ~]$ vi /etc/oratab
orcl:/opt/app1/db11g:N
[oracle@oracle142 ~]$ cd $ORACLE_HOME/network/admin
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.16.16.202)(PORT = 1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orclstd)
(SERVICE_NAME = orclst)
(ORACLE_HOME=/opt/app/db11g)
(SID_NAME=orcl))
(SID_DESC=
(GLOBAL_DBNAME=orclst_DGMGRL)
(SERVICE_NAME = orclstd)
(ORACLE_HOME=/opt/app/db11g)
(SID_NAME=orcl))
)
ADR_BASE_LISTENER = /opt/app1
4.4 主库启动监听,启动数据库,运行升级脚本
[oracle@oracle142 admin]$ lsnrctl start
[oracle@oracle142 admin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon May 7 19:07:05 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup upgrade;
ORACLE instance started.
Total System Global Area 3073216512 bytes
Fixed Size 2257192 bytes
Variable Size 1560284888 bytes
Database Buffers 1493172224 bytes
Redo Buffers 17502208 bytes
Database mounted.
Database opened.
在升级前可以执行dbupgdiag脚本(收集数据库升级/迁移诊断信息的脚本 (dbupgdiag.sql) (Doc ID 1577288.1))
SQL> @/home/oracle/dbupgdiag.sql
SQL> @?/rdbms/admin/utlu112i.sql
再执行catupgrd.sql升级脚本,执行完后会正常的关闭数据库
SQL>spool /home/oracle/upgrade.log
SQL>@?/rdbms/admin/catupgrd.sql;
执行完毕之后,正常启动数据库
验证组件是否升级成功
SQL> @?/rdbms/admin/utlu112s.sql
查看升级后的无效对象
SQL> @?/rdbms/admin/utluiobj.sql
执行catuppst.sql脚本
SQL>@$ORACLE_HOME/rdbms/admin/catuppst.sql;
编译无效对象
SQL>@$ORACLE_HOME/rdbms/admin/utlrp.sql;
执行完毕之后,主库的升级结束。
最后主库需要修改log_archive_dest_state_2参数为enable
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
5. 备库升级
5.1 将参数文件、密码文件、监听文件、解析文件都拷贝到相关的新目录
[oracle@oracle125 ~]$ cp /opt/app/db11g/dbs/* /opt/app1/db11g/dbs/
[oracle@oracle125 ~]$ cp -r /opt/app/db11g/network/admin/* /opt/app1/db11g/network/admin/
[oracle@oracle125 admin]$ vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.16.16.211)(PORT = 1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orclst)
(SERVICE_NAME = orclst)
(ORACLE_HOME=/opt/app1/db11g)
(SID_NAME=orcl))
(SID_DESC=
(GLOBAL_DBNAME=orclst_DGMGRL)
(SERVICE_NAME = orclst)
(ORACLE_HOME=/opt/app1/db11g)
(SID_NAME=orcl))
)
ADR_BASE_LISTENER = /opt/app1
5.2 更改.bash_profile文件,启动监听
[oracle@oracle125 admin]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 08-MAY-2018 11:00:01
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /opt/app1/db11g/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /opt/app1/db11g/network/admin/listener.ora
Log messages written to /opt/app1/diag/tnslsnr/oracle125/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.16.16.211)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.16.16.211)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 08-MAY-2018 11:00:06
Uptime 0 days 0 hr. 0 min. 4 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/app1/db11g/network/admin/listener.ora
Listener Log File /opt/app1/diag/tnslsnr/oracle125/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.16.16.211)(PORT=1521)))
Services Summary...
Service "orclst" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Service "orclst_DGMGRL" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
5.3 启动数据库到mount状态,在recover备库
[oracle@oracle125 admin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue May 8 11:12:29 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 3073216512 bytes
Fixed Size 2257192 bytes
Variable Size 1560284888 bytes
Database Buffers 1493172224 bytes
Redo Buffers 17502208 bytes
Database mounted.
SQL> recover managed standby database using current logfile disconnect;
Media recovery complete.
此时在告警日志中会看到如下:表示正在等待mem中的日志,recover完成了
在主库中看到
SQL> select process,status,sequence# from v$managed_standby;
PROCESS STATUS SEQUENCE#
--------- ------------ ----------
ARCH CLOSING 99
ARCH CLOSING 99
ARCH CLOSING 95
ARCH CLOSING 104
LGWR WRITING 106
确认recover完成后再打开数据库,否则会报错
SQL> alter database open read only;
Database altered.
到此,备库升级完成。
备库开启实时同步
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION parallel 6;
Database altered.
6.主备库切换测试验证
升级完成之后,通过主备库的来回切换测试来验证。
6.1查看主备库角色
主库
备库
6.2主库切换为备库
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.
SQL> shutdown immediate;
ORA-01012: not logged on
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 3073216512 bytes
Fixed Size 2257192 bytes
Variable Size 1577062104 bytes
Database Buffers 1476395008 bytes
Redo Buffers 17502208 bytes
SQL> alter database mount standby database;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
6.3备库切换为主库
SQL> alter database commit to switchover to primary;
Database altered.
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area 3073216512 bytes
Fixed Size 2257192 bytes
Variable Size 1560284888 bytes
Database Buffers 1493172224 bytes
Redo Buffers 17502208 bytes
Database mounted.
Database opened.
SQL> alter system switch logfile;
System altered.
6.4 原先的主库,当前的备库操作
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open read only;
Database altered.
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION parallel 6;
Database altered.
6.5 查看主备库状态以及延迟情况
新主库查看
新备库查看
至此验证完毕。
以上是关于Oracle DG数据库升级(11.2.0.1-11.2.0.4)的主要内容,如果未能解决你的问题,请参考以下文章