Tuesday, January 26, 2016

How to compile invalid objects in oracle

SELECT CASE object_type
  2         WHEN 'PACKAGE' THEN
  3          'ALTER '||object_type||' '||owner||'.'||object_name||' COMPILE;'
  4         ELSE
  5          'ALTER PACKAGE '||owner||'.'||object_name||' COMPILE BODY;'
  6         END
  7    FROM dba_objects
  8   WHERE STATUS = 'INVALID'
  9    and owner = 'TESTCMS'
 10     AND object_type IN ('PACKAGE','PACKAGE BODY','FUNCTION','PROCEDURE');

CASEOBJECT_TYPEWHEN'PACKAGE'THEN'ALTER'||OBJECT_TYPE||''||OWNER||'.'||OBJECT_NAM
--------------------------------------------------------------------------------
ALTER PACKAGE TESTCMS.BCE_DOWNLOAD_LIST_PORTLET COMPILE BODY;
ALTER PACKAGE TESTCMS.BCE_CMS_ITEM_DISPLAY_PORTLET COMPILE BODY;
ALTER PACKAGE TESTCMS.BCE_CMS_EDIT_CONTENT_PORTLET COMPILE BODY;
ALTER PACKAGE TESTCMS.BCE_IMAGE_GALLERY_PORTLET COMPILE BODY;
ALTER PACKAGE TESTCMS.BCE_CMS_RSS_FEED COMPILE BODY;

For function and procedure use:
alter function TESTCMS.object_name compile;
alter trigger schema.object_type compile;
alter procedure schema.object_type compile;

alter trigger PORTAL.WWDOC_DOCU_BRU_TRG compile;

=====================
TESTCMS                        BCE_CMS_NOTIFICATION_PORTLET                                                                                                     PACKAGE BODY
TESTCMS                        BCE_CMS_APPROVAL                                                                                                                 PACKAGE BODY

ALTER PACKAGE TESTCMS.BCE_CMS_NOTIFICATION_PORTLET COMPILE BODY;
ALTER PACKAGE TESTCMS.BCE_CMS_APPROVAL COMPILE BODY;

Oracle Text indexes synchronisation

PURPOSE=======
To show how the Oracle Text indexes are synchronized and how to control it. 

SCOPE & APPLICATION===================
This note is for Oracle Text administrators and developers. 

Synchronizing Text Indexes
A text index always responds within the same transaction to DELETE in the indexed column, but the response to INSERT and UPDATE which is modeled as a DELETE followed by an INSERT is asynchronous. An internal trigger which isinvisible to the customer requests index maintenance by inserting a row intoa queue table in CTXSYS schema for each new row in the indexed column.This DML queue can be tracked by querying the CTX_PENDING or CTX_USER_PENDINGText data dictionary view. 
Example: 
  create table docs (id number primary key, doc varchar2(60));
  create index i_doc on docs (doc) indextype is ctxsys.context; 
  insert into docs values (1,'A man walking on the street with a barking dog.'); 
  select * from ctx_user_pending; 
  PND_INDEX_NAME                 PND_ROWID          PND_TIMES   ------------------------------ ------------------ ---------   I_DOC                          AAAHVoAAEAAAEiqAAA 14-NOV-06 
  select * from docs where contains(doc,'dog')>0; 
  no rows selected 
In this situation the table and the text index on a column of this table are notsynchronized. A text query on the indexed column does not return the new row eventhough the new document fulfills the condition. So the table and the index have to be synchronized. The above defined DML queue contains information about rows in the document tableto be synchronized with the text index. We say that the table is synchronized withits text index when there is no entry referencing to this text index in the DML queue. 
After synchronizing the table and its index text queries return with the new/updateddocuments fulfilling the condition. Of course, the entry referencing the rows to besynchronized disappear from the DML queue. 
Example: 
  select * from docs where contains(doc,'man')>0; 
         ID DOC   --------- ----------------------------------------------------------------           1 A man walking on the street with a barking dog 
  select * from ctx_user_pending; 
  no rows selected 
There are two approaches for synchronization: 
  1. Explicit one-shot request for a given index   2. Implicit continuous request for all indexes database-wide 
1. Explicit Synchronization 
Explicit synchronization can be implemented using ctx_ddl.sync_index PL/SQL procedure.
  begin   ctx_ddl.sync_index(idx_name => '<index_name>', memory => '50M');  end;
The memory parameter determines the maximum memory which will be allocated by theprocess which synchronizes the table and the index. Its default and maximum valueis determined by the DEFAULT_INDEX_MEMORY and MAX_INDEX_MEMORY system parameterrespectively which can be queried from CTX_PARAMETERS Text data dictionary viewand can be modified with ctx_adm.set_parameter PL/SQL procedure. It is worth setting larger values for faster completion and there will be fewer recordsper token in the token table. 

PL/SQL procedures have to be written for implementing synchronization in order to start jobs running automatically. Defining jobs requires at least one job queue process running. 
Example: 
  create or replace procedure my_index_sync   is   begin     ctx_ddl.sync_index( idx_name => 'my_index', memory => '50M');   end;   / 
  declare   v_job number;     begin    dbms_job.submit( job=>v_job, what=>'my_index_sync;', next_date=>sysdate, interval=>'sysdate+1/24');  end;   / 
One of the advantages of this method is to make differences between indexes,i.e. less important indexes can be syncronized rarely and more important often.So synchronization policy can be implemented for each text index. On the other hand, DBA always has to keep track the job system and if a new text index is created in the database DBA has to look after its synchronization. 

2. Explicit Synchronization for all text indexes database-wide 
This is a short script that runs sync in a loop with a variable delay.It remains logged on, continually scanning for DML to do on any index.
Note that this script will never exit on its own.

create table stop_sync(aa varchar(10)); declare  the_count integer;  sleep_time number := 5;begin  loop    -- scan and process pending dml to do    ctx_ddl.sync_index('null');    select count(*) into the_count from stop_sync;    exit when the_count > 0;    -- sleep for 5 seconds to avoid spinning    dbms_lock.sleep(sleep_time);  end loop;  delete from stop_sync;  commit;end;/
To stop it, you simply insert a row into the table "stop_sync" from another session.
insert into stop_sync values ('X');commit;


Monday, January 18, 2016

How to check which are the object cached in memory

 How to check which are the object cached in memory:-

select SUBSTR(owner,1,10) Owner,SUBSTR(Type,1,12) Type,SUBSTR(name,1,20) Name,
executions,sharable_mem Mem_used,
SUBSTR(Kept||' ',1,4) "Kept"
from v$db_object_cache
where type in('trigger','procedure','Package Body','Package')
order by executions desc;

Sunday, January 17, 2016

How would an application developer execute a query based on specific partition

What is interval partitioning:


 Oracle Database 11g does, with a feature called Interval Partitioning. Here, you don't define partitions and their boundaries but merely an interval that defines each partition's boundaries. Here is the same example in interval partitioning:

create table sales6
(
   sales_id    number,
   sales_dt    date
)
partition by range (sales_dt)
                              
interval (numtoyminterval(1,'MONTH'))
(
   partition p0701 values less than (to_date('2007-02-01','yyyy-mm-dd'))
);

How would an application developer address a specific partition? One way is to know the name, which may not be possible, and even if you know, it is highly error prone. To facilitate the access to specific partition, Oracle Database 11g offers a new syntax for partitioning SQLs:

SQL> select * from sales6 partition for (to_date('15-may-2007','dd-mon-yyyy'));

  SALES_ID SALES_DT
  ----------    ---------
      1    01-MAY-07


Note the new clause for (value), which allows you to directly reference partitions without explicitly calling them by their exact name. If you want to truncate or drop a partition, you can call this extended portioning syntax.


After the table is created in this manner, the PARTITIONING_TYPE column in view DBA_PART_TABLES shows INTERVAL

Tuesday, January 12, 2016

How to add a new disk in ASM

How to add a new disk in ASM Filesystem:-


/dev/sdi1            259610368    538324 259072044   1% /flash4
/etc/init.d/oracleasm createdisk ASMDISK02

====
/etc/init.d/oracleasm createdisk ASMDISK02 /dev/sdi1

=====
ALTER DISKGROUP DBGROUP1 ADD DISK 'ORCL:ASMDISK02';

alter system set asm_diskstring='/dev/oracleasm/disks/*' scope=both;

ALTER DISKGROUP DBGROUP1 ADD DISK 'ORCL:ASMDISK02' NAME  ASMDISK02  REBALANCE POWER 11;

ALTER DISKGROUP DBGROUP1 DROP DISK 'ORCL:ASMDISK02';

=============
select NAME, PATH, MOUNT_STATUS, HEADER_STATUS, MODE_STATUS, TOTAL_MB, FREE_MB
from v$asm_disk;


2. Add new ASM disks to the diskgroup:

alter diskgroup ORADB_DATA01_DG add disk 'ORCL:H_1253_1521';
alter diskgroup ORADB_DATA01_DG add disk 'ORCL:H_1253_1522';
alter diskgroup ORADB_DATA01_DG add disk 'ORCL:H_1253_1523';

alter diskgroup ORADB_DATA01_DG REBALANCE POWER 10; or
alter system set asm_power_limit=10 scope=memory;

-- Check the rebalance operation
select * from v$asm_operation;


Time taken to rebalance the diskgroup: app. 90 min.


3. Identify the disks to drop from the diskgroup:

set linesize 200;
col path format a20;

select NAME, PATH, MOUNT_STATUS, HEADER_STATUS, MODE_STATUS, TOTAL_MB, FREE_MB
from v$asm_disk;

ALTER DISKGROUP ORADB_DATA01_DG DROP DISK B_1530_1091;
ALTER DISKGROUP ORADB_DATA01_DG DROP DISK C_1530_1090;
ALTER DISKGROUP ORADB_DATA01_DG DROP DISK D_1530_1081;

alter diskgroup ORADB_DATA01_DG REBALANCE POWER 10; or
alter system set asm_power_limit=10 scope=memory;

-- Check the rebalance operation
select * from v$asm_operation;


====================


/etc/init.d/oracleasm createdisk ORA_G1D6 /dev/sdn1

ALTER DISKGROUP DBGROUP1 ADD DISK 'ORCL:ORA_G1D5';
ALTER DISKGROUP DBGROUP1 ADD DISK 'ORCL:ORA_G1D6';
ALTER DISKGROUP DBGROUP1 ADD DISK 'ORCL:ORA_G1D7';
ALTER DISKGROUP DBGROUP1 ADD DISK 'ORCL:ORA_G1D8';

alter diskgroup DBGROUP1 REBALANCE POWER 10;

ALTER DISKGROUP DBGROUP1 DROP DISK 'ORCL:ASMDISK02';

ORA_G1D1
ORA_G1D2
ORA_G1D3
ORA_G1D4
ORA_G1D5
ORA_G1D6
ORA_G1D7
ORA_G1D8
 

How to estimate the size of a export dump:

How to estimate the size of a export dump:

expdp system/pw SCHEMAS=BACDBA LOGFILE=dir1:BACDBA.LOG estimate_only=y

How to change archive log destination:

How to change archive log destination:

ALTER SYSTEM SET log_archive_dest ='/flash2/arch/PMSDB/archivelog' scope=both;

or

ALTER SYSTEM ARCHIVE LOG ALL TO ‘/u04/oradata/PROD’;




How to change the database from noarchivelog to archivelog:

SQL> startup mount exclusive;
ORACLE instance started.

Total System Global Area  574619648 bytes
Fixed Size                   780240 bytes
Variable Size             304879664 bytes
Database Buffers          268435456 bytes
Redo Buffers                 524288 bytes
Database mounted.
SQL> ALTER DATABASE ARCHIVELOG;

Database altered.

SQL> ARCHIVE LOG START
Statement processed.
SQL> ALTER DATABASE OPEN;


Alternatively, add the above commands into your database's startup command script, and bounce the database.

The following parameters needs to be set for databases in ARCHIVELOG mode:

log_archive_start         = TRUE
log_archive_dest_1        = 'LOCATION=/arch_dir_name'
log_archive_dest_state_1  = ENABLE
log_archive_format        = %d_%t_%s.arc