Saturday, March 21, 2015

Compile Invalid Objects using UTLRP.SQL and UTLIRP.SQL in R12

UTLIRP.SQL

This is a SQL script which Invalidates PL/SQL modules (procedures, functions, packages, types, triggers, views in a database). This script expects standard.sql, dbmsstdx.sql files. 

There should be no other DDL on the database while running the script.

For better performance set following parameter
set  _disable_fast_validate=TRUE in init.ora file 

connected AS SYSDBA

start database in UPGRADE mode 
SQL>STARTUP UPGRADE; or SQL>ALTER DATABASE OPEN UPGRADE;
Run script utlirp.sql 
SQL>@<ORACLE_HOME>/rdbms/admin/utlirp.sql


UTLRP.SQL

This script recompiles all existing invalid PL/SQL modules in a database. this invokes utlrcmp.sql

There should be no other DDL on the database while running the script. 

Connected AS SYSDBA

Shut down the database and restart in normal mode 

Run script utlrp.sql 
SQL>@<ORACLE_HOME>/rdbms/admin/utlrp.sql

Saturday, March 7, 2015

Setup Printers for Cheque printing on Oracle EBS R12


For Printer setup first need to setup from OS level and then setup from application

Setup the printer at the OS level

First we need to check the status for the Linux/UNIX based CUPS print server
[root@ etc /]# /etc/init.d/cups status
Then add the new printer to the LINUX environment, login to linux CUPS using following URL
http://localhost:631/admin

Click on Add Printer button and add printer details



Click Continue button and select Device from drop down list for network printer select Apps Socket


Enter IP for network printer 


Select printer model and type



And press continue. Now Printer is added from OS


Setup through Application

Navigation -  System Administrator -> Install -> Printer -> Register
Define a new printer by entering the Printer Name and Type (Printer name must be same for both OS and application)


For Custom style we can define new style  Add The printer to 'printer' profile option
Navigation -  System Administrator -> Profile -> System 

Select the style as 'PDF Publisher' and printer name for concurrent program.
Navigation -  System Administrator -> Concurrent -> Program -> Define 
Find the the relevant cheque printing program

Bounce the Concurrent Manager to reflect the changes

When run the concurrent program select the no of copies need to print

RMAN Error : ORA-19625: error identifying file

Problem
RMAN> run{
2> allocate channel ch1 device type disk format '+DATA/RAC/BACKUP/%T_DB_%U';
3> backup database;
4> backup archivelog all format '+DATA/RAC/BACKUP/%T_Archive_%U';
5> backup current controlfile format '+DATA/RAC/BACKUP/%T_Control_%U';
6> }

using target database control file instead of recovery catalog
allocated channel: chq
channel chq: SID=53 instance=RAC2 device type=DISK

Starting backup at 06-MAR-15
current log archived
released channel: chq
RMAN-00571: ================================================
RMAN-00569: ========= ERROR MESSAGE STACK FOLLOWS ==========
RMAN-00571: ================================================
RMAN-03002: failure of backup command at 03/06/2015 17:57:28
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability
ORA-19625: error identifying file /u01/archive/1_7_873551068.dbf
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

Recovery Manager complete.

Solution

Delete expired archivelog those are not in the DB
RMAN> crosscheck archivelog all;

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 instance=RAC2 device type=DISK
validation failed for archived log
archived log file name=/u01/archive/1_7_873551068.dbf RECID=3 STAMP=873556504
validation failed for archived log
archived log file name=/u01/archive/1_8_873551068.dbf RECID=2 STAMP=873556504
validation failed for archived log
archived log file name=/u01/archive/1_9_873551068.dbf RECID=4 STAMP=873557382
validation failed for archived log
archived log file name=/u01/archive/1_10_873551068.dbf RECID=5 STAMP=873557389
validation failed for archived log
validation succeeded for archived log
archived log file name=+DATA/rac/archivelog/1_14_873551068.dbf RECID=15 STAMP=873567711
validation succeeded for archived log
archived log file name=+DATA/rac/archivelog/1_15_873551068.dbf RECID=19 STAMP=873567781
validation succeeded for archived log
archived log file name=+DATA/rac/archivelog/1_16_873551068.dbf RECID=21 STAMP=873615567
Crosschecked 22 objects
RMAN> delete expired archivelog all;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 instance=RAC2 device type=DISK
List of Archived Log Copies for database with db_unique_name RAC
=========================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
3       1    7       X 05-MAR-15
        Name: /u01/archive/1_7_873551068.dbf

2       1    8       X 05-MAR-15
        Name: /u01/archive/1_8_873551068.dbf

4       1    9       X 05-MAR-15
        Name: /u01/archive/1_9_873551068.dbf

5       1    10      X 05-MAR-15
        Name: /u01/archive/1_10_873551068.dbf


Do you really want to delete the above objects (enter YES or NO)? YES
deleted archived log
archived log file name=/u01/archive/1_7_873551068.dbf RECID=3 STAMP=873556504
deleted archived log
archived log file name=/u01/archive/1_8_873551068.dbf RECID=2 STAMP=873556504
deleted archived log
archived log file name=/u01/archive/1_9_873551068.dbf RECID=4 STAMP=873557382
deleted archived log
archived log file name=/u01/archive/1_10_873551068.dbf RECID=5 STAMP=873557389
deleted archived log
Deleted 11 EXPIRED objects

After delete expired backup, re-try the backup then it will successful 
RMAN> run{
2> allocate channel ch1 device type disk format '+DATA/RAC/BACKUP/%T_DB_%U';
3> backup database;
4> backup archivelog all format '+DATA/RAC/BACKUP/%T_Archive_%U';
5> backup current controlfile format '+DATA/RAC/BACKUP/%T_Control_%U';
6> }

allocated channel: ch1
channel ch1: SID=53 instance=RAC2 device type=DISK

Starting backup at 06-MAR-15
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/rac/datafile/system.256.873550825
input datafile file number=00002 name=+DATA/rac/datafile/sysaux.257.873550829
input datafile file number=00003
name=+DATA/rac/datafile/undotbs1.258.873550831
input datafile file number=00005 name=+DATA/rac/datafile/example.264.873551129
input datafile file number=00006
name=+DATA/rac/datafile/undotbs2.265.873551485
input datafile file number=00004 name=+DATA/rac/datafile/users.259.873550831
channel ch1: starting piece 1 at 06-MAR-15
channel ch1: finished piece 1 at 06-MAR-15
piece handle=+DATA/rac/backup/20150306_db_0dq15sbj_1_1 tag=TAG20150306T182451
comment=NONE
channel ch1: backup set complete, elapsed time: 00:01:55
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ch1: starting piece 1 at 06-MAR-15
channel ch1: finished piece 1 at 06-MAR-15
piece handle=+DATA/rac/backup/20150306_db_0eq15sf6_1_1 tag=TAG20150306T182451
comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-MAR-15

Starting backup at 06-MAR-15
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=2 sequence=1 RECID=1 STAMP=873555316
input archived log thread=2 sequence=6 RECID=13 STAMP=873567601
input archived log thread=1 sequence=14 RECID=15 STAMP=873567711
input archived log thread=2 sequence=7 RECID=14 STAMP=873567610
input archived log thread=2 sequence=8 RECID=16 STAMP=873567733
input archived log thread=1 sequence=15 RECID=19 STAMP=873567781
input archived log thread=2 sequence=9 RECID=17 STAMP=873567774
input archived log thread=2 sequence=10 RECID=18 STAMP=873567777
input archived log thread=2 sequence=11 RECID=20 STAMP=873568822
input archived log thread=1 sequence=16 RECID=21 STAMP=873615567
channel ch1: starting piece 1 at 06-MAR-15
channel ch1: finished piece 1 at 06-MAR-15
piece handle=+DATA/rac/backup/20150306_archive_0fq15sfj_1_1
tag=TAG20150306T182658 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:07
Finished backup at 06-MAR-15

Starting backup at 06-MAR-15
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
channel ch1: starting piece 1 at 06-MAR-15
channel ch1: finished piece 1 at 06-MAR-15
piece handle=+DATA/rac/backup/20150306_control_0gq15sfs_1_1
tag=TAG20150306T182708 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:07
Finished backup at 06-MAR-15
released channel: ch1

Saturday, February 28, 2015

Enable/Disable Archivelog mode in oracle RAC DB

Enable Archivelog Mode

1. Connect to DB from one node
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 27 20:16:10 2015
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

2. Check the archivelog mode
SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /u01/app/oracle/product/11.2.0/db_1/dbs/arch
Oldest online log sequence     8
Current log sequence           9

3. Disable the RAC
SQL> alter system set cluster_database=false scope=spfile sid='RAC1';
System altered.

4. Shutdown the All RAC instances
[oracle@ol5-112-rac1 ~]$ srvctl stop database -d RAC

5. Connect to DB 
[oracle@ol5-112-rac1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 27 20:18:19 2015
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.

6. Mount the DB
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1023004672 bytes
Fixed Size                  2219752 bytes
Variable Size             721420568 bytes
Database Buffers          293601280 bytes
Redo Buffers                5763072 bytes
Database mounted.

7. Enable Archivelog mode
SQL> alter database archivelog;
Database altered.

8. Enable the RAC
SQL> alter system set cluster_database=true scope=spfile sid='RAC1';
System altered.

9. Shutdown the DB
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.

10. Start all the RAC instances
[oracle@ol5-112-rac1 ~]$ srvctl start database -d RAC
Disable Archivelog Mode

1. Connect to DB
[oracle@ol5-112-rac1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 27 20:28:41 2015
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

2. Check the archivelog mode
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/product/11.2.0/db_1/dbs/arch
Oldest online log sequence     8
Next log sequence to archive   9
Current log sequence           9

3. Disable the RAC
SQL> alter system set cluster_database=false scope=spfile sid='RAC1';
System altered.

4. Shutdown the All RAC instances
[oracle@ol5-112-rac1 ~]$ srvctl stop database -d RAC

5. Connect to DB
[oracle@ol5-112-rac1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 27 20:11:10 2015
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.

6. Mount the DB
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1023004672 bytes
Fixed Size                  2219752 bytes
Variable Size             721420568 bytes
Database Buffers          293601280 bytes
Redo Buffers                5763072 bytes
Database mounted.

7. Disable Archivelog mode
SQL> alter database noarchivelog;
Database altered.

8. Enable the RAC
SQL> alter system set cluster_database=true scope=spfile sid='RAC1';
System altered.

9. Shutdown the DB
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.

10. Start the All RAC instances
[oracle@ol5-112-rac1 ~]$ srvctl start database -d RAC

Thursday, February 19, 2015

E-mail Generation for Daily Health Check Report via mailx OS utility


For e-mail generation we need SQL script and shell script files. SQL script extract data from DB to health check report and the shell script generate e-mail via mailx utility with sql output and then scheduled this for daily. 

SQL Scripts

[oracle@kiawiz ~]$ cat ts.sql
set feedback off echo off
set linesize 100
set pagesize 200
set colsep |
SET TRIMSPOOL ON
spool /home/oracle/tablespace.log
column tablespace_name format a25
column FreePC format a15
column FullPC format a15
select b.tablespace_name,round(tbs_size,0) SizeMb,round((tbs_size- a.free_space),0)UsedMb,round(a.free_space,0) FreeMb,to_char((round(((a.free_space*100)/tbs_size),2)),'00.00')||'%' FreePC,to_char((100-round(((a.free_space*100)/tbs_size),2)),'00.00')||'%' FullPC
from (select tablespace_name, round(sum(bytes)/1024/1024 ,2) as free_space
from dba_free_space group by tablespace_name
UNION
select tablespace_name,((free_space/1024)/1024) free_space
from dba_temp_free_space) a,
(select tablespace_name, sum(bytes)/1024/1024 as tbs_size
from dba_data_files group by tablespace_name
UNION
select tablespace_name, sum(bytes)/1024/1024 tbs_size
from dba_temp_files
group by tablespace_name ) b
where a.tablespace_name=b.tablespace_name
order by 100-round(((a.free_space*100)/tbs_size),2) desc;
select count(*) Invalid_objects from dba_objects where status ='INVALID';
column object_name format a30
column owner format a15
select object_name,owner,object_type from dba_objects where status ='INVALID';
spool off
exit


Schell Script

[oracle@kiawiz ~]$ cat tablespace_new.sh
#!/bin/sh
. /finsys/db/tech_st/11.1.0/PROD_kiawiz.env
cat /home/oracle/tablespace.log
sqlplus '/ as sysdba' << EOF
@ts.sql;
EOF
if [ `cat /home/oracle/tablespace.log|wc -l` -gt 0 ]
then

echo -e "\n"  2>&1>>/home/oracle/tablespace.log
df -h 2>&1>>/home/oracle/tablespace.log

cat /home/oracle/tablespace.log |mailx -s "Production instance - Health Check" test@gmail.com
rm -rf /home/oracle/tablespace.log
fi


Schedule .sh file via crontab
00 09 * * 0-6 . /home/oracle/tablespace_new.sh

Monday, February 16, 2015

ORA-00020: maximum number of processes (%s) exceeded


Problem

The issue is due to process/sessions parameter exceeds the limit. Need to increase those parameter to solve this issue.


Solution

When ORA-00020 occurred then you wont able to  connect to the DB via sys user to change the parameter. You can use following steps to overcome the issue.

1. Login to DB using following command
[oracle@prod 11.1.0]$ sqlplus -prelim "/ as sysdba"
2. Shutdown the DB
SQL>shutdown abort;
3. Exit from session
SQL>exit;
4. Connect to DB via sys
[oracle@prod 11.1.0]$ sqlplus / as sysdba
5. Start the DB
SQL>startup;
6. Check the Value for Process and sessions parameter
SQL>select resource_name, current_utilization, max_utilization, limit_value from v$resource_limit where resource_name in ('sessions', 'processes');
7. Change the Parameter values
SQL> alter system set processes=300 scope=spfile;
SQL> alter system set sessions=500 scope=spfile;

Saturday, February 7, 2015

Tablespace Related Queries


Create Tablespace   
SQL> create tablespace xxli_ts01 datafile '/finsys/UAT1/db/apps_st/data/xxli_data.dbf' SIZE 1500M autoextend on next 256M maxsize 10000M;

Resize Tablespace 
SQL> alter database datafile '/finsys/UAT1/db/apps_st/data/sysaux02.dbf' resize 7000M;

Add Datafile
SQL> alter TABLESPACE APPS_TS_TX_DATA add datafile '/finsys/UAT1/db/apps_st/data/a_txn_data05.dbf' SIZE 1800M autoextend on next 256M maxsize 3500M;

Auto extend on/off
SQL> ALTER DATABASE DATAFILE '/finsys/UAT1/db/apps_st/data/xxkia01.dbf' AUTOEXTEND ON maxsize unlimited;
SQL> ALTER DATABASE DATAFILE '/finsys/UAT1/db/apps_st/data/xxkia01.dbf' AUTOEXTEND OFF;

Unlimited Quota
SQL> alter user apps quota unlimited on apps_ts_tx_data;

Drop datafile
SQL> alter tablespace APPS_TS_TX_DATA drop datafile '/finsys/UAT1/db/apps_st/data/xxkia01.dbf';

Move Datafile
1)
SQL> ALTER TABLESPACE XXTEST OFFLINE NORMAL;
2)
Copy the datafile (/tmp/test.dbf) to their new location (/finsys/UAT1/db/apps_st/data/) and rename (XXTEST1.DBF) them using the operating system command
3)
SQL> ALTER TABLESPACE XXTEST RENAME DATAFILE '/tmp/test.dbf' TO '/finsys/UAT1/db/apps_st/data/XXTEST1.DBF';
4)
SQL> ALTER TABLESPACE XXTEST ONLINE;

Tablespace Related Views
dba_data_files
dba_free_space
v$tablespace


Create Temp Tablespace
SQL> create temporary tablespace temp4 tempfile '/finsys/UAT1/db/apps_st/data/temp04.dbf' size 1000M tablespace group TEMP;

Resize Temp Tablespace
SQL> ALTER DATABASE TEMPFILE '/finsys/UAT1/db/apps_st/data/temp01.dbf' RESIZE 1000M;

Add Temp File
SQL> alter TABLESPACE TEMP1 add tempfile '/finsys/UAT1/db/apps_st/data/temp01.dbf' SIZE 2000M autoextend on next 256M maxsize 10240M;

Drop Temp File
SQL> alter TABLESPACE TEMP1 drop tempfile '/finsys/UAT1/db/apps_st/data/temp01.dbf';

Drop Temp Tablespace
SQL> DROP TABLESPACE temp1 including CONTENTS AND DATAFILES;

Make  Temp Tablespace default
SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp4;

Adding tablespce to group
SQL> ALTER TABLESPACE temp01 TABLESPACE GROUP TEMP;


Remove tablespce from group
SQL> ALTER TABLESPACE temp01 TABLESPACE GROUP '';

Temp Tablespace Related Views

DBA_TEMP_FILES
dba_temp_free_space
DBA_TABLESPACE_GROUPS;
V$TEMP_SPACE_HEADER

Details/Usage of Tablespaces
set linesize 5000;
col tablespace_name for a30;
col FreePC for a10;
set pagesize 1000;
select
b.tablespace_name,
round(tbs_size,0) SizeMb,
round((tbs_size- a.free_space),0)UsedMb,
round(a.free_space,0) FreeMb,
to_char((round(((a.free_space*100)/tbs_size),2)),'00.00')||'%' FreePC,
to_char((100-round(((a.free_space*100)/tbs_size),2)),'00.00')||'%' FullPC
from 
(  select 
     tablespace_name, 
     round(sum(bytes)/1024/1024 ,2) as free_space 
   from dba_free_space 
   group by tablespace_name
 UNION
   select 
     tablespace_name,
     ((free_space/1024)/1024) free_space
   from dba_temp_free_space
)a, 

(  select 
     tablespace_name,
     sum(bytes)/1024/1024 as tbs_size 
   from dba_data_files 
   group by tablespace_name
 UNION
   select 
     tablespace_name,
     sum(bytes)/1024/1024 tbs_size
   from dba_temp_files
   group by tablespace_name 
)b
where a.tablespace_name=b.tablespace_name
order by 100-round(((a.free_space*100)/tbs_size),2) desc;
OR
set linesize 5000;
col tablespace_name for a30;
col FreePC for a10;
set pagesize 1000;
select
b.tablespace_name,
round(tbs_size,0) SizeMb,
round((a.tot_used),0)UsedMb,
round((tbs_size-a.tot_used),0) FreeMb,
decode((round(((a.tot_used*100)/tbs_size),2)),0,(100-round(((a.tot_used*100)/tbs_size),2)||'%'),(to_char((100-round(((a.tot_used*100)/tbs_size),2)),'00.00')||'%')) FreePC,
to_char((round(((a.tot_used*100)/tbs_size),2)),'00.00')||'%' FullPC
from 
(  select 
     tablespace_name, 
     sum(bytes/1024/1024) tot_used
   from dba_segments
   group by tablespace_name
 UNION
   select 
     tablespace_name,
     round(used_blocks*8/1024) tot_used
   from v$sort_segment 
)a, 
(  select 
     tablespace_name,
     sum(bytes)/1024/1024 as tbs_size 
   from dba_data_files 
   group by tablespace_name
 UNION
   select 
     tablespace_name,
     sum(bytes)/1024/1024 tbs_size
   from dba_temp_files
   group by tablespace_name 
)b
where a.tablespace_name=b.tablespace_name
order by round(((a.tot_used*100)/tbs_size),2) desc;