Quantcast
Channel: Sameer Shaik. B.E,M.S,M.B.A,P.M.P,C.S.M
Viewing all 191 articles
Browse latest View live

Oracle remap schema and remap tablespace

$
0
0

Remap_schema & remap_tablespace:

Below we will load the contents of "hr" schema into "hr_test" schema and from tablespace "USERS" to "hr_test"
SQL> create directory data_dir as '/home/oracle/sshaik';

Directory created.

SQL> create directory log_dir as '/home/oracle/sshaik/log';

Directory created.

SQL> grant all on directory data_dir to system;

Grant succeeded.

SQL> grant all on directory log_dir to system;

Grant succeeded.


SQL> create tablespace hr_test datafile '+DATA' size 100m autoextend on next 10m;

Tablespace created.

SQL>create user hr_test identified by hr_test default tablespace hr_test;

User created.
SQL> !

[oracle@collabn1 sshaik]$
expdp \"/ as sysdba\" dumpfile=data_dir:hr.dmp logfile=log_dir:hr_exp.log schemas=hr

Export: Release 11.2.0.1.0 - Production on Wed Aug 5 15:37:29 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
FLASHBACK automatically enabled to preserve database integrity.
Starting "SYS"."SYS_EXPORT_SCHEMA_01":  "/******** AS SYSDBA" dumpfile=data_dir:hr.dmp logfile=log_dir:hr_exp.log schemas=hr
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 512 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "HR"."COUNTRIES"                           6.367 KB      25 rows
. . exported "HR"."DEPARTMENTS"                         7.007 KB      27 rows
. . exported "HR"."EMPLOYEES"                           16.81 KB     107 rows
. . exported "HR"."JOBS"                                6.992 KB      19 rows
. . exported "HR"."JOB_HISTORY"                         7.054 KB      10 rows
. . exported "HR"."LOCATIONS"                           8.273 KB      23 rows
. . exported "HR"."REGIONS"                             5.476 KB       4 rows
. . exported "HR"."REGIONS2"                            5.476 KB       4 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
 /home/oracle/sshaik/hr.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at 15:38:18


[oracle@collabn1 sshaik]$
impdp system/XXXXXX dumpfile=data_dir:hr.dmp logfile=log_dir:hr_imp.log remap_schema=hr:hr_test remap_tablespace=hr:hr_test

Import: Release 11.2.0.1.0 - Production on Wed Aug 5 15:43:29 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** dumpfile=data_dir:hr.dmp logfile=log_dir:hr_imp.log remap_schema=hr:hr_test remap_tablespace=hr:hr_test
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"HR_TEST" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "HR_TEST"."COUNTRIES"                      6.367 KB      25 rows
. . imported "HR_TEST"."DEPARTMENTS"                    7.007 KB      27 rows
. . imported "HR_TEST"."EMPLOYEES"                      16.81 KB     107 rows
. . imported "HR_TEST"."JOBS"                           6.992 KB      19 rows
. . imported "HR_TEST"."JOB_HISTORY"                    7.054 KB      10 rows
. . imported "HR_TEST"."LOCATIONS"                      8.273 KB      23 rows
. . imported "HR_TEST"."REGIONS"                        5.476 KB       4 rows
. . imported "HR_TEST"."REGIONS2"                       5.476 KB       4 rows
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" completed successfully at 15:43:38


Verify the data is loaded into the new schema.


SQL> drop user hr_test cascade;

User dropped.

SQL> drop tablespace hr_test including contents;

Tablespace dropped.

Oracle transportable tablespaces

$
0
0
Below I will show you how to use transportable tablespace feature in Oracle:

Creating the tablespace for the demo:

SQL> create tablespace tt_temp_sales datafile '+DATA2' size 10m autoextend on next 1m;

Tablespace created.

SQL> conn sh/sh
Connected.

Creating a table for verification after transportable tablespace:

SQL> create table temp_jan_sales tablespace tt_temp_sales as select * from sales  where time_id between '31-DEC-1999' AND '01-feb-2000';

Table created.

Make the tablespace read-only

SQL> alter tablespace tt_temp_sales read only;

Tablespace altered.


SQL> create directory orcl_dir as '/home/oracle/sshaik';

Directory created.

SQL> grant all on directory orcl_dir to sh;

Grant succeeded.



[oracle@collabn1 ~]$ expdp system dumpfile=orcl_dir:tt_temp_Sales.dmp logfile=orcl_dir:tt_temp_sales.log TRANSPORT_TABLESPACES=tt_temp_sales

Export: Release 11.2.0.1.0 - Production on Fri Aug 7 17:22:55 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/******** dumpfile=orcl_dir:tt_temp_Sales.dmp logfile=orcl_dir:tt_temp_sales.log TRANSPORT_TABLESPACES=tt_temp_sales
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 is:
 /home/oracle/sshaik/tt_temp_Sales.dmp
******************************************************************************
Datafiles required for transportable tablespace TT_TEMP_SALES:
 +DATA2/orcl/datafile/tt_temp_sales.319.887131035
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 17:23:32

Change back the tablespace to READ-WRITE:

SQL> alter tablespace tt_temp_sales read write;

Tablespace altered.


[oracle@collabn1 ~]$ asmcmd
ASMCMD> cd data2
ASMCMD> cd orcl    
ASMCMD> cd datafile
ASMCMD> ls -l
Type      Redund  Striped  Time             Sys  Name
DATAFILE  UNPROT  COARSE   AUG 07 14:00:00  Y    HR_TEST.283.886951885
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    SYSAUX.265.886783809
DATAFILE  UNPROT  COARSE   AUG 07 14:00:00  Y    SYSTEM.266.886783809
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    TT_TEMP_SALES.319.887131035
DATAFILE  UNPROT  COARSE   AUG 07 14:00:00  Y    UNDOTBS1.264.886783809
DATAFILE  UNPROT  COARSE   AUG 07 14:00:00  Y    UNKNOWN.256.886783857
DATAFILE  UNPROT  COARSE   AUG 07 16:00:00  Y    USERS.288.886868147

Copy the datafile from ASM to the local disk:
or
You can use dbms_copy and so on..

ASMCMD> cp tt_temp_sales.319.887131035 /home/oracle/sshaik/
copying +data2/orcl/datafile/tt_temp_sales.319.887131035 -> /home/oracle/sshaik//tt_temp_sales.319.887131035
ASMCMD>   


Transfer the files to target:

[oracle@collabn1 sshaik]$ ls -lrt /home/oracle/sshaik//tt_temp_sales.319.887131035
-rw-r----- 1 oracle oinstall 10493952 Aug  7 17:32 /home/oracle/sshaik//tt_temp_sales.319.887131035

[oracle@collabn1 sshaik]$ scp /home/oracle/sshaik//tt_temp_sales.319.887131035 collabn2.shaiksameer:$PWD
tt_temp_sales.319.887131035                                                                              100%   10MB  10.0MB/s   00:00    
    
[oracle@collabn1 sshaik]$ scp tt_temp_Sales.dmp collabn2.shaiksameer:$PWD
tt_temp_Sales.dmp                                                                                        100%   92KB  92.0KB/s   00:00    
[oracle@collabn1 sshaik]$


Verify the files on Target:


[oracle@collabn2 sshaik]$ ls -lrt
total 10340
-rw-r----- 1 oracle oinstall 10493952 Aug  7 17:33 tt_temp_sales.319.887131035
-rw-r----- 1 oracle oinstall    94208 Aug  7 17:35 tt_temp_Sales.dmp
[oracle@collabn2 sshaik]$


Create directory On target:

SQL> create directory prod1_dir as '/home/oracle/sshaik';

Directory created.

[oracle@collabn2 ~]$ cd sshaik/

[oracle@collabn2 sshaik]$ ls -lrt
total 10344
-rw-r----- 1 oracle oinstall 10493952 Aug  7 17:33 tt_temp_sales.319.887131035
-rw-r----- 1 oracle oinstall    94208 Aug  7 17:35 tt_temp_Sales.dmp
-rw-r--r-- 1 oracle dba          1032 Aug  7 17:49 tt_temp_sales_imp.log

[oracle@collabn2 sshaik]$ asmcmd
ASMCMD> cd data2

ASMCMD> cd prod1/datafile
ASMCMD> ls -l
Type      Redund  Striped  Time             Sys  Name
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    RCTS.280.886861183
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    SYSAUX.269.886859391
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    SYSTEM.268.886859391
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    UNDOTBS1.270.886859391
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    UNKNOWN.278.886859439
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    USERS.271.886859391

Copy the datafile into  Target ASM.

ASMCMD> cp /home/oracle/sshaik/tt_temp_sales.319.887131035 '+DATA2/prod1/datafile/tt_temp_sales'
copying /home/oracle/sshaik/tt_temp_sales.319.887131035 -> +DATA2/prod1/datafile/tt_temp_sales

Since ASM will automatically append file/incarnation pair to ensure uniqueness, you will have give the name except the incarnation number….


ASMCMD> ls -l
Type      Redund  Striped  Time             Sys  Name
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    RCTS.280.886861183
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    SYSAUX.269.886859391
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    SYSTEM.268.886859391
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    UNDOTBS1.270.886859391
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    UNKNOWN.278.886859439
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  Y    USERS.271.886859391
DATAFILE  UNPROT  COARSE   AUG 07 17:00:00  N    tt_temp_sales => +DATA2/ASM/DATAFILE/tt_temp_sales.321.887133535

[oracle@collabn2 sshaik]$ impdp system directory=prod1_dir dumpfile=tt_temp_Sales.dmp logfile=tt_temp_sales.log transport_datafiles='+data2/prod1/datafile/tt_temp_sales'

Import: Release 11.2.0.1.0 - Production on Fri Aug 7 18:33:02 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Password:

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/******** directory=prod1_dir dumpfile=tt_temp_Sales.dmp logfile=tt_temp_sales.log transport_datafiles=+data2/prod1/datafile/tt_temp_sales
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 18:33:07


SQL> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
PROD1      READ WRITE


SQL> alter tablespace tt_temp_sales read write;

Tablespace altered.

SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='TT_TEMP_SALES';

TABLESPACE_NAME            STATUS
------------------------------ ---------
TT_TEMP_SALES              ONLINE

SQL> select count(*) from sh.temp_jan_sales;

 COUNT(*)
----------
    22594

ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 486 with ORA-15124: ASM file name contains an invalid alias name

$
0
0
If you use any of the below syntax you will get the below mentioned error, instead try the suggested fix.



Using dot here "."

ASMCMD> cp /home/oracle/sshaik/tt_temp_sales.319.887131035 .
or


Using just path here "+DATA/prod1/daatfile"
cp /home/oracle/sshaik/tt_temp_sales.319.887131035 '+DATA2/prod1/datafile/'

or
 Using just first two letters of the file name with no quotes here "+DATA2/prod1/datafile/tt"
cp /home/oracle/sshaik/tt_temp_sales.319.887131035 +DATA2/prod1/datafile/tt*

or

Using just first two letters of the file name with quotes here "+DATA2/prod1/datafile/tt"

cp /home/oracle/sshaik/tt_temp_sales.319.887131035 '+DATA2/prod1/datafile/tt*'

or
Using complete file name with quotes here "+DATA2/prod1/datafile/tt_temp_sales.319.887131035'
 
cp /home/oracle/sshaik/tt_temp_sales.319.887131035 '+DATA2/prod1/datafile/tt_temp_sales.319.887131035'

copying /home/oracle/sshaik/tt_temp_sales.319.887131035 -> +DATA2/prod1/datafile/tt*
ASMCMD-8016: copy source '/home/oracle/sshaik/tt_temp_sales.319.887131035' and target '+DATA2/prod1/datafile/tt*' failed
ORA-15124: ASM file name '+DATA2/prod1/datafile/tt*' contains an invalid alias name
ORA-15124: ASM file name '+DATA2/prod1/datafile/tt*' contains an invalid alias name
ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 486
ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)


Workaround:
==========

ASMCMD> cp /home/oracle/sshaik/tt_temp_sales.319.887131035 '+DATA2/prod1/datafile/tt_temp_sales'
copying /home/oracle/sshaik/tt_temp_sales.319.887131035 -> +DATA2/prod1/datafile/tt_temp_sales

Since ASM will automatically append file/incarnation pair to ensure uniqueness, you will have give the name except the incarnation number….

Setting up the oracle environment

$
0
0
I have three Oracle databases and each have its own environment that needs to be run.

Ex:-

1.ORCL
2.PROD1
3.GRID

Wrote a small crude shell script to run the env files.

[oracle@collabn1 ~]$ vi setup_ora_env.sh

#!/bin/bash
function unset1
{
echo "You are in func"
unset ORACLE_SID ORACLE_BASE TNS_ADMIN ORACLE_HOME
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin
}

k=1
echo -e "\n"
echo -e "You have below ENV files..."
array1=( $(ls ~/*.env) )
for i in "${array1[@]}";do
echo "Select $k for $i"
let "k=$k+1"
done
echo -e "\n"

#Unsetting the ORA ENV variables
unset1

echo -e "Enter your choince now:        "
read input
if [ $input -eq 1 ];then
echo -e "\n"
echo -e "Running environment file...   ${array1[0]}"
. ${array1[0]}
elif [ $input -eq 2 ];then
echo -e "\n"
echo -e "Running environment file...    ${array1[1]}"
.  ${array1[1]}
elif [ $input -eq 3 ];then
echo -e "\n"
echo -e "Running environment file...    ${array1[2]}"
. ${array1[2]}
else
echo -e "Wrong choice...Plz try again"
fi

Oracle EBS 11i log file locations

$
0
0

Application Tier Logs

Start/Stop script log files location:
$COMMON_TOP/admin/log/CONTEXT_NAME/

OPMN log file location
$ORACLE_HOME/opmn/logs/ipm.log

Apache, Jserv, JVM log files locations:
$IAS_ORACLE_HOME/Apache/Apache/logs/ssl_engine_log
$IAS_ORACLE_HOME/Apache/Apache/logs/ssl_request_log
$IAS_ORACLE_HOME/Apache/Apache/logs/access_log
$IAS_ORACLE_HOME/Apache/Apache/logs/error_log
$IAS_ORACLE_HOME/Apache/JServ/logs

Concurrent log file location:
$APPL_TOP/admin/PROD/log or $APPLLOG/$APPLCSF

Patch log file location:
$APPL_TOP/admin/PROD/log

Worker Log file location:
$APPL_TOP/admin/PROD/log

AutoConfig log files location:
Application Tier:
$APPL_TOP/admin/SID_Hostname/log//DDMMTime/adconfig.log

Database Tier:
$ORACLE_HOME/appsutil/log/SID_Hostname/DDMMTime/adconfig.log

Error log file location:
Application Tier:
$APPL_TOP/admin/PROD/log

Database Tier :
$ORACLE_HOME/appsutil/log/SID_Hostname

Oracle R12 Logs location

$
0
0


In Oracle Applications R12, the log files are located in $LOG_HOME ($INST_TOP/logs)


Concurrent Reqeust related logs
$LOG_HOME/appl/conc - > location for concurrent requests log and out files
$LOG_HOME/appl/admin - > location for mid tier startup scripts log files

Apache Logs (10.1.3 Oracle Home which is equivalent to iAS Oracle Home - Apache, OC4J and OPMN)
$LOG_HOME/ora/10.1.3/Apache - > Location for Apache Error and Access log files
$LOG_HOME/ora/10.1.3/j2ee - > location for j2ee related log files
$LOG_HOME/ora/10.1.3/opmn - > location for opmn related log files

Forms & Reports related logs (10.1.2 Oracle home)
$LOG_HOME/ora/10.1.2/forms
$LOG_HOME/ora/10.1.2/reports

Startup/Shutdown Log files location:
$INST_TOP/apps/$CONTEXT_NAME/logs/appl/admin/log

Patch log files location:
$APPL_TOP/admin/$SID/log/

Clone and AutoConfig log files location in Oracle E-Business Suite Release 12

Logs for the adpreclone.pl are located:
On the database tier:
RDBMS $ORACLE_HOME/appsutil/log/<context>/StageDBTier_< timestamp >.log

On the application tier:
$INST_TOP/admin/log/StageAppsTier_< timestamp >.log

Where the logs for the admkappsutil.pl are located?
On the application tier:
$INST_TOP/admin/log/MakeAppsUtil_< timestamp >.log

How to update EBS XML Publisher Temporary Directory

$
0
0



SQL> select value from apps.XDO_CONFIG_VALUES WHERE  property_code = 'SYSTEM_TEMP_DIR';

VALUE
--------------------------------------------------------------------------------
/u1/appl/SHAIK1/wrongdir_tmp


SQL> update apps.XDO_CONFIG_VALUES set value='/u01/share/temp' WHERE  property_code = 'SYSTEM_TEMP_DIR';

1 row updated.

SQL> commit;

Commit complete.

SQL> select value from apps.XDO_CONFIG_VALUES WHERE  property_code = 'SYSTEM_TEMP_DIR';

VALUE
--------------------------------------------------------------------------------
/u01/share/temp



Reference:-
How To Find the EBS XML Publisher Temporary Directory Via SQL? (Doc ID 1189723.1)

Direct NFS: please check that oradism is setuid --> Enable/ Disable oradism ORADISM

$
0
0
Direct NFS: please check that oradism is setuid

 Issue:
Getting the following message in alert log and instance not starting:
Direct NFS: please check that oradism is setuid

To correct, the following permissions are needed on:
ls -la $ORACLE_HOME/bin/oradism
-rwsr-x— 1 root oinstall 72416 Aug 12  2015 /u01/app/oracle/product/11.1.0.1/db/bin/oradism




Fix:

If required, shutdown DB and change permission as follows:
sudo su
cd /u01/app/oracle/product/11.1/db/bin
chmod 750 oradism
chmod u+s oradism
Restart instance

or 
run $ORACLE_HOM/root.sh

  


Useful SQL
– View servers accessed using Direct NFS
select * from v$dnfs_servers;
– View files currently open using Direct NFS
select * from v$dnfs_files;
– View open network paths or channels to servers for which Direct NFS is providing files
select * from v$dnfs_channels;
– View performance statistics for Direct NFS
select * from v$dnfs_stats;


To Enable DFNS:
===========
Shutdown DB
On all hosts:
cd $ORACLE_HOME/lib
mv libodm11.so libodm11.so_bak
ln –s libnfsodm11.so libodm11.so
Restart Instance

Disable DNFS:
===========
Shutdown DB
On all hosts:
cd $ORACLE_HOME/lib
mv libodm11.so_bak libodm11.so
Restart Instance

 

  



EBS 11i Add resposibility api

$
0
0

Find the necessary details for a particular responsibility:

    
 SELECT fa.application_short_name,
                fr.responsibility_key,
                frg.security_group_key,                     
                frt.description
    FROM apps.fnd_responsibility fr,
                apps.fnd_application fa,
                apps.fnd_security_groups frg,
                apps.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 = 'RESP_NAME_HERE'


  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
                                            );

SQL> exec fnd_user_pkg.addresp('SHAIKS','XXSSHAIK','RESP_NAME_HERE,'STANDARD',null,sysdate,NULL);

PL/SQL procedure successfully completed.

SQL> COMMIT;

Commit complete.



Find the log file and output file from concurrent request

$
0
0

--to find the log file and output file from concurrent request
SELECT REQUEST_ID,logfile_name, outfile_name, outfile_node_name, last_update_date
FROM apps.FND_CONCURRENT_REQUESTS
WHERE REQUEST_ID =&Req_ID

EBS 11i: Fnd the ICM current logfile

$
0
0

--To find the ICM current logfile

SELECT 'LOG=' || cp.logfile_name LogFile
FROM fnd_concurrent_processes cp, fnd_concurrent_queues cq
WHERE cp.concurrent_queue_id = cq.concurrent_queue_id
AND cp.queue_application_id = cq.application_id
AND cq.manager_type = '0' AND cp.process_status_code = 'A';

EBS create adpatch defaults file

$
0
0


Lets create defaults file to make adpatch a little non-interactive:
==============================================
Put addefaults.txt at a safe place and make sure it is not overwritten or deleted.
adpatch defaultsfile=/home/applmgr/SHAIK1/addefaults.env


When the adpatch asks for patch directory location then terminate the autopatch session using ctrl +c

Verify the addefaults.env is created
 
To use the defaults file while applying the patches just pass the above file that we created ...
adpatch defaultsfile=/home/applmgr/SHAIK1/addefaults.env logfile=XXXXX.log patchtop=/u01/stage/patches/XXXXX driver=uabc.drv interactive=no


adpatch should automatically pick up APP_TOP, ORACLE_HOME, system password and apps password from defaults file.



Oracle: 11gR2 Fine Grain Auditing(FGA). dbms_fga

$
0
0

Fine Grain Auditing(FGA):


Now you can audit SELECT, INSERT, UPDATE, and DELETE statements under one policy using Fine Grain Auditing package(dbms_fga.add_policy).

To manage a fine-grained audit policy, you use the DBMS_FGA PL/SQL package. This package enables you to add all combinations of SELECT, INSERT, UPDATE, and DELETE statements to one policy. Only one record is generated for each policy for successful MERGE operations.


The audit policy is confined/limited to the table for which you created it. This simplifies the management of audit policies because the policy only must be changed once in the database. In addition, no matter how a user connects to the database—from an application, a Web interface, or through SQL*Plus or Oracle SQL Developer—Oracle Database records any actions that affect the policy. If any rows returned from a query match the audit condition that you define, then Oracle Database inserts an audit entry into the fine-grained audit trail. This entry excludes all the information that is reported in the regular audit trail. In other words, only one row of audit information is inserted into the audit trail for every fine-grained audit policy that evaluates to true.

Note: If you audit tables that have sensitive data, remember that DB+EXTENDED and XML+EXTENDED settings for the DBMS_FGA.ADD_POLICY audit_trail parameter will capture this data.

Use of audit_condition
You can define a condition under this variable for example...If anyone tries to access the salary and commission_pct columns.

Then the condition would be:
audit_condition => 'DEPARTMENT_ID = 50', audit_column => 'SALARY,COMMISSION_PCT,'


Create new policy:

SQL> show user
USER is "SEC"
SQL>

SQL> exec dbms_fga.add_policy(object_schema=>'HR',object_name=>'EMPLOYEES',policy_name=>'AUDIT_EMPS_SALARY',audit_condition=>null,audit_column=>'SALARY',enable=>FALSE);

PL/SQL procedure successfully completed.


Check the status of the new policy:

SQL> show user
USER is "SYS"

SQL> @sql.sql
SQL> select object_name,policy_owner,policy_name,enabled from dba_audit_policies;

OBJECT_NAME              POLICY_OWNER             POLICY_NAME            ENA
------------------------------ ------------------------------ ------------------------------ ---
EMPLOYEES              SEC                 AUDIT_EMPS_SALARY          NO


Enable Policy:

SQL> exec dbms_fga.enable_policy(object_schema=>'HR',object_name=>'EMPLOYEES',policy_name=>'AUDIT_EMPS_SALARY');

PL/SQL procedure successfully completed.

Verify whether the policy is enabled or not:

SQL> show user
USER is "SYS"

SQL> select object_name,policy_owner,policy_name,enabled from dba_audit_policies;

OBJECT_NAME              POLICY_OWNER             POLICY_NAME            ENA
------------------------------ ------------------------------ ------------------------------ ---
EMPLOYEES              SEC                 AUDIT_EMPS_SALARY          YES

Note the audit logs data:

col dbuid format a10
col lsqltext format a66
col ntimestamp# format a15
SELECT DBUID, LSQLTEXT, NTIMESTAMP# FROM SYS.FGA_LOG$ ;

no rows selected


SQL> select * from DBA_FGA_AUDIT_TRAIL;

no rows selected

Time to make the fga_policy work for us:

Connect as one of the user who has access to hr.employees and try to pull the salary data from the hr.employees.

SQL> show user  
USER is "LOVEME"

SQL> select salary from hr.employees where rownum<=5;

    SALARY
----------
     2600
     2600
     4400
    13000
     6000

Verify the audit trail /logs data:

SQL> SELECT DBUID, LSQLTEXT, NTIMESTAMP# FROM SYS.FGA_LOG$;

DBUID       LSQLTEXT                                 NTIMESTAMP#
---------- ------------------------------------------------------------------ ---------------
PFAY       select salary from hr.employees where rownum<=5             13-AUG-15 07.03
                                        .56.326751 PM


SQL> select * from DBA_FGA_AUDIT_TRAIL;

SESSION_ID TIMESTAMP DB_USER
---------- --------- ------------------------------
OS_USER
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
USERHOST                                                CLIENT_ID
-------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------
ECONTEXT_ID
----------------------------------------------------------------
EXT_NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OBJECT_SCHEMA              OBJECT_NAME                               POLICY_NAME
------------------------------ -------------------------------------------------------------------------------------------------------------------------------- ------------------------------
      SCN
----------
SQL_TEXT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_BIND
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
COMMENT$TEXT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
STATEME EXTENDED_TIMESTAMP                               PROXY_SESSIONID GLOBAL_UID                INSTANCE_NUMBER OS_PROCESS       TRANSACTIONID    STATEMENTID
------- --------------------------------------------------------------------------- --------------- -------------------------------- --------------- ---------------- ---------------- -----------
  ENTRYID OBJ_EDITION_NAME           DBID
---------- ------------------------------ ----------
  3060182 13-AUG-15 PFAY
oracle
collabn1.shaiksameer

oracle
HR                  EMPLOYEES                               AUDIT_EMPS_SALARY
  1443239
select salary from hr.employees where rownum<=5


SELECT    13-AUG-15 03.03.56.326751 PM -04:00                                   0 10574                   11
    2                 1414564590




To Disable the audit policy:

SQL> exec dbms_fga.disable_policy(object_schema=>'HR',object_name=>'EMPLOYEES',policy_name=>'AUDIT_EMPS_SALARY');

PL/SQL procedure successfully completed.


To drop the audit policy:

SQL>  exec dbms_fga.drop_policy(object_schema=>'HR',object_name=>'EMPLOYEES',policy_name=>'AUDIT_EMPS_SALARY');

PL/SQL procedure successfully completed.

Oracle how to encrypt tablespaces

$
0
0

How to Encrypt OracleTablespace



Set the Tablespace Master Encryption Key before you can encrypt or decrypt the tablespaces, you must generate or set a master encryption key.

The tablespace master encryption key is stored in an external security module and is used to encrypt the TDE tablespace encryption keys. Check to ensure that the ENCRYPTION_WALLET_LOCATION (or WALLET_LOCATION) parameter in the sqlnet.ora file points to the correct software wallet location.


ENCRYPTION_WALLET_LOCATION= (SOURCE=(METHOD=FILE)(METHOD_DATA= (DIRECTORY=/app/wallet)))

Unified Master Encryption Key or the master encryption key for transparent tablespace encryption and transparent column encryption are now combined to one unified master encryption key. Combining these keys enables transparent re-key operations for both of these transparent data encryption features, regardless of whether the master encryption key is stored in the Oracle Wallet or in one of the certified Hardware Security Modules offered by RSA, SafeNet, Thales (including nCipher), and Utimaco.


Create the directory for the wallet:

[oracle@collabn1 ~]$ mkdir -p /u01/app/oracle/admin/wallet

Add the wallet details in the sqlnet.ora file:

[oracle@collabn1 ~]$ vi $TNS_ADMIN/sqlnet.ora
ENCRYPTION_WALLET_LOCATION= (SOURCE=(METHOD=FILE)(METHOD_DATA= (DIRECTORY=/u01/app/oracle/admin/wallet)))

Verify the sqlnet.ora

[oracle@collabn1 ~]$ cat /u01/app/oracle/product/11.2.0.2/SHAIKPROD/network/admin/sqlnet.ora
ENCRYPTION_WALLET_LOCATION= (SOURCE=(METHOD=FILE)(METHOD_DATA= (DIRECTORY=/u01/app/oracle/admin/wallet)))

Create the master encryption key & wallet:


NAME      OPEN_MODE
--------- --------------------
ORCL      READ WRITE


When you create the master encryption key using the ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "password" command, TDE checks to see if a wallet exists in the default or specified location. If no wallet exists, then a wallet is created automatically.


SQL> alter system set encryption key identified by "secretpass";

System altered.

Verify the wallet file is created:

SQL> !ls /u01/app/oracle/admin/wallet
ewallet.p12


Create the tablespace with the encryption:

Here: algorithm can have one of the following values:
■ 3DES168
■ AES128
■ AES192
■ AES256

SQL> create tablespace securetbs datafile '+DATA2' size 10m autoextend on next 1m
     encryption using 'AES256'
     default storage(encrypt);

Tablespace created.

Verify whether the tablespace encryption is enabled or not:

SQL> select tablespace_name,status,encrypted from dba_tablespaces;

TABLESPACE_NAME            STATUS     ENC
------------------------------ --------- ---
SYSTEM                  ONLINE     NO
SYSAUX                  ONLINE     NO
UNDOTBS1                  ONLINE     NO
TEMP                  ONLINE     NO
USERS                  ONLINE     NO
EXAMPLE                   ONLINE     NO
HR_TEST                   ONLINE     NO
TT_TEMP_SALES              ONLINE     NO
SECURETBS              ONLINE     YES

9 rows selected.

How to open/close the wallet:


SQL> alter system set encryption wallet close identified by "secretpass";

System altered.


SQL> alter system set encryption wallet open identified by "secretpass";

System altered.


Enable oracle Wallet auto_login:

You can create an auto login wallet with Oracle Wallet Manager or the orapki command-line utility. The auto login wallet allows convenient access to encrypted data across database instance restarts.

[oracle@collabn1 ~]$ which orapki
/u01/app/oracle/product/11.2.0.2/SHAIKPROD/bin/orapki


[oracle@collabn1 ~]$ orapki wallet create -wallet /u01/app/oracle/admin/wallet/ewallet.p12 -auto_login
Oracle PKI Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.

Enter wallet password:           

[oracle@collabn1 ~]$ ls -lrt /u01/app/oracle/admin/wallet/
total 8
-rw-r--r-- 1 oracle dba      1573 Aug 14 02:21 ewallet.p12
-rw------- 1 oracle oinstall     1651 Aug 14 03:01 cwallet.sso

After the auto_login you don’t have to worry about opening and closing the wallet manually.


Took sometime to figure out What is HSM ?= (Hardware Security Module)

source: http://docs.oracle.com/cd/E11882_01/network.112/e40393/toc.htm

Oracle Flashback versions query/ Flashback query

$
0
0

Flashback Query:


To configure your database for the Oracle Flashback Transaction Query feature, make sure:
■ The Oracle Database is running with version 10.0 or higher compatibility.
■ Enable supplemental logging:
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

If not done, enable minimal and primary key supplemental logging:

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;


■ If you want to track foreign key dependencies, enable foreign key supplemental logging:
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS;


SQL> select SUPPLEMENTAL_LOG_DATA_MIN, SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_DATA_ALL from v$database;

SUP_MIN_LOG     SUP_PK            SUP_ALL
--------             ---                ---
YES                NO                  NO


SQL> select location_id,postal_code from hr.locations;

LOCATION_ID POSTAL_CODE
----------- ------------
      1000 00989
      1100 10934
      1200 1689
      1300 6823
      1400 26192
      1500 99236
      1600 50090
      1700 98199
      1800 M5V 2L7
      1900 YSW 9T2
      2000 190518
      2100 490231
      2200 2901
      2300 540198
      2400            ←- Null postal_code here
      2500 OX9 9ZB
      2600 09629850293
      2700 80925
      2800 01307-002
      2900 1730
      3000 3095
      3100 3029SK
      3200 11932

23 rows selected.




SQL> select name,open_mode,flashback_on from v$database;

NAME      OPEN_MODE           FLASHBACK_ON
--------- -------------------- ------------------
ORCL      READ WRITE           YES


SQL> show user
USER is "HR"

Update the postal_code for location_id -2400 to some random junk.

SQL> update locations set postal_code ='FLASHQRY' where location_id=2400;

1 row updated.

SQL> commit;

Commit complete.


SQL> select location_id,postal_code from locations where location_id=2400;

LOCATION_ID POSTAL_CODE
----------- ------------
      2400 FLASHQRY


SQL> show parameter flashback

NAME                    TYPE     VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target         integer     1440

SQL> select 1440/60 in_hours from dual;

 IN_HOURS
----------
   24

To use Oracle Flashback Query, use a SELECT statement with an AS OF clause. Oracle Flashback Query retrieves data as it existed at an earlier time. The query explicitly references a past time through a time stamp or System Change Number (SCN). It returns committed data that was current at that point in time.


SQL> !date;            
Fri Aug 14 06:14:12 EDT 2015

Look up the data changes:

SQL>  select location_id,postal_code from locations as of timestamp
 2  to_timestamp('2015-08-14 06:00:00','yyyy-mm-dd hh:mi:ss') where location_id=2400;

LOCATION_ID POSTAL_CODE
----------- ------------
      2400 FLASHQRY


SQL> select location_id,postal_code from locations as of timestamp
 2  to_timestamp('2015-08-14 05:00:00','yyyy-mm-dd hh:mi:ss') where location_id=2400;

LOCATION_ID POSTAL_CODE
----------- ------------
      2400

Rollback the row data as of 08/14/2015 5:00 am

SQL> update locations set postal_code=(select postal_code from locations as of timestamp
     to_timestamp('2015-08-14 05:00:00','yyyy-mm-dd hh:mi:ss') where location_id=2400)
      where location_id=2400;

1 row updated.

SQL> commit;

Commit complete.

Verify the flashback versions query:

SQL> select location_id,postal_code from locations where location_id=2400;

LOCATION_ID POSTAL_CODE
----------- ------------
      2400

Oracle user context details:

$
0
0
How to get the user context details:

Run the below query to get the details:
select sys_context('userenv','&arg_name') from dual;


SQL> select sys_context('userenv','&arg_name') from dual;


Enter value for arg_name: server_host
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','server_host') from dual

SYS_CONTEXT('USERENV','SERVER_HOST')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
collabn1

SQL> /
Enter value for arg_name: ip_address
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','ip_address') from dual

SYS_CONTEXT('USERENV','IP_ADDRESS')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


SQL> /
Enter value for arg_name: os_user
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','os_user') from dual

SYS_CONTEXT('USERENV','OS_USER')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
oracle

SQL> /
Enter value for arg_name: IP_ADDRESS
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','IP_ADDRESS') from dual

SYS_CONTEXT('USERENV','IP_ADDRESS')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


SQL> /
Enter value for arg_name: NETWORK_PROTOCOL
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','NETWORK_PROTOCOL') from dual

SYS_CONTEXT('USERENV','NETWORK_PROTOCOL')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


SQL> /
Enter value for arg_name: PROXY_USER
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','PROXY_USER') from dual

SYS_CONTEXT('USERENV','PROXY_USER')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


SQL> /
Enter value for arg_name: AUTHENTICATION_TYPE
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','AUTHENTICATION_TYPE') from dual

SYS_CONTEXT('USERENV','AUTHENTICATION_TYPE')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DATABASE

SQL> /
Enter value for arg_name: AUTHENTICATION_DATA
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','AUTHENTICATION_DATA') from dual

SYS_CONTEXT('USERENV','AUTHENTICATION_DATA')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


SQL> /
Enter value for arg_name: CLIENT_IDENTIFIER
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','CLIENT_IDENTIFIER') from dual

SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

SQL> /
Enter value for arg_name: HOST
old   1: select sys_context('userenv','&arg_name') from dual
new   1: select sys_context('userenv','HOST') from dual

SYS_CONTEXT('USERENV','HOST')
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
collabn1.shaiksameer



More variables can be found here:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions165.htm

Oracle Total Recall or Flashback data archive:

$
0
0

Total Recall or Flashback data archive:

 

A Flashback Data Archive provides the ability to track and store transactional changes to a table over its lifetime. A Flashback Data Archive is useful for compliance with record stage policies and audit reports.


Flashback data archive is stored in one or more tablespaces and can have multiple flashback data archives at the same time in the database.

Flashback data archive is configured using retention time i.e you can define the flashback data archive to live as long as you want..


SQL> show user
USER is "SYS"

SQL> create tablespace tbs1 datafile '+DATA2' size 10m autoextend on next 1m;

Tablespace created.

SQL> create tablespace tbs2 datafile '+DATA2' size 10m autoextend on next 1m;

Tablespace created.

SQL> create user archive identified by archive default tablespace tbs1;

User created.

SQL> alter user archive quota unlimited on tbs1;

User altered.

SQL> alter user archive quota unlimited on tbs2;

User altered.

SQL> grant create session,resource, create table,create database link to archive;

Grant succeeded.

SQL> grant create procedure to archive;

Grant succeeded.

SQL> grant flashback archive administer to archive;

Grant succeeded.

create flashback data archive:

SQL> show user
USER is "ARCHIVE"

SQL> create flashback archive fda tablespace tbs1 retention 100 year;

Flashback archive created.

Once enabled only a user with DBA privileges or user with FLASHBACK ARCHIVE ADMINISTER” privilege can disable this flashback data archive on a table.


SQL> alter flashback archive fda add tablespace tbs2 quota 5g;

Flashback archive altered.

SQL> grant flashback archive on fda to hr;

Grant succeeded.

SQL> show user
USER is "HR"

SQL> alter table employees flashback archive fda;

Table altered.

Lets make changes to the employees table:

SQL> update employees set first_name='SAMEER' where first_name ='Peter';

3 rows updated.

SQL> commit;

Commit complete.

SQL> select first_name,salary from employees where first_name='SAMEER';

FIRST_NAME        SALARY
-------------------- ----------
SAMEER           2500
SAMEER           10000
SAMEER           9000

SQL> select employee_id ,salary from employees where first_name='SAMEER';

EMPLOYEE_ID    SALARY
----------- ----------
   144      2500
   150     10000
   152      9000


SQL> update employees set salary=90000 where first_name='SAMEER';

3 rows updated.

SQL> commit;

Commit complete.

SQL> select employee_id ,salary from employees where first_name='SAMEER';

EMPLOYEE_ID    SALARY
----------- ----------
   144     90000
   150     90000
   152     90000

Horaaaa ….. Now i can draw three paychecks… Shhhh…is there a HR person around?

DBA_FLASHBACK_ARCHIVE
DBA_FLASHBACK_ARCHIVE_TABLES
DBA_FLASHBACK_ARCHIVE_TS


select * from dba_flashback_Archive;

OWNER_NAME
------------------------------
FLASHBACK_ARCHIVE_NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FLASHBACK_ARCHIVE# RETENTION_IN_DAYS CREATE_TIME                            LAST_PURGE_TIME                                STATUS
------------------ ----------------- --------------------------------------------------------------------------- --------------------------------------------------------------------------- -------
ARCHIVE
FDA
       1           36500 14-AUG-15 02.17.33.000000000 PM                    14-AUG-15 02.17.33.000000000 PM

SQL> select table_name,flashback_archive_name,status from dba_flashback_archive_tables;

TABLE_NAME            FLASHBACK_ARCHIVE_NAME         STATUS
----------------------------------------------------------------------------------------------------------------------------------------------------------
EMPLOYEES                FDA                    ENABLED


Mr Peter went to the HR and complained he didn’t receive the paycheck for the previous week? Hmm what happened?
Lets do the audit:

SQL> select employee_id,first_name,salary from employees where upper(first_name)='PETER';

no rows selected

Where did Peter go?


SQL> select employee_id,first_name,salary from employees as of timestamp (systimestamp -interval '20' minute) where upper(first_name)='PETER';

EMPLOYEE_ID FIRST_NAME            SALARY
----------- -------------------- ----------
   152 Peter              9000
   144 Peter              2500
   150 Peter             10000



SQL>  select employee_id,first_name,salary from employees  where employee_id in (152,144,150);

EMPLOYEE_ID FIRST_NAME            SALARY
----------- -------------------- ----------
   144 SAMEER             90000
   150 SAMEER             90000
   152 SAMEER             90000

Gotcha… Mr SAMEER is the culprit here …. Lets fix the things up..

SQL> update employees set first_name =(select first_name from employees as of timestamp (systimestamp -interval '40' minute ) where employee_id=144) where employee_id=144;

1 row updated.

SQL> update employees set first_name =(select first_name from employees as of timestamp (systimestamp -interval '40' minute ) where employee_id=144) where employee_id=150;

1 row updated.

SQL> update employees set first_name =(select first_name from employees as of timestamp (systimestamp -interval '40' minute ) where employee_id=152) where employee_id=152;

1 row updated.

SQL> commit;

Commit complete.

SQL> select employee_id,first_name,salary from employees where employee_id in (152,144,150);

EMPLOYEE_ID FIRST_NAME            SALARY
----------- -------------------- ----------
   144 Peter             90000
   150 Peter             90000
   152 Peter             90000

SQL> update employees set salary = (select salary from employees as of timestamp (systimestamp -interval '40' minute ) where employee_id=152) where employee_id=152;

1 row updated.

SQL> select employee_id,first_name,salary from employees where employee_id in (152,144,150);

EMPLOYEE_ID FIRST_NAME            SALARY
----------- -------------------- ----------
   144 Peter             90000
   150 Peter             90000
   152 Peter              9000

SQL> update employees set salary = (select salary from employees as of timestamp (systimestamp -interval '40' minute ) where employee_id=150)where employee_id=150;

1 row updated.

SQL> update employees set salary = (select salary from employees as of timestamp (systimestamp -interval '40' minute ) where employee_id=144)where employee_id=144;

1 row updated.

SQL> select employee_id,first_name,salary from employees where employee_id in (152,144,150);

EMPLOYEE_ID     FIRST_NAME            SALARY
-----------         --------------------         ----------
   144            Peter              2500
   150             Peter             10000
   152             Peter              9000

SQL> commit;

Commit complete.

SQL> show user
USER is "ARCHIVE"
SQL> drop flashback archive fda;

Flashback archive dropped.

SQL>
SQL>

Oracle explain Plan & auto trace usage

$
0
0

Explain Plan:


Create PLUSTRACE role:

SQL> show user
USER is "SYS"

SQL> @$ORACLE_HOME/sqlplus/admin/plustrce.sql
SQL>
SQL> drop role plustrace;
drop role plustrace
         *
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist


SQL> create role plustrace;

Role created.

SQL>
SQL> grant select on v_$sesstat to plustrace;

Grant succeeded.

SQL> grant select on v_$statname to plustrace;

Grant succeeded.

SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL>
SQL> set echo off

SQL> grant plustrace to hr;

Grant succeeded.


SQL> show user
USER is "HR"




SQL> select employee_id,first_name,last_name from employees where first_name ='Peter';

EMPLOYEE_ID FIRST_NAME        LAST_NAME
----------- -------------------- -------------------------
   144 Peter        Vargas
   150 Peter        Tucker
   152 Peter        Hall

3 rows selected.

SQL> explain plan for
         select employee_id,first_name,last_name from employees where first_name ='Peter';

Explained.

SQL> @?/rdbms/admin/utlxpls.sql
SQL> Rem
SQL> Rem $Header: utlxpls.sql 26-feb-2002.19:49:37 bdagevil Exp $
SQL>-------
SQL> Rem
SQL> Rem Use the display table function from the dbms_xplan package to display the last
SQL> Rem explain plan. Force serial option for backward compatibility
SQL> Rem

SQL> select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3375806929

-------------------------------------------------------------------------------------------
| Id  | Operation           | Name         | Rows  | Bytes | Cost (%CPU)| Time      |
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |         |    3 |    57 |    3  (34)| 00:00:01 |
|   1 |  VIEW              | index$_join$_001 |    3 |    57 |    3  (34)| 00:00:01 |
|*  2 |   HASH JOIN           |         |      |      |           |      |
|*  3 |    INDEX FAST FULL SCAN| EMP_NAME_IX      |    3 |    57 |    1   (0)| 00:00:01 |
|   4 |    INDEX FAST FULL SCAN| EMP_EMP_ID_PK      |    3 |    57 |    1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

  2 - access(ROWID=ROWID)
  3 - filter("FIRST_NAME"='Peter')

17 rows selected.



Auto trace options:

SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]

Explain plan with Trace & Statistics:


SQL> set autot on

select employee_id,first_name,last_name from employees where first_name ='Peter';

EMPLOYEE_ID FIRST_NAME        LAST_NAME
----------- -------------------- -------------------------
   144 Peter        Vargas
   150 Peter        Tucker
   152 Peter        Hall


Execution Plan
----------------------------------------------------------
Plan hash value: 3375806929

-------------------------------------------------------------------------------------------
| Id  | Operation           | Name         | Rows  | Bytes | Cost (%CPU)| Time      |
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |         |    3 |    57 |    3  (34)| 00:00:01 |
|   1 |  VIEW              | index$_join$_001 |    3 |    57 |    3  (34)| 00:00:01 |
|*  2 |   HASH JOIN           |         |      |      |           |      |
|*  3 |    INDEX FAST FULL SCAN| EMP_NAME_IX      |    3 |    57 |    1   (0)| 00:00:01 |
|   4 |    INDEX FAST FULL SCAN| EMP_EMP_ID_PK      |    3 |    57 |    1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

  2 - access(ROWID=ROWID)
  3 - filter("FIRST_NAME"='Peter')


Statistics
----------------------------------------------------------
     0  recursive calls
     0  db block gets
     9  consistent gets
     0  physical reads
     0  redo size
   768  bytes sent via SQL*Net to client
   523  bytes received via SQL*Net from client
     2  SQL*Net roundtrips to/from client
     0  sorts (memory)
     0  sorts (disk)
     3  rows processed

Only explain Plan:

SQL> set autot on exp
SQL> select employee_id,first_name,last_name from employees where first_name ='Peter';

EMPLOYEE_ID FIRST_NAME        LAST_NAME
----------- -------------------- -------------------------
   144 Peter        Vargas
   150 Peter        Tucker
   152 Peter        Hall


Execution Plan
----------------------------------------------------------
Plan hash value: 3375806929

-------------------------------------------------------------------------------------------
| Id  | Operation           | Name         | Rows  | Bytes | Cost (%CPU)| Time      |
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |         |    3 |    57 |    3  (34)| 00:00:01 |
|   1 |  VIEW              | index$_join$_001 |    3 |    57 |    3  (34)| 00:00:01 |
|*  2 |   HASH JOIN           |         |      |      |           |      |
|*  3 |    INDEX FAST FULL SCAN| EMP_NAME_IX      |    3 |    57 |    1   (0)| 00:00:01 |
|   4 |    INDEX FAST FULL SCAN| EMP_EMP_ID_PK      |    3 |    57 |    1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

  2 - access(ROWID=ROWID)
  3 - filter("FIRST_NAME"='Peter')



Only Statistics:


SQL> set autot on stat
SQL> select employee_id,first_name,last_name from employees where first_name ='Peter';

EMPLOYEE_ID FIRST_NAME        LAST_NAME
----------- -------------------- -------------------------
   144 Peter        Vargas
   150 Peter        Tucker
   152 Peter        Hall


Statistics
----------------------------------------------------------
     0  recursive calls
     0  db block gets
     9  consistent gets
     0  physical reads
     0  redo size
   768  bytes sent via SQL*Net to client
   523  bytes received via SQL*Net from client
     2  SQL*Net roundtrips to/from client
     0  sorts (memory)
     0  sorts (disk)
     3  rows processed

Oracle how to use tkprof

$
0
0

Using TKPROF to view the sql trace file data:



SQL> break on table_name skip 1 on index_name


Current Indexex on EMPLOYEES table:

SQL> select table_name,index_name,column_name from user_ind_columns where table_name='EMPLOYEES';


TABLE_NAME              INDEX_NAME             COLUMN_NAME
------------------------------ ------------------------------ -----------------------------------
EMPLOYEES       EMP_EMAIL_UK             EMAIL
                 EMP_EMP_ID_PK                      EMPLOYEE_ID
                 EMP_DEPARTMENT_IX             DEPARTMENT_ID
                 EMP_JOB_IX                               JOB_ID
                 EMP_MANAGER_IX                    MANAGER_ID
                 EMP_NAME_IX                            LAST_NAME
                                                                      FIRST_NAME


SQL> drop index  EMP_NAME_IX;

Index dropped.

SQL> alter session set tracefile_identifier='TKPROF_TEST';

Session altered.

SQL> set autot off

SQL> alter session set sql_trace=true;

Session altered.

SQL> select employee_id,first_name,last_name from employees where first_name ='Peter';

EMPLOYEE_ID FIRST_NAME        LAST_NAME
----------- -------------------- -------------------------
   144 Peter        Vargas
   150 Peter        Tucker
   152 Peter        Hall

SQL> alter session set sql_trace=false;

Session altered.


SQL> show parameter diag

NAME                    TYPE     VALUE
------------------------------------ ----------- ------------------------------
diagnostic_dest             string     /u01/app/oracle

[oracle@collabn1 ~]$ cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace/

[oracle@collabn1 trace]$ find . -type f -name "*TKPROF_TEST*"
./orcl_ora_8871_TKPROF_TEST.trc
./orcl_ora_8871_TKPROF_TEST.trm



sample trace file content:
[oracle@collabn1 trace]$ vi ./orcl_ora_8871_TKPROF_TEST.trc

trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_8871_TKPROF_TEST.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.2.0.2/SHAIKPROD
System name:    Linux
Node name:      collabn1.shaiksameer
Release:        3.8.13-44.1.1.el6uek.x86_64
Version:        #2 SMP Wed Sep 10 06:10:25 PDT 2014
Machine:        x86_64
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 41
Unix process pid: 8871, image: oracle@collabn1.shaiksameer (TNS V1-V3)


*** 2015-08-15 16:31:17.838
*** SESSION ID:(49.22) 2015-08-15 16:31:17.838
*** CLIENT ID:() 2015-08-15 16:31:17.838
*** SERVICE NAME:(SYS$USERS) 2015-08-15 16:31:17.838
*** MODULE NAME:(SQL*Plus) 2015-08-15 16:31:17.838
*** ACTION NAME:() 2015-08-15 16:31:17.838

=====================
PARSING IN CURSOR #7 len=32 dep=0 uid=85 oct=42 lid=85 tim=1439670677838634 hv=1569151342 ad='7fa5e865fe40' sqlid='4tk6t8tfsfqbf'
alter session set sql_trace=true
END OF STMT
EXEC #7:c=0,e=37,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,plh=0,tim=1439670677837153

*** 2015-08-15 16:31:44.988
CLOSE #7:c=0,e=8,dep=0,type=0,tim=1439670704988770



[oracle@collabn1 trace]$ tkprof ./orcl_ora_8871_TKPROF_TEST.trc out.txt

TKPROF: Release 11.2.0.1.0 - Development on Sat Aug 15 16:37:54 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


[oracle@collabn1 trace]$ vi out.txt

********************************************************************************

SQL ID: bk0z2yhg4dq6u
Plan Hash: 1445457117
select employee_id,first_name,last_name
from
employees where first_name ='Peter'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          6          8          0           3
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          6          8          0           3

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows     Row Source Operation
-------  ---------------------------------------------------
     3  TABLE ACCESS FULL EMPLOYEES (cr=8 pr=6 pw=0 time=0 us cost=3 size=57 card=3)

********************************************************************************

SQL> create index  EMP_NAME_IX on employees(first_name,last_name);

Index created.

SQL> select table_name,index_name,column_name from user_ind_columns where table_name='EMPLOYEES';

TABLE_NAME              INDEX_NAME             COLUMN_NAME
------------------------------ ------------------------------ -----------------------------------
EMPLOYEES              EMP_EMAIL_UK             EMAIL
                 EMP_EMP_ID_PK             EMPLOYEE_ID
                 EMP_DEPARTMENT_IX          DEPARTMENT_ID
                 EMP_JOB_IX             JOB_ID
                 EMP_MANAGER_IX             MANAGER_ID
                 EMP_NAME_IX             LAST_NAME
                                FIRST_NAME


7 rows selected.


[oracle@collabn1 trace]$ find . -type f -name "*AFTER_INDEX*"
./orcl_ora_22841_AFTER_INDEX.trc
./orcl_ora_22841_AFTER_INDEX.trm


[oracle@collabn1 trace]$ tkprof ./orcl_ora_22841_AFTER_INDEX.trc out1.txt

TKPROF: Release 11.2.0.1.0 - Development on Sat Aug 15 16:49:28 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


[oracle@collabn1 trace]$ vi out1.txt


Parsing user id: 85
********************************************************************************

SQL ID: bk0z2yhg4dq6u
Plan Hash: 2077747057
select employee_id,first_name,last_name
from
employees where first_name ='Peter'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          0          4          0           3
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          4          0           3

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows     Row Source Operation
-------  ---------------------------------------------------
     3  TABLE ACCESS BY INDEX ROWID EMPLOYEES (cr=4 pr=0 pw=0 time=0 us cost=2 size=57 card=3)
     3   INDEX RANGE SCAN EMP_NAME_IX (cr=2 pr=0 pw=0 time=12 us cost=1 size=0 card=3)(object id 75140)

********************************************************************************

Oracle using dbms_monitor

$
0
0

Using DBMS_MONITOR:




SQL> show user
USER is "SYS"

SQL> select sid,serial# from v$session where username='HR';

      SID    SERIAL#
---------- ----------
   49       25

SQL> exec dbms_monitor.session_trace_enable(session_id=>49,-
> serial_num=>25,waits=>true,binds=>true);

PL/SQL procedure successfully completed.

SQL> alter system flush shared_pool;

System altered.

SQL> alter system flush buffer_cache;

System altered.


SQL> show user    
USER is "HR"
SQL> drop index EMP_NAME_IX;

Index dropped.

SQL> select employee_id,first_name,last_name from employees where first_name ='Peter';

EMPLOYEE_ID FIRST_NAME        LAST_NAME
----------- -------------------- -------------------------
   144 Peter        Vargas
   150 Peter        Tucker
   152 Peter        Hall

SQL> create index  EMP_NAME_IX on employees(first_name,last_name);

Index created.

SQL> select employee_id,first_name,last_name from employees where first_name ='Peter';

EMPLOYEE_ID FIRST_NAME        LAST_NAME
----------- -------------------- -------------------------
   152 Peter        Hall
   150 Peter        Tucker
   144 Peter        Vargas



SQL> select sid,serial# from v$session where username='HR';

      SID    SERIAL#
---------- ----------
   49       25




SQL> show user
USER is "SYS"

SQL> exec dbms_monitor.session_trace_disable(session_id=>49,serial_num=>25);

PL/SQL procedure successfully completed.

SQL> !

[oracle@collabn1 trace]$ vi orcl_ora_22841_AFTER_INDEX.trc
[oracle@collabn1 trace]$ tkprof orcl_ora_22841_AFTER_INDEX.trc out3.txt

TKPROF: Release 11.2.0.1.0 - Development on Sat Aug 15 17:04:34 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


[oracle@collabn1 trace]$ vi out3.txt




********************************************************************************

SQL ID: bk0z2yhg4dq6u
Plan Hash: 1445457117
select employee_id,first_name,last_name
from
employees where first_name ='Peter'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          6          8          0           3
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          6          8          0           3

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows     Row Source Operation
-------  ---------------------------------------------------
     3  TABLE ACCESS FULL EMPLOYEES (cr=8 pr=6 pw=0 time=0 us cost=3 size=57 card=3)


Elapsed times include waiting on following events:
 Event waited on                             Times   Max. Wait  Total Waited
 ----------------------------------------   Waited  ----------  ------------
 SQL*Net message to client                       2        0.00          0.00
 Disk file operations I/O                        1        0.00          0.00
 db file sequential read                         1        0.00          0.00
 db file scattered read                          1        0.00          0.00
 SQL*Net message from client                     2       22.40         22.40
********************************************************************************


Parsing user id: 85     (recursive depth: 1)
********************************************************************************

SQL ID: 7f05xuvxx6rdw
Plan Hash: 1708097244
create index  EMP_NAME_IX on employees(first_name,last_name)


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          1          0           0
Execute      1      0.00       0.01          7          9         52           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2      0.01       0.01          7         10         52           0

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows     Row Source Operation
-------  ---------------------------------------------------
     1  INDEX BUILD NON UNIQUE EMP_NAME_IX (cr=22 pr=8 pw=0 time=0 us)(object id 0)
    107   SORT CREATE INDEX (cr=7 pr=0 pw=0 time=212 us)
    107    TABLE ACCESS FULL EMPLOYEES (cr=7 pr=0 pw=0 time=0 us cost=3 size=1605 card=107)


Elapsed times include waiting on following events:
 Event waited on                             Times   Max. Wait  Total Waited
 ----------------------------------------   Waited  ----------  ------------
 db file sequential read                         7        0.00          0.00
 log file sync                                   1        0.00          0.00
 SQL*Net message to client                       1        0.00          0.00
 SQL*Net message from client                     1        4.14          4.14
********************************************************************************


Parsing user id: 85
********************************************************************************

SQL ID: bk0z2yhg4dq6u
Plan Hash: 2077747057
select employee_id,first_name,last_name
from
employees where first_name ='Peter'


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        2      0.00       0.00          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch        4      0.00       0.00          0          8          0           6
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        8      0.00       0.00          0          8          0           6

Misses in library cache during parse: 2
Optimizer mode: ALL_ROWS
Parsing user id: 85

Rows     Row Source Operation
-------  ---------------------------------------------------
     3  TABLE ACCESS BY INDEX ROWID EMPLOYEES (cr=4 pr=0 pw=0 time=0 us cost=2 size=57 card=3)
     3   INDEX RANGE SCAN EMP_NAME_IX (cr=2 pr=0 pw=0 time=12 us cost=1 size=0 card=3)(object id 75140)


Elapsed times include waiting on following events:
 Event waited on                             Times   Max. Wait  Total Waited
 ----------------------------------------   Waited  ----------  ------------
 SQL*Net message to client                       2        0.00          0.00
 SQL*Net message from client                     1        0.00          0.00
********************************************************************************
Viewing all 191 articles
Browse latest View live