[Oracle Cloud]DBCS間でPDBホットクローンでPDB(12c)をOracle19cにアップグレードしてみた。

# はじめに

Pluggable Databaseのホットクローン機能を使って
Oracle Database 12c (12.2)のPDBを Oracle Database 19cに
アップグレード作成手順を確認してみた。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/108635/4ed07cde-1843-e217-4036-64a5601465d5.png)

# PDBホットクローンとは

クローン元のPDBが READ/WRITE状態のままクローンPDBを作成することができる機能です。

以下の Qiita 記事を 参考にしました。
[[Oracle DB] ホットクローンでリフレッシュ可能PDBを作成する手順](https://qiita.com/y_imaaa/items/b84419bf1c8d07832d55)

# 作業手順
以下の作業を OCI上の DBCS間 で実施しました。

- PDBのクローン
    - Database Linkの作成
    - PDBクローンの作成
- PDBのUpgrade
- Upgrade後の作業

# 作業ログ

## PDBのクローン
### Database link の作成

- Oracle 19c が使用する tnsnames.ora ファイルに Oracle 12c(12.2) のPDBに接続するエントリを作成

- Oracle 19c の CDBに接続し、public database link を作成

```
create public database link pdb1 connect to system identified by <SYSTEMユーザパスワード> using 'pdb1';
```

### PDBクローンでのPluggable Database の作成

- Oracle 19c の CDBに接続し、PDBクローンでPluggable Databaseを作成

```
SQL> create pluggable database pdb1 from pdb1@pdb1 keystore identified by <keystore パスワード>;

Pluggable database created.
```

## PDBのUpgrade
### PDBのオープン
- 作成したPDB(PDB1)をUpgrade モードでオープン

```
SQL> ALTER PLUGGABLE DATABASE PDB1 OPEN UPGRADE;

Pluggable database altered.
SQL> quit
```

### dbupgradeの実行
- dbupgradeの実行 (処理対象として PDB1 を指定)

```
$ dbupgrade -c PDB1 -d $ORACLE_HOME/rdbms/admin -l /home/oracle

Argument list for [/u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/catctl.pl]
For Oracle internal use only A = 0
Run in                       c = PDB1
Do not run in                C = 0
Input Directory              d = /u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin
Echo OFF                     e = 1
Simulate                     E = 0
Forced cleanup               F = 0
Log Id                       i = 0
Child Process                I = 0
Log Dir                      l = /home/oracle
Priority List Name           L = 0
Upgrade Mode active          M = 0
SQL Process Count            n = 0
SQL PDB Process Count        N = 0
Open Mode Normal             o = 0
Start Phase                  p = 0
End Phase                    P = 0
Reverse Order                r = 0
AutoUpgrade Resume           R = 0
Script                       s = 0
Serial Run                   S = 0
RO User Tablespaces          T = 0
Display Phases               y = 0
Debug catcon.pm              z = 0
Debug catctl.pl              Z = 0

catctl.pl VERSION: [19.0.0.0.0]
           STATUS: [Production]
            BUILD: [RDBMS_19.9.0.0.0DBRU_LINUX.X64_200930]


/u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/orahome = [/u01/app/oracle/product/19.0.0.0/dbhome_1]
/u01/app/oracle/product/19.0.0.0/dbhome_1/bin/orabasehome = [/u01/app/oracle/product/19.0.0.0/dbhome_1]
catctlGetOraBaseLogDir = [/u01/app/oracle/product/19.0.0.0/dbhome_1]

Analyzing file /u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/catupgrd.sql

Log file directory = [/home/oracle]

catcon::set_log_file_base_path: ALL catcon-related output will be written to [/home/oracle/catupgrd_catcon_27539.lst]

catcon::set_log_file_base_path: catcon: See [/home/oracle/catupgrd*.log] files for output generated by scripts

catcon::set_log_file_base_path: catcon: See [/home/oracle/catupgrd_*.lst] files for spool files, if any


Number of Cpus        = 2
Database Name         = DB19c_iad333
DataBase Version      = 19.0.0.0.0
PDB Parallel SQL Process Count = [2] is higher or equal to CPU Count = [2]
Concurrent PDB Upgrades defaulting to CPU Count [2]
Parallel SQL Process Count (PDB)      = 2
Parallel SQL Process Count (CDB$ROOT) = 4
Concurrent PDB Upgrades               = 2
Generated PDB Inclusion:[PDB1]
CDB$ROOT  Open Mode = [OPEN]
Concurrent PDB Upgrades Reset           = 1
DataBase Version      = 19.0.0.0.0

Start processing of PDBs (PDB1)
[/u01/app/oracle/product/19.0.0.0/dbhome_1/perl/bin/perl /u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/catctl.pl -c 'PDB1' -d /u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin -l /home/oracle -I -i pdb1 -n 2 /u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/catupgrd.sql]

Argument list for [/u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/catctl.pl]
For Oracle internal use only A = 0
Run in                       c = PDB1
Do not run in                C = 0
Input Directory              d = /u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin
Echo OFF                     e = 1
Simulate                     E = 0
Forced cleanup               F = 0
Log Id                       i = pdb1
Child Process                I = 1
Log Dir                      l = /home/oracle
Priority List Name           L = 0
Upgrade Mode active          M = 0
SQL Process Count            n = 2
SQL PDB Process Count        N = 0
Open Mode Normal             o = 0
Start Phase                  p = 0
End Phase                    P = 0
Reverse Order                r = 0
AutoUpgrade Resume           R = 0
Script                       s = 0
Serial Run                   S = 0
RO User Tablespaces          T = 0
Display Phases               y = 0
Debug catcon.pm              z = 0
Debug catctl.pl              Z = 0

catctl.pl VERSION: [19.0.0.0.0]
           STATUS: [Production]
            BUILD: [RDBMS_19.9.0.0.0DBRU_LINUX.X64_200930]


/u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/orahome = [/u01/app/oracle/product/19.0.0.0/dbhome_1]
/u01/app/oracle/product/19.0.0.0/dbhome_1/bin/orabasehome = [/u01/app/oracle/product/19.0.0.0/dbhome_1]
catctlGetOraBaseLogDir = [/u01/app/oracle/product/19.0.0.0/dbhome_1]

Analyzing file /u01/app/oracle/product/19.0.0.0/dbhome_1/rdbms/admin/catupgrd.sql

Log file directory = [/home/oracle]

catcon::set_log_file_base_path: ALL catcon-related output will be written to [/home/oracle/catupgrdpdb1_catcon_28588.lst]

catcon::set_log_file_base_path: catcon: See [/home/oracle/catupgrdpdb1*.log] files for output generated by scripts

catcon::set_log_file_base_path: catcon: See [/home/oracle/catupgrdpdb1_*.lst] files for spool files, if any


Number of Cpus        = 2
Database Name         = DB19c_iad333
DataBase Version      = 19.0.0.0.0
PDB1 Open Mode = [MIGRATE]
Generated PDB Inclusion:[PDB1]
CDB$ROOT  Open Mode = [OPEN]
Components in [PDB1]
    Installed [APS CATALOG CATJAVA CATPROC CONTEXT DV JAVAVM OLS ORDIM OWM SDO XDB XML XOQ]
Not Installed [APEX EM MGW ODM RAC WK]
DataBase Version      = 19.0.0.0.0

------------------------------------------------------
Phases [0-107]         Start Time:[2021_03_03 11:56:20]
Container Lists Inclusion:[PDB1] Exclusion:[NONE]
------------------------------------------------------
***********   Executing Change Scripts   ***********
Serial   Phase #:0    [PDB1] Files:1    Time: 46s
***************   Catalog Core SQL   ***************
Serial   Phase #:1    [PDB1] Files:5    Time: 72s
Restart  Phase #:2    [PDB1] Files:1    Time: 1s
***********   Catalog Tables and Views   ***********
Parallel Phase #:3    [PDB1] Files:19   Time: 41s
Restart  Phase #:4    [PDB1] Files:1    Time: 1s
*************   Catalog Final Scripts   ************
Serial   Phase #:5    [PDB1] Files:7    Time: 31s
*****************   Catproc Start   ****************
Serial   Phase #:6    [PDB1] Files:1    Time: 18s
*****************   Catproc Types   ****************
Serial   Phase #:7    [PDB1] Files:2    Time: 17s
Restart  Phase #:8    [PDB1] Files:1    Time: 1s
****************   Catproc Tables   ****************
Parallel Phase #:9    [PDB1] Files:67   Time: 61s
Restart  Phase #:10   [PDB1] Files:1    Time: 1s
*************   Catproc Package Specs   ************
Serial   Phase #:11   [PDB1] Files:1    Time: 96s
Restart  Phase #:12   [PDB1] Files:1    Time: 2s
**************   Catproc Procedures   **************
Parallel Phase #:13   [PDB1] Files:94   Time: 19s
Restart  Phase #:14   [PDB1] Files:1    Time: 2s
Parallel Phase #:15   [PDB1] Files:121  Time: 28s
Restart  Phase #:16   [PDB1] Files:1    Time: 1s
Serial   Phase #:17   [PDB1] Files:22   Time: 8s
Restart  Phase #:18   [PDB1] Files:1    Time: 1s
*****************   Catproc Views   ****************
Parallel Phase #:19   [PDB1] Files:32   Time: 40s
Restart  Phase #:20   [PDB1] Files:1    Time: 2s
Serial   Phase #:21   [PDB1] Files:3    Time: 24s
Restart  Phase #:22   [PDB1] Files:1    Time: 1s
Parallel Phase #:23   [PDB1] Files:25   Time: 223s
Restart  Phase #:24   [PDB1] Files:1    Time: 2s
Parallel Phase #:25   [PDB1] Files:12   Time: 119s
Restart  Phase #:26   [PDB1] Files:1    Time: 1s
Serial   Phase #:27   [PDB1] Files:1    Time: 0s
Serial   Phase #:28   [PDB1] Files:3 ^[[C^[[C^[[C   Time: 8s
Serial   Phase #:29   [PDB1] Files:1    Time: 0s
Restart  Phase #:30   [PDB1] Files:1    Time: 1s
***************   Catproc CDB Views   **************
Serial   Phase #:31   [PDB1] Files:1    Time: 6s
Restart  Phase #:32   [PDB1] Files:1    Time: 1s
Serial   Phase #:34   [PDB1] Files:1    Time: 0s
*****************   Catproc PLBs   *****************
Serial   Phase #:35   [PDB1] Files:295  Time: 31s
Serial   Phase #:36   [PDB1] Files:1    Time: 0s
Restart  Phase #:37   [PDB1] Files:1    Time: 2s
Serial   Phase #:38   [PDB1] Files:6    Time: 9s
Restart  Phase #:39   [PDB1] Files:1    Time: 2s
***************   Catproc DataPump   ***************
Serial   Phase #:40   [PDB1] Files:3 ^[[C   Time: 85s
Restart  Phase #:41   [PDB1] Files:1    Time: 2s
******************   Catproc SQL   *****************
Parallel Phase #:42   [PDB1] Files:13   Time: 126s
Restart  Phase #:43   [PDB1] Files:1    Time: 1s
Parallel Phase #:44   [PDB1] Files:11   Time: 12s
Restart  Phase #:45   [PDB1] Files:1    Time: 1s
Parallel Phase #:46   [PDB1] Files:3    Time: 9s
Restart  Phase #:47   [PDB1] Files:1    Time: 1s
*************   Final Catproc scripts   ************
Serial   Phase #:48   [PDB1] Files:1    Time: 15s
Restart  Phase #:49   [PDB1] Files:1    Time: 2s
**************   Final RDBMS scripts   *************
Serial   Phase #:50   [PDB1] Files:1    Time: 10s
************   Upgrade Component Start   ***********
Serial   Phase #:51   [PDB1] Files:1    Time: 5s
Restart  Phase #:52   [PDB1] Files:1    Time: 2s
**********   Upgrading Java and non-Java   *********
Serial   Phase #:53   [PDB1] Files:2    Time: 382s
*****************   Upgrading XDB   ****************
Restart  Phase #:54   [PDB1] Files:1    Time: 1s
Serial   Phase #:56   [PDB1] Files:3    Time: 14s
Serial   Phase #:57   [PDB1] Files:3    Time: 8s
Parallel Phase #:58   [PDB1] Files:10   Time: 10s
Parallel Phase #:59   [PDB1] Files:25   Time: 12s
Serial   Phase #:60   [PDB1] Files:4    Time: 20s
Serial   Phase #:61   [PDB1] Files:1    Time: 0s
Serial   Phase #:62   [PDB1] Files:32   Time: 10s
Serial   Phase #:63   [PDB1] Files:1    Time: 0s
Parallel Phase #:64   [PDB1] Files:6    Time: 12s
Serial   Phase #:65   [PDB1] Files:2    Time: 35s
Serial   Phase #:66   [PDB1] Files:3    Time: 38s
****************   Upgrading ORDIM   ***************
Restart  Phase #:67   [PDB1] Files:1    Time: 1s
Serial   Phase #:69   [PDB1] Files:1    Time: 7s
Parallel Phase #:70   [PDB1] Files:2    Time: 18s
Restart  Phase #:71   [PDB1] Files:1    Time: 2s
Parallel Phase #:72   [PDB1] Files:2    Time: 140s
Serial   Phase #:73   [PDB1] Files:2    Time: 7s
*****************   Upgrading SDO   ****************
Restart  Phase #:74   [PDB1] Files:1    Time: 2s
Serial   Phase #:76   [PDB1] Files:1    Time: 46s
Serial   Phase #:77   [PDB1] Files:2    Time: 9s
Restart  Phase #:78   [PDB1] Files:1    Time: 2s
Serial   Phase #:79   [PDB1] Files:1    Time: 11s
Restart  Phase #:80   [PDB1] Files:1    Time: 1s
Parallel Phase #:81   [PDB1] Files:3    Time: 74s
Restart  Phase #:82   [PDB1] Files:1    Time: 2s
Serial   Phase #:83   [PDB1] Files:1    Time: 8s
Restart  Phase #:84   [PDB1] Files:1    Time: 1s
Serial   Phase #:85   [PDB1] Files:1    Time: 18s
Restart  Phase #:86   [PDB1] Files:1    Time: 2s
Parallel Phase #:87   [PDB1] Files:4    Time: 92s
Restart  Phase #:88   [PDB1] Files:1    Time: 1s
Serial   Phase #:89   [PDB1] Files:1    Time: 7s
Restart  Phase #:90   [PDB1] Files:1    Time: 1s
Serial   Phase #:91   [PDB1] Files:2    Time: 29s
Restart  Phase #:92   [PDB1] Files:1    Time: 1s
Serial   Phase #:93   [PDB1] Files:1    Time: 5s
Restart  Phase #:94   [PDB1] Files:1    Time: 1s
*******   Upgrading ODM, WK, EXF, RUL, XOQ   *******
Serial   Phase #:95   [PDB1] Files:1    Time: 21s
Restart  Phase #:96   [PDB1] Files:1    Time: 1s
***********   Final Component scripts    ***********
Serial   Phase #:97   [PDB1] Files:1    Time: 7s
*************   Final Upgrade scripts   ************
Serial   Phase #:98   [PDB1] Files:1    Time: 495s
*******************   Migration   ******************
Serial   Phase #:99   [PDB1] Files:1    Time: 8s
***   End PDB Application Upgrade Pre-Shutdown   ***
Serial   Phase #:100  [PDB1] Files:1    Time: 8s
Serial   Phase #:101  [PDB1] Files:1    Time: 11s
Serial   Phase #:102  [PDB1] Files:1    Time: 11s
*****************   Post Upgrade   *****************
Serial   Phase #:103  [PDB1] Files:1    Time: 127s
****************   Summary report   ****************
Serial   Phase #:104  [PDB1] Files:1    Time: 6s
***   End PDB Application Upgrade Post-Shutdown   **
Serial   Phase #:105  [PDB1] Files:1    Time: 5s
Serial   Phase #:106  [PDB1] Files:1    Time: 5s
Serial   Phase #:107  [PDB1] Files:1     Time: 0s

------------------------------------------------------
Phases [0-107]         End Time:[2021_03_03 12:45:06]
Container Lists Inclusion:[PDB1] Exclusion:[NONE]
------------------------------------------------------

Grand Total Time: 2928s [PDB1]

 LOG FILES: (/home/oracle/catupgrdpdb1*.log)

Upgrade Summary Report Located in:
/home/oracle/upg_summary.log

     Time: 2998s For PDB(s)

Grand Total Time: 2998s

 LOG FILES: (/home/oracle/catupgrd*.log)


Grand Total Upgrade Time:    [0d:0h:49m:58s]
$
```

### PDBのオープン

```
$ sqlplus / as sysdba
SQL>  alter pluggable database PDB1 open;

Warning: PDB altered with errors.

SQL> alter pluggable database PDB1 save state;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB0                           READ WRITE NO
         4 PDB1                           READ WRITE YES
SQL> quit
$
```

## Upgrade後の作業
### PL/SQLコード再コンパイル
- catcon.pl で utlrp.sql を実行

```
$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -c 'PDB1' -e -b utlrp -d /home/oracle $ORACLE_HOME/rdbms/admin/utlrp.sql
catcon::set_log_file_base_path: ALL catcon-related output will be written to [/home/oracle/utlrp_catcon_93112.lst]

catcon::set_log_file_base_path: catcon: See [/home/oracle/utlrp*.log] files for output generated by scripts

catcon::set_log_file_base_path: catcon: See [/home/oracle/utlrp_*.lst] files for spool files, if any

catcon.pl: completed successfully
$
```

### タイム・ゾーン・データをアップグレード
- catcon.pl で utltz_upg_check.sql/utltz_upg_apply.sql を実行

```
$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -c 'PDB1' -l /home/oracle -b utltz_upg_check -d /home/oracle $ORACLE_HOME/rdbms/admin/utltz_upg_check.sql
catcon::set_log_file_base_path: ALL catcon-related output will be written to [/home/oracle/utltz_upg_check_catcon_99134.lst]

catcon::set_log_file_base_path: catcon: See [/home/oracle/utltz_upg_check*.log] files for output generated by scripts

catcon::set_log_file_base_path: catcon: See [/home/oracle/utltz_upg_check_*.lst] files for spool files, if any

catcon.pl: completed successfully
$
```

```
$ $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -c 'PDB1' -l /home/oracle -b utltz_upg_apply -d /home/oracle $ORACLE_HOME/rdbms/admin/utltz_upg_apply.sql
catcon::set_log_file_base_path: ALL catcon-related output will be written to [/home/oracle/utltz_upg_apply_catcon_5114.lst]

catcon::set_log_file_base_path: catcon: See [/home/oracle/utltz_upg_apply*.log] files for output generated by scripts

catcon::set_log_file_base_path: catcon: See [/home/oracle/utltz_upg_apply_*.lst] files for spool files, if any

catcon.pl: completed successfully
$
```

# PDB状態の確認

```
$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Mar 3 13:10:32 2021
Version 19.9.0.0.0

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


Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.9.0.0.0

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB0                           READ WRITE NO
         4 PDB1                           READ WRITE NO

```

# おわりに
PDBホットクローンにより少ないステップでPDBのアップグレードができた。

# 参考情報

- [マルチテナント・コンテナOracle Database (CDB)の手動でのアップグレード](https://docs.oracle.com/cd/F19136_01/upgrd/manual-upgrade-scenarios-multitenant-architecture-oracle-databases.html#GUID-8231CE50-ABEC-4BA3-A4AC-D461EB791ACD)
- [Upgrade Testing – Online Clone a PDB to 19c](https://mikedietrichde.com/2020/03/06/upgrade-testing-online-clone-a-pdb-to-19c/)

## 補足

- [DataVault and OLS is valid for Standard Edition in 12.2 database. (Doc ID 2583879.1)](https://support.oracle.com/knowledge/Oracle%20Cloud/2583879_1.html)