码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 10g R2升级到Oracle 11g R2

时间:2014-05-15 19:02:03      阅读:616      评论:0      收藏:0      [点我收藏+]

标签:oracle

Oracle 10g R2升级到Oracle 11g R2

系统环境:

操作系统:RedHat EL55

Oracle 软件: Oracle 10g R2、Oracle 11g R2


bubuko.com,布布扣

Oracle 升级线路


本案例是从Oracle 10.2.0.4.0升级到Oracle 11.2.0.1.0

参考文档

Oracle patch CPU Update:

http://tiany.blog.51cto.com/513694/846066

Oracle 10g 升级(10.2.0.1.0升级到10.2.0.4.0)之--CPU Update

Oracle patch PSU Update:

http://tiany.blog.51cto.com/513694/846725

Oracle 10g升级之--PSU升级


一、升级前的准备工作

1、当前数据库版本

[oracle@rh55 ~]$ sqlplus ‘/as sysdba‘

SQL*Plus: Release 10.2.0.4.0 - Production on Thu May 15 14:12:07 2014

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

并且数据库做了PSU的升级,升级到10.2.0.4.4;按照Oracle 官方的升级线路图,10.2.0.4.0可以直接升级到Oracle 11g R2.


2、安装11gR2软件

配置Oracle 环境变量:

[oracle@rh55 ~]$ cat .bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

       . ~/.bashrc

fi

# User specific environment and startup programs

export TMP=/tmp

export TMPDIR=$TMP

export ORACLE_BASE=/u01/app/oracle

#export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1;

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1;

export ORACLE_SID=prod

export ORACLE_TERM=xterm

export PATH=/usr/sbin:$PATH

export PATH=$ORACLE_HOME/bin:$PATH; export PATH

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;

#alias sqlplus=‘rlwrap sqlplus‘

#alias rman=‘rlwrap rman‘


注意:将Oracle 11g R2安装到不同的目录下!

这里需要注意的是:如果你想在11gr2上打上最新的PSUCPU,可以先在软件级别上打上PSUCPU,这样就不用跑两次catbundle.sql,减少停机时间。


3、检查安装环境

1). 在升级之前,确保所有的组件和对象都是valid

针对组件:

selectsubstr(comp_name,1,40) comp_name, status, substr(version,1,10) version fromdba_registry order by comp_name;

针对对象:

selectsubstr(object_name,1,40) object_name,substr(owner,1,15) owner,object_type fromdba_objects where status=‘INVALID‘ order by owner,object_type;

如果有invalid的对象,运行utlrp.sql重新编译对象。

2). 确保syssystem下没有重复的对象:

selectobject_name, object_type from dba_objects where object_name||object_type in(select object_name||object_typefrom dba_objects where wner = ‘SYS‘) and wner = ‘SYSTEM‘;

上面这条语句只能返回以下4条记录:

OBJECT_NAMEOBJECT_TYPE

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

DBMS_REPCAT_AUTHPACKAGE BODY

DBMS_REPCAT_AUTHPACKAGE

AQ$_SCHEDULES_PRIMARYINDEX

AQ$_SCHEDULESTABLE

如果有其它记录返回,则必须根据下面这篇文档把重复记录删除:

Howto Clean Up Duplicate Objects Owned by SYS and SYSTEM Schema [ID 1030426.6]

4、升级前工作

Step1.

11gR2OracleHome下拷贝以下文件至一个临时文件夹:

$ORACLE_HOME/rdbms/admin/utlu112i.sql

Step2.

登陆数据库(10个),运行:

$ sqlplus ‘/ as sysdba‘

SQL> spool upgrade_info.log

SQL> @utlu112i.sql

SQL> spool off

生成的upgrade_info.log里的内容很重要,后续步骤要根据该文件的内容做相应的修改,因此一定要保留下来。

Step 3.

从下面这篇文档里可以下载到脚本dbupgdiag.sql:

Script. toCollect DB Upgrade/Migrate Diagnostic Information (dbupgdiag.sql) [ID 556610.1]

运行这个脚本:

cd <locationof the script>

$ sqlplus / assysdba

sql> altersession set nls_language=‘American‘;

sql>@dbupgdiag.sql

如果该脚本报告有invalid对象,运行以下命令重编译无效对象:

$ cd $ORACLE_HOME/rdbms/admin

$ sqlplus "/ as sysdba"

SQL> @utlrp.sql

Step 4.

10.2开始,CONNECT角色的权限变少了,所以如果你是从10.2之前升级到11g的话,升级之后,需要重新授予缺少的权限,但是如果是从10.2及之后升级到11g的话,就不需要重新赋权限了,本例是从10.2.0.4升级到11g的,因此不需要该步骤。

Step 5.

生成重建dblink的脚本,以防万一数据库需要降级。和Step4一样,本例是从10.2.0.4升级到11g的,因此不需要该步骤。

Step 6.

检查Timezone版本,主要参考:

Actions For DSTUpdates When Upgrading To Or Applying The 11.2.0.2 Patchset [ID 1201253.1]

注意:11g的软件里已经自带了版本1-14Timezone

先检查一下当前timezone版本:

SQL> conn / as sysdba

Connected.

SQL>SELECT version FROM v$timezone_file;

根据当前timezone的版本,又分三种情况:

1)等于14:这已经是11g需要的版本了,所以升级前后都不需要做任何事,这种情况很罕见。

2)高于14:升级前,必须得给11g软件打上该timezone版本的DST补丁,这种情况也很罕见。

3)低于14:大多数都是这种情况,在升级前不需要在11g软件层面打补丁,在升级后需要再数据库层面将Timezone升级至14,具体看后面的步骤

Step 7.

检查国家字符集是否是UTF8AL16UTF16

selectvalue from NLS_DATABASE_PARAMETERS where parameter = ‘NLS_NCHAR_CHARACTERSET‘;

如果是,则什么都不用做;如果不是,那你就惨了,跟着下面长长的这篇文档一步一步做吧:

The NationalCharacter Set ( NLS_NCHAR_CHARACTERSET ) in Oracle 9i, 10g and 11g [ID276914.1]

Step 8.

收集统计信息,以减少停机时间:

$ sqlplus "/as sysdba"

SQL> EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;

Step 9.

如果你有开启Vault,那么你需要先在11gR2软件下禁用Vault,等升级结束后,再启用Vault,否则会在升级过程中报错。

Step 10.

备份EnterpriseManager Database Control Data,因为本例并没有使用EM,所以不需要该步骤。

Step 11.

配置网络ACL‘s,在本例中不需要配置。

Step 12.

使用以下语句生产分析数据字典的脚本(as sysdba)

Set verify off

Set space 0

Set line 120

Set heading off

Set feedback off

Set pages 1000

Spool analyze.sql

SELECT ‘Analyze cluster "‘||cluster_name||‘" validate structure cascade;‘

FROM dba_clusters

WHERE owner=‘SYS‘

UNION

SELECT ‘Analyze table "‘||table_name||‘" validate structure cascade;‘

FROM dba_tables

WHERE owner=‘SYS‘

AND partitioned=‘NO‘

AND (iot_type=‘IOT‘ OR iot_type is NULL)

UNION

SELECT ‘Analyze table "‘||table_name||‘" validate structure cascade into invalid_rows;‘

FROM dba_tables

WHERE owner=‘SYS‘

AND partitioned=‘YES‘;

spool off

生成的脚本名称是:analyze.sql

现在运行该脚本:

$ sqlplus "/ as sysdba"

SQL> @$ORACLE_HOME/rdbms/admin/utlvalid.sql

SQL> @analyze.sql

Step 13.

确保所有的snapshot都已被成功刷新,且replication已被关闭:

SELECT DISTINCT(TRUNC(last_refresh))

FROM dba_snapshot_refresh_times;

Step 14.

确保当前没有文件需要介质恢复

SELECT * FROM v$recover_file;

上面语句没有返回结果才是正确的。

Step 15.

确保当前没有文件运行在备份模式下:

SELECT * FROM v$backup WHERE status != ‘NOT ACTIVE‘;

上面语句没有返回结果才是正确的。

Step 16.

解决分布式事务。

先查询是否还有分布式事务:

SQL> select * from dba_2pc_pending;

如果有返回结果,则:

SQL> SELECT local_tran_id

    FROM dba_2pc_pending;

SQL> EXECUTE dbms_transaction.purge_lost_db_entry(‘‘);

SQL> COMMIT;

Step 17.

检查是否有Standby数据库存在:

SELECT SUBSTR(value,INSTR(value,‘=‘,INSTR(UPPER(value),‘SERVICE‘))+1)

FROM v$parameter

WHERE name LIKE ‘log_archive_dest%‘ AND UPPER(value) LIKE ‘SERVICE%‘;

如果有返回结果,则在升级之前,要保证StandbyPrimary是处于同步的状态。

Step 18.

禁用所有的batchcronjobs

Step 19.

确保用户SYSSYSTEM的默认表空间都是SYSTEM

SQL> SELECT username, default_tablespace

    FROM dba_users

    WHERE username in (‘SYS‘,‘SYSTEM‘);

如果不是,则要用以下语句修改为SYSTEM

SQL> ALTER user SYS default tablespace SYSTEM;

SQL> ALTER user SYSTEM default tablespace SYSTEM;

Step 20.

确保AUD$表建在SYS用户下和SYSTEM表空间下:

SQL> SELECTowner,tablespace_name

    FROM dba_tables

    WHERE table_name=‘AUD$‘;

如果不是,则要做相应的修改。

Step 21.

检查是否有外部认证的SSL用户:

SQL> SELECT name FROM sys.user$

    WHERE ext_username IS NOT NULL

    AND password = ‘GLOBAL‘;

如果有,则在升级之后记得要做Step34

Step 22.

记下数据文件、联机日志文件和控制文件的位置:

SQL> SELECT name FROM v$controlfile;

SQL> SELECT file_name FROM dba_data_files;

SQL> SELECT group#, member FROM v$logfile;

且备份listener.ora,tnsnames.ora, sqlnet.ora等文件。

Step 23.

停止listener:

$ lsnrctl stop

停止其它可执行程序,如dbconsole,isqlplus

$ emctl stop dbconsole

$ isqlplusctl stop

Step 24.

关闭数据库:

$ sqlplus "/as sysdba"

SQL> shutdown immediate;

接着对全库做个冷备。

Step 25.

10gpfile为模板,并根据Step2生成的upgrade_info.log里的建议,为11g创建一个新的pfile

Step 26.

如果数据库原本是运行在archive模式下,最好先改为noarchive,这样可以减少升级停机时间,升级成功后再重新改回archive模式


二、开始升级

升级方式可以采用dbua图形方式或sqlplus 命令行方式,本案例采用DBUA。

以Oracle 11g的安装环境,Oracle用户执行dbua:

bubuko.com,布布扣

升级提示

bubuko.com,布布扣

选择要升级的库

bubuko.com,布布扣

按照提示完成前期准备工作

[oracle@rh55 ~]$ !sql

sqlplus ‘/as sysdba‘

SQL*Plus: Release 10.2.0.4.0 - Production on Thu May 15 14:25:00 2014

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select status from v$instance;

STATUS

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

OPEN MIGRATE

SQL> purge dba_recyclebin;

DBA Recyclebin purged.

SQL>

bubuko.com,布布扣

关闭归档模式,加快升级速度

bubuko.com,布布扣

升级过程是否迁移数据文件位置

bubuko.com,布布扣

11g后,建立的diagnostic 目录,集中存放trace和alert log

bubuko.com,布布扣

upgrade summary

bubuko.com,布布扣

提示:在升级过程要启动listener

bubuko.com,布布扣

升级安装


三、升级后的工作

1、修改listener.ora,使listener执行新的11gHome,然后重新启动listener

lsnrctl start

2、再次检查Step28中设置的环境变量确实是指向了新的11g Home.

3、Timezone数据库层面的升级。

注意:该步骤是否执行是和Step6中的检查结果相关的,只有当Timezone的版本小于14时,才需要执行该步骤。

主要参考:Updatingthe RDBMS DST version in 11gR2 (11.2.0.1 and up) using DBMS_DST [ID 977512.1]

1Timezone升级前的准备工作:

先检查一下当前的timezone版本:

SELECT versionFROM v$timezone_file;

SELECTPROPERTY_NAME, SUBSTR(property_value, 1, 30) value FROM DATABASE_PROPERTIES WHEREPROPERTY_NAME LIKE ‘DST_%‘ ORDER BY PROPERTY_NAME;

一个典型的输出是:

PROPERTY_NAME                 VALUE

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

DST_PRIMARY_TT_VERSION        4

DST_SECONDARY_TT_VERSION      0

DST_UPGRADE_STATE             NONE

然后开始准备工作:

alter session set"_with_subquery"=materialize;

execDBMS_DST.BEGIN_PREPARE(14);

接着检查准备状态:

SELECTPROPERTY_NAME, SUBSTR(property_value, 1, 30) value

FROMDATABASE_PROPERTIES

WHEREPROPERTY_NAME LIKE ‘DST_%‘

ORDER BYPROPERTY_NAME;

一个典型的输出是:

PROPERTY_NAME                 VALUE

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

DST_PRIMARY_TT_VERSION        4

DST_SECONDARY_TT_VERSION      14

DST_UPGRADE_STATE             PREPARE

-- truncatelogging tables if they exist.

TRUNCATE TABLESYS.DST$TRIGGER_TABLE;

TRUNCATE TABLEsys.dst$affected_tables;

TRUNCATE TABLEsys.dst$error_table;

-- log affecteddata

set serveroutputon

BEGIN

DBMS_DST.FIND_AFFECTED_TABLES

(affected_tables=> ‘sys.dst$affected_tables‘,

log_errors =>TRUE,

log_errors_table=> ‘sys.dst$error_table‘);

END;

/

下面的语句都不能有返回结果:

SELECT * FROMsys.dst$affected_tables;

SELECT * FROMsys.dst$error_table;

SELECT * FROMsys.dst$error_table where ERROR_NUMBER= ‘1883‘;

SELECT * FROMsys.dst$error_table where ERROR_NUMBER= ‘1878‘;

SELECT * FROMsys.dst$error_table where ERROR_NUMBER not in (‘1878‘,‘1883‘);

-- end preparewindow, the rows above will stay in those tables.

EXECDBMS_DST.END_PREPARE;

-- check if thisis ended

SELECTPROPERTY_NAME, SUBSTR(property_value, 1, 30) value

FROMDATABASE_PROPERTIES

WHEREPROPERTY_NAME LIKE ‘DST_%‘

ORDER BYPROPERTY_NAME;

一个典型的输出是:

PROPERTY_NAME                 VALUE

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

DST_PRIMARY_TT_VERSION        4

DST_SECONDARY_TT_VERSION      0

DST_UPGRADE_STATE             NONE

2)真正开始升级Timezone

conn / as sysdba

shutdownimmediate;

startup upgrade;

set serveroutputon

purgedba_recyclebin;

TRUNCATE TABLESYS.DST$TRIGGER_TABLE;

TRUNCATE TABLEsys.dst$affected_tables;

TRUNCATE TABLEsys.dst$error_table;

alter session set"_with_subquery"=materialize;

EXECDBMS_DST.BEGIN_UPGRADE(14);

SELECTPROPERTY_NAME, SUBSTR(property_value, 1, 30) value

FROMDATABASE_PROPERTIES

WHEREPROPERTY_NAME LIKE ‘DST_%‘

ORDER BYPROPERTY_NAME;

一个典型的输出是:

PROPERTY_NAME                 VALUE

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

DST_PRIMARY_TT_VERSION        14

DST_SECONDARY_TT_VERSION      4

DST_UPGRADE_STATE             UPGRADE

下面这条语句应该没有返回结果:

SELECT OWNER,TABLE_NAME, UPGRADE_IN_PROGRESS FROM ALL_TSTZ_TABLES whereUPGRADE_IN_PROGRESS=‘YES‘;

重启数据库:

shutdownimmediate

startup

升级相关的table

alter session set"_with_subquery"=materialize;

set serveroutputon

VAR numfailnumber

BEGIN

DBMS_DST.UPGRADE_DATABASE(:numfail,

parallel =>TRUE,

log_errors =>TRUE,

log_errors_table=> ‘SYS.DST$ERROR_TABLE‘,

log_triggers_table=> ‘SYS.DST$TRIGGER_TABLE‘,

error_on_overlap_time=> FALSE,

error_on_nonexisting_time=> FALSE);

DBMS_OUTPUT.PUT_LINE(‘Failures:‘||:numfail);

END;

/

如果没有错误,则结束升级:

VAR fail number

BEGIN

DBMS_DST.END_UPGRADE(:fail);

DBMS_OUTPUT.PUT_LINE(‘Failures:‘||:fail);

END;

/

最后一次检查:

SELECTPROPERTY_NAME, SUBSTR(property_value, 1, 30) value

FROMDATABASE_PROPERTIES

WHEREPROPERTY_NAME LIKE ‘DST_%‘

ORDER BYPROPERTY_NAME;

典型输出是:

PROPERTY_NAME                 VALUE

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

DST_PRIMARY_TT_VERSION        14

DST_SECONDARY_TT_VERSION      0

DST_UPGRADE_STATE             NONE

SELECT * FROMv$timezone_file;

FILENAME               VERSION

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

timezlrg_14.dat             14

4、升级外部认证SSL用户。

由于本例是从10.2升级到11g,所以可忽略该步骤。

5、如果在Step9中,你关闭了Vault,则必须在此步骤重新启用。

Note 453903.1 - Enabling and DisablingOracle Database Vault in UNIX

6、创建spfile:

SQL> create spfile from pfile;

7、最后,记得修改compatible参数:

SQL>ALTER SYSTEM SET COMPATIBLE = ’11.2.0’ SCOPE=SPFILE;

参考文档:CompleteChecklist for Manual Upgrades to 11gR2 [ID 837570.1]

@至此,数据库升级工作完成!

升级遇到的问题:

bubuko.com,布布扣

[oracle@rh55 admin]$ cd /u01/app/oracle/product/10.2.0/db_1/sqlplus/admin/

[oracle@rh55 admin]$ cat glogin.sql

set linesize 120

set pagesize 20

set time on

set timing on

set sqlprompt ‘_user@ _connect_identifier>‘


 在升级过程遇到以上问题,原因是在glogin.sql增加了以上的内容,删除后问题解决!


以下为相似案例:

问题:

10.2.0.4 -> 11.2 - dbua - fatal - db using asm as storage,... but it isn‘t

This question is Not Answered.

stuartu Jan 27, 2010 10:27 PM Currently Being Moderated

I‘m upgrading my 10.2.0.4 to 11.2.0.1 on RHEL5.4.

I start up the 11.2 dbua, and select the database to upgrade, then dbua pops up a box that says:

"The database is using ASM as storage. Before you upgrade the database, you need to upgrade ASM using Automatic Storage Configuration Assistant (ASMCA) from grid infrastructure home. Starting 11gR2, ASM should be running from grid infrastructure home"

The problem is.... I am not running ASM.

Any reasons why dbua is complaining about this, and how I can get past it?


Thanks in advance.

Stuart.

解决方法:

Problem has been resolved, with help from Oracle Support:

In my 10gR2 environment, the glogin.sql had the following custom entry:

set heading on

set pages 49999

set feedback on

set linesize 180

define _editor=vi

The problem is with ‘set feedback on‘. Once this is removed, I am able to get past the ASM instance popup error.

I had earlier removed a custom ‘sqlprompt‘ entry from glogin.sql, as I knew that caused problems when I upgraded from 9.2.0.8 -> 10.2.0.4 early last year, but left the other ones there.

Really,... this problem is quite logical when you think about it. It is just the cryptic error that was thrown when it was encountered... :-/

Stuart.

Edited by: stuartu on Feb 3, 2010 9:51 AM

以上,文档参考了一些网友的著作,在这里一并标示感谢,谢谢你们的辛勤劳动!

本文出自 “天涯客的blog” 博客,请务必保留此出处http://tiany.blog.51cto.com/513694/1411882

Oracle 10g R2升级到Oracle 11g R2,布布扣,bubuko.com

Oracle 10g R2升级到Oracle 11g R2

标签:oracle

原文地址:http://tiany.blog.51cto.com/513694/1411882

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!