Stay at Home!! Be Safe!! Take Care!!

For Any queries, please mail us at support@funoracleapps.com

Query to Find High Water Mark for a Given Table/All Table in Oracle

No comments

Query to Find High Water Mark for a Given Table/All Table in Oracle


Script:

Please note 
  • The first parameter you need to pass as a single Table name or ALL for all tables in the schema 
  • The second Parameter would be passed as Owner.

SET SERVEROUTPUT ON
SET VERIFY OFF

DECLARE
  CURSOR cu_tables IS
    SELECT a.owner,
           a.table_name
    FROM   dba_tables a
    WHERE  a.table_name = Decode(Upper('&&Table_Name'),'ALL',a.table_name,Upper('&&Table_Name'))
    AND    a.owner      = Upper('&&Table_Owner') 
    AND    a.partitioned='NO'
    AND    a.logging='YES'
order by table_name;


  op1  NUMBER;
  op2  NUMBER;
  op3  NUMBER;
  op4  NUMBER;
  op5  NUMBER;
  op6  NUMBER;
  op7  NUMBER;
BEGIN

  Dbms_Output.Disable;
  Dbms_Output.Enable(1000000);
  Dbms_Output.Put_Line('TABLE                             UNUSED BLOCKS     TOTAL BLOCKS  HIGH WATER MARK');
  Dbms_Output.Put_Line('------------------------------  ---------------  ---------------  ---------------');
  FOR cur_rec IN cu_tables LOOP
    Dbms_Space.Unused_Space(cur_rec.owner,cur_rec.table_name,'TABLE',op1,op2,op3,op4,op5,op6,op7);
    Dbms_Output.Put_Line(RPad(cur_rec.table_name,30,' ') ||
                         LPad(op3,15,' ')                ||
                         LPad(op1,15,' ')                ||
                         LPad(Trunc(op1-op3-1),15,' ')); 
  END LOOP;

END;
/

SET VERIFY ON

No comments :

Post a Comment

Query to shrink Datafiles and Reclaim unused Space in Oracle

No comments

 Query to shrink Datafiles and Reclaim unused Space in Oracle


Steps to Shrink the datafiles

set verify off
set pages 1000
column file_name format a50 word_wrapped
column smallest format 999,990 heading "Smallest|Size|Poss."
column currsize format 999,990 heading "Current|Size"
column savings  format 999,990 heading "Poss.|Savings"
break on report

Step1: To Check Database block size

column value new_val blksize
select value from v$parameter where name = 'db_block_size';


Step2: Check how much space can be reclaimed 

select file_name,
       ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
       ceil( blocks*&&blksize/1024/1024) currsize,
       ceil( blocks*&&blksize/1024/1024) -
       ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
from dba_data_files a,
     ( select file_id, max(block_id+blocks-1) hwm
         from dba_extents
        group by file_id ) b
where a.file_id = b.file_id(+);

You can also add condition if needs to be checked for a specific tablespace

Step3: Script to reclaim unused space from the datafiles 

set pages 0
set lines 300
column cmd format a300 word_wrapped

select 'alter database datafile '''||file_name||''' resize ' ||
       ceil( (nvl(hwm,1)*&&blksize)/1024/1024 )  || 'm;' cmd
from dba_data_files a, 
     ( select file_id, max(block_id+blocks-1) hwm
         from dba_extents
        group by file_id ) b
where a.file_id = b.file_id(+) 
  and ceil( blocks*&&blksize/1024/1024) -
      ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0;

No comments :

Post a Comment

Query to find Oracle Process consuming most of Memory and CPU

No comments

Query to find Oracle Process consuming most of the Memory and CPU


Session consuming the most memory

SELECT a.username, a.osuser, a.program, b.spid,b.pga_used_mem, a.sid, a.serial# ,a.module,a.logon_time,a.terminal FROM v$session a, v$process b WHERE a.paddr = b.addr
order by
b.pga_used_mem desc


Session Consuming Most Memory

select 
   ss.username,
   se.SID,
   VALUE/100 cpu_usage_seconds
from
   v$session ss, 
   v$sesstat se, 
   v$statname sn
where
   se.STATISTIC# = sn.STATISTIC#
and
   NAME like '%CPU used by this session%'
and
   se.SID = ss.SID
and 
   ss.status='ACTIVE'
and 
   ss.username is not null

No comments :

Post a Comment

How to identify a filesystem type in Linux System

No comments

 How to identify a filesystem type in Linux System



There are multiple ways to determine the file system type in a Linux Based Environment

1) df -Th

for this to work the filesystem should be mounted

2) fsck -N /dev/device

Example: 
fsck -N /dev/sdb2

3) lsblk -f

Displays the block device with filesystem type details

4) mount |grep -i "device"

Example:
mount| grep -i "sdb2"

5) blkid /dev/device

Example:
blkid /dev/sdb2

6) cat /etc/fstab

This would only work if the filesystem is updated in fstab.

No comments :

Post a Comment

How to perform Oracle 11g Data Guard Switchover and Switchback

No comments

 How to perform Oracle 11g Data Guard Switchover and Switchback 


Switchover:


Before performing switchover, please  verify the state of the data guard on both the instances by following SQL queries:


 SQL> ALTER SESSION SET nls_date_format='DD-MON-YYYY HH24:MI:SS';

 SQL> SELECT sequence#, first_time, next_time, applied

 FROM v$archived_log

 ORDER BY sequence#;


 

 SQL> select dest_name,status,error from v$archive_dest where dest_name='LOG_ARCHIVE_DEST_2';

 DEST_NAME

 --------------------------------------------------------------------------------

 STATUS ERROR

 --------- -----------------------------------------------------------------

 LOG_ARCHIVE_DEST_2

 VALID


 SQL> select message from v$dataguard_status;


Note: This command will give you an appropriate message about the data guard current status.


Kick-Off switchover activity by issuing the following  commands:


On Primary database:


Step-1

Connect to Primary database and convert primary database to standby.


 [oracle@funoracle ~]$ sqlplus / as sysdba

 SQL> alter database commit to switchover to standby;

 Database altered.


Step-2

Shutdown primary database:


SQL> shutdown immediate;


Step-3


Startup nomount old primary database as new standby database:


 SQL> startup nomount

 ORACLE instance started.

 

 

 SQL> alter database mount standby database;

 Database altered.

 SQL> alter database recover managed standby database disconnect from session;

 Database altered.


Verify database role on old primary database:


 SQL> select name,open_mode,database_role from v$database;

 NAME OPEN_MODE DATABASE_ROLE

 --------- -------------------- ----------------

 PROD MOUNTED PHYSICAL STANDBY

 


On Standby database:


Step-4

On the original standby database, Convert the old standby database to the primary database:

 SQL> alter database commit to switchover to primary;

 Database altered.


Step-5


Convert old standby database as primary and shutdown database:


[oracle@funoracledr ~]$ sqlplus / as sysdba


 SQL> shutdown immediate;

 ORA-01109: database not open

 Database dismounted.

 ORACLE instance shut down.


Step-6


Startup old standby database as the primary database:


 SQL> startup

 ORACLE instance started.

 

Verify database role on old standby database:


 SQL> select name,open_mode,database_role from v$database;

 NAME OPEN_MODE DATABASE_ROLE

 --------- -------------------- ----------------

 PROD READ WRITE PRIMARY


Switch overactivity have completed successfully, our old primary database has become standby and old standby database has become the primary database.


Note

We can test the above switchover activity, by generating multiple archive logs on the primary database and verify those archive logs being transferred on the standby database.


Switchback:

To switchback, we  have to follow the same above-mentioned steps

No comments :

Post a Comment

Cron to Schedule a Script on Last Day of Month

No comments

 Cron to Schedule a Script on Last Day of Month


00 01 28-31 * * [ "$(date +%d -d tomorrow)" = "01" ] && /script.sh


At 01:00 on every day-of-month from 28 through 31


00--> Minutes when you want to run
01--> Hour when the job needs to be executed
28-31--> 28,28,29 and 31’st of each month
*--> All month of year
*-->All day of week
/script.sh--> Script name which needs to be executed
[ "$(date +%d -d tomorrow)" = "01" ]--> Logic which will test if next date is 01


No comments :

Post a Comment

Query to find Plan Hash Values for a SQLID in Oracle

No comments

 Query to find Plan Hash Values for a SQLID in Oracle


SELECT DISTINCT sql_id, plan_hash_value
FROM dba_hist_sqlstat dhs,
    (
    SELECT /*+ NO_MERGE */ MIN(snap_id) min_snap, MAX(snap_id) max_snap
    FROM dba_hist_snapshot ss
    WHERE ss.begin_interval_time BETWEEN (SYSDATE - &No_Days) AND SYSDATE
    ) s
WHERE dhs.snap_id BETWEEN s.min_snap AND s.max_snap
  AND dhs.sql_id IN ( '&SQLID')

No comments :

Post a Comment

How to get Oracle SQL output in HTML format and send as a Mail Body

No comments

 How to get Oracle SQL output in HTML format and send as a Mail Body 


SQL Script to get the output as HTML

SET MARKUP HTML ON SPOOL ON
set termout off
set pages 999
set pagesize 999
set feedback off
SET MARKUP HTML ON TABLE "class=sysaud cellspacing=2 border='2' width='95%' align='center' " ENTMAP OFF

spool fnd_debug_report.html

set pagesize 1000
set pause off
set linesize 150

prompt
prompt FND Debug Profile Enabled Report 
prompt
prompt

/* Below can be any query based on your requirement*/

SELECT upper(sys_context('USERENV','DB_NAME')) "DB_NAME",fpot.user_profile_option_name NAME,
         DECODE (fpov.level_id,
                 10001, 'Site',
                 10002, 'Application',
                 10003, 'Responsibility',
                 10004, 'User',
                 10005, 'Server',
                 'UnDef')
            LEVEL_SET,
         DECODE (TO_CHAR (fpov.level_id),
                 '10001', '',
                 '10002', fap.application_short_name,
                 '10003', frsp.responsibility_key,
                 '10005', fnod.node_name,
                 '10006', hou.name,
                 '10004', fu.user_name,
                 'UnDef')
            "CONTEXT_NAME",
         fpov.profile_option_value VALUE
    FROM apps.fnd_profile_options fpo,
         apps.fnd_profile_option_values fpov,
         apps.fnd_profile_options_tl fpot,
         apps.fnd_user fu,
         apps.fnd_application fap,
         apps.fnd_responsibility frsp,
         apps.fnd_nodes fnod,
         apps.hr_operating_units hou
   WHERE     fpo.profile_option_id = fpov.profile_option_id(+)
         AND fpo.profile_option_name = fpot.profile_option_name
         AND fu.user_id(+) = fpov.level_value
         AND frsp.application_id(+) = fpov.level_value_application_id
         AND frsp.responsibility_id(+) = fpov.level_value
         AND fap.application_id(+) = fpov.level_value
         AND fnod.node_id(+) = fpov.level_value
         AND hou.organization_id(+) = fpov.level_value
                and fpot.language='US'
          and fpot.user_profile_option_name like 'FND: Debug Log Enabled%'
          and fpov.profile_option_value='Y';



spool off
exit

Example:




Sample script to send this as a mail body

. ~/.bash_profile
Inst_name=`echo $TWO_TASK|tr [a-z] [A-Z]`
Mail_id=himanshu@dummy.com
output_report=$HOME/scripts/fnd_debug_report.html
export content=${output_report}
export subject="FND Debug Profile is enabled in ${Inst_name}"
rm -f ${output_report}
cd $HOME/scripts
sqlplus $APPSLOGIN @fnd_debug.sql


if grep --quiet 'Log' $HOME/scripts/fnd_debug_report.html;
then
echo "Sending email"

(
echo "Subject: $subject"
echo "To: $Mail_id"
echo "MIME-version: 1.0"
echo "content-Type: text/html"
echo "content-Disposition: inline"
cat $content
) | sendmail -t
fi

No comments :

Post a Comment

sendmail errors: Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF (HP UX)

No comments

 sendmail errors: Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF (HP UX)


Error:

While checking the mailq below messages are being seen.

                /var/spool/mqueue (25 requests)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
084Fe2V7000352*     229 Fri Sep  4 23:40 root
                                         root
084FZ0EN019660      229 Fri Sep  4 23:35 root
                 (Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF)
                                         root
084FU0lB009058      229 Fri Sep  4 23:30 root
                 (Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF)
                                         root
084FP5de028755      229 Fri Sep  4 23:25 root
                 (Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF)
                                         root
084FKhx8023818      229 Fri Sep  4 23:20 root
                 (Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF)
                                         root
084Et10R002008*     229 Fri Sep  4 22:55 root
                 (Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF)
                                         root
084Ej2ib011301      229 Fri Sep  4 22:45 root
                 (Deferred: local mailer (/usr/bin/rmail) exited with EX_TEMPF)
                                         root
084FF1pO014533      229 Fri Sep  4 23:15 root


Solution:

/var/mail didn't exist 
/var/mail needs to be created and bin:mail ownership and 775 permissions

Also, check that no lock file present.

Check for /var/mail/*.lock and if present please remove.

Start and stop Sendmail services.

/sbin/init.d/sendmail stop
/sbin/init.d/sendmail start

No comments :

Post a Comment

FNDCPASS error in R12 - Error in password verification for APPS

No comments

FNDCPASS error in R12 - Error in password verification for APPS


Issue:


While changing password using FNDCPASS getting below error.


+----------------------------------------------------------------------------+

Working...

Error in password verification for APPS


+---------------------------------------------------------------------------+

Concurrent request completed


Solution:


SQL> show parameter case


NAME                                 TYPE        VALUE

------------------------------------ ----------- --------------------

sec_case_sensitive_logon             boolean     TRUE


SQL> alter system set sec_case_sensitive_logon=FALSE;

System altered.


Re-try FNDCPASS now

No comments :

Post a Comment