Tuesday, September 25, 2012

SOME HANDY DBA SCRIPTS

------------------------------------
TO LIST JOBS CURRENTLY RUNNING:

SELECT a.job "Job",
               a.sid,
               a.failures "Failures",
              Substr(To_Char(a.last_date,'DD-Mon-YYYY HH24:MI:SS'),1,20) "Last Date",
              Substr(To_Char(a.this_date,'DD-Mon-YYYY HH24:MI:SS'),1,20) "This Date"
FROM  dba_jobs_running a;

-------------------------------------
TO LIST ALL DB SESSIONS:

SELECT NVL(a.username, '(oracle)') AS username,
               a.osuser,
               a.sid,
               a.serial#,
               c.value AS,
               a.lockwait,
               a.status,
               a.module,
               a.machine,
               a.program,
               d.name,
               TO_CHAR(a.logon_Time,'DD-MON-YYYY HH24:MI:SS') AS logon_time
FROM    v$session a,
               v$sesstat c,
               v$statname d
WHERE a.sid = c.sid
     AND c.statistic# = d.statistic#
ORDER BY c.value DESC;

-------------------------------------
TO DISPLAY DB SESSIONS AS A HIERARCHY:

SELECT  LPAD(' ', (LEVEL - 1) * 2, ' ') || NVL (s.username, '(oracle)') AS username,
              s.osuser,
              s.sid,
              s.serial#,
              s.lockwait,
              s.status,
              s.module,
              s.machine,
              s.program,
              TO_CHAR(s.logon_Time,'DD-MON-YYYY HH24:MI:SS') AS logon_time
FROM v$session s
CONNECT BY PRIOR s.sid = s.blocking_session
START WITH s.blocking_session IS NULL;
-----------------------------------
TO GRANT INSERT ON SCHEMA TABLES:

SPOOL temp.sql

SELECT 'GRANT INSERT ON "' ||u.table_name|| '" TO &1;'
FROM   user_tables u
WHERE NOT EXISTS (SELECT '1'
                                      FROM all_tab_privs a
                                     WHERE a.grantee = UPPER('&1') AND
                                                   a.privilege = 'INSERT' AND
                                                   a.table_name = u.table_name);

SPOOL OFF
-- Comment out following line to prevent immediate run
-- @temp.sql

-------------------------------------
TO GRANT EXECUTE ON SCHEMAS OBJECTS:

SPOOL temp.sql
SELECT 'GRANT EXECUTE ON "' ||u.object_name|| '" TO &1;'
FROM   user_objects u
WHERE u.object_type IN ('PACKAGE','PROCEDURE','FUNCTION')
    AND NOT EXISTS (SELECT '1'
                                     FROM all_tab_privs a
                                     WHERE a.grantee = UPPER('&1')
                                          AND a.privilege = 'EXECUTE'
                                          AND a.table_name = u.object_name);

SPOOL OFF
-- Comment out following line to prevent immediate run
-- @temp.sql

-------------------------------------
TO CREATE SYNONYMS IN CURRENT SCHEMA:

SPOOL temp.sql

SELECT 'CREATE SYNONYM "' ||a.object_name ||'" FOR "' ||a.owner|| '"."' ||a.object_name|| '";' FROM   all_objects a
WHERE a.object_type IN ('PACKAGE','PROCEDURE','FUNCTION')
     AND a.owner = UPPER('&1')
     AND NOT EXISTS (SELECT '1'
                                       FROM user_synonyms u
                                      WHERE u.synonym_name = a.object_name
                                           AND u.table_owner = UPPER('&1'));

SPOOL OFF
-- Comment out following line to prevent immediate run
-- @temp.sql

-------------------------------------
TO KNOW USER CONTEXT:

SELECT SYS_CONTEXT ('USERENV', 'SESSION_USER') FROM DUAL;

-------------------------------------
TO SHOW INDEXES:

SELECT table_owner,
               table_name,
               owner AS index_owner,
               index_name,
               tablespace_name,
               num_rows,
               status,
               index_type
FROM   dba_indexes
WHERE table_owner = UPPER('&1')
     AND table_name = DECODE(UPPER('&2'), 'ALL', table_name, UPPER('&2'))
ORDER BY table_owner, table_name, index_owner, index_name;

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

API FOR APPLICATION USER PASSWD RESET :

begin
      fnd_user_pkg.UpdateUser(
           x_user_name                             => <user login id>,
           x_owner                                    => null,
           x_unencrypted_password          => 'welcome1',
           x_start_date                              => to_date(sysdate,'MM/DD/YYYY'),
           x_end_date                               => fnd_user_pkg.null_date,
           x_last_logon_date                     => fnd_user_pkg.null_date,
           x_description                            => <user full name>,
           x_password_date                     => fnd_user_pkg.null_date,
           x_password_accesses_left        => fnd_user_pkg.null_number,
           x_password_lifespan_accesses => fnd_user_pkg.null_number,
           x_password_lifespan_days       => 180,
           x_employee_id                         => null,
           x_fax                                       => fnd_user_pkg.null_char,
           x_customer_id                         => fnd_user_pkg.null_number,
           x_supplier_id                           => fnd_user_pkg.null_number,
          x_email_address                      => <User Email Address>);
end;

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


API FOR ASSIGN SYSADMIN RESPONSIBILITY TO AN APPLICATION USER:

begin
    fnd_user_pkg.AddResp(
               username => <user login id>,
               resp_app => 'SYSADMIN',
               resp_key => 'SYSTEM_ADMINISTRATOR',
               security_group => 'STANDARD',
               description => 'System Administrator',
               start_date => sysdate,
               end_date => null);
end;

begin
    fnd_user_pkg.AddResp(
               username => <user login id>,
               resp_app => 'ICX',
               resp_key => 'SYSTEM_ADMINISTRATION',
               security_group => 'STANDARD',
               description => 'System Administration',
               start_date => sysdate,
               end_date => null);
end;

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

R12 COMPILE JAVA SERVER PAGES :

Go to $HTML_TOP or where the JSPs are located.
For example; to compile "abcdef_12.jsp"

$FND_TOP/patch/115/bin/ojspCompile.pl --compile -s 'abcdef_12.jsp' --flush

Check the log for any errors, correct them and compile.
Bounce the apache from the $ADMIN_SCRIPTS_HOME

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

R12 USERS WITH NO LOG ON ACTIVITY IN APPLICATIONS FOR LAST 60 DAYS:

SELECT USER_NAME,
               DESCRIPTION FULL_NAME,
               TO_CHAR(LAST_LOGON_DATE, 'DD-MON-YYYY') LastLogon
  FROM  FND_USER
WHERE LAST_LOGON_DATE < SYSDATE - 60 AND
               USER_ID > 1100 AND
               END_DATE IS NULL
ORDER BY last_logon_date ASC


------------------------------------
Some Useful Links
http://www.orafaq.com/wiki/Scripts
http://oracle-base.com/dba/scripts.php
http://dbakevlar.com/scripts/
http://rafioracledba.blogspot.com/2010/08/database-health-check.html
------------------------------------

Thursday, September 6, 2012

SQL Trace with EBS

These MOS docs are handy for any performance issues:

How To Use SQL Trace And TKPROF For Performance Issues with EBusiness Suite [ID 980711.1] Author: Luis J. Gonzalez
https://support.oracle.com/epmos/faces/ui/km/DocContentDisplay.jspx?_afrLoop=1008981601705720&id=980711.1&_afrWindowMode=0&_adf.ctrl-state=pvt2x3r2b_74


How To Run Application Collection Tool (ACT/RDA) Diagnostics Test? [ID 559800.1]
https://support.oracle.com/epmos/faces/ui/km/DocContentDisplay.jspx?_afrLoop=1009691371364643&id=559800.1&_afrWindowMode=0&_adf.ctrl-state=pvt2x3r2b_313

Troubleshooting Oracle Applications Performance Issues [ID 169935.1] Author: Carlos Sierra
https://support.oracle.com/epmos/faces/ui/km/DocContentDisplay.jspx?_afrLoop=1100600262021534&id=169935.1&_afrWindowMode=0&_adf.ctrl-state=v9vy1cibx_388


https://support.oracle.com/epmos/faces/ui/km/DocContentDisplay.jspx?_afrLoop=1507179551130647&id=438652.1&_afrWindowMode=0&_adf.ctrl-state=19e01bmqeu_101

R12: How To Trace and TKPROF A Concurrent Program With Performance Issue
1) As System Administrator, go to Concurrent-> programs -> Define, and query program
     with the problem

2) Enable the check box called 'Enable Trace' and save

3) Before starting trace, make sure the following DB parameters are set:
    MAX_DUMP_FILE_SIZE = UNLIMITED
    TIMED_STATISTICS = TRUE
    STATISTICS_LEVEL = ALL

   If they are not set as above, run the following as SYS:
     SQL> alter system set MAX_DUMP_FILE_SIZE=UNLIMITED;
     SQL> alter system set TIMED_STATISTICS=TRUE;
     SQL> alter system set STATISTICS_LEVEL=ALL;

4) Run the report reproducing the issue


5) After the process finishes, get the trace file from the directory set from below:
       SELECT value
         FROM v$parameter
         WHERE name = 'user_dump_dest';  

     then run tkprof for the trace file
           with  sort=exeela,prsela,fchela and explain=apps/appspw.
    Use tkprof from DB Oracle Home, and that the process already finished.
    If the process has not finished the rows column in tkprof will be all zeros and useless.

6) Once the log file, raw trace and sorted tkprof trace files are ready,
     ZIP them into a single file and upload to My Oracle Support (Metalink).

7) Run RDA Collection Test per Note:559800.1/Note:732091.1 for corresponding modules
     for ex., AR and SLA

Another way of Tracing a Concurrent Program:


1. Ensure that patch# 8743459 is applied
(Patch 8743459: 12.1.1: 'SQL TRACE' IN 'DEBUG OPTIONS' IS UNLIKELY WORKING)

2. Next, Navigate to System Administrator - and set the profile - FND: Debug Enabled
     to No - at all levels (site and user) to ensure this is not turned on.

3. Move to Concurrent/Program/Define - query the concurrent program and uncheck the 'Enable trace' box

4. To create the trace:

a. Navigate to System Administrator responsibility
b. Navigate to Profiles->System
c. Query the Profile Option Concurrent: Allow Debugging and set it to Yes at User level
d. Navigate to responsibility to excute the concurrent program
e. From the Requests form, choose the Concurrent Program and set the required Parameters
f. Click the Debug button on the SUBMIT Form that is now enabled. This will open a new window
g. Check the SQL Trace checkbox and specify Trace with Binds and Waits
     - Choose Ok - then it will tell you debug rule has been created - close the window
h. now back at the Submit form - Submit the Concurrent program - let it complete
i. Reset the value of the profile Option Concurrent: Allow Debugging
j. Retrieve the trace file created - it should have the user-name and concurrent request
    number in the filename

Finding Trace Files

Trace files are stored in the Automatic Diagnostic Repository (ADR), in the trace directory under each ADR home. To locate individual trace files within this directory, one can use data dictionary views. For example, find the path to the current session's trace file or to the trace file for each Oracle Database process.


To find the trace file for your current session:
SELECT VALUE FROM V$DIAG_INFO WHERE NAME = 'Default Trace File';
The full path to the trace file is returned.

To find all trace files for the current instance:
SELECT VALUE FROM V$DIAG_INFO WHERE NAME = 'Diag Trace';
The path to the ADR trace directory for the current instance is returned.

To determine the trace file for each Oracle Database process:
SELECT PID, PROGRAM, TRACEFILE FROM V$PROCESS;

To find trace file directory path:
SELECT VALUE FROM SYS.V_$DIAG_INFO WHERE NAME = 'Diag Trace';