Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts

Thursday, April 14, 2016

Audit Trail for Custom Table in Oracle Apps - Step By Step


Hi All ...

Here the step by step for Audit Trail for Custom Table in Oracle Apps

1. Register Custom Schema 
Navigate to System Administrator Menu/Security/ORACLE/Register

2. Ensure that Audit on the Application is Enabled
Navigate to System Administrator Menu Security/AuditTrail/Install

The owner of table XX_TABLE  is XX_SCHEMA. Hence query on 
XX_SCHEMA to ensure that Audit is enabled for this Application.


3. Register table,columns and primary key
Here the procedure to register the custom able,columns and primary key in Oracle Applications. Install the procedure on your DB and run the following:

begin
register_table('XX_TABLE','XX_SCHEMA'); /* (table name, table owner) */
commit;
end;

Procedure "register_table":

CREATE OR REPLACE PROCEDURE register_table (
table_name VARCHAR2,
application_short_name VARCHAR2
)
AS
status VARCHAR2 (10);

CURSOR c_columns ( p_table_name all_tab_columns.table_name%TYPE )
IS
SELECT column_name,
data_type,
data_length,
nullable,
ROWNUM,
data_precision,
data_scale
FROM all_tab_columns
WHERE table_name = p_table_name;

CURSOR c_constraints (p_table_name all_tab_columns.table_name%TYPE,
p_application_short_name all_tab_columns.owner%TYPE )
IS
SELECT constraint_name,
table_name,
status
FROM all_constraints
WHERE table_name = p_table_name AND owner = p_application_short_name AND constraint_type = 'P';

CURSOR c_constraint_columns (
p_table_name all_tab_columns.table_name%TYPE,
p_application_short_name all_tab_columns.owner%TYPE
)
IS
SELECT acc.constraint_name,
acc.column_name,
acc.POSITION
FROM all_cons_columns acc, all_constraints ac
WHERE ac.constraint_name = acc.constraint_name
AND ac.table_name = p_table_name
AND ac.constraint_type = 'P'
AND ac.owner = p_application_short_name;
BEGIN

DBMS_OUTPUT.put_line ('Registering Table '|| table_name ||'in application ' || application_short_name);

ad_dd.register_table (p_appl_short_name => application_short_name,
p_tab_name => table_name,
p_tab_type => 'T'
);

FOR r_columns IN c_columns (table_name)
LOOP

DBMS_OUTPUT.put_line ('Registering Column '|| r_columns.column_name);

ad_dd.register_column (p_appl_short_name => application_short_name,
p_tab_name => table_name,
p_col_name => r_columns.column_name,
p_col_seq => r_columns.ROWNUM,
p_col_type => r_columns.data_type,
p_col_width => r_columns.data_length,
p_nullable => r_columns.nullable,
p_translate => 'N',
p_precision => r_columns.data_precision,
p_scale => r_columns.data_scale
);

END LOOP;

FOR r_constraints IN c_constraints (table_name, application_short_name)
LOOP

DBMS_OUTPUT.put_line ('Creating Primary Key Constraint ' || r_constraints.constraint_name);

SELECT DECODE (r_constraints.status,
'ENABLED', 'Y',
'N'
)
INTO status
FROM DUAL;

ad_dd.register_primary_key (p_appl_short_name => application_short_name,
p_key_name => r_constraints.constraint_name,
p_tab_name => table_name,
p_description => 'Primary Key for Table '|| table_name,
p_key_type => 'D',
p_audit_flag => 'Y',
p_enabled_flag => status
);
END LOOP;

FOR r_constraint_columns IN c_constraint_columns (table_name, application_short_name)
LOOP

DBMS_OUTPUT.put_line ( 'Registering Primary Key Column '||
r_constraint_columns.column_name||
' for Constraint '||
r_constraint_columns.constraint_name);

ad_dd.register_primary_key_column (p_appl_short_name => application_short_name,
p_key_name => r_constraint_columns.constraint_name,
p_tab_name => table_name,
p_col_name => r_constraint_columns.column_name,
p_col_sequence => r_constraint_columns.POSITION
);
END LOOP;
END register_table;




4. Create Audit Group
Once you table registered,navigate to System Administrator Menu Security/AuditTrail/Groups 

Application Name: XX Custom Schema
Audit Group: XX Audit
Group State: Enabled

Now, add audit tables to this group[you can add as many tables]
User Table Name: XX_TABLE


5. Run Concurrent program “AuditTrail Update Tables”

This process can be run from System Administrator responsibility. It has no parameter. Running this process will create the Audit tables and the triggers that manage Audit data.


6. Ensure that Audit Tables have been created as expected
SELECT object_name, object_type
FROM all_objects
WHERE object_name LIKE 'XX_TABLE_A%'

OBJECT_NAME                            OBJECT_TYPE
--------------------------                      --------------------------
XX_TABLE_A                               TABLE
XX_TABLE_A                               SYNONYM
XX_TABLE_AC                            TRIGGER
XX_TABLE_AC1                          VIEW
XX_TABLE_AD                            TRIGGER
XX_TABLE_ADP                          PROCEDURE
XX_TABLE_AH                            TRIGGER
XX_TABLE_AI                              TRIGGER
XX_TABLE_AIP                            PROCEDURE
XX_TABLE_AT                             TRIGGER
XX_TABLE_AU                            TRIGGER
XX_TABLE_AUP                          PROCEDURE
XX_TABLE_AV1                           VIEW

Fine, this proves that the concurrent program in Step 5 did its job.
Optionally, you may run concurrent process “AuditTrail Report for Audit Group Validation” to validate the success of Audit Table/Trigger creation.

7. Add further columns for Audit Trail
By default Oracle will Audit Trail on all columns that are a part of first available Unique Index on XX_TABLE.
However further columns can be added to the Audit Trail. Lets say you wish to Audit Trail on Column Meaning too.
Navigate to System Administrator Menu Security/AuditTrail/Tables

You can add additional columns to audit trail and re-execute Step 5.
Please note that adding columns for Audit could have been done immediately after Step 4.

You are DONE...

Usefull notes:
How To Enable Auditing On A Table (Doc ID 1359749.1)
Unable to Enable Audit Trail for Custom Objects (Doc ID 433527.1)


Good Luck ...

Monday, June 29, 2015

How to re-open EXPIRED & LOCKED user with the same password



Hi All ...

Here the fast way to re-open the DB users when it in  EXPIRED & LOCKED status and you don't want to change the password and not remember the old one.

Run the following with "/as sysdba" :

1. Change the FAILED_LOGIN_ATTEMPTS profile to UNLIMITED.
alter profile default limit failed_login_attempts unlimited password_life_time unlimited;

2. Sql to change the status from LOCKED to OPEN  (copy the result and run in sqlplus).

select 'alter user '|| username || ' account unlock;' 
from dba_users where account_status = 'LOCKED'

3. Sql to remove the expired status (copy the result and run in sqlplus).
select 'alter user ' || su.name || ' identified by values' || ' ''' || spare4 || ';' || su.password || ''';'
from sys.user$ su join dba_users du on ACCOUNT_STATUS like 'EXPIRED%'
and su.name = du.username;


Good Luck ...

Tuesday, June 10, 2014

Adcfgclone on DB tier fail with ouicli.pl

Hi All ... 

Here the issue that I have found during the clone DB tier:

AutoConfig could not successfully execute the following scripts:

    Directory: /clone/oracle/product/11.2.0/perl/bin/perl -I /clone/oracle/product/11.2.0/perl/lib/5.8.3 -I /clone/oracle/product/11.2.0/perl/lib/site_perl/5.8.3 -I /clone/oracle/product/11.2.0/appsutil/perl /clone/oracle/product/11.2.0/appsutil/clone

      ouicli.pl               INSTE8_APPLY       255

AutoConfig is exiting with status 1


RC-50013: Fatal: Instantiate driver did not complete successfully.

Action Plan:
1.  Change the DB CONTEXT_FILE PERL5LIB  parameter from 5.8.3 to 5.10.0 
2.  Change the $ORACLE_HOME/appsutil/template/adxdbctx.tmp as well as env file.
3. Run autoconfig on DB node
4. Run adpreclone procedure on DB tier
5. Copy the data to clone instance and rerun adcfgclone.

Good Luck ...

Thursday, May 8, 2014

Recover corrupted datafile - step by step.


Hi All ...

Here the step by step how to recover corrupted  datafile.
I got the following error after DB crush:

ORA-01110: data file 12: '/oraprd/prddata/sysaux02.dbf'
ORACLE Instance PRD (pid = 12) - Error 376 encountered while recovering transaction (115, 24) on object 373247.
Errors in file /oraprd/prddb/diag/rdbms/prd/PRD/trace/PRD_smon_21693.trc:
ORA-00376: file 11 cannot be read at this time
ORA-01110: data file 11: '/oraprd/prddata/sysaux01.dbf'

Action Plan:

1. alter database datafile '/oraprd/prddata/sysaux01.dbf' offline;
    alter database datafile '/oraprd/prddata/sysaux02.dbf' offline;

2. alter system switch logfile; (do it 10 times to be sure)

3. shutdown abort;
4. startup mount;
5. recover datafile '/oraprd/prddata/sysaux02.dbf';
ORA-00279: change 1306769 generated at 05/05/2014 22:54:48 needed for thread 1
ORA-00289: suggestion : /oraprd/archive/817T001S02245.arc
ORA-00280: change 1306769 for thread 1 is in sequence #2245

Specify log: {=suggested | filename | AUTO | CANCEL}
AUTO

Log applied.
Media recovery complete.
--- Do it for all your corrupted files
6. alter database open;
7. alter database datafile '/oraprd/prddata/sysaux01.dbf' online;
8. select tablespace_name, file_name, status from dba_data_files;
--- All files need to be with AVAILABLE status.

Good Luck ...

Wednesday, May 7, 2014

Script to compile APPS schema without running adadmin


Hi All ...

Here the  Script to compile APPS schema without running adadmin.


As the appl user in linux, define both env vars :
export APPS_PASS=xxxx
export  SYSTEM_PASS=xxxx

Then Run:

#R12
sqlplus -s APPS/$APPS_PASS @$AD_TOP/sql/adutlrcmp.sql APPLSYS $APPS_PASS APPS $APPS_PASS $SYSTEM_PASS 0 0 NONE FALSE

#11i
sqlplus -s APPS/$APPS_PASS @$AD_TOP/admin/sql/adutlrcmp.pls APPLSYS $APPS_PASS APPS $APPS_PASS $SYSTEM_PASS 0 0 NONE FALSE


Good Luck ...

Sunday, April 27, 2014

The Upgrade Assistant failed in bringing up the database .


Hi All

Got this error during the upgrading the database to 11.2.0.4 (DBUA step 2-3) :
The Upgrade Assistant failed in bringing up the database ....

Here the action for fix the issue.

1. Remove all  spfile from Old ORACLE HOME/dbs (copy them or change there names).
2. Remove all from $ORACLE_BASE/cfgtoollogs/dbua
*** ORACLE_BASE - base directory given by you during software installation
3. Re-run the DBUA: cd $ORACLE_HOME/bin; ./dbua


Good Luck ...

[INS-32025] The chosen installation conflicts with software already installed in the given Oracle home


Hi All ,

Some times we can got the following error :
[INS-32025] The chosen installation conflicts with software already installed in the given Oracle home.
while re-installing the  DB on the same machine.


This is the step by step to fix the issue quickly:

1. cat /etc/oraInst.loc 
2  cd <oraInventory path>/oraInventory/ContextXML (In windows you can find the inventory.xml in C:\Program Files\Oracle\Inventory\ContentsXML)
3. vi inventory.xml
4. Remove the line that contain the new ORACLE Home
5. Exit and re-run the installer.


Good Luck ...

Tuesday, August 14, 2012

adpreclone.pl dbTier failed on 0%

Hi All

Here the error that I got after upgrade the DB to 11g.
When I run the command: perl adpreclone.pl  dbTier it failed on 0%.

perl adpreclone.pl dbTier
Running Rapid Clone with command...
        perl /d01/oracle/product/11.2.0/appsutil/bin/adclone.pl java=/d01/oracle/product/11.2.0/jdk mode=stage stage=/d01/oracle/product/11.2.0/appsutil/clone component=dbTier method=CUSTOM dbctx=/d01/oracle/product/11.2.0/appsutil/PROD_server.xml  showProgress

Beginning database tier Stage - Mon Aug 13 14:23:49 2012
APPS Password : apps
Log file located at /d01/oracle/product/11.2.0/appsutil/log/PROD_server/StageDBTier_08131423.log
  -      0% completed
ERROR while running Stage...

ERROR while running perl /d01/oracle/product/11.2.0/appsutil/bin/adclone.pl java=/d01/oracle/product/11.2.0/jdk mode=stage stage=/d01/oracle/product/11.2.0/appsutil/clone component=dbTier method=CUSTOM dbctx=/d01/oracle/product/11.2.0/appsutil/PROD_server.xml  showProgress ... Please check the log for more details..


In the log file:

#############################################################
Started StageDBTier at Mon Aug 13 14:05:16 IDT 2012
Version:
        StageDBTier.java        :       115.27
#############################################################

---------------------------------------------------------------
                   ADX Database Utility
---------------------------------------------------------------

getConnectionUsingAppsJDBCConnector() -->
    APPS_JDBC_URL='null'
    Trying to get connection using SID based connect descriptor
getConnection() -->
    sDbHost    : server
    sDbDomain  : domain
    sDbPort    : 1591
    sDbSid     : PROD
    sDbUser    : apps
    Trying to connect using SID...
getConnectionUsingSID() -->
    JDBC URL: jdbc:oracle:thin:@server.domain:1521:PROD
    Connection obtained

-------------------ADX Database Utility Finished---------------

Cause:  Zip executable in $ORACLE_HOME/bin have version 3.0 and need to be 2.3x
$ORACLE_HOME/bin/zip -v

Solution:
Need to change the executable to be point to /usr/bin/zip
1. mv $ORACLE_HOME/bin/zip $ORACLE_HOME/bin/zip_orig
2. ln -s /usr/bin/zip $ORACLE_HOME/bin/zip
3. $ORACLE_HOME/bin/zip -v
4. Re run perl adpreclone.pl dbTier

Good Luck ...