Escolar Documentos
Profissional Documentos
Cultura Documentos
These scripts must be copied from the new 12c $ORACLE_HOME/rdbms/admin to the
$ORACLE_HOME/rdbms/admin directory of the database being upgrade.
Preupgrd.sql must be run from the environment of the database being upgraded.
The preupgrade_fixups.sql script is created to address issues that can be fixed using
SQL*Plus in the source database.
The postupgrade_fixups.sql script is created to address issues that can be fixed after
the database has been upgraded.
Pre-Upgrade Information Tool displays recommendations but does not execute the
recommendations automatically in order to ensure that you have control over how and when
the fix-up scripts are run.
Parallelism will break down each SQL file into stand-alone (independent) components.
If the SQL file is stand-alone then it can be run in parallel with another SQL file.
This is not always the case for all SQL scripts as some SQL scripts depend on each other and
can call other utilities.
In this case, Oracle ensures those dependencies are satisfied before calling the next script or
reference to them.
The purpose of dividing the upgrade into phases is due to the upgrade parallelism.
Phases are how Oracle upgrade will load sql files in parallel.
One phase has to complete before moving onto the next phase.
If ORACLE_BASE is not defined, then the generated scripts and log files are created under:
$ORACLE_HOME/cfgtoollogs/tool_name/SID/upgrade<n>
where n represents the incarnation number of the upgrade that been performed on this
system for a particular ORACLE_SID.
One log file for each parallel thread.The catctl.pl script will create multiple logfiles depending
on the degree of parallelism selected while running the catctl.pl and catupgrd.sql scripts.
For example:
catupgrd0.log
catupgrd1.log
catupgrd2.log
catupgrd3.log
Default log location is the current working directory.
Oracle EM Express
EM DB control is superseded in 12c by Oracle EM Express .
- Therefore no repository is needed anymore .
- If the EM repository is not removed up front ,it will be automatically removed during the
catuppst.sql post-upgrade phase.
OR
- Remove Enterprise Manager Database Control repository.
$emctl stop dbcontrol
SQL> @ ?/rdbms/admin/emremove.sql
This post describes how to move an 11.2.0.3 database into a 12.1 PDB. Anything that
wants to plug in to the new style architecture has to already be at oracle 12.1 or you have
to logically migrate
it into 12.1 (using datapump for example). You cannot plug in an 11.2 (or any other earlier
version) into 12.1. An upgrade to 12.1 in the 'normal' way is required. Actually even the
'normal' upgrade from 11.1 to 12.1 is slightly different to what you may be used to (at
least when using command line as i am here).
To start with lets create an 11.2 database in the simplest way possible (be prepared to be
amazed - i was the first time i ran this in its simplest syntax form). As always i alias s as
"sqlplus / as sysdba"
So first up lets create a (very) basic pfile for the database i'll call TEST2
[oracle@server-name]:TEST2:[/oracle/11.2.0.3.1.DB/dbs]# vi initTEST2.ora
[oracle@server-name]:TEST2:[/oracle/11.2.0.3.1.DB/dbs]# cat initTEST2.ora
*.control_files='/oracle/TEST2/oradata/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='/oracle/TEST2/oradata'
*.db_name='TEST2'
*.db_recovery_file_dest='/oracle/TEST2/recovery_area'
*.db_recovery_file_dest_size=4G
*.pga_aggregate_target=209715200
*.sga_target=800M
*.sga_max_size=800M
As you can see there is very little in it. I then create some directories it will need (note
the -p which creates all directories in the tree if the dont exist - quite a useful flag)
[oracle@server-name]:TEST2:[/oracle/11.2.0.3.1.DB/dbs]# mkdir -p
/oracle/TEST2/oradata
[oracle@server-name]:TEST2:[/oracle/11.2.0.3.1.DB/dbs]# mkdir -p
/oracle/TEST2/recovery_area
Now we log on and startup nomount to just read the pfile and create the instance
(processes and memory)
[oracle@server-name]:TEST2:[/oracle/11.2.0.3.1.DB/dbs]# s
SQL*Plus: Release 11.2.0.3.0 Production on Mon Aug 5 16:21:53 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.
SYS@TEST2>startup nomount
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size
2232960 bytes
Variable Size
230690176 bytes
Database Buffers
595591168 bytes
Redo Buffers
6590464 bytes
SYS@TEST2>
4
Then we create the database (and yes this really is all you type - quite a surprise when
you first see it this condensed)
SYS@TEST2>create database;
Database created.
SYS@TEST2>
Then we run the normal catalog/catproc scripts to create dba views etc
SYS@TEST2>@?/rdbms/admin/catalog
SYS@TEST2>@?/rdbms/admin/catproc
Now we have our source system created we want to be able to plug it in but first we need
to upgrade to 12c. I've done the minimum possible in the example below there may well
be a lot more you need
to go through for real..... First we run the pre upgrade check:
[oracle@server-name]:TEST2:[~]# s
SQL*Plus: Release 11.2.0.3.0 Production on Tue Aug 6 15:58:00 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning option
SYS@TEST2>@/oracle/12.0.0/rdbms/admin/preupgrd
Loading Pre-Upgrade Package...
WARNING: Failed to open preupgrade.log for write access
script will generate terminal output only
WARNING: Failed to open preupgrade_fixups.sql for write access
script will not generate fixup scripts.
Executing Pre-Upgrade Checks...
Oracle Database Pre-Upgrade Information Tool 08-06-2013 15:58:39
Script Version: 12.1.0.1.0 Build: 006
**********************************************************************
Database Name: TEST2
Version: 11.2.0.3.0
Compatible: 11.2.0
Blocksize: 8192
Platform: Linux x86 64-bit
Timezone file: V14
**********************************************************************
[Renamed Parameters]
[No Renamed Parameters in use]
5
**********************************************************************
**********************************************************************
[Obsolete/Deprecated Parameters]
[No Obsolete or Desupported Parameters in use]
**********************************************************************
[Component List]
**********************************************************************
--> Oracle Catalog Views
[upgrade] VALID
--> Oracle Packages and Types
[upgrade] VALID
**********************************************************************
[Tablespaces]
**********************************************************************
--> SYSTEM tablespace is adequate for the upgrade.
minimum required size: 641 MB
--> SYSAUX tablespace is adequate for the upgrade.
minimum required size: 500 MB
--> SYS_UNDOTS tablespace is adequate for the upgrade.
minimum required size: 400 MB
[No adjustments recommended]
**********************************************************************
**********************************************************************
[Pre-Upgrade Checks]
**********************************************************************
INFORMATION: --> Older Timezone in use
Database is using a time zone file older than version 18.
After the upgrade, it is recommended that DBMS_DST package
be used to upgrade the 11.2.0.3.0 database time zone version
to the latest version which comes with the new release.
Please refer to My Oracle Support note number 977512.1 for details.
**********************************************************************
[Pre-Upgrade Recommendations]
**********************************************************************
*****************************************
********* Dictionary Statistics *********
*****************************************
Please gather dictionary statistics 24 hours prior to
upgrading the database.
To gather dictionary statistics execute the following command
while connected as SYSDBA:
EXECUTE dbms_stats.gather_dictionary_stats;
^^^ MANUAL ACTION SUGGESTED ^^^
**********************************************************************
[Post-Upgrade Recommendations]
**********************************************************************
*****************************************
******** Fixed Object Statistics ********
*****************************************
Please create stats on fixed objects two weeks
after the upgrade using the command:
EXECUTE DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;
^^^ MANUAL ACTION SUGGESTED ^^^
**********************************************************************
************ Summary ************
0 ERRORS exist in your database.
0 WARNINGS exist in your database.
1 INFORMATIONAL message that should be reviewed prior to your upgrade.
After your database is upgraded and open in normal mode you must run
rdbms/admin/catuppst.sql which executes several required tasks and completes
the upgrade process.
You should follow that with the execution of rdbms/admin/utlrp.sql, and a
comparison of invalid objects before and after the upgrade using
rdbms/admin/utluiobj.sql
If needed you may want to upgrade your timezone data using the process
described in My Oracle Support note 977512.1
***********************************
Pre-Upgrade Checks Complete.
************************************************************
Results of the checks are located at:
*** Scripts/Logs are not being Generated ***preupgrade.log
************************************************************
====>> USER ACTION REQUIRED <<====
************************************************************
The following are *** ERROR LEVEL CONDITIONS *** that must be addressed
prior to attempting your upgrade.
Failure to do so will result in a failed upgrade.
You MUST resolve the above errors prior to upgrade
************************************************************
SYS@TEST2>
Then we shut it down
SYS@TEST2>shutdown immediate;
Database closed.
Database dismounted.
7
cddst.sql
10
12
prvtrwee.plb
prvtidxu.plb
prvtrcmp.plb
prvtchnf.plb
prvtedu.plb
prvtlsby.plb
prvtlsib.plb
prvtlssb.plb
prvtsmv.plb
prvtsma.plb
prvtbxfr.plb
prvtbord.plb
prvtjdbb.plb
prvtslrt.plb
prvtslxp.plb
prvtatsk.plb
prvtmntr.plb
prvtsmgu.plb
prvtdadv.plb
prvtadv.plb
prvtawr.plb
prvtawrs.plb
prvtawri.plb
prvtash.plb
prvtawrv.plb
prvtsqlf.plb
prvtsqli.plb
prvtsqlt.plb
prvtautorepi.plb prvtautorep.plb prvtfus.plb
prvtmp.plb
prvthdm.plb
prvtaddm.plb
prvtrtaddm.plb prvt_awr_data_cp.plb
prvtcpaddm.plb prvtuadv.plb
prvtsqlu.plb
prvtspai.plb
prvtspa.plb
prvtratmask.plb prvtspmi.plb
prvtspm.plb
prvtsmbi.plb
prvtsmb.plb
prvtfus.plb
catfusrg.sql
prvtwrk.plb
prvtsmaa.plb
prvtxpln.plb
prvtstat.plb
prvtstai.plb
prvtsqld.plb
prvtspcu.plb
prvtodm.plb
prvtkcl.plb
prvtdst.plb
prvtcmpr.plb
prvtilm.plb
prvtpexei.plb prvtpexe.plb
prvtcapi.plb
prvtfuse.plb
prvtfspi.plb
prvtpspi.plb
prvtdnfs.plb
prvtfs.plb
prvtadri.plb
prvtadr.plb
prvtadra.plb
prvtadmi.plb
prvtutils.plb prvtxsrs.plb
prvtsc.plb
prvtacl.plb
prvtds.plb
prvtns.plb
prvtdiag.plb
prvtkzrxu.plb
prvtnacl.plb
prvtredacta.plb prvtpdb.plb
prvttlog.plb
prvtsqll.plb
prvtappcont.plb prvtspd.plb
prvtspdi.plb
prvtpprof.plb prvtsqlm.plb
prvtpart.plb
prvtrupg.plb
prvtrupgis.plb prvtrupgib.plb prvtpstdy.plb prvttsdp.plb
prvtqopi.plb
prvtlog.plb
[Phase 34] type is 1 with 1 Files
ora_load_with_comp.sql
[Phase 35] type is 1 with 1 Files
ora_restart.sql
[Phase 36] type is 1 with 4 Files
catmetinsert.sql catpcnfg.sql
utluppkg.sql
catdph.sql
catsnmp.sql
execocm.sql
ora_restart.sql
[Phase 42] type is 1 with 1 Files
catpend.sql
[Phase 43] type is 1 with 1 Files
ora_restart.sql
[Phase 44] type is 1 with 1 Files
catupprc.sql
[Phase 45] type is 1 with 1 Files
cmpupstr.sql
[Phase 46] type is 1 with 1 Files
ora_restart.sql
[Phase 47] type is 1 with 2 Files
cmpupjav.sql
cmpupnjv.sql
[Phase 48] type is 1 with 1 Files
ora_restart.sql
[Phase 49] type is 1 with 2 Files
cmpupxdb.sql
cmpupnxb.sql
[Phase 50] type is 1 with 1 Files
ora_restart.sql
[Phase 51] type is 1 with 2 Files
cmpupord.sql
cmpupmsc.sql
[Phase 52] type is 1 with 1 Files
ora_restart.sql
[Phase 53] type is 1 with 1 Files
cmpupend.sql
[Phase 54] type is 1 with 1 Files
catupend.sql
[Phase 55] type is 1 with 1 Files
catuppst.sql
[Phase 56] type is 1 with 1 Files
catshutdown.sql
Using 6 processes.
Serial Phase #: 0 Files: 1
Serial Phase #: 1 Files: 3
Restart Phase #: 2 Files: 1
Parallel Phase #: 3 Files: 18
Restart Phase #: 4 Files: 1
Serial Phase #: 5 Files: 5
Time: 72s
Time: 30s
Time: 0s
Time: 4s
Time: 0s
Time: 14s
15
And were done - total time about 14 minutes which seems very similar to 11.2 from what i
remember but i guess there is more in 12 so maybe the parallel stuff is helping.
Few more post upgrade scripts now:
SQL> startup
SQL> @utlu121s.sql
.
Oracle Database 12.1 Post-Upgrade Status Tool
08-06-2013 16:26:21
.
Component
Current
Version Elapsed Time
Name
Status
Number HH:MM:SS
.
Oracle Server
.
UPGRADED
12.1.0.1.0 00:07:26
Oracle XML Database
.
VALID
12.1.0.1.0 00:03:25
Final Actions
.
00:01:05
Total Upgrade Time: 00:11:59
PL/SQL procedure successfully completed.
SQL>
SQL> @catuppst.sql
Session altered.
Session altered.
Session altered.
TIMESTAMP
-------------------------------------------------------------------------------COMP_TIMESTAMP POSTUP_BGN 2013-08-06 16:27:11
TIMESTAMP
-------------------------------------------------------------------------------COMP_TIMESTAMP CATREQ_BGN 2013-08-06 16:27:11
PL/SQL procedure successfully completed.
catrequtlmg:
catrequtlmg:
catrequtlmg:
catrequtlmg:
b_StatEvt
= TRUE
b_SelProps = FALSE
b_UpgradeMode = FALSE
b_InUtlMig = FALSE
17
...
Completed Moving the Baseline Data ...
...
If there are no Move BL Data messages ...
above, then there are no renamed
...
baseline tables in the system.
...
...
...
Completed the Dropping of the
...
Renamed Baseline Tables
...
...
If there are no Drop Table messages ...
above, then there are no renamed
...
baseline tables in the system.
...
...
18
Commit complete.
Table created.
2 rows created.
1 row updated.
2 rows updated.
0 rows updated.
Table dropped.
Commit complete.
0 rows updated.
Commit complete.
0 rows updated.
Commit complete.
0 rows updated.
Commit complete.
0 rows created.
Commit complete.
0 rows created.
Commit complete.
19
Session altered.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
20
21
SQL> COMMIT;
Commit complete.
SQL> SPOOL off
SQL> SET echo off
Check the following log file for errors:
/oracle/cfgtoollogs/catbundle/catbundle_PSU_TEST2_APPLY_2013Aug06_16_27_14.log
Session altered.
Session altered.
SQL>
Now the standard recompile
SQL> @?/rdbms/admin/utlrp
TIMESTAMP
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------COMP_TIMESTAMP UTLRP_BGN 2013-08-06 16:28:33
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
DOC>
SELECT job_name FROM dba_scheduler_jobs
DOC>
WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC> 2. Query showing UTL_RECOMP jobs that are running
DOC>
SELECT job_name FROM dba_scheduler_running_jobs
DOC>
WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#
PL/SQL procedure successfully completed.
TIMESTAMP
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------COMP_TIMESTAMP UTLRP_END 2013-08-06 16:30:33
DOC> The following query reports the number of objects that have compiled
DOC> with errors.
DOC>
DOC> If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#
OBJECTS WITH ERRORS
------------------0
DOC> The following query reports the number of errors caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC>#
ERRORS DURING RECOMPILATION
--------------------------0
Function created.
PL/SQL procedure successfully completed.
Function dropped.
PL/SQL procedure successfully completed.
23
SQL>
create the spfile now and restart
SQL>
SQL> create spfile from pfile;
File created.
SQL> startup force
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size
2293880 bytes
Variable Size
243273608 bytes
Database Buffers
583008256 bytes
Redo Buffers
6529024 bytes
Database mounted.
Database opened.
SQL>
SO now we have a 12.1 database up and running - it's perfectly usable in this format but
we want to plug in and move into the future.....
First thing to do is open the database read only - some more trial and error here trying to
be lazy and ending up taking longer...
[oracle@server-name]:TEST2:[~]# s
SQL*Plus: Release 12.1.0.1.0 Production on Tue Aug 6 20:30:15 2013
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing
opt
ions
SQL> startup force read only;
SP2-0714: invalid combination of STARTUP options
SQL> startup force mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size
2293880 bytes
Variable Size
243273608 bytes
Database Buffers
583008256 bytes
Redo Buffers
6529024 bytes
Database mounted.
SQL> alter database open readonly;
24
25
SQL> shutdown;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
The generated file has the following content
[oracle@server-name]:TEST2:[/tmp]# cat test2.xml
<?xml version="1.0" encoding="UTF-8"?>
<PDB>
<pdbname>TEST2</pdbname>
<cid>0</cid>
<byteorder>1</byteorder>
<vsn>202375424</vsn>
<dbid>906690115</dbid>
<cdbid>906690115</cdbid>
<guid>E349F1E1851D01E3E0433201EC0AA1BA</guid>
<uscnbas>867460</uscnbas>
<uscnwrp>0</uscnwrp>
<rdba>4226235</rdba>
<tablespace>
<name>SYSTEM</name>
<type>0</type>
<tsn>0</tsn>
<status>1</status>
<issft>0</issft>
<file>
<path>/oracle/TEST2/oradata/TEST2/datafile/o1_mf_system_8zzjsosr_.dbf</path>
<afn>1</afn>
<rfn>1</rfn>
<createscnbas>7</createscnbas>
<createscnwrp>0</createscnwrp>
<status>1</status>
<fileblocks>38400</fileblocks>
<blocksize>8192</blocksize>
<vsn>202375424</vsn>
<fdbid>906690115</fdbid>
<fcpsw>0</fcpsw>
<fcpsb>867459</fcpsb>
<frlsw>0</frlsw>
<frlsb>1</frlsb>
<frlt>822673347</frlt>
</file>
</tablespace>
<tablespace>
<name>SYSAUX</name>
<type>0</type>
<tsn>1</tsn>
<status>1</status>
<issft>0</issft>
<file>
<path>/oracle/TEST2/oradata/TEST2/datafile/o1_mf_sysaux_8zzjsqvc_.dbf</path>
<afn>2</afn>
26
<rfn>2</rfn>
<createscnbas>2173</createscnbas>
<createscnwrp>0</createscnwrp>
<status>1</status>
<fileblocks>38400</fileblocks>
<blocksize>8192</blocksize>
<vsn>202375424</vsn>
<fdbid>906690115</fdbid>
<fcpsw>0</fcpsw>
<fcpsb>867459</fcpsb>
<frlsw>0</frlsw>
<frlsb>1</frlsb>
<frlt>822673347</frlt>
</file>
</tablespace>
<optional>
<csid>1</csid>
<ncsid>2000</ncsid>
<options>
<option>CATALOG=12.1.0.1.0</option>
<option>CATPROC=12.1.0.1.0</option>
<option>XDB=12.1.0.1.0</option>
</options>
<dv>0</dv>
<ncdb2pdb>1</ncdb2pdb>
<APEX>NULL</APEX>
<parameters>
<parameter>sga_max_size=838860800</parameter>
<parameter>sga_target=838860800</parameter>
<parameter>db_block_size=8192</parameter>
<parameter>compatible=12.1.0.1</parameter>
<parameter>pga_aggregate_target=209715200</parameter>
</parameters>
<tzvers>
<tzver>primary version:14</tzver>
<tzver>secondary version:0</tzver>
</tzvers>
<walletkey>0</walletkey>
</optional>
</PDB>
Now we switch to the main container database so we can plug in
[oracle@server-name]:TEST2:[/tmp]# . oraenv
ORACLE_SID = [TEST2] ? ED12G
The Oracle base remains unchanged with value /oracle
Now we just need to plug the thing in using the xml file we generated in the last step.
[oracle@server-name]:ED12G:[/tmp]# s
SQL*Plus: Release 12.1.0.1.0 Production on Tue Aug 6 20:36:55 2013
Copyright (c) 1982, 2013, Oracle. All rights reserved.
27
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
SQL> create pluggable database test2 using '/tmp/test2.xml' nocopy;
Pluggable database created.
SQL>
SO now we are plugged in - now we have to run a conversion script to change all the
dictionary so it spans the pdb and the cdb.This is done using noncdb_to_pdb.sql. Lets log
on (switch to the
correct container) and run it.
[oracle@server-name]:TEST2:[/tmp]# cd $ORACLE_HOME/rdbms/admin
[oracle@server-name]:ED12G:[/oracle/12.0.0/rdbms/admin]# s
SQL*Plus: Release 12.1.0.1.0 Production on Tue Aug 6 20:43:16 2013
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> alter session set container=test2;
Session altered.
SQL> @noncdb_to_pdb.sql
SQL> SET SERVEROUTPUT ON
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL>
SQL> WHENEVER SQLERROR EXIT;
SQL>
SQL> DOC
DOC>#######################################################################
DOC>#######################################################################
DOC> The following statement will cause an "ORA-01403: no data found"
DOC> error if we're not in a PDB.
DOC> This script is intended to be run right after plugin of a PDB,
DOC> while inside the PDB.
DOC>#######################################################################
DOC>#######################################################################
DOC>#
SQL>
28
old 7:
new 7:
OPEN_STATE_COL
RESTRICTED
--------------------------------------------- ---------1 row selected.
SQL>
SQL>
SQL>
SQL>
2
3
4
5
1 row selected.
SQL>
SQL> -- if pdb was already closed, don't exit on error
SQL> WHENEVER SQLERROR CONTINUE;
SQL>
SQL> alter pluggable database "&pdbname" close;
old 1: alter pluggable database "&pdbname" close
new 1: alter pluggable database "TEST2" close
alter pluggable database "TEST2" close
*
ERROR at line 1:
ORA-65020: pluggable database TEST2 already closed
SQL>
SQL> WHENEVER SQLERROR EXIT;
SQL>
SQL> alter session set container = CDB$ROOT;
Session altered.
SQL> alter system flush shared_pool;
System altered.
SQL> /
System altered.
SQL> /
System altered.
30
Session altered.
SQL>
SQL> -- create temporary object-linked view to get list of objects marked as common
SQL> -- in CDB$ROOT
SQL> create or replace view sys.cdb$common_root_objects&pdbid sharing=object as
2 select u.name owner, o.name object_name, o.type# object_type, o.namespace nsp,
3
o.subname object_subname, o.signature object_sig,
4
decode(bitand(o.flags, 65536), 65536, 'MDL', 'OBL') sharing
31
5
6
old
new
View created.
SQL>
SQL> -- object-linked view for list of common users
SQL> create or replace view sys.cdb$common_users&pdbid sharing=object as
2 select name from sys.user$ where bitand(spare1, 128) <> 0;
old 1: create or replace view sys.cdb$common_users&pdbid sharing=object as
new 1: create or replace view sys.cdb$common_users5 sharing=object as
View created.
SQL>
SQL> -- object-linked view for accessing dependency$
SQL> create or replace view sys.cdb$rootdeps&pdbid sharing=object as select du.name as
owner, do.name as name, do.type#
as d_type#, do.namespace as d_namespace,pu.name as referenced_owner, po.name as
referenced_name, po.type# as p_type#,
po.namespace as p_namespace,d.order#,d.property,d.d_attrs,d.d_reason from sys.obj$
do, sys.obj$ po, sys.user$ du,
sys.user$ pu, sys.dependency$ d where du.user#=do.owner# and pu.user#=po.owner# and
do.obj#=d_obj# and po.obj#=p_obj#;
old 1: create or replace view sys.cdb$rootdeps&pdbid sharing=object as select du.name
as owner, do.name as name,
do.type# as d_type#, do.namespace as d_namespace,pu.name as referenced_owner,
po.name as referenced_name, po.type# as
p_type#, po.namespace as p_namespace,d.order#,d.property,d.d_attrs,d.d_reason from
sys.obj$ do, sys.obj$ po, sys.user$
du, sys.user$ pu, sys.dependency$ d where du.user#=do.owner# and pu.user#=po.owner#
and do.obj#=d_obj# and po.obj#=p_obj#
new 1: create or replace view sys.cdb$rootdeps5 sharing=object as select du.name as
owner, do.name as name, do.type# as
d_type#, do.namespace as d_namespace,pu.name as referenced_owner, po.name as
referenced_name, po.type# as p_type#,
po.namespace as p_namespace,d.order#,d.property,d.d_attrs,d.d_reason from sys.obj$
do, sys.obj$ po, sys.user$ du,
sys.user$ pu, sys.dependency$ d where du.user#=do.owner# and pu.user#=po.owner# and
do.obj#=d_obj# and po.obj#=p_obj#
View created.
32
SQL>
SQL> -- switch into PDB
SQL> alter session set container="&pdbname";
old 1: alter session set container="&pdbname"
new 1: alter session set container="TEST2"
Session altered.
SQL>
SQL> create or replace view sys.cdb$common_root_objects&pdbid sharing=object as
2 select u.name owner, o.name object_name, o.type# object_type, o.namespace nsp,
3
o.subname object_subname, o.signature object_sig,
4
decode(bitand(o.flags, 65536), 65536, 'MDL', 'OBL') sharing
5 from sys.obj$ o, sys.user$ u where
6 o.owner#=u.user# and bitand(o.flags, 196608) <> 0;
old 1: create or replace view sys.cdb$common_root_objects&pdbid sharing=object as
new 1: create or replace view sys.cdb$common_root_objects5 sharing=object as
View created.
SQL>
SQL> create or replace view sys.cdb$common_users&pdbid sharing=object as
2 select name from sys.user$ where bitand(spare1, 128) <> 0;
old 1: create or replace view sys.cdb$common_users&pdbid sharing=object as
new 1: create or replace view sys.cdb$common_users5 sharing=object as
View created.
SQL>
SQL> create or replace view sys.cdb$rootdeps&pdbid sharing=object as select du.name as
owner, do.name as name, do.type#
as d_type#, do.namespace as d_namespace,pu.name as referenced_owner, po.name as
referenced_name, po.type# as p_type#,
po.namespace as p_namespace,d.order#,d.property,d.d_attrs,d.d_reason from sys.obj$
do, sys.obj$ po, sys.user$ du,
sys.user$ pu, sys.dependency$ d where du.user#=do.owner# and pu.user#=po.owner# and
do.obj#=d_obj# and po.obj#=p_obj#;
old 1: create or replace view sys.cdb$rootdeps&pdbid sharing=object as select du.name
as owner, do.name as name,
do.type# as d_type#, do.namespace as d_namespace,pu.name as referenced_owner,
po.name as referenced_name, po.type# as
p_type#, po.namespace as p_namespace,d.order#,d.property,d.d_attrs,d.d_reason from
sys.obj$ do, sys.obj$ po, sys.user$
du, sys.user$ pu, sys.dependency$ d where du.user#=do.owner# and pu.user#=po.owner#
and do.obj#=d_obj# and po.obj#=p_obj#
new 1: create or replace view sys.cdb$rootdeps5 sharing=object as select du.name as
owner, do.name as name, do.type# as
33
DOC>
Data in columns of evolved types must be converted before the
DOC>
database can be converted.
DOC>
DOC> The following commands, run inside the PDB, will perform the data
DOC>
conversion for Oracle supplied data:
DOC>
DOC>
@?/rdbms/admin/utluppkg.sql
DOC>
SET SERVEROUTPUT ON;
DOC>
exec dbms_preup.run_fixup_and_report('INVALID_SYS_TABLEDATA');
DOC>
SET SERVEROUTPUT OFF;
DOC>
DOC> You should then confirm that any non-Oracle supplied data is also
DOC>
converted. You should review the data and determine if it needs
DOC>
to be converted or removed.
DOC>
DOC> To view the data that is affected by type evolution, execute the
DOC>
following inside the PDB:
DOC>
DOC>
SELECT rpad(u.name,128) TABLENAME, rpad(o.name,128) OWNER,
DOC>
rpad(c.name,128) COLNAME FROM SYS.OBJ$ o, SYS.COL$ c, SYS.COLTYPE$ t,
DOC>
SYS.USER$ u
DOC>
WHERE o.OBJ# = t.OBJ# AND c.OBJ# = t.OBJ# AND c.COL# = t.COL#
DOC>
AND t.INTCOL# = c.INTCOL# AND BITAND(t.FLAGS, 256) = 256
DOC>
AND o.OWNER# = u.USER# AND o.OWNER# NOT IN
DOC>
(SELECT UNIQUE (d.USER_ID) FROM SYS.DBA_USERS d, SYS.REGISTRY$ r
DOC>
WHERE d.USER_ID = r.SCHEMA# and r.NAMESPACE='SERVER');
DOC>
DOC>
Once the data is confirmed, the following commands, run inside the PDB,
DOC>
will convert the data returned by the above query.
DOC>
DOC>
@?/rdbms/admin/utluppkg.sql
DOC>
SET SERVEROUTPUT ON;
DOC>
exec dbms_preup.run_fixup_and_report('INVALID_USR_TABLEDATA');
DOC>
SET SERVEROUTPUT OFF;
DOC>
DOC>
Depending on the amount of data involved, converting the evolved type
DOC>
data can take a significant amount of time.
DOC>
DOC> After this is complete, please rerun noncdb_to_pdb.sql.
DOC>
DOC>#######################################################################
DOC>#######################################################################
DOC>#
SQL>
SQL> declare
2 do_abort boolean := false;
3 begin
4 if dbms_preup.condition_exists ('INVALID_SYS_TABLEDATA') then
5
-- dump out the info
6
dbms_preup.run_check('INVALID_SYS_TABLEDATA');
7
do_abort := TRUE;
8 end if;
9 if dbms_preup.condition_exists ('INVALID_USR_TABLEDATA') THEN
10
-- dump out the info
35
11
dbms_preup.run_check('INVALID_USR_TABLEDATA');
12
do_abort := TRUE;
13 END IF;
14 If do_abort THEN
15
dbms_output.put_line ('Invalid table data.');
16
dbms_output.put_line ('Non-CDB conversion aborting.');
17
dbms_output.put_line ('For instructions, look for ORA-01722 in this script.');
18
dbms_output.put_line ('Please resolve these and rerun noncdb_to_pdb.sql.');
19
RAISE INVALID_NUMBER;
20 end if;
21 end;
22 /
PL/SQL procedure successfully completed.
SQL>
SQL> -- END PRE-SCRIPT CHECKS
SQL> --------------------------------------------------------------------------SQL>
SQL> -- mark users and roles in our PDB as common if they exist as common in ROOT
SQL> DECLARE
2 cursor c is
3
select p.user# from sys.cdb$common_users&pdbid r, sys.user$ p
4
where r.name=p.name and bitand(p.spare1, 128)=0;
5 BEGIN
6 FOR u in c
7 LOOP
8
BEGIN
9
execute immediate 'update sys.user$ set spare1=spare1+128 where user#=' ||
10
u.user#;
11
END;
12 END LOOP;
13 commit;
14 END;
15 /
old 3: select p.user# from sys.cdb$common_users&pdbid r, sys.user$ p
new 3:
select p.user# from sys.cdb$common_users5 r, sys.user$ p
PL/SQL procedure successfully completed.
SQL>
SQL> select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') from dual;
TO_CHAR(SYSDATE,'DYDD-MO
-----------------------Tue 06-Aug-2013 20:43:52
1 row selected.
SQL>
SQL> -- mark objects in our PDB as common if they exist as common in ROOT
SQL> DECLARE
2 cursor c is
3
select p.object_id, p.flags-bitand(p.flags, 196608) flags,
36
4
decode(r.sharing, 'MDL', 65536, 131072) sharing_flag
5
from sys.cdb$common_root_objects&pdbid r, sys.cdb$objects&pdbid p
6
where r.owner=p.owner and r.object_name=p.object_name
7
and r.object_type=p.object_type and r.nsp=p.nsp
8
and (p.object_subname is null and r.object_subname is null
9
or r.object_subname=p.object_subname)
10
and decode(bitand(p.flags, 196608), 65536, 'MDL', 131072, 'OBL',
'NONE')<>r.sharing;
11 BEGIN
12 FOR obj in c
13 LOOP
14
BEGIN
15
execute immediate 'update sys.obj$ set flags=' || (obj.flags + obj.sharing_flag) ||
16
' where obj#=' || obj.object_id;
17
END;
18 END LOOP;
19 commit;
20 END;
21 /
old 5:
from sys.cdb$common_root_objects&pdbid r, sys.cdb$objects&pdbid p
new 5:
from sys.cdb$common_root_objects5 r, sys.cdb$objects5 p
PL/SQL procedure successfully completed.
SQL>
SQL> select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') from dual;
TO_CHAR(SYSDATE,'DYDD-MO
-----------------------Tue 06-Aug-2013 20:44:06
1 row selected.
SQL>
SQL> -- generate signatures for the common tables which don't have them
SQL> DECLARE
2 cursor c is
3
select r.owner, r.object_name
4
from sys.cdb$common_root_objects&pdbid r, sys.cdb$tables&pdbid p
5
where r.owner=p.owner and r.object_name=p.object_name
6
and r.object_type=2 and p.object_sig is null
7
and p.object_name not in ('OBJ$', 'USER$');
8 BEGIN
9 FOR tab in c
10 LOOP
11
BEGIN
12
execute immediate 'ALTER TABLE ' || tab.owner || '."' ||
13
tab.object_name || '" UPGRADE';
14
EXCEPTION
15
WHEN OTHERS THEN
16
BEGIN
17
IF (sqlcode = -600 or sqlcode = -602 or sqlcode = -603) THEN
18
raise;
19
END IF;
37
20
END;
21
END;
22 END LOOP;
23 commit;
24 END;
25 /
old 4:
from sys.cdb$common_root_objects&pdbid r, sys.cdb$tables&pdbid p
new 4:
from sys.cdb$common_root_objects5 r, sys.cdb$tables5 p
PL/SQL procedure successfully completed.
SQL>
SQL> -- for each table whose signature doesn't match ROOT's, mark its PL/SQL
SQL> -- dependents for local MCode
SQL> DECLARE
2 cursor c is
3
select obj#
4
from sys.obj$ o, sys.user$ u, sys.cdb$common_root_objects&pdbid ro
5
where o.type# <> 4 and u.name=ro.owner and u.user#=o.owner#
6
and o.name=ro.object_name and o.type#=ro.object_type and obj# in
7
(select d_obj# from sys.dependency$ where p_obj# in
8
(select p.object_id from sys.CDB$common_root_objects&pdbid r,
9
sys.cdb$tables&pdbid p
10
where r.owner=p.owner and r.object_name=p.object_name
11
and r.object_type=2 and r.object_sig <> p.object_sig));
12 BEGIN
13 FOR obj in c
14 LOOP
15
execute immediate
16
'update sys.obj$ set flags=flags+33554432-bitand(flags, 33554432) where obj#=' ||
obj.obj#;
17 END LOOP;
18 commit;
19 END;
20 /
old 4:
from sys.obj$ o, sys.user$ u, sys.cdb$common_root_objects&pdbid ro
new 4:
from sys.obj$ o, sys.user$ u, sys.cdb$common_root_objects5 ro
old 8:
(select p.object_id from sys.CDB$common_root_objects&pdbid r,
new 8:
(select p.object_id from sys.CDB$common_root_objects5 r,
old 9:
sys.cdb$tables&pdbid p
new 9:
sys.cdb$tables5 p
PL/SQL procedure successfully completed.
SQL>
SQL> select owner#, name from sys.obj$ where bitand(flags, 33554432)=33554432
2 order by 1, 2;
OWNER#
---------NAME
-------------------------------------------------------------------------------0
DBMS_APPLY_ADM_INTERNAL
38
0
DBMS_APPLY_ERROR
0
DBMS_APPLY_HANDLER_INTERNAL
0
DBMS_CAPTURE_SWITCH_INTERNAL
0
DBMS_DBFS_CONTENT
0
DBMS_DBFS_CONTENT_ADMIN
0
DBMS_DBFS_SFS_ADMIN
0
DBMS_ISCHED
0
DBMS_LOGREP_IMP_INTERNAL
0
DBMS_PICKLER
0
DBMS_REGISTRY_SYS
0
DBMS_REPCAT_UTL4
0
DBMS_SCHED_MAIN_EXPORT
0
DBMS_SPACE
0
DBMS_SPM_INTERNAL
0
DBMS_SQLTUNE_INTERNAL
0
DBMS_SQLTUNE_INTERNAL
0
DBMS_SQLTUNE_UTIL1
0
DBMS_STATS
39
0
DBMS_STATS_INTERNAL
0
DBMS_STATS_INTERNAL
0
DBMS_STREAMS_ADM_IVK
0
DBMS_STREAMS_ADM_UTL
0
DBMS_STREAMS_HANDLER_INTERNAL
0
DBMS_WORKLOAD_REPLAY
0
DBMS_WRR_INTERNAL
0
DBMS_XSTREAM_ADM_UTL
0
PRVTPARENTCHILD
0
PRVT_ADVISOR
0
PRVT_COMPRESSION
0
PRVT_SQLPA
0
PRVT_WORKLOAD
OWNER#
---------NAME
-------------------------------------------------------------------------------0
WRI$_ADV_HDM_T
0
WRI$_ADV_OBJSPACE_TREND_T
0
WRI$_ADV_SQLTUNE
40
0
XS_ACL_INT
0
XS_DATA_SECURITY_INT
0
XS_DIAG_INT
0
XS_NAMESPACE_INT
53
DBMS_CSX_INT
53
DBMS_XDB_ADMIN
53
DBMS_XMLSTORAGE_MANAGE
53
PRVT_DBMS_MANAGE_XMLSTORAGE
53
XDB$PATCHUPDELETESCHEMA
53
XDB$PATCHUPSCHEMA
53
XDBCONFIG_VALIDATE
46 rows selected.
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
2
3
4
5
-- Step (II)
--- Mark all metadata links as status 6
-- skip types w/ non-null subname
update sys.obj$ set status = 6
where (type# not in (2, 28, 29, 30, 56))
and (type# <> 13 or subname is null)
and status not in (5,6)
and bitand(flags, 65536)=65536;
SQL>
SQL> -- Invalidate all synonym dependents of dbms_standard. If not we will end up
SQL> -- with a timestamp mismatch between dependency and obj
SQL>
SQL> update sys.obj$ set status=6 where obj# in
2 (select d_obj# from sys.dependency$
3 where p_obj# in (select obj# from sys.obj$ where name='DBMS_STANDARD' and
4
type# in ( 9, 11) and owner#=0)
5 ) and type#=5
6 /
1 row updated.
SQL> commit
2 /
Commit complete.
SQL>
SQL> alter system flush shared_pool
2 /
System altered.
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
-- Step (II)
--- Recreate package standard and dbms_standard. This is needed to execute
-- subsequent anonymous blocks
SET ECHO OFF
Session altered.
Session altered.
Package created.
42
Session altered.
Session altered.
Package body created.
Session altered.
Grant succeeded.
Session altered.
Session altered.
Package created.
Synonym created.
Grant succeeded.
Session altered.
SQL> -- Step (III)
SQL> -SQL> -- Invalidate views and synonyms which depend (directly or indirectly) on
SQL> -- invalid objects.
SQL> begin
2 loop
3
update sys.obj$ o_outer set status = 6
4
where
type# in (4, 5)
5
and status not in (5, 6)
6
and linkname is null
7
and ((subname is null) or (subname <> 'DBMS_DBUPGRADE_BABY'))
8
and exists (select o.obj# from sys.obj$ o, sys.dependency$ d
9
where
d.d_obj# = o_outer.obj#
10
and d.p_obj# = o.obj#
11
and (bitand(d.property, 1) = 1)
12
and o.status > 1);
13
exit when sql%notfound;
14
nd loop;
15 end;
16 /
43
44
Synonym altered.
SQL> alter view V_$PARAMETER compile;
View altered.
SQL>
SQL> WHENEVER SQLERROR CONTINUE;
SQL> alter type ANYDATA compile;
Type altered.
SQL> WHENEVER SQLERROR EXIT;
SQL>
45
1 row selected.
SQL> select count(*) from sys.obj$ where bitand(flags, 65536)=65536 and obj# in
2 (select obj# from sys.view$);
COUNT(*)
---------5242
1 row selected.
SQL> select count(*) from sys.procedure$;
COUNT(*)
---------1677
1 row selected.
SQL> select count(*) from sys.obj$ where bitand(flags, 65536)=65536 and obj# in
2 (select obj# from sys.procedure$);
COUNT(*)
---------1645
1 row selected.
SQL> select count(*) from sys.dir$;
COUNT(*)
---------10
1 row selected.
SQL> select count(*) from sys.obj$ where bitand(flags, 65536)=65536 and obj# in
2 (select obj# from sys.dir$);
COUNT(*)
---------4
1 row selected.
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
@@utlrp
Rem
Rem $Header: utlrp.sql 24-jul-2003.10:06:51 gviswana Exp $
Rem
Rem utlrp.sql
Rem
Rem Copyright (c) 1998, 2003, Oracle Corporation. All rights reserved.
47
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
Rem
Rem NAME
Rem
utlrp.sql - Recompile invalid objects
Rem
Rem DESCRIPTION
Rem This script recompiles invalid objects in the database.
Rem
Rem
When run as one of the last steps during upgrade or downgrade,
Rem
this script will validate all remaining invalid objects. It will
Rem
also run a component validation procedure for each component in
Rem
the database. See the README notes for your current release and
Rem
the Oracle Database Upgrade book for more information about
Rem
using utlrp.sql
Rem
Rem Although invalid objects are automatically re-validated when used,
Rem
it is useful to run this script after an upgrade or downgrade and
Rem
after applying a patch. This minimizes latencies caused by
Rem
on-demand recompilation. Oracle strongly recommends running this
Rem
script after upgrades, downgrades and patches.
Rem
Rem NOTES
Rem
* This script must be run using SQL*PLUS.
Rem
* You must be connected AS SYSDBA to run this script.
Rem
* There should be no other DDL on the database while running the
Rem
script. Not following this recommendation may lead to deadlocks.
Rem
Rem MODIFIED (MM/DD/YY)
Rem gviswana 06/26/03 - Switch default to parallel if appropriate
Rem gviswana 06/12/03 - Switch default back to serial
Rem gviswana 05/20/03 - 2814808: Automatic parallelism tuning
Rem rburns
04/28/03 - timestamps and serveroutput for diagnostics
Rem gviswana 04/13/03 - utlrcmp.sql load -> catproc
Rem gviswana 06/25/02 - Add documentation
Rem gviswana 11/12/01 - Use utl_recomp.recomp_serial
Rem rdecker
11/09/01 - ADD ALTER library support FOR bug 1952368
Rem rburns
11/12/01 - validate all components after compiles
Rem rburns
11/06/01 - fix invalid CATPROC call
Rem rburns
09/29/01 - use 9.2.0
Rem rburns
09/20/01 - add check for CATPROC valid
Rem rburns
07/06/01 - get version from instance view
Rem rburns
05/09/01 - fix for use with 8.1.x
Rem arithikr 04/17/01 - 1703753: recompile object type# 29,32,33
Rem skabraha 09/25/00 - validate is now a keyword
Rem kosinski 06/14/00 - Persistent parameters
Rem skabraha 06/05/00 - validate tables also
Rem jdavison 04/11/00 - Modify usage notes for 8.2 changes.
Rem rshaikh
09/22/99 - quote name for recompile
Rem ncramesh 08/04/98 - change for sqlplus
Rem usundara 06/03/98 - merge from 8.0.5
Rem usundara 04/29/98 - creation (split from utlirp.sql).
Rem
Mark Ramacher (mramache) was the original
Rem
author of this script.
Rem
48
SQL> Rem
===========================================================================
SQL> Rem BEGIN utlrp.sql
SQL> Rem
===========================================================================
SQL>
SQL> @@utlprp.sql 0
SQL> Rem Copyright (c) 2003, 2011, Oracle and/or its affiliates.
SQL> Rem All rights reserved.
SQL> Rem
SQL> Rem NAME
SQL> Rem
utlprp.sql - Recompile invalid objects in the database
SQL> Rem
SQL> Rem DESCRIPTION
SQL> Rem
This script recompiles invalid objects in the database.
SQL> Rem
SQL> Rem
This script is typically used to recompile invalid objects
SQL> Rem
remaining at the end of a database upgrade or downgrade.
SQL> Rem
SQL> Rem
Although invalid objects are automatically recompiled on demand,
SQL> Rem
running this script ahead of time will reduce or eliminate
SQL> Rem
latencies due to automatic recompilation.
SQL> Rem
SQL> Rem
This script is a wrapper based on the UTL_RECOMP package.
SQL> Rem
UTL_RECOMP provides a more general recompilation interface,
SQL> Rem
including options to recompile objects in a single schema. Please
SQL> Rem
see the documentation for package UTL_RECOMP for more details.
SQL> Rem
SQL> Rem INPUTS
SQL> Rem
The degree of parallelism for recompilation can be controlled by
SQL> Rem
providing a parameter to this script. If this parameter is 0 or
SQL> Rem
NULL, UTL_RECOMP will automatically determine the appropriate
SQL> Rem
level of parallelism based on Oracle parameters cpu_count and
SQL> Rem
parallel_threads_per_cpu. If the parameter is 1, sequential
SQL> Rem
recompilation is used. Please see the documentation for package
SQL> Rem
UTL_RECOMP for more details.
SQL> Rem
SQL> Rem NOTES
SQL> Rem
* You must be connected AS SYSDBA to run this script.
SQL> Rem
* There should be no other DDL on the database while running the
SQL> Rem
script. Not following this recommendation may lead to deadlocks.
SQL> Rem
SQL> Rem MODIFIED (MM/DD/YY)
SQL> Rem kquinn
11/01/11 - 13059165: amend 'OBJECTS WITH ERRORS' SQL
SQL> Rem cdilling 05/15/10 - fix bug 9712478 - call local enquote_name
SQL> Rem anighosh 02/19/09 - #(8264899): re-enabling of function based indexes
SQL> Rem
not needed.
SQL> Rem cdilling 07/21/08 - check bitand for functional index - bug 7243270
SQL> Rem cdilling 01/21/08 - add support for ORA-30552
SQL> Rem cdilling 08/27/07 - check disabled indexes only
SQL> Rem cdilling 05/22/07 - add support for ORA-38301
SQL> Rem cdilling 02/19/07 - 5530085 - renable invalid indexes
SQL> Rem rburns
03/17/05 - use dbms_registry_sys
SQL> Rem gviswana 02/07/05 - Post-compilation diagnostics
49
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
Rem
Rem
Rem
Rem
Rem
Rem
TIMESTAMP
-------------------------------------------------------------------------------COMP_TIMESTAMP UTLRP_BGN 2013-08-06 20:44:24
1 row selected.
SQL>
SQL> DOC
DOC> The following PL/SQL block invokes UTL_RECOMP to recompile invalid
DOC> objects in the database. Recompilation time is proportional to the
DOC> number of invalid objects in the database, so this command may take
DOC> a long time to execute on a database with a large number of invalid
DOC> objects.
DOC>
DOC> Use the following queries to track recompilation progress:
DOC>
DOC> 1. Query returning the number of invalid objects remaining. This
DOC>
number should decrease with time.
DOC>
SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
DOC>
DOC> 2. Query returning the number of objects compiled so far. This number
DOC>
should increase with time.
DOC>
SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
DOC>
DOC> This script automatically chooses serial or parallel recompilation
DOC> based on the number of CPUs available (parameter cpu_count) multiplied
DOC> by the number of threads per CPU (parameter parallel_threads_per_cpu).
DOC> On RAC, this number is added across all RAC nodes.
DOC>
DOC> UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
DOC> recompilation. Jobs are created without instance affinity so that they
DOC> can migrate across RAC nodes. Use the following queries to verify
DOC> whether UTL_RECOMP jobs are being created and run correctly:
DOC>
DOC> 1. Query showing jobs created by UTL_RECOMP
DOC>
SELECT job_name FROM dba_scheduler_jobs
DOC>
WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC> 2. Query showing UTL_RECOMP jobs that are running
DOC>
SELECT job_name FROM dba_scheduler_running_jobs
DOC>
WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#
SQL>
50
SQL> DECLARE
2
threads pls_integer := &&1;
3 BEGIN
4
utl_recomp.recomp_parallel(threads);
5 END;
6 /
PL/SQL procedure successfully completed.
SQL>
SQL> SELECT dbms_registry_sys.time_stamp('utlrp_end') as timestamp from dual;
TIMESTAMP
-------------------------------------------------------------------------------COMP_TIMESTAMP UTLRP_END 2013-08-06 20:47:11
1 row selected.
SQL>
SQL> Rem #(8264899): The code to Re-enable functional indexes, which used to exist
SQL> Rem here, is no longer needed.
SQL>
SQL> DOC
DOC> The following query reports the number of objects that have compiled
DOC> with errors.
DOC>
DOC> If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#
SQL> select COUNT(DISTINCT(obj#)) "OBJECTS WITH ERRORS" from utl_recomp_errors;
OBJECTS WITH ERRORS
------------------0
1 row selected.
SQL>
SQL>
SQL> DOC
DOC> The following query reports the number of errors caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC>#
SQL> select COUNT(*) "ERRORS DURING RECOMPILATION" from utl_recomp_errors;
ERRORS DURING RECOMPILATION
--------------------------0
51
1 row selected.
SQL>
SQL>
SQL> Rem
SQL> Rem Declare function local_enquote_name to pass FALSE
SQL> Rem into underlying dbms_assert.enquote_name function
SQL> Rem
SQL> CREATE OR REPLACE FUNCTION local_enquote_name (str varchar2)
2 return varchar2 is
3
begin
4
return dbms_assert.enquote_name(str, FALSE);
5
end local_enquote_name;
6 /
Function created.
SQL> Rem
SQL> Rem If sys.enabled$index table exists, then re-enable
SQL> Rem list of functional indexes that were enabled prior to upgrade
SQL> Rem The table sys.enabled$index table is created in catupstr.sql
SQL> Rem
SQL> SET serveroutput on
SQL> DECLARE
2 TYPE tab_char IS TABLE OF VARCHAR2(32767) INDEX BY BINARY_INTEGER;
3
commands tab_char;
4
p_null CHAR(1);
5
p_schemaname VARCHAR2(30);
6
p_indexname VARCHAR2(30);
7
rebuild_idx_msg BOOLEAN := FALSE;
8
non_existent_index exception;
9
recycle_bin_objs exception;
10
cannot_change_obj exception;
11
no_such_table exception;
12
pragma exception_init(non_existent_index, -1418);
13
pragma exception_init(recycle_bin_objs, -38301);
14
pragma exception_init(cannot_change_obj, -30552);
15
pragma exception_init(no_such_table, -942);
16
type cursor_t IS REF CURSOR;
17
reg_cursor cursor_t;
18
19 BEGIN
20
-- Check for existence of the table marking disabled functional indices
21
22
SELECT NULL INTO p_null FROM DBA_OBJECTS
23
WHERE owner = 'SYS' and object_name = 'ENABLED$INDEXES' and
24
object_type = 'TABLE' and rownum <=1;
25
26
-- Select indices to be re-enabled
27
EXECUTE IMMEDIATE q'+
28
SELECT 'ALTER INDEX ' ||
29
local_enquote_name(e.schemaname) || '.' ||
30
local_enquote_name(e.indexname) || ' ENABLE'
31
FROM enabled$indexes e, ind$ i
52
32
WHERE e.objnum = i.obj# AND bitand(i.flags, 1024) != 0 AND
33
bitand(i.property, 16) != 0+'
34
BULK COLLECT INTO commands;
35
36
IF (commands.count() > 0) THEN
37
FOR i IN 1 .. commands.count() LOOP
38
BEGIN
39
EXECUTE IMMEDIATE commands(i);
40
EXCEPTION
41
WHEN NON_EXISTENT_INDEX THEN NULL;
42
WHEN RECYCLE_BIN_OBJS THEN NULL;
43
WHEN CANNOT_CHANGE_OBJ THEN rebuild_idx_msg := TRUE;
44
END;
45
END LOOP;
46
END IF;
47
48
-- Output any indexes in the table that could not be re-enabled
49
-- due to ORA-30552 during ALTER INDEX...ENBLE command
50
51
IF rebuild_idx_msg THEN
52
BEGIN
53
DBMS_OUTPUT.PUT_LINE
54 ('The following indexes could not be re-enabled and may need to be rebuilt:');
55
56
OPEN reg_cursor FOR
57
'SELECT e.schemaname, e.indexname
58
FROM enabled$indexes e, ind$ i
59
WHERE e.objnum = i.obj# AND bitand(i.flags, 1024) != 0';
60
61
LOOP
62
FETCH reg_cursor INTO p_schemaname, p_indexname;
63
EXIT WHEN reg_cursor%NOTFOUND;
64
DBMS_OUTPUT.PUT_LINE
65
('.... INDEX ' || p_schemaname || '.' || p_indexname);
66
END LOOP;
67
CLOSE reg_cursor;
68
69
EXCEPTION
70
WHEN NO_DATA_FOUND THEN CLOSE reg_cursor;
71
WHEN NO_SUCH_TABLE THEN CLOSE reg_cursor;
72
WHEN OTHERS THEN CLOSE reg_cursor; raise;
73
END;
74
75
END IF;
76
77
EXECUTE IMMEDIATE 'DROP TABLE sys.enabled$indexes';
78
79
EXCEPTION
80
WHEN NO_DATA_FOUND THEN NULL;
81
82 END;
83 /
PL/SQL procedure successfully completed.
53
SQL>
SQL> DROP function local_enquote_name;
Function dropped.
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
Rem =====================================================================
Rem Run component validation procedure
Rem =====================================================================
EXECUTE dbms_registry_sys.validate_components;
80
1 row selected.
SQL> select count(*) from sys.obj$ where bitand(flags, 65536)=65536 and obj# in
2 (select obj# from sys.procedure$);
COUNT(*)
---------48
1 row selected.
SQL> select count(*) from sys.dir$;
COUNT(*)
---------10
1 row selected.
SQL> select count(*) from sys.obj$ where bitand(flags, 65536)=65536 and obj# in
2 (select obj# from sys.dir$);
COUNT(*)
---------4
1 row selected.
SQL>
SQL> -- mark old version types as valid, as utlrp skips these
SQL> update sys.obj$ set status = 1
2 where type#=13 and subname is not null and status > 1;
164 rows updated.
SQL> commit;
Commit complete.
SQL>
SQL> alter pluggable database "&pdbname" close;
Pluggable database altered.
SQL> alter system flush shared_pool;
System altered.
SQL> /
System altered.
55
SQL> /
System altered.
SQL> alter pluggable database "&pdbname" open restricted;
Warning: PDB altered with errors.
SQL> ALTER SYSTEM SET "_system_trig_enabled"=FALSE SCOPE=MEMORY;
System altered.
SQL>
SQL> alter session set "_ORACLE_SCRIPT"=true;
Session altered.
SQL> drop view sys.cdb$tables&pdbid;
View dropped.
SQL> drop view sys.cdb$objects&pdbid;
View dropped.
SQL> drop view sys.cdb$common_root_objects&pdbid;
View dropped.
SQL> drop view sys.cdb$common_users&pdbid;
View dropped.
SQL> drop view sys.cdb$rootdeps&pdbid;
View dropped.
SQL>
SQL> alter session set container=CDB$ROOT;
Session altered.
SQL> drop view sys.cdb$common_root_objects&pdbid;
View dropped.
SQL> drop view sys.cdb$common_users&pdbid;
View dropped.
SQL> drop view sys.cdb$rootdeps&pdbid;
View dropped.
56
SQL>
SQL> alter session set container="&pdbname";
Session altered.
SQL>
SQL> -- handle Resource Manager plan conversions
SQL> exec dbms_rmin.rm$_noncdb_to_pdb;
PL/SQL procedure successfully completed.
SQL>
SQL> -- delete SYS$BACKGROUND and SYS$USERS from service$
SQL> delete from sys.service$ where name in ('SYS$BACKGROUND', 'SYS$USERS');
2 rows deleted.
SQL> commit;
Commit complete.
SQL>
SQL> -- reset the parameters at the end of the script
SQL> exec dbms_pdb.noncdb_to_pdb(2);
PL/SQL procedure successfully completed.
SQL> alter session set "_ORACLE_SCRIPT"=false;
Session altered.
SQL> alter session set "_NONCDB_TO_PDB"=false;
Session altered.
SQL> ALTER SYSTEM SET "_system_trig_enabled"=&sys_trig_enabled SCOPE=MEMORY;
System altered.
SQL>
SQL> alter pluggable database "&pdbname" close;
Pluggable database altered.
SQL> alter session set container = CDB$ROOT;
Session altered.
SQL> alter system flush shared_pool;
System altered.
SQL> /
57
System altered.
SQL> /
System altered.
SQL> alter session set container = "&pdbname";
Session altered.
SQL>
SQL> -- leave the PDB in the same state it was when we started
SQL> BEGIN
2 execute immediate '&open_sql &restricted_state';
3 EXCEPTION
4 WHEN OTHERS THEN
5 BEGIN
6
IF (sqlcode <> -900) THEN
7
RAISE;
8
END IF;
9 END;
10 END;
11 /
PL/SQL procedure successfully completed.
SQL>
SQL> WHENEVER SQLERROR CONTINUE;
SQL>
OK no errors all looks good lets fire it up from mount mode into open mode
SQL> sho pdbs
CON_ID CON_NAME
OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ---------5 TEST2
MOUNTED
SQL> alter pluggable database test2 open;
Warning: PDB altered with errors.
Hmm hold on that's not in the script - what went wrong?
SQL> sho errors
No errors.
SQL> alter pluggable database test2 open read write;
alter pluggable database test2 open read write
*
ERROR at line 1:
ORA-65019: pluggable database TEST2 already open
SQL> alter pluggable database test2 close;
58
AL32UTF8.
PENDING Database option APS mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING Database option CATJAVA mismatch: PDB installed version NULL. CDB
installed version 12.1.0.1.0.
PENDING Database option CONTEXT mismatch: PDB installed version NULL. CDB
installed version 12.1.0.1.0.
PENDING Database option DV mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING Database option JAVAVM mismatch: PDB installed version NULL. CDB
installed version 12.1.0.1.0.
PENDING Database option OLS mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING Database option ORDIM mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING Database option OWM mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING Database option SDO mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING Database option XML mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING Database option XOQ mismatch: PDB installed version NULL. CDB installed
version 12.1.0.1.0.
PENDING APEX mismatch: PDB installed version NULL CDB installed version
4.2.0.00.27
18 rows selected.
SQL>
At this point i thought of Monty Python and 'what have the romans ever done for us?'. SO
apart from the xml,sdo,catjava,aps,dv etc what has the pdb done for us. Oh well i digress.
SO what to do next - can i use test2?
SQL> sho pdbs
2 PDB$SEED
3 ORA12GCONTAINER
4 TEST
5 TEST2
READ ONLY NO
READ WRITE NO
READ WRITE NO
READ WRITE YES
60
61