第十章:数据库的升级和补丁

点击数:2147发布日期:2020-04-19 15:06:45 来源:老鹰

第十章:数据库的升级和补丁

10.1 版本补丁概况

    数据库系统规划好之后,就要安装一个全新的数据库。安装的时候,一定要安装最后的稳定的版本,不能安装一个最初发行的版本。购买正版的OracleOracle官方给的那个介质就是最初发行的版本,安装完成之后必须打补丁,或者直接从https://support.oracle.com上下载最后的版本和补丁安装才行。如果只安装一个10.2.0.111.2.0.112.1.0.2.0这样的版本,那bug就多了,说是后患无穷有点过分,但跑起生产来,警告日志的报错肯定是一堆堆的,况且还没办法处理,只能升级,报错太多了。

    Oracle软件没有序列号,从网上免费Down的和购买的正版的光盘介质完全一样,下载后你可以用于学习和测试运行。但只能下载最初发行的版本,在https://support.oracle.com上下载,是需要账号的,这个账号需要购买授权之后才能申请到,账号是需要花钱的。Oracle的理念就是最初发行的版本随便用,等大家用的顺手了,开始卖授权,卖服务,有了账号才能升级到稳定的版本。数据库的授权就是一张纸,授权这张纸卖的很贵,让20%的大公司大单位给Oracle提供80%的利润。

    刚才说了,千万不要把数据库装成10.2.0.1.011.2.0.1.012.1.0.2.0这样的版本,这样的版本bug很多,很难长期稳定运行。那么,要装成什么版本呢?

    9i要装成9.2.0.8.6

    10g要装成10.2.0.5.12

    11g当前的最新的要装成11.2.0.4.7

    12c要安装12.1.0.2.4

    12c因为目前直接上生产的还比较少,预计201612c才能陆续安装生产。11g还有三四年的旺盛期,一般客户在投产了以后,三四年是不会再轻易动它了。11g Grid Infrastructure PSU补丁现在很大,看来11.2.0.4也不是11g最后的一个release版本,还要更新。

   

    版本11.2.0.4.7这几个数字分别代表什么意思呢?我们分拆成112047来说明。

    11Major Database Release Number,数据库的主版本号,革命性的更新会反应在这个版本号上,如8i9i10gi代表internetg代表grid,是从网络到网格的变化,grid来源于电网,数据库系统形成一个像电网一样的服务系统,就是有几个电厂损坏或毁灭,也不影响整个电网的运行和提供服务。从11g12cc代表cloud云。云是分布式计算,将大的计算分拆成较小的子程序。从气象角度讲,水气在天上叫云,在地上叫雾,搞不好就弄成霾,云雾霾要分清楚。

    2Database Maintenance Release Number,数据库维护版本号,包括一些新功能的引入,大的功能变革,会体现在这个版本上,11g2版就不支持裸设备了,在第1版还支持。
    0
代表Application Server Release Number,反映Oracle应用服务的发行版本号。

    4Component Specific Release Number,组件特效发行版本号。组件的每次更新都会反映在这个版本上。其中就包含补丁包集合,所以更新这个版本号很重要,影响数据库的稳定性,最好更新至最后一个发布版本。

    7代表Platform-Specific Release Number,操作系统平台相关的补丁包或补丁包集合,这个补丁包,也应该更新到最新补丁,它修复了一些特定的bug,增强了安全性。

10.2 补丁的分类

    Release发行的标准版本,如11.2.0.1.012.1.0.2.0可以在www.oracle.com上公开下载。

    PSR (Patch Set Release),主版本发布的补丁集,修复了较多的bug,比如11.2.0.1是一个主版本,那么11.2.0.311.2.0.4就是两个patch set,这些补丁经过了严格的测试,可以放心安全的使用,所以务必安装最新的patch set

    PSU (Patch Set Updates) 补丁集升级,就是我们通常说的小补丁。打完之后,它体现在11.2.0.4.7的最后一位上。目前最新的就是这个7。每个季度更新一次,是累积补丁,后一个包含前一个。可以修复一些较严重的问题。最新的PSU可以在support.oracle.com上搜PSU查找相关文档,一般结果都排在最上面,确认最新的PSU补丁。这些补丁经过了严格的集成测试,推荐打到最新的PSU

    CPU (Critical Patch Update) 直接翻译就是:危险的补丁升级。也是三个月更新一次,累积补丁,主要修复安全方面的问题。

    One-Off/Interim Patch,一次性,暂时性补丁,为了解决某一(几)个特定的问题,暂时先打一个小补丁,做为临时的解决办法。一般在测试库上测试通过后,再打到生产库上。

    Bundle Patches 补丁包或翻译成windows补丁包,在windows平台上的补丁不叫PSU,叫bundle。也是累积补丁,最新的包含之前的补丁。同样建议安装最新的bundle patch

10.3 升级前的准备工作

    为了防止在升级过程中出现问题,我们需要有一套回退机制,在紧急状态下,使用这套方案,避免升级失败造成严重损失。最差的结果就是相当于我们没有升级,还是原来的版本,还是原来的数据库状态,不至于数据库无法启动,到了生产的时间,还是不能恢复服务,那问题就严重了。

    准备阶段的工作就应该包括:

    1、备份数据库,RMANexpdp导出。

    2、备份CRS软件,root用户使用tar -cvf命令备份安装目录。

    3、备份数据库软件,root用户使用tar -cvf命令备份安装目录。

    4、备份ASM盘。asmcmd md_backup命令。

10.4 版本升级

    9i数据库,必须先安装9.2.0.1.0然后再升级至9.2.0.8.0,然后再打PSUbundle补丁至9.2.0.8.610g 也类似,必须先安装10.2.0.1.0,然后升级至10.2.0.5.0,最后打补丁至10.2.0.5.12。从版本角度讲,我们的数据库就算安装完美了。

    11g9i 10g不一样,如果我们原来的生产库是11.2.0.3.0,我们可以升级至11.2.0.4.0,再打补丁至11.2.0.4.7。我们也可以另起一个ORACLE_HOME,新安装一套11.2.0.4.7的软件,用这个新安装的软件,升级并启动数据库,最后可以删除老的11.2.0.3的软件。我们在全新安装的时候,不需要再安装11.2.0.1版本了,我们直接安装11.2.0.4.0版本,然后打一下11.2.0.4.7的补丁就可以了,前几个版本发布的介质,都用不着了,而9i 10g必须要用9.2.0.110.2.0.1的介质。应该说11g在补丁方面比9i 10g做的要好。

   

    本章节主要介绍升级小补丁PSU。升级组件发行版本,我们放在数据库安装章节。

    10.4.1  grid打补丁11.2.0.4.0升级至11.2.0.4.7

    1、在support.oracle.com下载最新的补丁包,其中patch:20760982是数据库补丁集,patch:20996923grid infrastructure补丁集。我们还需要一个最新的OPatch 11.2.0.3.11,也就是p6880880_112000_Linux-x86-641.zip,按照README的要求,打patch:20996923这个补丁,OPatch的版本至少是OPatch utility version 11.2.0.3.6或更高的版本。

拷贝至主机,我们这里放在/oramed下。

    2、解压下载的补丁包。

    使用root用户,可以将下载的三个zip文件权限改为777,对应的属性grid的补丁,权限改为grid.oinstall,数据库的补丁权限改为oracle.oinstall

cd /oramed/

[root@yingshu oramed]# chown -R grid.oinstall p20996923_112040_Linux-x86-64.zip

[root@yingshu oramed]# chown -R grid.oinstall p6880880_112000_Linux-x86-641.zip

[root@yingshu oramed]# chown -R oracle.oinstall p20760982_112040_Linux-x86-64.zip

[root@yingshu oramed]# chmod 777 p*.zip

[oracle@yingshu oramed]$ unzip p20996923_112040_Linux-x86-64.zip

[oracle@yingshu oramed]$ unzip p20760982_112040_Linux-x86-64.zip

[oracle@yingshu oramed]$ unzip p6880880_112000_Linux-x86-641.zip

    3、更新opatch

    整个升级过程,需要参考readme文档,readme文档在补丁解压后的文件夹里。

    我们这里的CRS_HOME/u01/app/grid/crs,我们要把新的opatch解压至这里面,将老的opatch废除。

    使用root用户先把crs这个文件夹的权限改为777

    然后将opatch压缩包拷贝至CRS_HOME下;

    将旧的opatch改名为OPatch.bak

    使用grid用户解压新的opatch,新的opatch安装完毕。

    检查新的opatch版本。

[root@yingshu grid]# su - root

[root@yingshu ~]# cd /u01/app/grid/

[root@yingshu grid]# chmod 777 crs

su - grid

$cp p6880880_112000_Linux-x86-641.zip  $ORACLE_HOME/p6880880_112000_Linux-x86-641.zip

[grid@yingshu crs]$ mv  OPatch  OPatch.ba

[grid@yingshu crs]$ unzip p6880880_112000_Linux-x86-641.zip

[grid@yingshu OPatch]$ ./opatch lsinv

Oracle Interim Patch Installer version 11.2.0.3.11

Copyright (c) 2015, Oracle Corporation.  All rights reserved.


Oracle Home       : /u01/app/grid/crs

Central Inventory : /u01/app/oraInventory

   from           : /u01/app/grid/crs//oraInst.loc

OPatch version    : 11.2.0.3.11

OUI version       : 11.2.0.4.0

    4、将grid11.2.0.4.0更新至11.2.0.4.7

使用oracle 用户停止dbconsole

su - oracle

emctl stop dbconsole

    5、生成响应文件

[grid@yingshu oramed]$ cd /oramed/20996923

[grid@yingshu 20996923]$ $ORACLE_HOME/OPatch/ocm/bin/emocmrsp -output  /tmp/psu.rsp

OCM Installation Response Generator 10.3.7.0.0 - Production

Copyright (c) 2005, 2012, Oracle and/or its affiliates.  All rights reserved.


Provide your email address to be informed of security issues, install and

initiate Oracle Configuration Manager. Easier for you if you use your My

Oracle Support Email address/User Name.

Visit http://www.oracle.com/support/policies.html for details.

Email address/User Name:


You have not provided an email address for notification of security issues.

Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]:  y

The OCM configuration response file (/tmp/psu.rsp) was successfully created.

    6、查看目前的软件安装情况,执行结果省略。

opatch lsinventory -detail -oh /u01/app/grid/crs/

    7、使用auto进行安装升级,升级rac需要每个节点都执行一次auto

[root@yingshu init.d]# su - grid

 [grid@yingshu ~]$ su root

Password:

[root@yingshu grid]# opatch auto /oramed/20996923 -ocmrf /tmp/psu.rsp -oh /u01/app/grid/crs/

Executing /u01/app/grid/crs/perl/bin/perl /u01/app/grid/crs/OPatch/crs/patch11203.pl -patchdir /oramed -patchn 20996923 -ocmrf /tmp/psu.rsp -oh /u01/app/grid/crs/ -paramfile /u01/app/grid/crs/crs/install/crsconfig_params


This is the main log file: /u01/app/grid/crs/cfgtoollogs/opatchauto2015-07-29_11-46-45.log

This file will show your detected configuration and all the steps that opatchauto attempted to do on your system:

/u01/app/grid/crs/cfgtoollogs/opatchauto2015-07-29_11-46-45.report.log


2015-07-29 11:46:45: Starting Oracle Restart Patch Setup

Using configuration parameter file: /u01/app/grid/crs/crs/install/crsconfig_params


Stopping CRS...

Stopped CRS successfully

patch /oramed/20996923/20760982  apply successful for home  /u01/app/grid/crs

patch /oramed/20996923/20831122  apply successful for home  /u01/app/grid/crs

patch /oramed/20996923/20299019  apply successful for home  /u01/app/grid/crs

Starting CRS...

CRS-4123: Oracle High Availability Services has been started.

opatch auto succeeded.

    8、验证升级结果

[grid@yingshu ~]$ opatch lsinv

Oracle Interim Patch Installer version 11.2.0.3.11

Copyright (c) 2015, Oracle Corporation.  All rights reserved.

... ...

Patch  20831122     : applied on Wed Jul 29 11:56:37 CST 2015

Patch description:  "OCW Patch Set Update : 11.2.0.4.7 (20831122)"

   Created on 1 Jul 2015, 06:26:45 hrs PST8PDT

   Bugs fixed:

     19270660, 18328800, 18691572, 20365005, 17750548, 17387214, 17617807

     14497275, 17733927, 18180541, 18962892, 17292250, 17378618, 16759171

... ...

Patch  20760982     : applied on Wed Jul 29 11:51:45 CST 2015

Unique Patch ID:  18908105

Patch description:  "Database Patch Set Update : 11.2.0.4.7 (20760982)"

   Created on 4 Jun 2015, 00:23:20 hrs PST8PDT

Sub-patch  20299013; "Database Patch Set Update : 11.2.0.4.6 (20299013)"

Sub-patch  19769489; "Database Patch Set Update : 11.2.0.4.5 (19769489)"

... ...

    10.4.2  数据库打补丁11.2.0.4.0升级至11.2.0.4.7

    1ORACLE_HOME下更新opatch请参见升级grid部分的3更新opatch章节。

    2、整个升级过程需要参考readme文档,此文档在补丁解压后的文件夹里。

    3、验证补丁冲突。

[oracle@yingshu oramed]$ cd 20760982

[oracle@yingshu 20760982]$ opatch prereq CheckConflictAgainstOHWithDetail -ph ./

Oracle Interim Patch Installer version 11.2.0.3.10

Copyright (c) 2015, Oracle Corporation.  All rights reserved.

Oracle Home       : /oracle/app/oracle/product/10.2.0/db_1

... ...

Invoking prereq "checkconflictagainstohwithdetail"

Prereq "checkConflictAgainstOHWithDetail" passed.

OPatch succeeded.

    4opatch apply安装补丁,过程部分省略。

[oracle@yingshu ~]$ cd /oramed/20760982


[oracle@yingshu 20760982]$ opatch apply -local

OPatch continues with these patches:   17478514  18031668  18522509  19121551  19769489  20299013  20760982 


Do you want to proceed? [y|n]

y

User Responded with: Y

All checks passed.

Provide your email address to be informed of security issues, install and

initiate Oracle Configuration Manager. Easier for you if you use your My

Oracle Support Email address/User Name.

Visit http://www.oracle.com/support/policies.html for details.

Email address/User Name:


You have not provided an email address for notification of security issues.

Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]:  y


Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.

(Oracle Home = '/oracle/app/oracle/product/10.2.0/db_1')


Is the local system ready for patching? [y|n]

y

... ...

Composite patch 20760982 successfully applied.

Log file location: /oracle/app/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/opatch2015-07-29_13-28-33PM_1.log

OPatch succeeded.

    5、执行catbundle.sql psu apply

[oracle@yingshu ~]$ sqlplus /nolog


SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 29 13:47:07 2015


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


SQL> conn /as sysdba

Connected to an idle instance.

SQL>

SQL> startup;

ORACLE instance started.


Total System Global Area 1023062016 bytes

Fixed Size                  2259520 bytes

Variable Size             318768576 bytes

Database Buffers          696254464 bytes

Redo Buffers                5779456 bytes

Database mounted.

Database opened.

SQL>@$ORACLE_HOME/rdbms/admin/catbundle.sql psu apply

    6、重新编译失效对象

sqlplus /nolog

conn /as sysdba

@?/rdbms/admin/utlrp.sql

    7、验证数据库补丁情况

[oracle@yingshu ~]$ opatch lsinv

Oracle Interim Patch Installer version 11.2.0.3.10

Copyright (c) 2015, Oracle Corporation.  All rights reserved.


Oracle Home       : /oracle/app/oracle/product/10.2.0/db_1

Interim patches (1) :


Patch  20760982     : applied on Wed Jul 29 13:35:01 CST 2015

Unique Patch ID:  18908105

Patch description:  "Database Patch Set Update : 11.2.0.4.7 (20760982)"

   Created on 4 Jun 2015, 00:23:20 hrs PST8PDT

Sub-patch  20299013; "Database Patch Set Update : 11.2.0.4.6 (20299013)"

Sub-patch  19769489; "Database Patch Set Update : 11.2.0.4.5 (19769489)"

Sub-patch  19121551; "Database Patch Set Update : 11.2.0.4.4 (19121551)"

Sub-patch  18522509; "Database Patch Set Update : 11.2.0.4.3 (18522509)"

Sub-patch  18031668; "Database Patch Set Update : 11.2.0.4.2 (18031668)"

Sub-patch  17478514; "Database Patch Set Update : 11.2.0.4.1 (17478514)"

   Bugs fixed:

     17288409, 21051852, 18607546, 17205719, 17811429, 17816865, 20506699

     17922254, 17754782, 16934803, 13364795, 17311728, 17441661, 17284817

     16992075, 17446237, 14015842, 19972569, 17449815, 17375354, 19463897

     17982555, 17235750, 13866822, 18317531, 17478514, 18235390, 14338435

... ...

--------------------------------------------------------------------------------

OPatch succeeded.

   

    8、查看DBA_REGISTRY_HISTORY验证升级情况

sqlplus /nolog

conn /as sysdba

set line 200

set pagesize 999

col action_time for a30

col action for a10

col comments for a40

col object_name for a25

col object_type for a30

col comp_name for a

col comp_id for a10

col version for a12

col status for a8

select comp_id,comp_name,version,status from dba_registry;

COMP_ID    COMP_NAME                                          VERSION      STATUS

---------- -------------------------------------------------- ------------ --------

OWM        Oracle Workspace Manager                           11.2.0.4.0   VALID

CATALOG    Oracle Database Catalog Views                      11.2.0.4.0   VALID

CATPROC    Oracle Database Packages and Types                 11.2.0.4.0   VALID


select action_time, action, comments from dba_registry_history;

SQL>

ACTION_TIME                    ACTION     COMMENTS

------------------------------ ---------- ----------------------------------------

24-JUL-15 12.26.31.712545 PM   APPLY      Patchset 11.2.0.2.0

29-JUL-15 01.49.53.443522 PM   APPLY      PSU 11.2.0.4.7

29-JUL-15 01.50.55.103300 PM   APPLY      PSU 11.2.0.4.7

29-JUL-15 01.51.04.159587 PM   APPLY      PSU 11.2.0.4.7


10.5 版本升级总结

    从力求完美的角度考虑,我们要安装PSU补丁的,但有不少客户不安装PSU补丁,那无疑增加了出现故障的几率,问题可能就出现在你察觉不到的地方,导致数据库运行变慢,响应迟钝。

    升级过程中,主要的参考文档就是readmereadme中要求停止的,一定要停干净,停不干净可能导致升级失败,连原来的数据库软件都不能用了,有可能结果就是必须重装。

    最好是在新装数据库软件时就安装补丁至最新,别等到投产之后再打补丁,毕竟动生产库和新装的数据库责任差别是巨大的,新安装时打补丁成本最底,生产库升级打补丁成本要高很多。

    单机版的数据库升级比RAC要简单,RAC需要先升grid用户下的CRS,再升数据库。所以把数据库配成双机热备,对于数据库来说就是单机版,也是很好的选择,安装简单,维护成本低,出故障的几率小。

图文推荐