Friday, May 13, 2011

Monitoring TEMP & UNDO Space Usage

Monitoring TEMP Space Usage in Oracle

It's a common problem encountered by many DBAs on a daily basis; developers writing queries which run out of TEMP space. It can come at the worst of times, too. For example, you've run in the scripts many times overnight into a development environment and they worked fine. They are signed off and run into PROD. However, when running them into PROD they run out of TEMP space because some other processes were contending for TEMP space.

We use this query to monitor TEMP space. We have an OEM job which runs every 5 minutes during selected times and then alerts us when the TEMP space reaches a certain threshold.

SELECT ROUND(SUM( u.blocks * blk.block_size)/1024/1024,0)
FROM v$sort_usage u,
(SELECT block_size
FROM dba_tablespaces
WHERE contents = 'TEMPORARY') blk;

It can be easy to forget about TEMP space usage, but when it goes wrong it usually goes wrong badly. After all, if your job is using that much TEMP space it's probably doing a lot of work!

If you are concerned about monitoring the TEMP space within your Oracle environment,

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

How to Monitor UNDO Usage in Oracle 9i

To put it simply, there are two main ways to monitor UNDO usage within the Oracle database. Which one you decide to use will depend upon your requirements. The two ways are:

  1. View currently active UNDO usage
  2. Using current undo usage figures, estimate percentage of UNDO required based on UNDO_RETENTION

Method 1

Requires a query to look at the actively used blocks within the database. It will show you at any point in time how much UNDO is currently being used by actively running transactions.

SELECT (used_ublk * (SELECT block_size
FROM dba_tablespaces
WHERE contents = 'UNDO'))/1024/1024 MB
FROM v$transaction;

This query calculates your block size, providing that you have the UNDO tablespace set up correctly, and then outputs the amount of space being used by active transactions in the database in MBs. This query will display one line per session. If you would like to know the total amount used, you can just put a SUM at the beginning of the query

Method 2

Within most databases, the UNDO_RETENTION parameter will be set. The UNDO_RETENTION parameter specifies, in seconds, how long non-active UNDO, that is UNDO that is not currently being used by a session but was used recently, should be kept for. This UNDO is refered to as unexpired UNDO.

This setting provides the DBA with some control over what UNDO space is used first. The UNDO space which is expired - UNDO blocks which are older than the UNDO_RETENTION period - will be used first, followed by unexpired UNDO if necessary.

The database will try to honour this setting wherever possible but this is not always necessary. For example, a long running update from an active transaction will take precedence over UNDO that is unexpired.

The idea behind the UNDO_RETENTION parameter is for the DBA to provide a value for this so that the longest running SELECT statements can still be satisfied after X number of seconds of transactions happening in the database.

This brings us into 2nd method of monitoring UNDO usage, which requires a slightly more complex query with a couple more variables.

SELECT ROUND(((ur * (ups * dbs)) + (dbs * 24))/ut*100,0) AS "%"
FROM (SELECT VALUE AS ur
FROM v$parameter
WHERE NAME = 'undo_retention'),
(SELECT (SUM (undoblks) / SUM (((end_time - begin_time) * 25200))
) AS ups
FROM v$undostat),
(SELECT block_size AS dbs
FROM dba_tablespaces
WHERE tablespace_name = (SELECT VALUE
FROM v$parameter
WHERE NAME = 'undo_tablespace')),
(SELECT sum(bytes) as ut
FROM dba_data_files
WHERE tablespace_name = (SELECT VALUE
FROM v$parameter
WHERE NAME = 'undo_tablespace'));

There is a view in the database called V$UNDOSTAT, and this view shows the hostorical usage of the database. As with all the other V$ views, it is cumulative since instance startup. In the case of the V$UNDOSTAT view, it shows data for a maximum of 7 days prior to the point in time.

Our query above looks at the total amount of UNDO blocks used in that time, divides it by the timespan that is recorded in V$UNDOSTAT and then multiplies it by the UNDO_RETENTION period to give a value for the undo per second (ups).

Using this, some other variables and a few calulations it is possible to work out, based on the historical UNDO usage since instance startup, what percentage of the UNDO tablespace is used.

This query should be used if you have specified an UNDO_RETENTION paramter which should be adhered to all the time in order to allow long running queries to complete.

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

source :-

http://www.ora00600.com/scripts/databasemonitoring/undo.html

Tuesday, May 10, 2011

Diff. or Adv. between AWR and STATSPACK report


1)The AWR is the next evolution of the STATSPACK utility.

2)The AWR repository holds all of the statistics available in STATSPACK as well as some additional statistics which are not.

3)STATSPACK does not store the Active Session History (ASH) statistics which are available in the AWR dba_hist_active_sess_history view.

4)An important difference between STATSPACK and the AWR is that STATSPACK does not store history for new metric statistics introduced in Oracle10g. The key AWR views, dba_hist_sysmetric_history and dba_hist_sysmetric_summary.

5)The AWR also contains views such as dba_hist_service_stat , dba_hist_service_wait_class and dba_hist_service_name , which store history for performance cumulative statistics tracked for specific services.

6)The latest version of STATSPACK included with Oracle10g contains a set of specific tables, which track history of statistics that reflect the performance of the Oracle Streams feature. These tables are stats$streams_capture , stats$streams_apply_sum , stats$buffered_subscribers , stats$rule_set , stats$propagation_sender , stats$propagation_receiver and stats$buffered_queues . The AWR does not contain the specific tables that reflect Oracle Streams activity; therefore, if a DBA relies heavily on the Oracle Streams feature, it would be useful to monitor its performance using STATSPACK utility.

7)Statspack snapshots must be run by an external scheduler (dbms_jobs, CRON, etc.). AWR snapshots are scheduled every 60 minutes by default. Administrators can manually adjust the snapshot interval if so desired.

8)ADDM captures a much greater depth and breadth of statistics than Statspack does. During snapshot processing, MMON transfers an in-memory version of the statistics to the permanent statistics tables.

9)Statspack snapshot purges must be scheduled manually. When the Statspack tablespace runs out of space, Statspack quits working. AWR snapshots are purged automatically by MMON every night. MMON, by default, tries to keep one week's worth of AWR snapshots available. If AWR detects that the SYSAUX tablespace is in danger of running out of space, it will free space in SYSAUX by automatically deleting the oldest set of snapshots. If this occurs, AWR will initiate a server-generated alert to notify administrators of the out-of-space error condition. Administrators can manually adjust the amount of information retained by invoking the MODIFY_SNAPSHOT_SETTINGS PL/SQL stored procedure and specifying the RETENTION parameter input variable.

10)AWR snapshots provide a persistent view of database statistics. They are stored in the system-defined schema, which resides in a new tablespace called SYSAUX. A snapshot is a collection of performance statistics that are captured at a specific point in time. The snapshot data points are used to compute the rate of change for the statistic being measured. A unique SNAP_ID snapshot identifier identifies each snapshot.

Related Documents
http://arjudba.blogspot.com/2008/08/how-to-invoke-collect-and-run-awr-and.html

Monday, May 9, 2011

How to Recreate the OraInventory

How can I recreate the OraInventory if it gets corrupted or removed?

Solution

In cases where the OraInventory is missing or otherwise corrupt, recreate the oraInventory directory on UNIX systems, using the following steps. In a normal installation, there is a Global Inventory (OraInventory) and a Local Inventory ($ORACLE_HOME/inventory).

  1. Locate the oraInst.loc file, which may be in different locations, depending on your system:

    /var/opt/oracle/oraInst.loc file
    or
    /etc/oraInst.loc
  2. Modify the file oraInst.loc file:

    cp /var/opt/oracle/oraInst.loc /var/opt/oracle/oraInst.loc.bak
    mkdir /u01/oracle/oraInventory

    ---file contents---
    inventory_loc=/u01/oracle/oraInventory
    inst_group=oinstall
    ---file contents---
    Important:
    Theses example uses a typical directory, considered an $ORACLE_BASE, and a typical UNIX group which installed the Oracle products. Ensure that the correct values are used for your system.

    The oraInventory directory is usually a directory under the $ORACLE_HOME. For example, if the $ORACLE_HOME is equal to "/u01/oracle/product/10g", then the OraInventory could be "/u01/oracle/OraInventory".
  3. Change the permissions to be appropriate, (using your directory location):

    chmod 644 /var/opt/oracle/oraInst.loc
  4. For consistency, copy the file to Oracle home directory, (using your directory location):

    cp $ORACLE_HOME/oraInst.loc $ORACLE_HOME/oraInst.loc.bak
    cp /var/opt/oracle/oraInst.loc $ORACLE_HOME/oraInst.loc
  5. Run Oracle Universal Installer from your Oracle home as below, (using your site specific directory location and Oracle home name):

    cd $ORACLE_HOME/oui/bin
    ./runInstaller -silent -attachHome ORACLE_HOME="/u01/oracle/product/10.2" ORACLE_HOME_NAME="Ora10gHome"
  6. Check the inventory output is correct for your Oracle home:

    $ORACLE_HOME/OPatch/opatch lsinventory -detail
  7. If the table at the beginning of the output is showing the proper directories, and the Oracle home components are properly reflected in the details, then the Global Inventory has been successfully created from the Local Inventory. At this time, you may patch an maintain your Oracle home, as normal.
-----------------------------------------------------------------------------------------------
Source:http://onlineappsdba.blogspot.com/2008/06/how-to-recreate-orainventory.html

Sunday, May 8, 2011

Oracle APPS R12 Post Cloning issue - Form not launching

Oracle APPS R12 Post Cloning issue - Form not launching

We need to follow the below steps.

Step 1- Stop all APPS Tier services.

Step 2- Rename the directory "tldcache" under following directories.
o /INST_NAME/inst/apps/INST_NAME_MACHINE_NAME/ora/10.1.3/j2ee/oafm
o /INST_NAME/inst/apps/INST_NAME_MACHINE_NAME/ora/10.1.3/j2ee/oacore
o /INST_NAME/inst/apps/INST_NAME_MACHINE_NAME/ora/10.1.3/j2ee/forms

Step 3- Create the emplty directory with the name "tldcache" under the above directories.

Step 4- Restart the APPS Tier services.

Step 5- Start the apps tier services and test the issue.

Some Important Queries for an Apps DBA/DBA

Some Important Queries for an Apps DBA/DBA

1. Query to find Database Size

The database mainly comprises of datafiles, temp files and redo log files.

The biggest portion of a database’s size comes from the datafiles.

To find out how many megabytes are allocated to all datafiles:

SELECT sum(bytes)/1024/1024 data_size FROM dba_data_files;

2. Query to get the size of all TEMP files:

SELECT nvl(sum(bytes),0)/1024/1024 temp_size FROM dba_temp_files;

3. Query to get the size of the on-line redo-logs:

SELECT sum(bytes)/1024/1024 redo_size FROM sys.v_$log;

Finally, summing up the three above, total database size can be found:

SELECT (dsize.data_size + tsize.temp_size + rsize.redo_size)/1024/1024 "total_size"

FROM (SELECT sum(bytes) data_sizeFROM dba_data_files ) dsize,

(SELECT nvl(sum(bytes),0) temp_size FROM dba_temp_files ) tsize,

(SELECT sum(bytes) redo_size FROM sys.v_$log ) rsize;

4. Query to find space used by a database user.

Following query can be used to know the space used by the logged in user in MBs:

SELECT sum(bytes)/1024/1024 user_size FROM user_segments;

5.Query to find the space occupied by all the users in a database.

This requires access to dba_segments table:

SELECT owner, sum(bytes)/1024/1024 total_size FROM dba_segments

GROUP BY owner ORDER BY total_size DESC;

Total space occupied by all users:

SELECT sum(bytes)/1024/1024 total_size FROM dba_segments;

6. Query to find free space in temporary tablesapce:

SELECT tablespace_name,SUM(bytes_used),SUM(bytes_free) FROM

V$temp_space_header GROUP BY tablespace_name;

7. Script to find Table size in a database.

select sum(BYTES/1024/1024) as TOTAL_GIG from user_segments where

SEGMENT_NAME = 'TABLE_NAME';

Please Note: Need to execute as owner of the table.

Steps to remove, not needed context files after cloning

Steps to remove, not needed context files after cloning.

Step 1. Look at the $APPL_TOP/admin
Make sure that there is only the Target Machine's .xml available under:
$APPL_TOP/admin/

Step 2. Remove the source *.xml file if it is there.

Step 3. Then run the following.
SQL*Plus:
SQL> EXEC FND_CONC_CLONE.SETUP_CLEAN; COMMIT; EXIT;

Step4. Re-run AutoConfig on every tiers(DB Tier/s then on Apps Tier/s) to
repopulate the required system tables.

Step 5. Bounce the Applications Services.

Some useful Linux/Unix Commands

Some useful Linux/Unix Commands
 Check the forms version:
strings -a $AU_TOP/forms/US/sachin_test.fmb | grep '$Header'
strings -a $SACHIN_TOP/forms/US/sachin_test.fmx | grep '$Header'

 Install our own script
install -c /usr/local/bin

 List the information for partitions
[root@erp ~]# parted -l

 Monitor backup in RHEL 5
[root@erp ~]# watch df -m

 Check the size of a directory
[root@erp ~ ]# du -sch .

 Monitor rapid clone
[root@erp ~]# tail -f file_name_with_location

 Check the last updated file name on current location
[root@erp ~]# ls -lrt | tail -1
-rwxr-xr-x 1 root dba 41 Feb 22 01:33 new2.sh

 Get the CPU info
[root@erp ~]# vi /proc/cpuinfo
[root@erp ~]# vi /proc/slabinfo

 Remove the last updated file
[root@erp ~]# ls -lrt | tail -1| awk ‘{print $9}’|xargs rm -f

 Check the server up time
[root@erp ~]# uptime

 Get the Information about memory
[root@erp ~]# vmstat
[root@erp ~]# vmstat -m

Alternatively ,we can check with the following command.
[root@erp ~]# iostat -t 10 5

 Search and remove files
$find . -name file_name | xargs -i rm -rf {}

 Top 10 file regarding there size:
find . -type f | xargs ls -s | sort -rn | awk ‘{size=$1/1024; printf(“%dMb %s\n”,
size,$2);}’ | head
or
du -xak . | sort -n | awk ‘{size=$1/1024; path=”"; for (i=2; i 50) { printf(“%dMb
%s\n”, size,path); } }’
or
du -a /var | sort -n -r | head -n 10

 Delete the files by Month
ls -lh | awk ‘{print $6 ” ” $9}’ | sed -n ‘/Mar/p’ | xargs rm -rf



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