Friday, 1 March 2019

Enforce Password Complexity for users in Oracle Database 11g/12c

Enforce Password Complexity for users in Oracle Database 11g/12c

create or replace function     ora_string_distance

(s varchar2,

 t varchar2)

return integer is

   s_len    integer := nvl (length(s), 0);

   t_len    integer := nvl (length(t), 0);

   type arr_type is table of number index by binary_integer;

   d_col    arr_type ;

   dist     integer := 0;

begin

   if s_len = 0 then

      dist := t_len;

   elsif t_len = 0 then

      dist := s_len;

   -- Bug 18237713 : If source or target length exceeds max DB password length

   -- that is 128 bytes, then raise exception.

   elsif t_len > 128 or s_len > 128 then

     raise_application_error(-20027,'Password length more than 128 bytes');

   elsif s = t then

     return(0);

   else

      for j in 1 .. (t_len+1) * (s_len+1) - 1 loop

          d_col(j) := 0 ;

      end loop;

      for i in 0 .. s_len loop

          d_col(i) := i;

      end loop;

      for j IN 1 .. t_len loop

          d_col(j * (s_len + 1)) := j;

      end loop;



      for i in 1.. s_len loop

        for j IN 1 .. t_len loop

          if substr(s, i, 1) = substr(t, j, 1)

          then

             d_col(j * (s_len + 1) + i) := d_col((j-1) * (s_len+1) + i-1) ;

          else

             d_col(j * (s_len + 1) + i) := LEAST (

                       d_col( j * (s_len+1) + (i-1)) + 1,      -- Deletion

                       d_col((j-1) * (s_len+1) + i) + 1,       -- Insertion

                       d_col((j-1) * (s_len+1) + i-1) + 1 ) ;  -- Substitution

          end if ;

        end loop;

      end loop;

      dist :=  d_col(t_len * (s_len+1) + s_len);

   end if;



   return (dist);

end;





create or replace function     ora_complexity_check

(password varchar2,

 chars integer := null,

 letter integer := null,

 upper integer := null,

 lower integer := null,

 digit integer := null,

 special integer := null)

return boolean is

   digit_array varchar2(10) := '0123456789';

   alpha_array varchar2(26) := 'abcdefghijklmnopqrstuvwxyz';

   cnt_letter integer := 0;

   cnt_upper integer := 0;

   cnt_lower integer := 0;

   cnt_digit integer := 0;

   cnt_special integer := 0;

   delimiter boolean := false;

   len integer := nvl (length(password), 0);

   i integer ;

   ch char(1);

begin

   -- Check that the password length does not exceed 2 * (max DB pwd len)

   -- The maximum length of any DB User password is 128 bytes.

   -- This limit improves the performance of the Edit Distance calculation

   -- between old and new passwords.

   if len > 256 then

      raise_application_error(-20020, 'Password length more than 256 characters');

   end if;



   -- Classify each character in the password.

   for i in 1..len loop

      ch := substr(password, i, 1);

      if ch = '"' then

         delimiter := true;

      elsif instr(digit_array, ch) > 0 then

         cnt_digit := cnt_digit + 1;

      elsif instr(alpha_array, nls_lower(ch)) > 0 then

         cnt_letter := cnt_letter + 1;

         if ch = nls_lower(ch) then

            cnt_lower := cnt_lower + 1;

         else

            cnt_upper := cnt_upper + 1;

         end if;

      else

         cnt_special := cnt_special + 1;

      end if;

   end loop;



   if delimiter = true then

      raise_application_error(-20012, 'password must NOT contain a '

                               || 'double-quotation mark which is '

                               || 'reserved as a password delimiter');

   end if;

   if chars is not null and len < chars then

      raise_application_error(-20001, 'Password length less than ' ||

                              chars);

   end if;



   if letter is not null and cnt_letter < letter then

      raise_application_error(-20022, 'Password must contain at least ' ||

                                      letter || ' letter(s)');

   end if;

   if upper is not null and cnt_upper < upper then

      raise_application_error(-20023, 'Password must contain at least ' ||

                                      upper || ' uppercase character(s)');

   end if;

   if lower is not null and cnt_lower < lower then

      raise_application_error(-20024, 'Password must contain at least ' ||

                                      lower || ' lowercase character(s)');

   end if;

   if digit is not null and cnt_digit < digit then

      raise_application_error(-20025, 'Password must contain at least ' ||

                                      digit || ' digit(s)');

   end if;

   if special is not null and cnt_special < special then

      raise_application_error(-20026, 'Password must contain at least ' ||

                                      special || ' special character(s)');

   end if;



   return(true);

end;









create or replace FUNCTION ora12c_verify_function14

(username varchar2,

 password varchar2,

 old_password varchar2)

RETURN boolean IS

   differ integer;

   pw_lower varchar2(256);

   db_name varchar2(40);

   i integer;

   simple_password varchar2(10);

   reverse_user varchar2(32);

BEGIN

   IF NOT ora_complexity_check(password, chars => 14, UPPER => 2, LOWER => 2,

                           digit => 2, special => 2) THEN

      RETURN(FALSE);

   END IF;



   -- Check if the password contains the username

   pw_lower := NLS_LOWER(password);

   IF instr(pw_lower, NLS_LOWER(username)) > 0 THEN

     raise_application_error(-20002, 'Password contains the username');

   END IF;



   -- Check if the password contains the username reversed

   reverse_user := '';

   FOR i in REVERSE 1..length(username) LOOP

     reverse_user := reverse_user || substr(username, i, 1);

   END LOOP;

   IF instr(pw_lower, NLS_LOWER(reverse_user)) > 0 THEN

     raise_application_error(-20003, 'Password contains the username ' ||

                                     'reversed');

   END IF;



   -- Check if the password contains the server name

   select name into db_name from sys.v$database;

   IF instr(pw_lower, NLS_LOWER(db_name)) > 0 THEN

      raise_application_error(-20004, 'Password contains the server name');

   END IF;



   -- Check if the password contains 'oracle'

   IF instr(pw_lower, 'oracle') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



   -- Check if the password contains ' company'

   IF instr(pw_lower, ' company') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



 -- Check if the password contains 'password'

   IF instr(pw_lower, 'password') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



    -- Check if the password is too simple

   IF instr(pw_lower, 'abc') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



    IF instr(pw_lower, 'xyz') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



   IF instr(pw_lower, '123') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



   IF instr(pw_lower, '&') > 0 THEN

        raise_application_error(-20006, 'Password must not contain & ');

   END IF;



   IF instr(pw_lower, '@') > 0 THEN

        raise_application_error(-20006, 'Password must not contain @ ');

   END IF;





      -- Check if the password is too simple. A dictionary of words may be

   -- maintained and a check may be made so as not to allow the words

   -- that are too simple for the password.

   IF pw_lower IN ('hello123','welcome1','database1', 'account1', 'user1234',

                              'password1', 'oracle123', 'computer1',

                              'abcdefg1', 'change_on_install') THEN

      raise_application_error(-20006, 'Password too simple');

   END IF;



   -- Check if the password differs from the previous password by at least

   -- 3 characters

   IF old_password IS NOT NULL THEN

     differ := ora_string_distance(old_password, password);

     IF differ < 3 THEN

        raise_application_error(-20010, 'Password should differ from the '

                                || 'old password by at least 3 characters');

     END IF;

   END IF ;



   RETURN(TRUE);

END;





create or replace FUNCTION ORA12C_VERIFY_FUNCTION8

(username varchar2,

 password varchar2,

 old_password varchar2)

RETURN boolean IS

   differ integer;

   pw_lower varchar2(256);

   db_name varchar2(40);

   i integer;

   simple_password varchar2(10);

   reverse_user varchar2(32);

BEGIN

   IF NOT ora_complexity_check(password, chars => 8, UPPER => 1, LOWER => 1,

                           digit => 1, special => 1) THEN

      RETURN(FALSE);

   END IF;



   -- Check if the password contains the username

   pw_lower := NLS_LOWER(password);

   IF instr(pw_lower, NLS_LOWER(username)) > 0 THEN

     raise_application_error(-20002, 'Password contains the username');

   END IF;



   -- Check if the password contains the username reversed

   reverse_user := '';

   FOR i in REVERSE 1..length(username) LOOP

     reverse_user := reverse_user || substr(username, i, 1);

   END LOOP;

   IF instr(pw_lower, NLS_LOWER(reverse_user)) > 0 THEN

     raise_application_error(-20003, 'Password contains the username ' ||

                                     'reversed');

   END IF;



   -- Check if the password contains the server name

   select name into db_name from sys.v$database;

   IF instr(pw_lower, NLS_LOWER(db_name)) > 0 THEN

      raise_application_error(-20004, 'Password contains the server name');

   END IF;



   -- Check if the password contains 'oracle'

   IF instr(pw_lower, 'oracle') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



   -- Check if the password contains ' company'

   IF instr(pw_lower, ' company') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



-- Check if the password contains 'password'

   IF instr(pw_lower, 'password') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



    -- Check if the password is too simple

   IF instr(pw_lower, 'abc') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



    IF instr(pw_lower, 'xyz') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



   IF instr(pw_lower, '123') > 0 THEN

        raise_application_error(-20006, 'Password too simple');

   END IF;



   IF instr(pw_lower, '&') > 0 THEN

        raise_application_error(-20006, 'Password must not contain & ');

   END IF;



   IF instr(pw_lower, '@') > 0 THEN

        raise_application_error(-20006, 'Password must not contain @ ');

   END IF;





      -- Check if the password is too simple. A dictionary of words may be

   -- maintained and a check may be made so as not to allow the words

   -- that are too simple for the password.

   IF pw_lower IN ('hello123','welcome1','database1', 'account1', 'user1234',

                              'password1', 'oracle123', 'computer1',

                              'abcdefg1', 'change_on_install') THEN

      raise_application_error(-20006, 'Password too simple');

   END IF;



   -- Check if the password differs from the previous password by at least

   -- 3 characters

   IF old_password IS NOT NULL THEN

     differ := ora_string_distance(old_password, password);

     IF differ < 3 THEN

        raise_application_error(-20010, 'Password should differ from the '

                                || 'old password by at least 3 characters');

     END IF;

   END IF ;



   RETURN(TRUE);

END;

Wednesday, 2 January 2019

Oracle Database Configuration Assistant DBCA - Silent Mode

Oracle DBCA Silent Mode 

This article demonstrates how to create a new database using the Database Configuration Assistant (DBCA) in silent mode.

Response File

Response files provide all the answers to the questions normally asked by the Database Configuration Assistant (DBCA). You can find a sample DBCA response file under the ORACLE_HOME ($ORACLE_HOME/assistants/dbca/dbca.rsp). 

1. Copy source RDBMS software:
1.1 On the source database server:

Copy the source oracle database home
cd /u01/app/oracle/product
Example:
tar -cvzf /scratch/db_source/OH.tar.gz 11.2.0.4

1.2 On the target database server:

Example:
cd /u02/app/oracle/product
 tar -xvzf /scratch/db_source/OH.tar.gz

2. Clone the Target Oracle home:
cd $ORACLE_HOME/clone/bin
 perl clone.pl ORACLE_HOME="<target_home>" ORACLE_HOME_NAME="<unique_home_name>" ORACLE_BASE="<path_for_ORACLE_BASE>" OSDBA_GROUP=<OSDBA_privileged_group> OSOPER_GROUP=<OSOPER_privileged_group>
Example:
perl clone.pl ORACLE_HOME="/u02/app/oracle/product/11.2.0.4/test_db" ORACLE_HOME_NAME="test_db" ORACLE_BASE="/u02/app/oracle" OSDBA_GROUP=dba OSOPER_GROUP=oinstall

3. DBCA in Silent  Mode:
Edit the response file(.rsp)  as per the Target database:
Set the below parameters specific to target database.
GDBNAME
SID
SYSPASSWORD
SYSTEMPASSWORD
DATAFILEDESTINATION
RECOVERYAREADESTINATION
STORAGETYPE
DISKGROUPNAME
RECOVERYGROUPNAME
CHARACTERSET
NATIONALCHARACTERSET
MEMORYPERCENTAGE
Below is an example of database creation using dbca silent install mode for db_source database.
Example:
[oracle@exadatahost- bin]$ ./dbca -silent -responseFile /u02/app/oracle/product/11.2.0.4/test_db/assistants/dbca/dbca_test_db.rsp
Copying database files
1% complete
3% complete
10% complete
17% complete
24% complete
35% complete
Creating and starting Oracle instance
37% complete
42% complete
47% complete
52% complete
53% complete
56% complete
58% complete
Registering database with Oracle Restart
64% complete
Completing Database Creation
68% complete
71% complete
75% complete
76% complete
77% complete
78% complete
79% complete
80% complete
90% complete
100% complete
Look at the log file "/u02/app/oracle/cfgtoollogs/dbca/test_db/test_db.log" for further details.

4. Set Init Parameters in target :

Compare init parameters in source database  and update them in target database.

Tuesday, 18 December 2018

Weblogic server takes long time to start. Performance tuning of Weblogic server startup.


Weblogic server takes long time to start. Performance tuning of Weblogic server startup.

Cause:

It is observed on some Linux boxes that WebLogic server startup takes several minutes and hangs for a while. Similar behavior happens during the domain creation, when the security information gets populated.

It has also been observed WLS Admin Console slowness due to low entropy.
Linux has two devices to provide random data at any time: /dev/random and /dev/urandom. Both ways should be secure enough to use them in generating PGP keys, ssh challenges, and other applications where secure random numbers are required. Starting on kernel 2.6, default entropy is 4096 bits and problem arises when the entropy available on the system is minimum (around 100 bits or less).
The main difference between those two devices is that /dev/random runs out of random bits and makes you wait for more to be accumulated. Note that on some systems, it can block for a long time waiting for new user-generated entropy to be entered into the system.

In terms of the outcome, /dev/random is categorized as a high quality entropy device if we compare it with /dev/urandom. The latter uses the entropy pool as long as it is available, but falls back on pseudo random numeric algorithms when depleted.

Why a system could be running out of entropy?
You have to consider that an Operating System performs cryptographic operations frequently (on ssh challenges, https connections, etc.) so the /dev/random pool gets consumed quite quickly. OS also expects to feed that pool with I/O operations coming from disk, network, mouse or keyboard but that situation does not happen as quickly. This is a common pattern on virtualized environments or headless boxes.
Is important to mention that Java uses /dev/random by default as entropy generator device.
How to verify if you are encountering this issue?
  1. Check the default system entropy.
$ cat /proc/sys/kernel/random/poolsize
4096
  1. Check the available entropy.
$ cat /proc/sys/kernel/random/entropy_avail
125
On previous example, entropy is too low.
  1. Monitor the current entropy of the system by using the following command:
$ for i in $(seq 500); do cat /proc/sys/kernel/random/entropy_avail ; sleep 5; done
  1. Start a WebLogic server instance. You should see that entropy decreases or stalls.


Solution:
a) WebLogic Server Scope
i.   Edit the Weblogic startup script ($DOMAIN_HOME/bin/startWebLogic.sh)
ii.  Add the following to the JAVA_OPTIONS variable: -Djava.security.egd=file:/dev/./urandom
iii. Save the file.
iv. Set the domain environment. ($DOMAIN_HOME/bin/setDomainEnv.sh)
v.  Start WebLogic instances.
b) JDK Scope

i.   Edit the Java Security Properties file ($JAVA_HOME/jre/lib/security/java.security)
ii.  The securerandom.source property specifies the source of seed data for secure random. If that property points to /dev/random, set it as one of the options listed below.
securerandom.source=file:/dev/./urandom
securerandom.source=file:/dev/urandom
iii.  Save changes and start the WebLogic Server instances.

Temporary solution :
i. Override the JAVA_OPTIONS environment variable before starting WebLogic Server via shell scripts.
$ export JAVA_OPTIONS="${JAVA_OPTIONS} -Djava.security.egd=file:/dev/./urandom"
ii. Start WebLogic instances.




Happy Learning!

Weblogic Not Starting with Error: JPS-06514: Opening of file based keystore failed

Recently, I encountered an issue where the Weblogic Admin server did not start due to an error  JPS-06514: Opening of file based keystore failed

Error Message:
<Error> <Security> <BEA-090892> <The loading of OPSS java security policy provider failed due to exception, see the exception stack trace or the server log file for root cause. If still see no obvious cause, enable the debug flag -Djava.security.debug=jpspolicy to get more information. Error message: JPS-06514: Opening of file based keystore failed.>
 <Critical> <WebLogicServer> <BEA-000386> <Server subsystem failed. Reason: weblogic.security.SecurityInitializationException: The loading of OPSS java security policy provider failed due to exception, see the exception stack trace or the server log file for root cause. If still see no obvious cause, enable the debug flag -Djava.security.debug=jpspolicy to get more information. Error message: JPS-06514: Opening of file based keystore failed.
weblogic.security.SecurityInitializationException: The loading of OPSS java security policy provider failed due to exception, see the exception stack trace or the server log file for root cause. If still see no obvious cause, enable the debug flag -Djava.security.debug=jpspolicy to get more information. Error message: JPS-06514: Opening of file based keystore failed.
        at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.loadOPSSPolicy(CommonSecurityServiceManagerDelegateImpl.java:1402)
        at weblogic.security.service.CommonSecurityServiceManagerDelegateImpl.initialize(CommonSecurityServiceManagerDelegateImpl.java:1022)
        at weblogic.security.service.SecurityServiceManager.initialize(SecurityServiceManager.java:888)
        at weblogic.security.SecurityService.start(SecurityService.java:141)
        at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
        Truncated. see log file for complete stacktrace
Caused By: oracle.security.jps.JpsRuntimeException: JPS-06514: Opening of file based keystore failed.
        at oracle.security.jps.internal.policystore.PolicyDelegationController.<init>(PolicyDelegationController.java:190)
        at oracle.security.jps.internal.policystore.TenantJavaPolicyProvider.<init>(TenantJavaPolicyProvider.java:161)
        at oracle.security.jps.internal.policystore.JavaPolicyProvider.<init>(JavaPolicyProvider.java:306)
        at oracle.security.jps.internal.policystore.JavaPolicyProvider.<init>(JavaPolicyProvider.java:279)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        Truncated. see log file for complete stacktrace
Caused By: oracle.security.jps.JpsException: JPS-06514: Opening of file based keystore failed.
        at oracle.security.jps.internal.policystore.PolicyUtil.getDefaultPDPService(PolicyUtil.java:3180)
        at oracle.security.jps.internal.policystore.PolicyUtil.getPDPService(PolicyUtil.java:3480)
        at oracle.security.jps.internal.policystore.PolicyUtil.getPDPService(PolicyUtil.java:3466)
        at oracle.security.jps.internal.policystore.PolicyDelegationController.<init>(PolicyDelegationController.java:188)
        at oracle.security.jps.internal.policystore.TenantJavaPolicyProvider.<init>(TenantJavaPolicyProvider.java:161)
        Truncated. see log file for complete stacktrace
Caused By: oracle.security.jps.service.keystore.KeyStoreServiceException: JPS-06514: Opening of file based keystore failed.
        at oracle.security.jps.internal.keystore.file.FileKeyStoreManager.openKeyStore(FileKeyStoreManager.java:458)
        at oracle.security.jps.internal.keystore.file.FileKeyStoreManager.openKeyStore(FileKeyStoreManager.java:392)
        at oracle.security.jps.internal.keystore.file.FileKeyStoreServiceImpl.doInit(FileKeyStoreServiceImpl.java:128)
        at oracle.security.jps.internal.keystore.file.FileKeyStoreServiceImpl.start(FileKeyStoreServiceImpl.java:901)
        at oracle.security.jps.internal.keystore.FarmKeyStoreServiceImpl.initialize(FarmKeyStoreServiceImpl.java:148)
        Truncated. see log file for complete stacktrace
Caused By: oracle.security.jps.service.keystore.KeyStoreServiceException: JPS-06519: Failed to get/set credential with map fks and key null in bootstrap credstore. Reason oracle.security.jps.service.keystore.KeyStoreServiceException: JPS-06519: Failed to get/set credential with map fks and key current.key in bootstrap credstore. Reason null
        at oracle.security.jps.internal.keystore.util.KeyStoreServiceUtil.getMasterKey(KeyStoreServiceUtil.java:453)
        at oracle.security.jps.internal.keystore.file.FileKeyStoreManager$3.run(FileKeyStoreManager.java:412)
        at oracle.security.jps.internal.keystore.file.FileKeyStoreManager$3.run(FileKeyStoreManager.java:410)
        at java.security.AccessController.doPrivileged(Native Method)
        at oracle.security.jps.internal.keystore.file.FileKeyStoreManager.openKeyStore(FileKeyStoreManager.java:410)
        Truncated. see log file for complete stacktrace
Caused By: oracle.security.jps.service.keystore.KeyStoreServiceException: JPS-06519: Failed to get/set credential with map fks and key current.key in bootstrap credstore. Reason null
        at oracle.security.jps.internal.keystore.util.KeyStoreServiceUtil.getCurrentMasterKeyAlias(KeyStoreServiceUtil.java:303)
        at oracle.security.jps.internal.keystore.util.KeyStoreServiceUtil$3.run(KeyStoreServiceUtil.java:446)
        at oracle.security.jps.internal.keystore.util.KeyStoreServiceUtil$3.run(KeyStoreServiceUtil.java:444)
        at java.security.AccessController.doPrivileged(Native Method)
        at oracle.security.jps.internal.keystore.util.KeyStoreServiceUtil.getMasterKey(KeyStoreServiceUtil.java:444)
        Truncated. see log file for complete stacktrace
Caused By: oracle.security.jps.service.credstore.CredStoreException: JPS-01061: Access to bootstrap credential store denied to application code.

Solution:


1.Delete all pki files under /tmp and rename keystores.xml(domain/config) and cwallet.sso(domain/config/fmwconfig/bootstrap).
2. Delete the tmp directory under the $DOMAIN_HOME/servers/AdminServer
3.Start the weblogic server


Happy Learning!

Wednesday, 11 July 2018

Oracle EBS R12.2 : Check Ports in Run Edition and Patch Edition



Check Context Files Version are the same in Database


select path,status,serial_number,version
  from apps.fnd_oam_context_files
 where name not in ('TEMPLATE','METADATA') and (status is null or status !='VALID')
order by path, version;


Check Ports in Run Edition

SELECT  extractValue(XMLType(TEXT),'//host[@oa_var="s_hostname"]'),
extractValue(XMLType(TEXT),'//oacore_server_ports'),
extractValue(XMLType(TEXT),'//forms_server_ports'),
extractValue(XMLType(TEXT),'//oafm_server_ports'),
extractValue(XMLType(TEXT),'//forms-c4ws_server_ports'),
extractValue(XMLType(TEXT),'//oaea_server_ports')
from apps.fnd_oam_context_files
where name not in ('TEMPLATE','METADATA')
and (status is null or status !='H')
and EXTRACTVALUE(XMLType(TEXT),'//file_edition_type')='run'
and CTX_TYPE = 'A';


Check Ports in Patch Edition

SELECT  extractValue(XMLType(TEXT),'//host[@oa_var="s_hostname"]'),
extractValue(XMLType(TEXT),'//oacore_server_ports'),
extractValue(XMLType(TEXT),'//forms_server_ports'),
extractValue(XMLType(TEXT),'//oafm_server_ports'),
extractValue(XMLType(TEXT),'//forms-c4ws_server_ports'),
extractValue(XMLType(TEXT),'//oaea_server_ports')
from apps.fnd_oam_context_files
where name not in ('TEMPLATE','METADATA')
and (status is null or status !='H')
and EXTRACTVALUE(XMLType(TEXT),'//file_edition_type')='patch'
and CTX_TYPE = 'A';

Wednesday, 27 December 2017

Trace Forms Enable – Oracle EBS R12


Enable Trace from Forms

Help -> Diagnostic -> Trace ->

we have many options available (default is ‘No Trace’). We can enable tracing by selecting on of the options from here. ‘Regular Trace’ gives the least information and ‘Trace with Binds and Waits’ (level 12) gives maximum information. 

Note: Be careful while enabling SQL trace with wait and binds as this will make the trace file huge.

So after we fill all the values in the fields, we can start the tracing so that the initial select statement does not come in trace file.

When we enable the trace it will give the trace file location (This location will be the location of USER_DUMP_DESTINATION parameter of database).

Disable Trace:
After you save the form you can stop tracing by selecting ‘No Trace’ again from Help -> Diagnostic -> Trace -> No Trace
Use tkprof to covert trace file in readable format.

$ tkprof dv1_ora_35782850.trc dv1_ora_35782850.txt sys=no explain=apps/*******sort='(prsela,exeela,fchela)'


Ref:  Oracle E-Business SQL Trace and TKPROF Guide(1674024.1) 
Metalink note ID 373548.1



Enable Tracing For The Concurrent Manager  Program 
Responsibility: System Administrator
Navigate: Concurrent > Program > Define
Query Concurrent Program
Select the Enable Trace Checkbox 

Turn On Tracing
Responsibility: System Administrator
Navigate: Profiles > System
Query Profile Option Concurrent: Allow Debugging
Set profile to Yes

Run Concurrent Program With Tracing Turned On    
Please login to the Responsibility that runs the Concurrent Program 
In the Submit Request Screen click on Debug Options (B)
Select the Checkbox for SQL Trace

Find Trace File Name

  Run the following SQL to find out the Raw trace name and location for the concurrent program.  The SQL prompts the user for the request id 

SELECT
    req.request_id
    ,req.logfile_node_name node
    ,req.oracle_Process_id
    ,req.enable_trace
    ,dest.VALUE||'/'||LOWER(dbnm.VALUE)||'_ora_'||oracle_process_id||'.trc' trace_filename
    ,prog.user_concurrent_program_name
    ,execname.execution_file_name
    ,execname.subroutine_name
    ,phase_code
    ,status_code
    ,ses.SID
    ,ses.serial#
    ,ses.module
    ,ses.machine
    FROM
    fnd_concurrent_requests req
    ,v$session ses
    ,v$process proc
    ,v$parameter dest
    ,v$parameter dbnm
    ,fnd_concurrent_programs_vl prog
    ,fnd_executables execname
    WHERE 1=1
    AND req.request_id = &request --Request ID

/opt/oracle/enable/admin/ENBL1/udump  --> trace file location



/* Query for Identifying correct trace file for request id */

set lines 800
set pages 400

PROMPT IDENTIFY CONCURRENT REQUEST FILE
PROMPT From Bug.3211206
PROMPT Use the following query to identify the correct trace file:
PROMPT where "request" is the concurrent request id for the inventory transaction 
PROMPT worker. 

SELECT 'Request id: '||request_id ,
'Trace id: '||oracle_Process_id,
'Trace Flag: '||req.enable_trace,
'Trace Name: 
'||dest.value||'/'||lower(dbnm.value)||'_ora_'||oracle_process_id||'.trc',
'Prog. Name: '||prog.user_concurrent_program_name,
'File Name: '||execname.execution_file_name|| execname.subroutine_name ,
'Status : '||decode(phase_code,'R','Running') 
||'-'||decode(status_code,'R','Normal'),
'SID Serial: '||ses.sid||','|| ses.serial#,
'Module : '||ses.module
from apps.fnd_concurrent_requests req, v$session ses, v$process proc,
v$parameter dest, v$parameter dbnm, apps.fnd_concurrent_programs_vl prog, 
apps.fnd_executables execname
where req.request_id = &request
and req.oracle_process_id=proc.spid(+)
and proc.addr = ses.paddr(+)
and dest.name='user_dump_dest'
and dbnm.name='db_name'
and req.concurrent_program_id = prog.concurrent_program_id
and req.program_application_id = prog.application_id
and prog.application_id = execname.application_id
and prog.executable_id=execname.executable_id;




3. TKPROF Trace File

Once you have obtained the Raw trace file you need to generate TKPROF.

output_file: tkprof out file


$ tkprof sys=no explain=apps/ sort=’(prsela,exeela,fchela)’ print=10

Other ways to take trace:
SQL> ALTER SESSION SET sql_trace=TRUE;
SQL> ALTER SESSION SET sql_trace=FALSE;

SQL> EXEC DBMS_SESSION.set_sql_trace(sql_trace => TRUE);
SQL> EXEC DBMS_SESSION.set_sql_trace(sql_trace => FALSE);

SQL> ALTER SESSION SET EVENTS '10046 trace name context forever, level 8';
SQL> ALTER SESSION SET EVENTS '10046 trace name context off';

SQL> EXEC DBMS_SYSTEM.set_sql_trace_in_session(sid=>123, serial#=>1234, sql_trace=>TRUE);
SQL> EXEC DBMS_SYSTEM.set_sql_trace_in_session(sid=>123, serial#=>1234, sql_trace=>FALSE);

SQL> EXEC DBMS_SYSTEM.set_ev(si=>123, se=>1234, ev=>10046, le=>8, nm=>' ');

SQL> EXEC DBMS_SYSTEM.set_ev(si=>123, se=>1234, ev=>10046, le=>0, nm=>' ');

Happy Learning!

Thursday, 26 January 2017

Oracle TDE encryption verification

For TDE tablespace  encryption, the following SQL statement lists all encrypted tablespaces with their encryption  algorithm and corresponding, encrypted, data files

SELECT t.name "TSName", e.encryptionalg "Algorithm", d.file_name
"File Name"
FROM
v$tablespace t, v$encrypted_tablespaces e, dba_data_files d
WHERE
t.ts# = e.ts# and t.name = d.tablespace_name;

Query to lists the table owner, tables within encrypted tablespaces, and the encryption algorithm:

 SELECT a.owner "Owner", a.table_name "Table Name", e.encryptionalg
"Algorithm"
FROM
dba_tables a, v$encrypted_tablespaces e
WHERE
a.tablespace_name in (select t.name from v$tablespace t,
v$encrypted_tablespaces e where t.ts# = e.ts#);

Happy Learning!