Recompile the invalid object for oracle.

1. How does the invalid object come?

The Oracle database will invalidate objects if a dependent object is changed. If I rebuild a table, the indexes on that table will become invalid because they use the table‘srowids and rebuilding the table changes a row‘s rowid. It is the same with objects like packages, procedures and functions.

2.Build-in scripts to recompile the invalid objects.

We now have a supported script utlrp.sql located in the $ORACLE_HOME/rdbms/admin/utlrp.sql to do recompile for us.

Below code will list out all the current invalid object and run utlrp.sql to compile all of them.

COLUMN owner format a30
COLUMN object_name format a30 wrap
COLUMN object_type format a30 wrap

SET pages 56 lines 130 feedback off echo off
TTITLE "Report of Invalid Objects In Database" skip 2
SELECT owner, object_name, object_type
  FROM dba_objects
 WHERE status = ‘INVALID‘;
PROMPT "Will now run utlrp.sql to try to recompile objects"
@?/rdbms/admin/utlrp.sql

The following PL/SQL block invokes UTL_RECOMP to recompile invalid objects in the database.
Recompilation time is proportional to the number of invalid objects in the database,
so this command may take a long time to execute on a database with a large number of invalid objects.

Use the following queries to track recompilation progress:

1. Query returning the number of invalid objects remaining. This number should decrease with time.
SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);

2. Query returning the number of objects compiled so far. This number should increase with time.
SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;

This script automatically chooses serial or parallel recompilation based on the number of CPUs
available (parameter cpu_count) multiplied by the number of threads per CPU (parameter parallel_threads_per_cpu).
On RAC, this number is added across all RAC nodes.

UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel recompilation. Jobs are created without instance
affinity so that they can migrate across RAC nodes. Use the following queries to verify
whether UTL_RECOMP jobs are being created and run correctly:

1. Query showing jobs created by UTL_RECOMP
SELECT job_name FROM dba_scheduler_jobs WHERE job_name like ‘UTL_RECOMP_SLAVE_%‘;

2. Query showing UTL_RECOMP jobs that are running
SELECT job_name FROM dba_scheduler_running_jobs WHERE job_name like ‘UTL_RECOMP_SLAVE_%‘;

Below is a sql with a good format to list all the invalid database object.
break on c1 skip 2
set pages 999
col c1 heading ‘owner‘ format a15
col c2 heading ‘name‘ format a40
col c3 heading ‘type‘ format a10
ttitle ‘Invalid|Objects‘
select
   owner       c1,
   object_type c3,
   object_name c2
from
   dba_objects
where
   status != ‘VALID‘
order by
   owner,
   object_type;

3. Recompile with UTL_RECOMP package

EXEC UTL_RECOMP.recomp_serial(‘schema name‘);

4. compile command for individual object.

For function:

alter function gpcomp1.fn_load_notes_from_jde compile;

For procedure:

alter procedure gpcomp1.updatetemplate compile;

For view

alter view gpcomp1.gamatchedcashapplied compile;

For public synonym, which can only be recompiled by sys

alter public synonym  gpcrfcode  compile

Here is a script to recompile invalid PL/SQL packages and package bodies.

You may need to run it more than once for dependencies, if you get errors from the script.

Set heading off;
set feedback off;
set echo off;
Set lines 999;

Spool run_invalid.sql

select
   ‘ALTER ‘ || OBJECT_TYPE || ‘ ‘ ||
   OWNER || ‘.‘ || OBJECT_NAME || ‘ COMPILE;‘
from
   dba_objects
where
   status = ‘INVALID‘
and
   object_type in (‘PACKAGE‘,‘FUNCTION‘,‘PROCEDURE‘)
;
spool off;
set heading on;
set feedback on;
set echo on;
@run_invalid.sql

check the status of oracle component.

select comp_id,  comp_name,  version, status, namespace, schema from dba_registry;

Recompile the invalid object for oracle.,布布扣,bubuko.com

时间: 2024-08-24 11:30:17

Recompile the invalid object for oracle.的相关文章

Invalid object name ‘sys.configurations’. (Microsoft SQL Server, Error: 208)

http://blogs.msdn.com/b/ramaprasanna/archive/2009/09/16/invalid-object-name-sys-configurations-microsoft-sql-server-error-208.aspx ---------- When you use Microsoft SQL Server Management Studio 2008 to access SQL Azure, if you get the following error

探索Oracle之数据库升级二 11.2.0.3升级到11.2.0.4完整步骤

探索Oracle之数据库升级二  11.2.0.3升级到11.2.0.4完整步骤 说明:         这篇文章主要是记录下单实例环境下Oracle 11.2.0.1升级到11.2.0.3的过程,当然RAC的升级是会有所不同.但是他们每个版本之间升级步骤都是差不多的,先升级Database Software,再升级Oracle Instance. Oracle 11.2.0.4的Patchset No:19852360下载需要有Oracle Support才可以.  Patchset包含有7个

升级数据字典,解决ORA-01092: ORACLE instance terminated. Disconnection forced问题

在oracle 实例关闭的情况下,Oracle 软件从10.2.0.1 升级到 10.2.0.5 之后,存在的数据库也要升级. 此时启动实例会报错 ORA-01092: ORACLE instance terminated. Disconnection forced SQL> alter database open; ERROR at line 1: ORA-01092: ORACLE instance terminated. Disconnection forced 第一步,通过startup

探索Oracle之数据库升级八 12c Downgrade 11gR2

探索Oracle之数据库升级八 12c Downgrade 11gR2 前言: 我们前面已经完成了11gR2 upgrade to 12c 的升级,整个过程还是比较顺利的,虽然和以前版本升级有些不太一样,但是整个难度不是太大,但是由于太多的特性不同,大大的加长了升级的时间. 但是对于Oracle 12c降回到之前版本,会有些限制,只能降级到升级前所用的版本和补丁级别. 如果我们是直接从10.2.0.5.11.1.0.7或版本11.2.0.2及更高版进行升级.那么将无法降级到10.2.0.5. 如

oracle database 10.2.0.4 升级到 10.2.0.5

某发票开发测试库升级      升级前准备,此次升级只是很对测试环境数据库升级,所以没有事先一个月来获取系统,数据库的统计信息,机器性能比对 为了加快升级只是清理了以下信息 01.截断SYS.AUD$基表: SQL>TRUNCATE TABLE SYS.AUD$; 02.清理DBA回收站: SQL>purge DBA_RECYCLEBIN; 1.升级开始,升级前首先断开测试环境的中间件应用 查看本机的ORACLE_HOME [[email protected]_10 ~]$ echo $ORA

ORACLE 11.2.0.1升级到11.2.0.3

ORACLE 11.2.0.1升级到11.2.0.3 最近听了李光老师的关于oracle的升级公开课,深有感悟,之前一直想自己测试的,没有下定决心,这几天自己在虚拟机上测试了一下,测试的过程如下,当然这个只是一些基本的步骤,实际的生产环境我想比这个复杂的多了,但是不用急,慢慢来,循序渐进吧... 1. 数据库情况 单实例非ASM存储 ORACLE_SID : orcl ORACLE_HOME: /u01/app/oracle/product/11.2.0/dbhome_1 1. 数据库原始状态

Oracle Analyze 命令 详解

官网的链接如下: http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_4005.htm#SQLRF01105 使用DBMS_STATS 收集统计信息参考: Oracle Statistic 统计信息 小结 http://blog.csdn.net/tianlesoftware/article/details/4668723 Oracle 判断 并 手动收集 统计信息 脚本 http://blog.csdn.net/ti

Oracle Global Finanicals Oracle Global Financials Technical Reference(一)

Skip Headers Oracle Global Finanicals Oracle Global Financials Technical Reference Manual Release 11i         Globalization Flexfields This document describes the globalization flexfields that store certain pieces of country- and region-specific info

oracle 巡检脚本

#!/bin/sh # Get Hostname HOSTNAME=`hostname` logfile=xunjian_`date +%y%m%d`.log hostinfodir=/home/oracle/xunjian if [[ ! -d  $hostinfodir ]] then mkdir -p $hostinfodir fi date >> $hostinfodir/$logfile echo " hostname " >> $hostinfodi