Skip to content

Upgrade PDB using Unplug/Plugin

    Prepare the PDB for Upgrade

    The PDB must be prepared for upgrade, then unplugged from the source container databases.

    Switch to the “cdb1” instance in the “12.1.0.1” environment.

    export ORACLE_BASE=/u01/app/oracle
    
    export ORAENV_ASK=NO
    export ORACLE_SID=cdb1
    . oraenv
    export ORAENV_ASK=YES
    sqlplus /nolog

    From Oracle 12.2 onward the “preupgrd.sql” script has been removed and replaced by the “preupgrade.jar” file, which is run as follows. The “preupgrade.jar” file is shipped with the Oracle software, but you should really download the latest version.

    $ORACLE_HOME/jdk/bin/java -jar /u01/app/oracle/product/12.1.0.2/db_1/rdbms/admin/preupgrade.jar TERMINAL TEXT -c "pdb1"

    The resulting output is similar to the “preupgrd.sql” script, an example of which is shown below.

    Run the “preupgrd.sql” script from the “12.1.0.2” home, not the current 12.1.0.1 home!

    CONN / AS SYSDBA
    ALTER SESSION SET CONTAINER=pdb1;
    
    @/u01/app/oracle/product/12.1.0.2/db_1/rdbms/admin/preupgrd.sql
    

    The output displays the generated scripts, including the “preupgrade.log” file. Both the log file and fixup scripts will be in the “$ORACLE_BASE/cfgtoollogs” directory or the “$ORACLE_HOME/cfgtoollogs” directory, depending on whether the $ORACLE_BASE has been specified or not. Run the fixup script and perform any manual tasks listed in the “preupgrade.log” file. These should be listed by the “preupgrade_fixups.sql” script also.

    CONN / AS SYSDBA
    ALTER SESSION SET CONTAINER=pdb1;
    
    @/u01/app/oracle/cfgtoollogs/cdb1/preupgrade/preupgrade_fixups.sql
    
    SQL>
    
    EXEC DBMS_STATS.gather_dictionary_stats;

    Connect to the root container and unplug the PDB.

    CONN / AS SYSDBA
    ALTER PLUGGABLE DATABASE pdb1 CLOSE;
    ALTER PLUGGABLE DATABASE pdb1 UNPLUG INTO '/tmp/pdb1.xml';
    EXIT;

    You have a couple of options about how to deal with the source pluggable database.

    -- Option 1
    -- 1) Drop the PDB, but keep the datafiles.
    DROP PLUGGABLE DATABASE pdb1 KEEP DATAFILES;
    -- 2) Copy the files to the destination location.
    -- 2) Manually clean up the files.
    
    
    -- Option 2
    -- 1) Copy the files to the destination location.
    -- 2) Drop the PDB, including the datafiles, as they have already been copied to the destination.
    DROP PLUGGABLE DATABASE pdb1 INCLUDING DATAFILES;
    Upgrade the PDB

    The PDB must be plugged into the destination CDB and upgraded.

    Switch to the “cdb2” instance in the “12.1.0.2” environment.

    export ORACLE_BASE=/u01/app/oracle
    
    export ORAENV_ASK=NO
    export ORACLE_SID=cdb2
    . oraenv
    export ORAENV_ASK=YES
    sqlplus /nolog

    Plugin the “pdb1” pluggable database into the “cdb2” container.

    CONN / AS SYSDBA
    
    CREATE PLUGGABLE DATABASE pdb1 USING '/tmp/pdb1.xml'
      FILE_NAME_CONVERT=('/oradata/cdb1/pdb1', '/oradata/cdb2/pdb1');
    
    ALTER PLUGGABLE DATABASE pdb1 OPEN UPGRADE;
    
    Warning: PDB altered with errors.
    
    SQL> EXIT;

    Don’t worry about the “Warning: PDB altered with errors.” message at this point.

    Run the “catupgrd.sql” script against the PDB. Notice the use of the “-c” flag to specify an inclusion list. If you were upgrading multiple PDBs, you could list them in a space-separated list so they are all upgraded in a single step.

    cd $ORACLE_HOME/rdbms/admin 
    $ORACLE_HOME/perl/bin/perl catctl.pl -c "pdb1" -l /tmp catupgrd.sql

    Start the PDB and recompile any invalid objects.

    CONN / AS SYSDBA
    ALTER SESSION SET CONTAINER=pdb1;
    STARTUP;
    
    @?/rdbms/admin/utlrp.sql

    Run the “postupgrade_fixups.sql” script. Remember to perform any recommended manual steps.

    @/u01/app/oracle/cfgtoollogs/cdb1/preupgrade/postupgrade_fixups.sql
    
    SQL> 
    
    EXECUTE DBMS_STATS.gather_fixed_objects_stats;

    The PDB upgrade is now complete.