探索Oracle之資料庫升級八 12c Downgrade 11gR2

dbhelper發表於2015-01-17

探索Oracle之資料庫升級八
12c Downgrade 11gR2

前言:

       我們前面已經完成了11gR2 upgrade to 12c 的升級,整個過程還是比較順利的,雖然和以前版本升級有些不太一樣,但是整個難度不是太大,但是由於太多的特性不同,大大的加長了升級的時間。

       但是對於Oracle 12c降回到之前版本,會有些限制,只能降級到升級前所用的版本和補丁級別。

       如果我們是直接從10.2.0.511.1.0.7或版本11.2.0.2及更高版進行升級。那麼將無法降級到10.2.0.5

       如果透過應用中間補丁程式11.1.0.7 Oracle 11.1.0.6升級到Oracle 12c12.1.0),則不能降級到Oracle 11.1.0.6。降級只能對直接執行升級版本執行。

例外:

雖然可以對 10.2.0.5 直接升級,但降級不適用於 10.2.0.5

這是因為在升級過程中,compatible 引數已設定為最低 11.0.0。這使得無法降級到 10.2.0.5。可以降級的版本為 11.1.0.711.2.0.211.2.0.3 或更高版本。

如果有任何補丁程式應用到了從升級後的主目錄執行的源資料庫,則需要先回退,然後才能開始降級過程。

解除安裝和回退補丁程式的步驟記錄在所涉及補丁程式的自述檔案中。

未能解除安裝和回退補丁程式可能會導致無法降級,包括無法重新驗證字典物件。

Exadata 捆綁補丁程式示例,其過程為:

解除安裝補丁程式

       示例:  $ opatch auto /u01/app/oracle/patches/14103267 -rollback 

回退任何在補丁程式應用過程中應用的 SQL     

       示例: SQL> @rdbms/admin/catbundle_EXA_<資料庫 SID>_ROLLBACK.sql,用於回退 SQL 更改。
一、開始執行降級前的檢查操作
        升級前確保所有元件狀態正常,且沒有無效元件

  1. ###檢查各元件狀態
  2. SQL> select substr(comp_id,1,15) comp_id,substr(comp_name,1,30) comp_name,substr(version,1,10) version,status from dba_registry;

  3. COMP_ID COMP_NAME VERSION STATUS
  4. ---------- ------------------------------ ---------- --------
  5. DV Oracle Database Vault 12.1.0.1.0 VALID
  6. APEX Oracle Application Express 4.2.0.00.2 VALID
  7. OLS Oracle Label Security 12.1.0.1.0 VALID
  8. SDO Spatial 12.1.0.1.0 VALID
  9. ORDIM Oracle Multimedia 12.1.0.1.0 VALID
  10. CONTEXT Oracle Text 12.1.0.1.0 VALID
  11. OWM Oracle Workspace Manager 12.1.0.1.0 VALID
  12. XDB Oracle XML Database 12.1.0.1.0 VALID
  13. CATALOG Oracle Database Catalog Views 12.1.0.1.0 VALID
  14. CATPROC Oracle Database Packages and T 12.1.0.1.0 VALID
  15. JAVAVM JServer JAVA Virtual Machine 12.1.0.1.0 VALID

  16. COMP_ID COMP_NAME VERSION STATUS
  17. ---------- ------------------------------ ---------- --------
  18. XML Oracle XDK 12.1.0.1.0 VALID
  19. CATJAVA Oracle Database Java Packages 12.1.0.1.0 VALID
  20. APS OLAP Analytic Workspace 12.1.0.1.0 VALID
  21. XOQ Oracle OLAP API 12.1.0.1.0 VALID
  22. RAC Oracle Real Application Cluste 12.1.0.1.0 OPTION O
  23.                                                      FF
  24. 16 rows selected.

  25. #####檢查無效元件
  26. SQL> select owner, count(object_name) "Invalid object count" from dba_objects where status!='VALID' and owner in ('SYS','SYSTEM') group by owner;

  27. no rows selected

  28. SQL>
二、開始執行降級操作
  1. ###2.1 關閉資料庫
  2. SQL> shutdown immediate
  3. Database closed.
  4. Database dismounted.
  5. ORACLE instance shut down.

  6. ###2.1 將資料庫啟動到downgrade模式
  7. SQL> startup downgrade;
  8. ORACLE instance started.

  9. Total System Global Area 5027385344 bytes
  10. Fixed Size 2298736 bytes
  11. Variable Size 1040190608 bytes
  12. Database Buffers 3976200192 bytes
  13. Redo Buffers 8695808 bytes
  14. Database mounted.
  15. Database opened.
  16. SQL>

  17. ###2.2 執行降級指令碼
  18. SQL> spool downgrade_12c_to_11g.log
  19. SQL> @$ORACLE_HOME/rdbms/admin/catdwgrd.sql
  20. ………
  21. PL/SQL procedure successfully completed.

  22. SQL>
  23. SQL> -- lrg 7259350: objects created in this script need their flags that won't fit
  24. SQL> -- in a ub2 cleared
  25. SQL> update obj$mig set flags=bitand(flags,65535) where flags>65535;

  26. 222 rows updated.

  27. SQL>
  28. SQL> /*****************************************************************************/
  29. SQL> /* Step 9 - Swap bootstrap$mig with bootstrap$
  30. SQL> */
  31. SQL> /*****************************************************************************/
  32. SQL> /* According to JKLEIN, performing 3 count(*) will ensure there are
  33. SQL> no dirty itl's present in bootstrap$. */
  34. SQL> select count(*) from bootstrap$;

  35.   COUNT(*)
  36. ----------
  37.         60

  38. 1 row selected.

  39. SQL> select count(*) from bootstrap$;

  40.   COUNT(*)
  41. ----------
  42.         60

  43. 1 row selected.

  44. SQL> select count(*) from bootstrap$;

  45.   COUNT(*)
  46. ----------
  47.         60

  48. 1 row selected.

  49. SQL> select count(*) from bootstrap$mig;

  50.   COUNT(*)
  51. ----------
  52.         60

  53. 1 row selected.

  54. SQL> select count(*) from bootstrap$mig;

  55.   COUNT(*)
  56. ----------
  57.         60

  58. 1 row selected.

  59. SQL> select count(*) from bootstrap$mig;

  60.   COUNT(*)
  61. ----------
  62.         60

  63. 1 row selected.

  64. SQL>
  65. SQL> WHENEVER SQLERROR CONTINUE
  66. SQL>
  67. SQL> begin
  68.   2
  69.   3 -- Now we can do the swap.
  70.   4 declare
  71.   5 procedure swap_bootstrap(replacement_tbl_name IN VARCHAR2)
  72.   6 is language c library DBMS_DDL_INTERNAL_LIB
  73.   7 name "swap_bootstrap"
  74.   8 with context
  75.   9 parameters(context, replacement_tbl_name String,
  76.  10 replacement_tbl_name LENGTH ub2,
  77.  11 replacement_tbl_name INDICATOR sb2);
  78.  12 begin
  79.  13 swap_bootstrap('BOOTSTRAP$MIG');
  80.  14 end;
  81.  15
  82.  16 -- We've completed the swap.
  83.  17 -- Remove the BOOTSTRAP_DOWNGRADE_ERROR entry in props$.
  84.  18 delete from props$ where name = 'BOOTSTRAP_DOWNGRADE_ERROR';
  85.  19 commit;
  86.  20 end;
  87.  21 /

  88. PL/SQL procedure successfully completed.

  89. SQL>
  90. SQL> Rem ***********************************************************************
  91. SQL> Rem END catdwgrd.sql
  92. SQL> Rem ***********************************************************************
  93. SQL>
  94. SQL>
  95. SQL> shutdown immediate
  96. Database closed.
  97. Database dismounted.
  98. ORACLE instance shut down.
  99. SQL> exit
  100. Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
  101. With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
  102. [oracle@woo ~]
三、修改/etc/oratab 為Oracle 12gR2 HOME目錄
  1. [root@woo ~]# vi /etc/oratab
  2. woo:/DBSoft/oracle/product/11.2.4/dbhome_1
四、修改系統環境變數
  1. [root@woo oracle]# vi ~/.bash_profile
  2. [oracle@woo ~]$ echo $ORACLE_HOME
  3. /DBSoft/oracle/product/11.2.4/dbhome_1

五、啟動到upgrade模式,從降級版本$ORACLE_HOME/rdbms/admin目錄中執行catrelod指令碼

  1. [oracle@woo ~]$ sqlplus / as sysdba

  2. SQL*Plus: Release 11.2.0.4.0 Production on Tue Dec 23 18:13:17 2014

  3. Copyright (c) 1982, 2013, Oracle. All rights reserved.

  4. Connected to an idle instance.

  5. SQL> startup upgrade;
  6. ORACLE instance started.

  7. Total System Global Area 5027385344 bytes
  8. Fixed Size 2261888 bytes
  9. Variable Size 1191185536 bytes
  10. Database Buffers 3825205248 bytes
  11. Redo Buffers 8732672 bytes
  12. Database mounted.
  13. Database opened.
  14. SQL>SQL> $ORACLE_HOME/rdbms/admin/catrelod.sql
  15. ……..

  16. SQL> r
  17.   1 SELECT comp_name, status, substr(version,1,10) as version
  18.   2* from dba_server_registry order by modified

  19. COMP_NAME STATUS
  20. ----------------------------------- --------------------------------------------
  21. VERSION
  22. ----------------------------------------
  23. OWB VALID
  24. 11.2.0.4.0

  25. Oracle Database Packages and Types VALID
  26. 11.2.0.4.0

  27. Oracle Database Catalog Views INVALID
  28. 11.2.0.4.0

  29. JServer JAVA Virtual Machine VALID
  30. 11.2.0.4.0

  31. Oracle XDK VALID
  32. 11.2.0.4.0

  33. Oracle Database Java Packages VALID
  34. 11.2.0.4.0

  35. Oracle Text VALID
  36. 11.2.0.4.0

  37. Oracle XML Database VALID
  38. 11.2.0.4.0

  39. Oracle Workspace Manager VALID
  40. 11.2.0.4.0

  41. OLAP Analytic Workspace VALID
  42. 11.2.0.4.0

  43. Oracle OLAP API VALID
  44. 11.2.0.4.0

  45. Oracle Multimedia VALID
  46. 11.2.0.4.0

  47. Spatial INVALID
  48. 11.2.0.4.0

  49. Oracle Application Express INVALID
  50. 3.2.1.00.1

六、執行utlrp.sql指令碼重新編譯先前處於INVALID狀態的所有現有PL/SQL模組


  1. SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
  2. SQL> Rem
  3. SQL> Rem $Header: utlrp.sql 24-jul-2003.10:06:51 gviswana Exp $
  4. SQL> Rem
  5. SQL> Rem utlrp.sql
  6. SQL> Rem
  7. SQL> Rem Copyright (c) 1998, 2003, Oracle Corporation. All rights reserved.
  8. SQL> Rem
  9. SQL> Rem NAME
  10. SQL> Rem utlrp.sql - Recompile invalid objects
  11. SQL> Rem
  12. SQL> Rem DESCRIPTION
  13. SQL> Rem This script recompiles invalid objects in the database.
  14. SQL> Rem
  15. SQL> Rem When run as one of the last steps during upgrade or downgrade,
  16. SQL> Rem this script will validate all remaining invalid objects. It will
  17. SQL> Rem also run a component validation procedure for each component in
  18. SQL> Rem the database. See the README notes for your current release and
  19. SQL> Rem the Oracle Database Upgrade book for more information about
  20. SQL> Rem using utlrp.sql
  21. SQL> Rem
  22. SQL> Rem Although invalid objects are automatically re-validated when used,
  23. SQL> Rem it is useful to run this script after an upgrade or downgrade and
  24. SQL> Rem after applying a patch. This minimizes latencies caused by
  25. SQL> Rem on-demand recompilation. Oracle strongly recommends running this
  26. SQL> Rem script after upgrades, downgrades and patches.
  27. SQL> Rem
  28. SQL> Rem NOTES
  29. SQL> Rem * This script must be run using SQL*PLUS.
  30. SQL> Rem * You must be connected AS SYSDBA to run this script.
  31. SQL> Rem * There should be no other DDL on the database while running the
  32. SQL> Rem script. Not following this recommendation may lead to deadlocks.
  33. SQL> Rem
  34. SQL> Rem MODIFIED (MM/DD/YY)
  35. SQL> Rem gviswana 06/26/03 - Switch default to parallel if appropriate
  36. SQL> Rem gviswana 06/12/03 - Switch default back to serial
  37. SQL> Rem gviswana 05/20/03 - 2814808: Automatic parallelism tuning
  38. SQL> Rem rburns 04/28/03 - timestamps and serveroutput for diagnostics
  39. SQL> Rem gviswana 04/13/03 - utlrcmp.sql load -> catproc
  40. SQL> Rem gviswana 06/25/02 - Add documentation
  41. SQL> Rem gviswana 11/12/01 - Use utl_recomp.recomp_serial
  42. SQL> Rem rdecker 11/09/01 - ADD ALTER library support FOR bug 1952368
  43. SQL> Rem rburns 11/12/01 - validate all components after compiles
  44. SQL> Rem rburns 11/06/01 - fix invalid CATPROC call
  45. SQL> Rem rburns 09/29/01 - use 9.2.0
  46. SQL> Rem rburns 09/20/01 - add check for CATPROC valid
  47. SQL> Rem rburns 07/06/01 - get version from instance view
  48. SQL> Rem rburns 05/09/01 - fix for use with 8.1.x
  49. SQL> Rem arithikr 04/17/01 - 1703753: recompile object type# 29,32,33
  50. SQL> Rem skabraha 09/25/00 - validate is now a keyword
  51. SQL> Rem kosinski 06/14/00 - Persistent parameters
  52. SQL> Rem skabraha 06/05/00 - validate tables also
  53. SQL> Rem jdavison 04/11/00 - Modify usage notes for 8.2 changes.
  54. SQL> Rem rshaikh 09/22/99 - quote name for recompile
  55. SQL> Rem ncramesh 08/04/98 - change for sqlplus
  56. SQL> Rem usundara 06/03/98 - merge from 8.0.5
  57. SQL> Rem usundara 04/29/98 - creation (split from utlirp.sql).
  58. SQL> Rem Mark Ramacher (mramache) was the original
  59. SQL> Rem author of this script.
  60. SQL> Rem
  61. SQL>
  62. SQL> Rem ===========================================================================
  63. SQL> Rem BEGIN utlrp.sql
  64. SQL> Rem ===========================================================================
  65. SQL>
  66. SQL> @@utlprp.sql 0
  67. SQL> Rem Copyright (c) 2003, 2012, Oracle and/or its affiliates.
  68. SQL> Rem All rights reserved.
  69. SQL> Rem
  70. SQL> Rem NAME
  71. SQL> Rem utlprp.sql - Recompile invalid objects in the database
  72. SQL> Rem
  73. SQL> Rem DESCRIPTION
  74. SQL> Rem This script recompiles invalid objects in the database.
  75. SQL> Rem
  76. SQL> Rem This script is typically used to recompile invalid objects
  77. SQL> Rem remaining at the end of a database upgrade or downgrade.
  78. SQL> Rem
  79. SQL> Rem Although invalid objects are automatically recompiled on demand,
  80. SQL> Rem running this script ahead of time will reduce or eliminate
  81. SQL> Rem latencies due to automatic recompilation.
  82. SQL> Rem
  83. SQL> Rem This script is a wrapper based on the UTL_RECOMP package.
  84. SQL> Rem UTL_RECOMP provides a more general recompilation interface,
  85. SQL> Rem including options to recompile objects in a single schema. Please
  86. SQL> Rem see the documentation for package UTL_RECOMP for more details.
  87. SQL> Rem
  88. SQL> Rem INPUTS
  89. SQL> Rem The degree of parallelism for recompilation can be controlled by
  90. SQL> Rem providing a parameter to this script. If this parameter is 0 or
  91. SQL> Rem NULL, UTL_RECOMP will automatically determine the appropriate
  92. SQL> Rem level of parallelism based on Oracle parameters cpu_count and
  93. SQL> Rem parallel_threads_per_cpu. If the parameter is 1, sequential
  94. SQL> Rem recompilation is used. Please see the documentation for package
  95. SQL> Rem UTL_RECOMP for more details.
  96. SQL> Rem
  97. SQL> Rem NOTES
  98. SQL> Rem * You must be connected AS SYSDBA to run this script.
  99. SQL> Rem * There should be no other DDL on the database while running the
  100. SQL> Rem script. Not following this recommendation may lead to deadlocks.
  101. SQL> Rem
  102. SQL> Rem MODIFIED (MM/DD/YY)
  103. SQL> Rem apfwkr 01/03/12 - Backport apfwkr_blr_backport_13059165_11.2.0.3.0
  104. SQL> Rem from st_rdbms_11.2.0
  105. SQL> Rem cdilling 05/15/10 - fix bug 9712478 - call local enquote_name
  106. SQL> Rem anighosh 02/19/09 - #(8264899): re-enabling of function based indexes
  107. SQL> Rem not needed.
  108. SQL> Rem cdilling 07/21/08 - check bitand for functional index - bug 7243270
  109. SQL> Rem cdilling 01/21/08 - add support for ORA-30552
  110. SQL> Rem cdilling 08/27/07 - check disabled indexes only
  111. SQL> Rem cdilling 05/22/07 - add support for ORA-38301
  112. SQL> Rem cdilling 02/19/07 - 5530085 - renable invalid indexes
  113. SQL> Rem rburns 03/17/05 - use dbms_registry_sys
  114. SQL> Rem gviswana 02/07/05 - Post-compilation diagnostics
  115. SQL> Rem gviswana 09/09/04 - Auto tuning and diagnosability
  116. SQL> Rem rburns 09/20/04 - fix validate_components
  117. SQL> Rem gviswana 12/09/03 - Move functional-index re-enable here
  118. SQL> Rem gviswana 06/04/03 - gviswana_bug-2814808
  119. SQL> Rem gviswana 05/28/03 - Created
  120. SQL> Rem
  121. SQL>
  122. SQL> SET VERIFY OFF;
  123. SQL>
  124. SQL> SELECT dbms_registry_sys.time_stamp('utlrp_bgn') as timestamp from dual;

  125. TIMESTAMP
  126. --------------------------------------------------------------------------------
  127. COMP_TIMESTAMP UTLRP_BGN 2014-12-23 18:06:58

  128. 1 row selected.

  129. SQL>
  130. SQL> DOC
  131. DOC> The following PL/SQL block invokes UTL_RECOMP to recompile invalid
  132. DOC> objects in the database. Recompilation time is proportional to the
  133. DOC> number of invalid objects in the database, so this command may take
  134. DOC> a long time to execute on a database with a large number of invalid
  135. DOC> objects.
  136. DOC>
  137. DOC> Use the following queries to track recompilation progress:
  138. DOC>
  139. DOC> 1. Query returning the number of invalid objects remaining. This
  140. DOC> number should decrease with time.
  141. DOC> SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
  142. DOC>
  143. DOC> 2. Query returning the number of objects compiled so far. This number
  144. DOC> should increase with time.
  145. DOC> SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
  146. DOC>
  147. DOC> This script automatically chooses serial or parallel recompilation
  148. DOC> based on the number of CPUs available (parameter cpu_count) multiplied
  149. DOC> by the number of threads per CPU (parameter parallel_threads_per_cpu).
  150. DOC> On RAC, this number is added across all RAC nodes.
  151. DOC>
  152. DOC> UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
  153. DOC> recompilation. Jobs are created without instance affinity so that they
  154. DOC> can migrate across RAC nodes. Use the following queries to verify
  155. DOC> whether UTL_RECOMP jobs are being created and run correctly:
  156. DOC>
  157. DOC> 1. Query showing jobs created by UTL_RECOMP
  158. DOC> SELECT job_name FROM dba_scheduler_jobs
  159. DOC> WHERE job_name like 'UTL_RECOMP_SLAVE_%';
  160. DOC>
  161. DOC> 2. Query showing UTL_RECOMP jobs that are running
  162. DOC> SELECT job_name FROM dba_scheduler_running_jobs
  163. DOC> WHERE job_name like 'UTL_RECOMP_SLAVE_%';
  164. DOC>#
  165. SQL>
  166. SQL> DECLARE
  167.   2 threads pls_integer := &&1;
  168.   3 BEGIN
  169.   4 utl_recomp.recomp_parallel(threads);
  170.   5 END;
  171.   6 /

  172. PL/SQL procedure successfully completed.

  173. SQL>
  174. SQL> SELECT dbms_registry_sys.time_stamp('utlrp_end') as timestamp from dual;

  175. TIMESTAMP
  176. --------------------------------------------------------------------------------
  177. COMP_TIMESTAMP UTLRP_END 2014-12-23 18:08:59

  178. 1 row selected.

  179. SQL>
  180. SQL> Rem #(8264899): The code to Re-enable functional indexes, which used to exist
  181. SQL> Rem here, is no longer needed.
  182. SQL>
  183. SQL> DOC
  184. DOC> The following query reports the number of objects that have compiled
  185. DOC> with errors.
  186. DOC>
  187. DOC> If the number is higher than expected, please examine the error
  188. DOC> messages reported with each object (using SHOW ERRORS) to see if they
  189. DOC> point to system misconfiguration or resource constraints that must be
  190. DOC> fixed before attempting to recompile these objects.
  191. DOC>#
  192. SQL> select COUNT(DISTINCT(obj#)) "OBJECTS WITH ERRORS" from utl_recomp_errors;

  193. OBJECTS WITH ERRORS
  194. -------------------
  195.                   0

  196. 1 row selected.

  197. SQL>
  198. SQL>
  199. SQL> DOC
  200. DOC> The following query reports the number of errors caught during
  201. DOC> recompilation. If this number is non-zero, please query the error
  202. DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
  203. DOC> are due to misconfiguration or resource constraints that must be
  204. DOC> fixed before objects can compile successfully.
  205. DOC>#
  206. SQL> select COUNT(*) "ERRORS DURING RECOMPILATION" from utl_recomp_errors;

  207. ERRORS DURING RECOMPILATION
  208. ---------------------------
  209.                           0

  210. 1 row selected.

  211. SQL>
  212. SQL>
  213. SQL> Rem
  214. SQL> Rem Declare function local_enquote_name to pass FALSE
  215. SQL> Rem into underlying dbms_assert.enquote_name function
  216. SQL> Rem
  217. SQL> CREATE OR REPLACE FUNCTION local_enquote_name (str varchar2)
  218.   2 return varchar2 is
  219.   3 begin
  220.   4 return dbms_assert.enquote_name(str, FALSE);
  221.   5 end local_enquote_name;
  222.   6 /

  223. Function created.

  224. SQL> Rem
  225. SQL> Rem If sys.enabled$index table exists, then re-enable
  226. SQL> Rem list of functional indexes that were enabled prior to upgrade
  227. SQL> Rem The table sys.enabled$index table is created in catupstr.sql
  228. SQL> Rem
  229. SQL> SET serveroutput on
  230. SQL> DECLARE
  231.   2 TYPE tab_char IS TABLE OF VARCHAR2(32767) INDEX BY BINARY_INTEGER;
  232.   3 commands tab_char;
  233.   4 p_null CHAR(1);
  234.   5 p_schemaname VARCHAR2(30);
  235.   6 p_indexname VARCHAR2(30);
  236.   7 rebuild_idx_msg BOOLEAN := FALSE;
  237.   8 non_existent_index exception;
  238.   9 recycle_bin_objs exception;
  239.  10 cannot_change_obj exception;
  240.  11 no_such_table exception;
  241.  12 pragma exception_init(non_existent_index, -1418);
  242.  13 pragma exception_init(recycle_bin_objs, -38301);
  243.  14 pragma exception_init(cannot_change_obj, -30552);
  244.  15 pragma exception_init(no_such_table, -942);
  245.  16 type cursor_t IS REF CURSOR;
  246.  17 reg_cursor cursor_t;
  247.  18
  248.  19 BEGIN
  249.  20 -- Check for existence of the table marking disabled functional indices
  250.  21
  251.  22 SELECT NULL INTO p_null FROM DBA_OBJECTS
  252.  23 WHERE owner = 'SYS' and object_name = 'ENABLED$INDEXES' and
  253.  24 object_type = 'TABLE' and rownum <=1;
  254.  25
  255.  26 -- Select indices to be re-enabled
  256.  27 EXECUTE IMMEDIATE q'+
  257.  28 SELECT 'ALTER INDEX ' ||
  258.  29 local_enquote_name(e.schemaname) || '.' ||
  259.  30 local_enquote_name(e.indexname) || ' ENABLE'
  260.  31 FROM enabled$indexes e, ind$ i
  261.  32 WHERE e.objnum = i.obj# AND bitand(i.flags, 1024) != 0 AND
  262.  33 bitand(i.property, 16) != 0+'
  263.  34 BULK COLLECT INTO commands;
  264.  35
  265.  36 IF (commands.count() > 0) THEN
  266.  37 FOR i IN 1 .. commands.count() LOOP
  267.  38 BEGIN
  268.  39 EXECUTE IMMEDIATE commands(i);
  269.  40 EXCEPTION
  270.  41 WHEN NON_EXISTENT_INDEX THEN NULL;
  271.  42 WHEN RECYCLE_BIN_OBJS THEN NULL;
  272.  43 WHEN CANNOT_CHANGE_OBJ THEN rebuild_idx_msg := TRUE;
  273.  44 END;
  274.  45 END LOOP;
  275.  46 END IF;
  276.  47
  277.  48 -- Output any indexes in the table that could not be re-enabled
  278.  49 -- due to ORA-30552 during ALTER INDEX...ENBLE command
  279.  50
  280.  51 IF rebuild_idx_msg THEN
  281.  52 BEGIN
  282.  53 DBMS_OUTPUT.PUT_LINE
  283.  54 ('The following indexes could not be re-enabled and may need to be rebuilt:');
  284.  55
  285.  56 OPEN reg_cursor FOR
  286.  57 'SELECT e.schemaname, e.indexname
  287.  58 FROM enabled$indexes e, ind$ i
  288.  59 WHERE e.objnum = i.obj# AND bitand(i.flags, 1024) != 0';
  289.  60
  290.  61 LOOP
  291.  62 FETCH reg_cursor INTO p_schemaname, p_indexname;
  292.  63 EXIT WHEN reg_cursor%NOTFOUND;
  293.  64 DBMS_OUTPUT.PUT_LINE
  294.  65 ('.... INDEX ' || p_schemaname || '.' || p_indexname);
  295.  66 END LOOP;
  296.  67 CLOSE reg_cursor;
  297.  68
  298.  69 EXCEPTION
  299.  70 WHEN NO_DATA_FOUND THEN CLOSE reg_cursor;
  300.  71 WHEN NO_SUCH_TABLE THEN CLOSE reg_cursor;
  301.  72 WHEN OTHERS THEN CLOSE reg_cursor; raise;
  302.  73 END;
  303.  74
  304.  75 END IF;
  305.  76
  306.  77 EXECUTE IMMEDIATE 'DROP TABLE sys.enabled$indexes';
  307.  78
  308.  79 EXCEPTION
  309.  80 WHEN NO_DATA_FOUND THEN NULL;
  310.  81
  311.  82 END;
  312.  83 /

  313. PL/SQL procedure successfully completed.

  314. SQL>
  315. SQL> DROP function local_enquote_name;

  316. Function dropped.

  317. SQL>
  318. SQL> Rem =====================================================================
  319. SQL> Rem Run component validation procedure
  320. SQL> Rem =====================================================================
  321. SQL>
  322. SQL> EXECUTE dbms_registry_sys.validate_components;
  323. ...Database user "SYS", database schema "APEX_030200", user# "77" 18:09:01
  324. ...Compiled 0 out of 2210 objects considered, 0 failed compilation 18:09:01
  325. ...189 packages
  326. ...181 package bodies
  327. ...360 tables
  328. ...12 functions
  329. ...19 procedures
  330. ...4 sequences
  331. ...366 triggers
  332. ...946 indexes
  333. ...125 views
  334. ...0 libraries
  335. ...4 types
  336. ...0 type bodies
  337. ...0 operators
  338. ...0 index types
  339. ...Begin key object existence check 18:09:01
  340. ...Completed key object existence check 18:09:01
  341. ...Setting DBMS Registry 18:09:01
  342. ...Setting DBMS Registry Complete 18:09:01
  343. ...Exiting validate 18:09:01

  344. PL/SQL procedure successfully completed.

  345. SQL> SET serveroutput off
  346. SQL>
  347. SQL>
  348. SQL> Rem ===========================================================================
  349. SQL> Rem END utlrp.sql
  350. SQL> Rem ===========================================================================
  351. SQL>
  352. ##執行完以上指令碼後再做檢查,就沒有無效物件了
  353. SQL> set line 300
  354. SQL> r
  355.   1* SELECT comp_name, status, substr(version,1,10) as version from dba_server_registry order by modified

  356. COMP_NAME STATUS VERSION
  357. ----------------------------------- -------------------------------------------- ----------------------------------------
  358. Oracle Workspace Manager VALID 11.2.0.4.0
  359. OLAP Analytic Workspace VALID 11.2.0.4.0
  360. Spatial INVALID 11.2.0.4.0
  361. Oracle Multimedia VALID 11.2.0.4.0
  362. Oracle XML Database VALID 11.2.0.4.0
  363. Oracle Text VALID 11.2.0.4.0
  364. Oracle OLAP API VALID 11.2.0.4.0
  365. Oracle Database Catalog Views VALID 11.2.0.4.0
  366. Oracle Database Packages and Types VALID 11.2.0.4.0
  367. JServer JAVA Virtual Machine VALID 11.2.0.4.0
  368. Oracle XDK VALID 11.2.0.4.0
  369. Oracle Database Java Packages VALID 11.2.0.4.0
  370. Oracle Application Express VALID 3.2.1.00.1
  371. OWB VALID 11.2.0.4.0

  372. 14 rows selected.
七、重新登陸並open 11gR2 資料庫

  1. [oracle@woo ~]$ sqlplus / as sysdba

  2. SQL*Plus: Release 11.2.0.4.0 Production on Sun Dec 21 22:13:32 2014

  3. Copyright (c) 1982, 2013, Oracle. All rights reserved.

  4. Connected to an idle instance.

  5. SQL> startup
  6. ORACLE instance started.

  7. Total System Global Area 5027385344 bytes
  8. Fixed Size 2261888 bytes
  9. Variable Size 1107299456 bytes
  10. Database Buffers 3909091328 bytes
  11. Redo Buffers 8732672 bytes
  12. Database mounted.
  13. Database open.

  14. SQL>
      


                                                      
        

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8494287/viewspace-1405557/,如需轉載,請註明出處,否則將追究法律責任。

相關文章