[toc]

五一劳动节特辑:ORACLE 12.2.0.1.0 升级到 ORACLE 19.14

备份 12c

备份 12c 的软件目录

1
2
3
cp /etc/oraInst.loc  /12cbak/
cp /etc/oratab /12cbak/
cp -a /usr/local/bin /12cbak/
1
2
3
4
5
6
7
8
9
10
$echo $ORACLE_HOME
/u01/app/oracle/product/12.2.0/db
su - root
cd /u01/app/oracle/product/12.2.0/
tar -pzcvf /12cbak/oracle_home_bkup.tgz db

##--如果要恢复:
cd /u01/app/oracle/product/12.2.0/
mv db db_bkup
tar -zpxf /12cbak/oracle_home_bkup.tgz

备份 12c的数据库

1
2
mkdir -p /12cbak/rmanbak/
chown -R oracle:oinstall /12cbak/rmanbak/
1
2
3
4
5
6
7
8
9
10
11
12
13
su - oracle
rman target /
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset database format '/12cbak/rmanbak/db_%d_%T_%s_%p.bak';
backup as compressed backupset archivelog all format '/12cbak/rmanbak/ar_%d_%T_%s.bak';
backup current controlfile format '/12cbak/rmanbak/control01.ctl';
backup spfile format '/12cbak/rmanbak/spfileorcl.ora';
release channel c1;
release channel c2;
}

安装 19c

1
2
oracle 用户创建:mkdir -p /u01/app/oracle/product/19.3.0/db/
或者root创建,然后授予权限:chown -R oracle:oinstall /u01/app/oracle/product/19.3.0/db/
1
2
3
4
su - oracle
cd /soft
[oracle@LIUPSDB:/soft]$ unzip -q LINUX.X64_193000_db_home.zip -d /u01/app/oracle/product/19.3.0/db/

1
2
3
4
5
6
7
8
9
10
11
12
su - oracle
cd /soft/
[oracle@LIUPSDB:/soft]$ unzip -q LINUX.X64_193000_db_home.zip -d
/u01/app/oracle/product/19.3.0/db/
[oracle@LIUPSDB:~]$ cd /u01/app/oracle/product/19.3.0/db
[oracle@LIUPSDB:/u01/app/oracle/product/19.3.0/db]$ mv OPatch/ OPatch.bak/
[oracle@LIUPSDB:/u01/app/oracle/product/19.3.0/db]$ cd /soft/
[oracle@LIUPSDB:/soft]$ unzip -q p6880880_190000_Linux-x86-64.zip -d
/u01/app/oracle/product/19.3.0/db/
[oracle@LIUPSDB:/soft]$ cd /u01/app/oracle/product/19.3.0/db/
./runInstaller
## 手搓19c ,仅安装软件,并打 19.14 的补丁 略。
1
2
3
4
5
6
## 打补丁前
opatch lspatches
29585399;OCW RELEASE UPDATE 19.3.0.0.0 (29585399)
29517242;Database Release Update : 19.3.0.0.190416 (29517242)

OPatch succeeded.
1
2
3
4
5
6
## 打补丁后
opatch lspatches
33515361;Database Release Update : 19.14.0.0.220118 (33515361)
29585399;OCW RELEASE UPDATE 19.3.0.0.0 (29585399)

OPatch succeeded.

升级前检查

1
2
3
4
5
6
7
su - oracle
mkdir ~/upgrade
export ORACLE_HOME_12c=/u01/app/oracle/product/12.2.0/db
export ORACLE_HOME_19C=/u01/app/oracle/product/19.3.0/db
$ORACLE_HOME_12c/jdk/bin/java -jar $ORACLE_HOME_19C/rdbms/admin/preupgrade.jar FILE TEXT DIR /home/oracle/upgrade


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export ORACLE_HOME_12c=/u01/app/oracle/product/12.2.0/db
export ORACLE_HOME_19C=/u01/app/oracle/product/19.3.0/db
$ORACLE_HOME_12c/jdk/bin/java -jar $ORACLE_HOME_19C/rdbms/admin/preupgrade.jar FILE TEXT DIR /home/oracle/upgrade
==================
PREUPGRADE SUMMARY
==================
/home/oracle/upgrade/preupgrade.log
/home/oracle/upgrade/preupgrade_fixups.sql
/home/oracle/upgrade/postupgrade_fixups.sql

Execute fixup scripts as indicated below:

Before upgrade:

Log into the database and execute the preupgrade fixups
@/home/oracle/upgrade/preupgrade_fixups.sql

After the upgrade:

Log into the database and execute the postupgrade fixups
@/home/oracle/upgrade/postupgrade_fixups.sql

Preupgrade complete: 2025-05-02T22:56:13
[oracle@LIUPSDB:/home/oracle/upgrade]$

检查重复对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
SQL>select object_name, object_type
from dba_objects
where object_name||object_type in
(select object_name||object_type
from dba_objects
where owner = 'SYS')
and owner = 'SYSTEM';

OBJECT_NAME OBJECT_TYPE
------------------------------ -----------------------
AQ$_SCHEDULES TABLE
AQ$_SCHEDULES_PRIMARY INDEX

SQL>

如果没有记录或只有以下对象,表示正常,如果有其他重复的对象需要删除SYSTEM下的重复对象
AQ$_SCHEDULES TABLE
AQ$_SCHEDULES_PRIMARY INDEX
DBMS_REPCAT_AUTH PACKAGE
DBMS_REPCAT_AUTH PACKAGE BODY

检查组件和无效对象

1
2
3
4
5
6
7
set pagesize 500
set linesize 200
col comp_name for a40
select substr(comp_name,1,40) comp_name, status, substr(version,1,10) version from dba_registry order by comp_name;
select substr(object_name,1,40) object_name,substr(owner,1,15) owner,object_type from dba_objects where status='INVALID' order by owner,object_type;
select owner,object_type,count(*) from dba_objects where status='INVALID' group by owner,object_type order by owner,object_type ;

检查表空间使用率

支持19c,cdb和pdb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

CLEAR COLUMNS COMPUTES
SET DEFINE OFF

col pdbname for a20
col CON_ID HEADING '容器ID' format 999999
col PDBNAME HEADING 'PDB名称' format a15
col TS# HEADING '表空间号' format 999999
col TS_NAME HEADING '表空间名称' format a22
col TYPE HEADING '表空间类型' format a10
col TS_SIZE_M HEADING '总大小(MB)' format 999,999,999
col FREE_SIZE_M HEADING '空闲(MB)' format 999,999,999
col USED_SIZE_M HEADING '已用(MB)' format 999,999,999
col USED_PER HEADING '使用率%' format 999.99
col MAX_SIZE_G HEADING '最大扩展(GB)' format 999,999
col USED_PER_MAX HEADING '扩展利用率%' format 999.99
col BLOCK_SIZE HEADING '块大小' format 99999
col LOGGING HEADING '日志模式' format a10
col TS_DF_COUNT HEADING '文件数量' format 999999

SELECT CON_ID,
PDBNAME,
TS#,
TS_NAME,
type,
TS_SIZE_M,
FREE_SIZE_M,
USED_SIZE_M,
USED_PER,
MAX_SIZE_G,
USED_PER_MAX,
BLOCK_SIZE,
LOGGING,
TS_DF_COUNT
FROM (WITH wt1 AS (SELECT ts.CON_ID,
(SELECT np.NAME
FROM V$CONTAINERS np
WHERE np.CON_ID = tS.con_id) PDBNAME,
(SELECT A.TS#
FROM V$TABLESPACE A
WHERE A.NAME = UPPER(tS.TABLESPACE_NAME)
AND a.CON_ID = tS.con_id) TS#,
ts.TABLESPACE_NAME,
df.all_bytes,
decode(df.TYPE,
'D',
nvl(fs.FREESIZ, 0),
'T',
df.all_bytes - nvl(fs.FREESIZ, 0)) FREESIZ,
df.MAXSIZ,
ts.BLOCK_SIZE,
ts.LOGGING,
ts.FORCE_LOGGING,
ts.CONTENTS,
ts.EXTENT_MANAGEMENT,
ts.SEGMENT_SPACE_MANAGEMENT,
ts.RETENTION,
ts.DEF_TAB_COMPRESSION,
df.ts_df_count
FROM cdb_tablespaces ts,
(SELECT d.CON_ID,
'D' TYPE,
TABLESPACE_NAME,
COUNT(*) ts_df_count,
SUM(BYTES) all_bytes,
SUM(decode(MAXBYTES, 0, BYTES, MAXBYTES)) MAXSIZ
FROM cdb_data_files d
GROUP BY d.CON_ID,
TABLESPACE_NAME
UNION ALL
SELECT d.CON_ID,
'T',
TABLESPACE_NAME,
COUNT(*) ts_df_count,
SUM(BYTES) all_bytes,
SUM(decode(MAXBYTES, 0, BYTES, MAXBYTES))
FROM cdb_temp_files d
GROUP BY d.CON_ID,
TABLESPACE_NAME) df,
(SELECT d.CON_ID,
TABLESPACE_NAME,
SUM(BYTES) FREESIZ
FROM cdb_free_space d
GROUP BY d.CON_ID,
TABLESPACE_NAME
UNION ALL
SELECT d.CON_ID,
tablespace_name,
SUM(d.BLOCK_SIZE * a.BLOCKS) bytes
FROM gv$sort_usage a,
cdb_tablespaces d
WHERE a.tablespace = d.tablespace_name
AND a.CON_ID = d.CON_ID
GROUP BY d.CON_ID,
tablespace_name) fs
WHERE ts.TABLESPACE_NAME = df.TABLESPACE_NAME
AND ts.CON_ID = df.CON_ID
AND ts.TABLESPACE_NAME = fs.TABLESPACE_NAME(+)
AND ts.CON_ID = fs.CON_ID(+))
SELECT T.CON_ID,
(CASE
WHEN T.PDBNAME = LAG(T.PDBNAME, 1)
OVER(PARTITION BY T.PDBNAME ORDER BY TS#) THEN
NULL
ELSE
T.PDBNAME
END) PDBNAME,
TS#,
t.TABLESPACE_NAME TS_Name,
t.CONTENTS type,
round(t.all_bytes / 1024 / 1024) ts_size_M,
round(t.freesiz / 1024 / 1024) Free_Size_M,
round((t.all_bytes - t.FREESIZ) / 1024 / 1024) Used_Size_M,
round((t.all_bytes - t.FREESIZ) * 100 / t.all_bytes, 3) Used_per,
round(MAXSIZ / 1024 / 1024 / 1024, 3) MAX_Size_g,
round(decode(MAXSIZ,
0,
to_number(NULL),
(t.all_bytes - FREESIZ)) * 100 / MAXSIZ,
3) USED_per_MAX,
round(t.BLOCK_SIZE) BLOCK_SIZE,
t.LOGGING,
t.ts_df_count
FROM wt1 t
UNION ALL
SELECT DISTINCT T.CON_ID,
'' PDBNAME,
to_number('') TS#,
'ALL TS:' TS_Name,
'' type,
round(SUM(t.all_bytes) / 1024 / 1024, 3) ts_size_M,
round(SUM(t.freesiz) / 1024 / 1024) Free_Size_m,
round(SUM(t.all_bytes - t.FREESIZ) / 1024 / 1024) Used_Size_M,
round(SUM(t.all_bytes - t.FREESIZ) * 100 /
SUM(t.all_bytes),
3) Used_per,
round(SUM(MAXSIZ) / 1024 / 1024 / 1024) MAX_Size,
to_number('') "USED,% of MAX Size",
to_number('') BLOCK_SIZE,
'' LOGGING,
to_number('') ts_df_count
FROM wt1 t
GROUP BY rollup(CON_ID,PDBNAME)
)
ORDER BY CON_ID,type,TS# ;

检查 timezone

1
2
3
4
5
6
SQL>  SELECT * FROM v$timezone_file;

FILENAME VERSION CON_ID
-------------------- ---------- ----------
timezlrg_26.dat 26 0

检查隐藏参数

1
SELECT name,description from SYS.V$PARAMETER WHERE name LIKE '\_%' ESCAPE '\';

检查参数

1
2
show parameter SEC_CASE_SENSITIVE_LOGON
show parameter COMPATIBLE

确保没有设置废弃的参数 SEC_CASE_SENSITIVE_LOGONFALSE

升级数据库到19.1的 COMPATIBLE 参数最小的值是”11.2.0”,确认数据库 COMPATIBLE 参数已被设置为 11.2.0 或者更高

检查同义词AREA

如果安装了组件Oracle Multimedia 和/或者 Oracle Spatial,那么升级前需要确保存在PUBLIC synonym AREA,指向OGC_AREA对象;否则升级后会出现组件状态异常的情况。

1
2
3
4
5
 col OWNER for a20
col SYNONYM_NAME for a20
col TABLE_OWNER for a20
col TABLE_NAME for a20
select owner, synonym_name, table_owner, table_name from dba_synonyms where synonym_name = 'AREA';

检查源库中失效的组件及对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
set pagesize 500
set linesize 200
col comp_name for a40
col status for a15
col VERSION for a20
select substr(comp_name,1,40) comp_name, status, substr(version,1,10) version from dba_registry order by comp_name;
select substr(object_name,1,40) object_name,substr(owner,1,15) owner,object_type from dba_objects where status='INVALID' order by owner,object_type;
select owner,object_type,count(*) from dba_objects where status='INVALID' group by owner,object_type order by owner,object_type ;
COMP_NAME STATUS VERSION
---------------------------------------- --------------- --------------------
JServer JAVA Virtual Machine VALID 19.0.0.0.0
OLAP Analytic Workspace VALID 19.0.0.0.0
Oracle Database Catalog Views VALID 19.0.0.0.0
Oracle Database Java Packages VALID 19.0.0.0.0
Oracle Database Packages and Types VALID 19.0.0.0.0
Oracle Database Vault VALID 19.0.0.0.0
Oracle Label Security VALID 19.0.0.0.0
Oracle Multimedia VALID 19.0.0.0.0
Oracle OLAP API VALID 19.0.0.0.0
Oracle Real Application Clusters OPTION OFF 19.0.0.0.0
Oracle Text VALID 19.0.0.0.0
Oracle Workspace Manager VALID 19.0.0.0.0
Oracle XDK VALID 19.0.0.0.0
Oracle XML Database VALID 19.0.0.0.0
Spatial VALID 19.0.0.0.0

15 rows selected.

SQL>
no rows selected

SQL>
no rows selected


或者

1
2
SET SERVEROUTPUT ON;
EXECUTE DBMS_PREUP.INVALID_OBJECTS;

如果发现了任何无效组件或者对象,则执行下面的操作以使数据库中的无效对象变为有效:

执行 utlrp.sql 以编译数据库中的无效对象。您可以多次执行utlrp.sql脚本以编译无效对象。

1
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql

收集优化器统计信息来减少数据库停机时间

Oracle 强烈推荐升级前收集统计信息。Oracle 推荐使用 DBMS_STATS.GATHER_DICTIONARY_STATS 来收集统计信息,比如,执行下面的 SQL:

1
SQL> EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;

确认升级前物化视图刷新都已经完成

用下面的语句检查当前是否有物化视图正在刷新。在升级数据库前,我们需要确认所有的物化视图都已经完成了刷新。

1
SQL> SELECT o.name FROM sys.obj$ o, sys.user$ u, sys.sum$ s WHERE o.type# = 42 AND bitand(s.mflags, 8) =8;

确保没有数据文件需要介质恢复(media recovery)或处于备份的状态

执行下面的语句检查备份的状态:

1
SQL> SELECT * FROM v$backup WHERE status != 'NOT ACTIVE';

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

1
SQL> SELECT * FROM v$recover_file;

升级前清空回收站

1
SQL> PURGE DBA_RECYCLEBIN;

dbua 升级

需确认使用的是19C的DBUA程序

1
2
3
which dbua
[oracle@LIUPSDB:/home/oracle]$ which dbua
/u01/app/oracle/product/19.3.0/db/bin/dbua

检查数据库版本升级信息

1
2
3
4
5
6
7
8
9
10
11
col ACTION_TIME for a30;
col COMMENTS for a40;
col ACTION for a10;
col NAMESPACE for a15;
set lines 300;
select * from registry$history;
ACTION_TIME ACTION NAMESPACE VERSION ID COMMENTS BUNDLE_SERIES
------------------------------ ---------- --------------- ------------------------------ ---------- ---------------------------------------- ------------------------------
BOOTSTRAP DATAPATCH 12.2.0.1 RDBMS_12.2.0.1.0_LINUX.X64_170125

SQL>

升级后检查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
col ACTION_TIME for a30;
col COMMENTS for a40;
col ACTION for a10;
col NAMESPACE for a15;
set lines 300;
select * from registry$history;

COMP_NAME STATUS VERSION
---------------------------------------- -------------- ---------------
JServer JAVA Virtual Machine VALID 19.0.0.0.0
OLAP Analytic Workspace VALID 19.0.0.0.0
Oracle Database Catalog Views VALID 19.0.0.0.0
Oracle Database Java Packages VALID 19.0.0.0.0
Oracle Database Packages and Types VALID 19.0.0.0.0
Oracle Database Vault VALID 19.0.0.0.0
Oracle Label Security VALID 19.0.0.0.0
Oracle Multimedia VALID 19.0.0.0.0
Oracle OLAP API VALID 19.0.0.0.0
Oracle Real Application Clusters OPTION OFF 19.0.0.0.0
Oracle Text VALID 19.0.0.0.0
Oracle Workspace Manager VALID 19.0.0.0.0
Oracle XDK VALID 19.0.0.0.0
Oracle XML Database VALID 19.0.0.0.0
Spatial VALID 19.0.0.0.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
col ACTION_TIME for a30;
col COMMENTS for a40;
col ACTION for a10;
col NAMESPACE for a15;
set lines 300;
select * from registry$history;

ACTION_TIME ACTION NAMESPACE VERSION ID COMMENTS BUNDLE_SERIES
------------------------------ ---------- --------------- -------------------- ---------- ---------------------------------------- ------------------------------
BOOTSTRAP DATAPATCH 12.2.0.1 RDBMS_12.2.0.1.0_LINUX.X64_170125
BOOTSTRAP DATAPATCH 19 RDBMS_19.14.0.0.0DBRU_LINUX.X64_211224.3
05-MAY-25 05.15.31.734709 PM UPGRADE SERVER 19.0.0.0.0 Upgraded from 12.2.0.1.0 to 19.14.0.0.0

SQL>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[oracle@LIUPSDB:/home/oracle]$ tail -100 /u01/app/oracle/cfgtoollogs/dbua/upgrade2025-05-05_04-29-22PM/orcl/upg_summary.log

Oracle Database Release 19 Post-Upgrade Status Tool 05-05-2025 17:15:3
Database Name: ORCL

Component Current Full Elapsed Time
Name Status Version HH:MM:SS

Oracle Server UPGRADED 19.14.0.0.0 00:14:19
JServer JAVA Virtual Machine UPGRADED 19.14.0.0.0 00:00:48
Oracle XDK UPGRADED 19.14.0.0.0 00:01:07
Oracle Database Java Packages UPGRADED 19.14.0.0.0 00:00:16
OLAP Analytic Workspace UPGRADED 19.14.0.0.0 00:00:19
Oracle Label Security UPGRADED 19.14.0.0.0 00:00:11
Oracle Database Vault UPGRADED 19.14.0.0.0 00:01:29
Oracle Text UPGRADED 19.14.0.0.0 00:00:29
Oracle Workspace Manager UPGRADED 19.14.0.0.0 00:00:24
Oracle Real Application Clusters UPGRADED 19.14.0.0.0 00:00:00
Oracle XML Database UPGRADED 19.14.0.0.0 00:01:10
Oracle Multimedia UPGRADED 19.14.0.0.0 00:01:27
Spatial UPGRADED 19.14.0.0.0 00:07:44
Oracle OLAP API UPGRADED 19.14.0.0.0 00:00:11
Datapatch 00:00:51
Final Actions 00:00:55
Post Upgrade 00:00:00

Total Upgrade Time: 00:31:01

Database time zone version is 26. It is older than current release time
zone version 32. Time zone upgrade is needed using the DBMS_DST package.

Grand Total Upgrade Time: [0d:0h:32m:24s]
[oracle@LIUPSDB:/home/oracle]$
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
SQL> @/home/oracle/upgrade/postupgrade_fixups.sql

Session altered.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.


Package created.

No errors.

Package body created.


PL/SQL procedure successfully completed.

No errors.





Package created.

No errors.

Package body created.

No errors.
Executing Oracle POST-Upgrade Fixup Script

Auto-Generated by: Oracle Preupgrade Script
Version: 19.0.0.0.0 Build: 11
Generated on: 2025-05-05 09:33:57

For Source Database: ORCL
Source Database Version: 12.2.0.1.0
For Upgrade to Version: 19.0.0.0.0

Preup Preupgrade
Action Issue Is
Number Preupgrade Check Name Remedied Further DBA Action
------ ------------------------ ---------- --------------------------------
9. old_time_zones_exist YES None.
10. post_dictionary YES None.
11. post_fixed_objects NO Informational only.
Further action is optional.

The fixup scripts have been run and resolved what they can. However,
there are still issues originally identified by the preupgrade that
have not been remedied and are still present in the database.
Depending on the severity of the specific issue, and the nature of
the issue itself, that could mean that your database upgrade is not
fully complete. To resolve the outstanding issues, start by reviewing
the postupgrade_fixups.sql and searching it for the name of
the failed CHECK NAME or Preupgrade Action Number listed above.
There you will find the original corresponding diagnostic message
from the preupgrade which explains in more detail what still needs
to be done.

PL/SQL procedure successfully completed.


Session altered.

SQL>

Tips,dbua的时候会提示进行备份,可以不用提前备份,在dbua的时候进行备份。如果要使用flashbackup,记得提前设置 db_recovery_file_dest,如果在dbua的时候检测到 db_recovery_file_dest 未设置,及时你设置之后,dbua仍然检测不到,即使你 返回上一步,再点击next也检测不到。

参考资料:

Oracle 19c - 使用 DBUA 升级数据库到 Oracle Database 19c (19.x) 的完整核对清单 (Doc ID 2577574.1)

The new AutoUpgrade utility in Oracle 19c

原文作者: liups.com

原文链接: http://liups.com/posts/fda668cc/

许可协议: 知识共享署名-非商业性使用 4.0 国际许可协议