Labels

DB (11) Query (11) R12 (8) FWM (7) scripts (7) APPS (6) AD Tools (5) Patch (4) Concurrent request (3) DB Vault (3) Performance Tuning (3) RMAN (3) tips (3) LOG (2) clone (2) ASM (1) RAC (1) error (1) metalink (1) standby (1)
Showing posts with label Query. Show all posts
Showing posts with label Query. Show all posts

Wednesday, 30 January 2013

dba_scheduler_jobs

Scheduled Jobs

select
   owner,
   job_name,
   job_class,
   enabled,
   next_run_date,
   repeat_interval
from
   dba_scheduler_jobs

Sunday, 13 January 2013

how to check hidden parameter in oracle

select a.ksppinm name,
b.ksppstvl value,
b.ksppstdf deflt,
decode(a.ksppity, 1,
'boolean', 2,
'string', 3,
'number', 4,
'file', a.ksppity) type,
a.ksppdesc description
from
sys.x$ksppi a, sys.x$ksppcv b
where a.indx = b.indx
and a.ksppinm like '%replace_virtual%'
order by name;

Friday, 11 January 2013

Concurrent Request

 SELECT  fcrs.request_id, fcrs.user_concurrent_program_name,
         fcrs.actual_start_date, fcrs.actual_completion_date,
         FLOOR(((fcrs.actual_completion_date-fcrs.actual_start_date)*24*60*60)/3600)||':'||
         FLOOR((((fcrs.actual_completion_date-fcrs.actual_start_date)*24*60*60) -
         FLOOR(((fcrs.actual_completion_date-fcrs.actual_start_date)*24*60*60)/3600)*3600)/60)||':'||
         round((((fcrs.actual_completion_date-fcrs.actual_start_date)*24*60*60) -
         FLOOR(((fcrs.actual_completion_date-fcrs.actual_start_date)*24*60*60)/3600)*3600 -
         (FLOOR((((fcrs.actual_completion_date-fcrs.actual_start_date)*24*60*60) -
         FLOOR(((fcrs.actual_completion_date-fcrs.actual_start_date)*24*60*60)/3600)*3600)/60)*60) )) "HOURS:MINUTES:SECONDS",
         fcrs.argument_text, fcrs.requestor,
         DECODE (fcrs.status_code,
                'A', 'Waiting',
                'B', 'Resuming',
                'C', 'Normal',
                'D', 'Cancelled',
                'E', 'Errored',
                'F', 'Scheduled',
                'G', 'Warning',
                'H', 'On Hold',
                'I', 'Normal',
                'M', 'No Manager',
                'Q', 'Standby',
                'R', 'Normal',
                'S', 'Suspended',
                'T', 'Terminating',
                'U', 'Disabled',
                'W', 'Paused',
                'X', 'Terminated',
                'Z', 'Waiting',
                 fcrs.status_code
                ) "Status",
         decode(fcrs.phase_code,
                'C','Completed',
                'I','Inactive',
                'R','Running',
                'A','Active',
                fcrs.phase_code) "Phase Code",  fcrs.completion_text,
         fcrs.responsibility_application_id, frt.responsibility_name,
         fcrs.save_output_flag, fcrs.request_date ,
         decode (fcrs.execution_method_code,
                 'B', 'Request Set Stage Function',
                 'Q', 'SQL*Plus',
                 'H', 'Host',
                 'L', 'SQL*Loader',
                 'A', 'Spawned',
                 'I', 'PL/SQL Stored Procedure',
                 'P', 'Oracle Reports',
                 'S', 'Immediate',
                 fcrs.execution_method_code
               ) execution_method , fcrs.concurrent_program_id, fcrs.program_short_name, fcrs.printer,
               fcrs.parent_request_id
    FROM fnd_conc_req_summary_v fcrs,
         fnd_responsibility_tl frt
   WHERE 1 = 1
AND user_concurrent_program_name LIKE '%PRC: Generate Draft Revenue for a Single Project%'
--and argument_text LIKE '%'
--and requestor not in ('SYSADMIN','INVADMIN')
--and request_id = 9686914
AND frt.LANGUAGE = 'US' AND fcrs.responsibility_id = frt.responsibility_id
--and fcrs.actual_start_date < sysdate
--and actual_start_date between to_date('10-JAN-2019 17:00:00', 'DD-MON-YYYY HH24:MI:SS') and to_date('10-JAN-2019 17:30:00', 'DD-MON-YYYY HH24:MI:SS')
--and fcrs.phase_code = 'R'
--and fcrs.status_code = 'X'
--and fcrs.status_code not in ('P','D','Q','C')
--and trunc(fcrs.actual_start_date) =trunc(sysdate)
--and trunc(fcrs.actual_completion_date) = trunc(sysdate)
ORDER BY fcrs.actual_start_date DESC;


OPP log file:

 SELECT fcpp.concurrent_request_id req_id, fcp.node_name, fcp.logfile_name
  FROM fnd_conc_pp_actions fcpp, fnd_concurrent_processes fcp
 WHERE fcpp.processor_id = fcp.concurrent_process_id
   AND fcpp.action_type = 6
   AND fcpp.concurrent_request_id = 10711139;

Script for the about

echo "Enter Apps password: "
read apps
echo "Enter request_id: "
read request_id
OPPLOG=`sqlplus -s "apps/$apps" <<EOF
       set heading off feedback off verify off
set line 200
       SELECT fcp.logfile_name
  FROM fnd_conc_pp_actions fcpp, fnd_concurrent_processes fcp
 WHERE fcpp.processor_id = fcp.concurrent_process_id
   AND fcpp.action_type = 6
   AND fcpp.concurrent_request_id = $request_id;
       exit
EOF
`
vi $OPPLOG


List Responsibilities That Can Run a Given Concurrent Program

SELECT          responsibility_name RN
FROM            fnd_request_groups frg,
                fnd_request_group_units frgu,
                fnd_concurrent_programs_vl fcpv,
                fnd_responsibility_vl frv
WHERE           frgu.request_unit_type = 'P'
AND             (UPPER(fcpv.concurrent_program_name) = UPPER('&1')
                OR
                UPPER(fcpv.user_concurrent_program_name) = UPPER('&1'))
AND             frgu.request_group_id = frg.request_group_id
AND             frgu.request_unit_id = fcpv.concurrent_program_id
AND             frv.request_group_id = frg.request_group_id
ORDER BY        responsibility_name  ;

Thursday, 3 January 2013

R12 backend scripts

Maintenance Mode:

SQL> select fnd_profile.value('APPS_MAINTENANCE_MODE') from dual;

FND_PROFILE.VALUE('APPS_MAINTENANCE_MODE')
--------------------------------------------------------------------------------
NORMAL

SQL> @/u02/appldev/apps/apps_st/appl/ad/12.0.0/patch/115/sql/adsetmmd.sql
Enter value for 1: ENABLE
Enter value for 1: ENABLE

PL/SQL procedure successfully completed.

SQL> select fnd_profile.value('APPS_MAINTENANCE_MODE') from dual;

FND_PROFILE.VALUE('APPS_MAINTENANCE_MODE')
--------------------------------------------------------------------------------
MAINT

Patch details

Check R12 applied patch details

select *
FROM
ad_bugs a,
ad_patch_run_bugs b,
ad_patch_runs c,
ad_patch_drivers d ,
ad_applied_patches e
WHERE
a.bug_id = b.bug_id AND
b.patch_run_id = c.patch_run_id AND
c.patch_driver_id = d.patch_driver_id AND
d.applied_patch_id = e.applied_patch_id AND
a.bug_number in  ('9239089','8919491','10281212')
ORDER BY 1 DESC;

Discussion:

https://forums.oracle.com/forums/thread.jspa?threadID=2365402

Thursday, 6 December 2012

oracle rman commands

Query to check the status or progress of rman restore

 
SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK,
       ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
FROM V$SESSION_LONGOPS
WHERE OPNAME LIKE 'RMAN%'
  AND OPNAME NOT LIKE '%aggregate%'
  AND TOTALWORK != 0
  AND SOFAR <> TOTALWORK
 ;
 

 List archives older than 3 days and delete on confirmation

delete archivelog until time "SYSDATE-3";
delete noprompt archivelog until time "SYSDATE-2";

RMAN cold backup script



backup_loc="/pbp03/applptch/PFCPATCH_coldbkp"

rman target / log=${backup_loc}/rman_coldbkp.log << EOF
run {
shutdown immediate;
startup mount;
crosscheck backup;
crosscheck copy;
delete noprompt obsolete;
delete noprompt expired backup;
allocate channel c1 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
allocate channel c2 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
allocate channel c3 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
allocate channel c4 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
allocate channel c5 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
allocate channel c6 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
allocate channel c7 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
allocate channel c8 type disk format "${backup_loc}/%d_df_%D_%M_%Y_%s_%U.rman" maxpiecesize 2000 M;
backup full filesperset 5 as compressed BACKUPSET tag 'WEEKLY_COLD_BKP' database include current controlfile;
copy current controlfile to "${backup_loc}/%d_control_file_%D_%T_%s";
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
alter database open;
}
exit
EOF



Thursday, 1 November 2012

R12 Add User and Add Responsibility

Add User

DECLARE
   v_user_name     VARCHAR2 (100) := 'KARTHIKEYANC.GDC';
   v_owner              VARCHAR2 (50)   := NULL;
   v_password        VARCHAR2 (100) := 'Oracle123';
   v_description     VARCHAR2 (100) := 'NEW USER';
BEGIN
   fnd_user_pkg.createuser
                           (x_user_name                               => v_user_name,
                            x_owner                                        => v_owner,
                            x_unencrypted_password         => v_password,
                            x_session_number                      => 0,
                            x_start_date                                 => SYSDATE,
                            x_end_date                                   => NULL,
                            x_last_logon_date                       => NULL,
                            x_description                                => v_description,
                            x_password_date                         => NULL,
                            x_password_accesses_left         => NULL,
                            x_password_lifespan_accesses => NULL,
                            x_password_lifespan_days        => NULL,
                            x_employee_id                             => NULL,
                            x_email_address                          => NULL,
                            x_fax                                               => NULL,
                            x_customer_id                             => NULL,
                            x_supplier_id                               => NULL,
                            x_user_guid                                  => NULL,
                            x_change_source                        => NULL
                           );
   COMMIT;
   DBMS_OUTPUT.put_line ('User ' || v_user_name || ' is created successfully');
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line
                (   'Error encountered while creating user and the error is '|| SQLERRM
                );
END;

Verify User Creation

SELECT  fu.user_name,
               frt.responsibility_name
  FROM fnd_user_resp_groups furg,
              fnd_user fu,
              fnd_responsibility_tl frt
 WHERE furg.user_id = fu.user_id
   AND    furg.responsibility_id = frt.responsibility_id
   AND    fu.user_name = 'karthikeyanc.gdc'

Add Responsibility

DECLARE
   v_user_name                  VARCHAR2 (100) := 'KARTHIKEYANC.GDC';
   v_responsibility_name  VARCHAR2 (100) := 'System Administrator';
   v_application_name      VARCHAR2 (100) := NULL;
   v_responsibility_key      VARCHAR2 (100) := NULL;
   v_security_group           VARCHAR2 (100) := NULL;
   v_description                  VARCHAR2 (100) := NULL;
BEGIN
   SELECT fa.application_short_name,
                 fr.responsibility_key,
                 frg.security_group_key,                    
                 frt.description
      INTO  v_application_name,
                 v_responsibility_key,
                 v_security_group,
                 v_description
     FROM fnd_responsibility fr,
                 fnd_application fa,
                 fnd_security_groups frg,
                 fnd_responsibility_tl frt
    WHERE fr.application_id = fa.application_id
      AND    fr.data_group_id = frg.security_group_id
      AND    fr.responsibility_id = frt.responsibility_id
      AND    frt.LANGUAGE = USERENV ('LANG')
      AND    frt.responsibility_name = v_responsibility_name;

   fnd_user_pkg.addresp (username          => v_user_name,
                                              resp_app           => v_application_name,
                                              resp_key            => v_responsibility_key,
                                              security_group => v_security_group,
                                              description        => v_description,
                                              start_date          => SYSDATE,
                                              end_date            => NULL
                                             );
   COMMIT;

   DBMS_OUTPUT.put_line (   'Responsiblity '
                         || v_responsibility_name
                         || ' is attached to the user '
                         || v_user_name
                         || ' Successfully'
                        );
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line
         (   'Error encountered while attaching responsibilty to the user and the error is '
          || SQLERRM
         );
END;     

Verify Responsibility

SELECT fa.application_short_name,
              fr.responsibility_key,
              frg.security_group_key,
              frt.description
  FROM fnd_responsibility fr,
              fnd_application fa,
              fnd_security_groups frg,
              fnd_responsibility_tl frt
 WHERE fr.application_id = fa.application_id
   AND    fr.data_group_id = frg.security_group_id
   AND    fr.responsibility_id = frt.responsibility_id
   AND    frt.LANGUAGE = USERENV ('LANG')
   AND    frt.responsibility_name = 'System Administrator';


Sunday, 28 October 2012

Check Primary and Physical Standby in sync

Primary Database
1. Enable archive log - SELECT log_mode FROM v$database;(NOARCHIVELOG) ; ALTER DATABASE ARCHIVELOG;
2. ALTER DATABASE FORCE LOGGING;
3. Set log_archive_config of primary and standby ; ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(DB11G,DB11G_STBY)';
4. Set archive log for standby
    ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=db11g_stby NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB11G_STBY';
    ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;
    SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
5. Set primary to switch roles to become standby
    SET FAL_SERVER=DB11G_STBY;
    SET STANDBY_FILE_MANAGEMENT=AUTO;
6. Set primary and standby tnsnames in tnsnames.ora
7. Backup Primary Database
8. Create Standby control file and pfile
    ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/db11g_stby.ctl';
    CREATE PFILE='/tmp/initDB11G_stby.ora' FROM SPFILE;
    *.db_unique_name='DB11G_STBY'
    *.fal_server='DB11G'
    *.log_archive_dest_2='SERVICE=db11g ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB11G'

Standby Database
1. Start listener
2. Create spfile
    CREATE SPFILE FROM PFILE='/tmp/initDB11G_stby.ora';
3. Restore databse
4. Create online redo logs
    SET STANDBY_FILE_MANAGEMENT=MANUAL;
    ALTER DATABASE ADD LOGFILE ('/u01/app/oracle/oradata/DB11G/online_redo01.log') SIZE 50M;
    ALTER DATABASE ADD LOGFILE ('/u01/app/oracle/oradata/DB11G/online_redo02.log') SIZE 50M;
    ALTER DATABASE ADD LOGFILE ('/u01/app/oracle/oradata/DB11G/online_redo03.log') SIZE 50M;
    SET STANDBY_FILE_MANAGEMENT=AUTO;
5. Create standby redo logs
    ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/DB11G/standby_redo01.log') SIZE 50M;
    ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/DB11G/standby_redo02.log') SIZE 50M;
    ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/DB11G/standby_redo03.log') SIZE 50M;
    ALTER DATABASE ADD STANDBY LOGFILE ('/u01/app/oracle/oradata/DB11G/standby_redo04.log') SIZE 50M;
6. Start the apply process on standby server
    ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
    ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Done...

Protection Mode
Maximum Availability - On primary transactions do not commit until redo data been written to the online redo log of standby - on failure, switchs to Max perf
    LOG_ARCHIVE_DEST_2=AFFIRM ; SET STANDBY DATABASE TO MAXIMIZE AVAILABILITY;
Maximum Performance - Transactions on the primary commit as soon as redo information has been written to the online redo log
    LOG_ARCHIVE_DEST_2=NOAFFIRM ; SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE;
Maximum Protection - On primary transactions do not commit until redo data been written to the online redo log of standby - On failure, primary shutdown
    LOG_ARCHIVE_DEST_2=AFFIRM ; SET STANDBY DATABASE TO MAXIMIZE PROTECTION;

SELECT protection_mode FROM v$database;
 
Database switchover
Primary

ALTER DATABASE COMMIT TO SWITCHOVER TO STANDBY;
shutdown ; startup nomount;
ALTER DATABASE MOUNT STANDBY DATABASE;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Standby
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
shutdown; startup

Failover
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
ALTER DATABASE ACTIVATE STANDBY DATABASE;

Script to check in Primary Database:

SELECT THREAD# "Thread",SEQUENCE# "Last Sequence Generated"
FROM V$ARCHIVED_LOG
WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)
ORDER BY 1;

Output:

    Thread Last Sequence Generated

---------- -----------------------
         1                     315
         1                     315
         2                     194
         2                     194

Script to check in standby database:

SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence Applied",
(ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference"
FROM (SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME )
  IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)) ARCH,
         (SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME )
  IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL
WHERE ARCH.THREAD# = APPL.THREAD#
ORDER BY 1;

Output:

    Thread Last Sequence Received Last Sequence Applied Difference
---------- ---------------------- --------------------- ----------
         1                    315                   315          0
         2                    193                   193          0

Switch archive log in RAC database:

alter system archive log current;


Archived log not synchronized or transferred to standby

select dest_id,status,error from v$archive_dest;

Check MRP(Managed Recovery Process)

select recovery_mode from v$archive_dest_status; 


Start MRP

alter database recover managed standby database disconnect;

Register missing archive log

alter database register or replace logfile '/u01/archive/2_67197_740404074.dbf';

http://oraclemamukutti.blogspot.in/2011/09/recover-gaps-in-standby-database-from.html

Archive log apply speed MRP speed

set linesize 400
col Values for a65
col Recover_start for a21

select to_char(START_TIME,'dd.mm.yyyy hh24:mi:ss') "Recover_start",to_char(item)||' = '||to_char(sofar)||' '||to_char(units)||' '|| to_char(TIMESTAMP,'dd.mm.yyyy hh24:mi') "Values" from v$recovery_progress where start_time=(select max(start_time) from v$recovery_progress); 


Friday, 5 October 2012

APPS Error

Could not reserve record

SELECT 'alter system kill session ''' || s.SID || ',' || s.serial# || '''', d.object_name,  s.process,s.status,
       s.machine,  s.module, s.action, s.logon_time,
        s.last_call_et,s.client_identifier
  FROM gv$locked_object g, dba_objects d, gv$session s
 WHERE g.object_id = d.object_id AND s.SID = g.session_id
 and s.status<>'ACTIVE'
 --and s.MODULE='APXINWKB'
 and d.OBJECT_NAME like 'AP%'
-- and g.session_id in (2409)
 order by s.LOGON_TIME desc;
 

Reference: 

 

Thursday, 27 September 2012

Query to Get Profile Value

Query to Get Profile Value


set linesize 160
set pagesize 1000
column SHORT_NAME format A30
column NAME format A40
column LEVEL_VAL format 999999999
column VALUE format A60 wrap
select
p.profile_option_name SHORT_NAME,
n.user_profile_option_name NAME,
decode(v.level_id,10001,'Site',10002,'Application' ,10003,'Responsibility',10004,'User','UnDef') LEVEL_SET,
v.level_value LEVEL_VAL,
v.profile_option_value VALUE
from fnd_profile_options p,
fnd_profile_option_values v,
fnd_profile_options_tl n
where p.profile_option_id = v.profile_option_id (+)
and p.profile_option_name = n.profile_option_name
and upper(n.user_profile_option_name) like upper('%&ProfileName%');

Wednesday, 19 September 2012

Tablespace

Definition:

A database storage unit that groups related logical structures together. The database data files are stored in tablespaces.

Query to List Tablespace Usage Greater Than 75 %:

select * from (SELECT /* + RULE */  df.tablespace_name "Tablespace",
       df.bytes / (1024 * 1024) "Size (MB)",
       SUM(fs.bytes) / (1024 * 1024) "Free (MB)",
       Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free",
       Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used"
  FROM dba_free_space fs,
       (SELECT tablespace_name,SUM(bytes) bytes
          FROM dba_data_files
         GROUP BY tablespace_name) df
 WHERE fs.tablespace_name (+)  = df.tablespace_name
 GROUP BY df.tablespace_name,df.bytes
UNION ALL
SELECT /* + RULE */ df.tablespace_name tspace,
       fs.bytes / (1024 * 1024),
       SUM(df.bytes_free) / (1024 * 1024),
       Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1),
       Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes)
  FROM dba_temp_files fs,
       (SELECT tablespace_name,bytes_free,bytes_used
          FROM v$temp_space_header
         GROUP BY tablespace_name,bytes_free,bytes_used) df
 WHERE fs.tablespace_name (+)  = df.tablespace_name
 GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used
 ORDER BY 4 ) tu
 where tu."% Used" > 75