Concurrent Requests Stuck in Pending Phase

Summary of Possible Reasons and Solutions for the Problem Where All  Concurrent Requests Stuck in Pending Phase

Solution:-

Below are several different possible solutions to the problem where
concurrent requests are stuck in pending status:
1.  When shutting down the concurrent managers are there any FNDLIBR
processes still running at the OS level?   If so, do a kill -9 on them,
then restart the concurrent managers.
2.  Try Relinking $FND_TOP.
3.  Rebuild the concurrent manager views.

As applmgr run the following:-

From the OS:
This is non-destructive.
Concurrent Manager views can be rebuilt by running the following command  at the command line:
Ensure that concurrent managers are shutdown.
FNDLIBR FND FNDCPBWV apps/apps SYSADMIN 'System Administrator' SYSADMIN
Restart the concurrent managers.
4.  The Profile Option 'Concurrent: OPS Request Partitioning' may be set
incorrectly. This profile option should always be set to
OFF, regardless of whether you are running OPS(RAC) or not, because the profile is obsolete.
5.  The System Profile Option: Concurrent Active Requests is possibly to 0.
a.  Log into Oracle Applications as SYSADMIN.
  b.  Select System Administrator responsibility.
C.  Navigate to PROFILE > SYSTEM.
 d.  Query for %CONC%ACTIVE%.
  e.  Change the profile option for 'Concurrent: Active Request Limit'  to Null (blank).
f.  Exit Oracle Applications and log in again for the change to take affect.
g.  Run a new concurrent request.
6.  The Concurrent managers were brought down, while an outstanding request
was still running in the background.  In which case, update the
FND_CONCURRENT_REQUESTS table as follows:
sql>
update fnd_concurrent_requests
set status_code='X', phase_code='C'
where status_code='T';
sql> commit;
7.   The control_code for concurrent_queue_name = 'FNDCRM' is 'N' in the
FND_CONCURRENT_QUEUES table,  which means 'Target node/queue unavailable'.
This value should be NULL (CRM is running; target and actual process amount
are the same), or 'A' ('Activate concurrent manager' control status).
Set the control_code to 'A' in fnd_concurrent_queues for the Conflict Resolution

Manager:
 a.  Logon to Oracle Applications database server as 'applmgr'.
b.  Verify the Applications environment is setup correctly
($ORACLE_HOME and $ORACLE_SID).
c.  Logon to SQL*Plus as 'APPS' and run the following SQL statement:
 update fnd_concurrent_queues set control_code = 'A' where concurrent_queue_name = 'FNDCRM';
 commit;
 d.  Verify the status of the concurrent managers through the
Concurrent -> Manager -> Administer form. 
If the CRM is still not active, bounce (deactivate, activate) the Internal
Concurrent Manager.  This is done through the Concurrent > Manager >  Administer form
from the 'System Administrator' responsibility. It can also be done through
the CONCSUB command at the command level.      
Setting the control_code to 'A' in the fnd_concurrent_queues table for the
Conflict Resolution Manager indicates that this concurrent manager
is to be activated with the parameter values specified through this table
for this manager (MAX_PROCESSES, CACHE_SIZE, etc).

8.  What is the cache size?  

Try increasing the cache size then
stop/restart the concurrent managers.
If concurrent requests are rarely prioritized and there are managers
that service short-running requests, consider setting the cache size to
equal at least twice the number of target processes.  This increases the
throughput of the concurrent managers by attempting to avoid any sleep time. 
For example:
If more than one manager or worker processes the same type of requests
with only a small cache size, it may be unable to process any jobs in a
single processing cycle, because other processes have already run the cached requests.
When this happens, it is important to note that the manager will sleep
before refreshing its cache.  To increase manager throughput where there
are sufficient requests of the required type in the queue, increase the
cache size to improve the chance of the manager finding work to process
and thus avoid having to enter a sleep phase.
TIP: Ensure that the system is not resource-constrained before attempting
to increase the rate of concurrent processing in this way, otherwise,
these changes may actually reduce concurrent processing throughput because
jobs take longer to run.
 

Row Chaining and row Migration in 10g

What is Row Chaining?

Row Chaining happens when a row is too large to fit into a single database block. For example, if you use a 8KB block size for your database and you need to insert a row of 16KB into it, Oracle will use 2/3 blocks and store the row in chain of data blocks for that segment. And Row Chaining happens only when the row is being inserted.

you can show the block size of database by

SQL> conn / as sysdba
SQL> show parameter db_block_size

What is Row Migration?

Row Migration Occurs when a row that originally fitted into one data block is updated so
that the overall row length increases, and the block's free space is already
completely filled. In this case, Oracle migrates the data for the entire row
to a new data block, assuming the entire row can fit in a new block. Oracle
preserves the original row piece of a migrated row to point to the new block
containing the migrated row: the rowid of a migrated row does not change.

How to find Row Chaining and row migration?


There are 3 ways to identified Row Chaining and Row Migration

1) by Analyze command
2) USER_TABLES
3) V$SYSSTAT

Example :-

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Sep 22 13:00:32 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> set linesize 1000
SQL> set pagesize 1000
SQL>
SQL>
SQL>
SQL> conn sonu@bsnl
Enter password:
Connected.
SQL>
SQL>
SQL> @D:\oracle\APPl\BEFTN\RDBMS\ADMIN\utlchain.sql

Table created.

SQL>
SQL> desc CHAINED_ROWS ;
Name
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

OWNER_NAME
TABLE_NAME
CLUSTER_NAME
PARTITION_NAME
SUBPARTITION_NAME
HEAD_ROWID
ANALYZE_TIMESTAMP

SQL> select count(*) from CHAINED_ROWS ;

COUNT(*)
----------
0


SQL> SELECT owner, table_name, chain_cnt
2 FROM user_tables
3 WHERE chain_cnt > 0
4* and owner = 'STLBAS'
SQL>
SQL> /

no rows selected

SQL>
SQL>
SQL>SQL> SELECT name, value FROM v$sysstat WHERE name = 'table fetch continued row';

no rows selected

SQL>

Above we cannot find any row chaining below we create a table of row chaining


SQL> drop table chain_row_test ;

Table dropped.

SQL> create table chain_row_test (a varchar(4000),b varchar(4000), c varchar(4000));

Table created.

SQL> insert into chain_row_test (a,b,c) values ( 1, rpad('*',40000000,'*'), rpad('*',2300000,'*') )

SQL> /

1 row created.

SQL> commit ;

Commit complete.

SQL> SELECT count(*) FROM chained_rows;

COUNT(*)
----------
0

SQL> analyze table chain_row_test list chained rows into chained_rows ;

Table analyzed.

SQL> SELECT count(*) FROM chained_rows;

COUNT(*)
----------
1

SQL> select dbms_rowid.rowid_block_number(rowid) from chain_row_test;

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
25620

SQL> insert into chain_row_test (a,b,c) values ( 1, rpad('*',5620000000,'*'), rpad('*',55500000,'*') )
SQL> /

1 row created.

SQL> commit ;

Commit complete.

SQL> select dbms_rowid.rowid_block_number(rowid) from chain_row_test;

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
85530
25620

SQL> SELECT count(*) FROM chained_rows;

COUNT(*)
----------
1

SQL> analyze table chain_row_test list chained rows into chained_rows ;

Table analyzed.


SQL> SELECT count(*) FROM chained_rows;

COUNT(*)
----------
3

SQL> select dbms_rowid.rowid_block_number(rowid) from chain_row_test;

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
85530
25620

SQL> ANALYZE TABLE chain_row_test LIST CHAINED ROWS;

Table analyzed.

SQL> SELECT name, value FROM v$sysstat WHERE name = 'table fetch continued row';
NAME VALUE

table fetch continued row 3


SQL> SELECT table_name, initial_extent, num_rows, blocks, empty_blocks, avg_space,
2 chain_cnt, avg_row_len
3 FROM user_tables
4 WHERE table_name = 'CHAIN_ROW_TEST'
5 /

TABLE_NAME INITIAL_EXTENT NUM_ROWS BLOCKS EMPTY_BLOCKS AVG_SPACE CHAIN_CNT AVG_ROW_LEN
------------------------------ -------------- ---------- ---------- ------------ ---------- ---------- -----------
CHAIN_ROW_TEST 65536 5 16 3 4852 3 4826


SQL> EXEC dbms_stats.gather_table_stats('sonu','CHAIN_ROW_TEST');

PL/SQL procedure successfully completed.

SQL>

we can find which rows are chained

SQL> SELECT a, SUBSTR (b, 1, 10), SUBSTR (c, 1, 10)
2 FROM chain_row_test
3 WHERE ROWID IN (SELECT head_rowid
4 FROM chained_rows);

A
-----------------------------------------------------------------------

SUBSTR(B,1 SUBSTR(C,1
---------- ----------
1
********** **********

1
********** **********

1
********** **********


Avoid and eliminate Chained or Migrated rows ?

1-ALTER TABLE ... MOVE command.

You can MOVE the table by using ALTER TABLE ... MOVE statement that enables you to relocate data of a non partitioned table or of a partition of a partitioned table into a new segment, and optionally into a different tablespace for which you have quota. This statement also lets you modify any of the storage attributes of the table or partition, including those which cannot be modified using ALTER TABLE. You can also use the ALTER TABLE ... MOVE statement with the COMPRESS keyword to store the new segment using table compression.

Note : Moving a table changes the rowids of the rows in the table. This causes indexes on the table to be marked UNUSABLE,and DML accessing the table using these indexes will receive an ORA-01502 error. The indexes on the table must bedropped or rebuilt. Likewise, any statistics for the table become invalid and new statistics should be collected aftermoving the table.


2-Increase PCTFREE.

The PCTFREE parameter sets the minimum percentage of a data block to be reserved as free space for possible updates to rows that already exist in that block. For example, assume that you specify the following parameter within a CREATE TABLE statement.
If the PCTFREE has been set to a low value, that means there is not enough room in the block for updates. To avoid migration,all tables that are updated should have their PCTFREE set so that there is enough space within the block for updates.You need to increase PCTFREE to avoid migrated rows. If you leave more free space available in the block for updates, then the row will have more room to grow.

3- Import/Export can be taken as an approach to eliminate the migrated rows.

4- Avoid to create tables with more than 255 columns.

.dbc and .cfg file

What is a .dbc and a .cfg file?

The .dbc file is mostly used to define database parameters,stands for database connect descriptor file, used to connectto database, it authenticate users against database in FND_USER table.

How it work's

The .dbc file is actually the database connector descriptor file used to connect to database and this file is by-default located in $FND_TOP/secure directory, this file is quite important as whenever any program likes to connect to database like forms it uses dbc file where there you find the Guest_user_pwd ,when the guest user connect it does not allow it to directly connect to the database but it first connect goes via this file and cross verify the password of the guest which is kept in this file.

DBC file is quite important as whenever Java or any other program like forms want to connect to database it uses dbc file.

Typical entry in dbc file are:
GUEST_USER_PWDAPPS_JDBC_URLDB_HOST


The dbc file is used to set up the connectivity for a given database. Each vendor requires different values to determine the server name, database name, user and password, plus any native options including special instructions for the vendor's client API or utility loader.When you drag an Output Table/Input Table etc. onto the canvas, the DBC file lets the component know where to direct the activity. The DBC file is also the mechanism through which a given table can be accessed and its column definition pulled automatically into the given component's DML definition.

There will be lot of dbc file under $FND_SECURE, how we determine which dbc file to use from $FND_SECURE ?

This value is determined from profile option "Applications Database ID"
Authenication:-

In order to authenticate your user against database in FND_USER table this request is passed from core Apache Module to mod_pls ( plsql) and it uses few files like wdbsvr.app in Apache/modplsql/conf $CONTEXT_NAME.dbc , tnsnames.ora in 806/network/admin/$CONTEXT_NAME , GUEST user & few other file so focus on these files & directories & see what changed recently.

.dbc file in R12 -->the dbc file in R12 is in the new $INSTANCE_TOP

$INST_TOP/appl/fnd/12.0.0/secure or $INSTANCE_TOP/apps//appl/fnd/12.0.o/secure.

Last but not the least .cfg is a unix-level file that is fed into a Korn Shell script as an auto-parameter feeder for a parameter-driven shell script. Cfg files are unix-defined where dbc files are AbI-defined.

A Database Connection (DBC) file holds information used by application servers to identify and authenticate with an application database. DBC files must be created on all tiers if it is a multi-tier system.

To recreate DBC file Login to your system as the APPLMGR, ensure that your environment is set correctly by running /.env.
Run common_top/admin/install/adgendbc.sh (UNIX)
This will create the DBC file for the current environment instance. Verify log file to check environment, which should be pointing to 806.Location of file is in /admin/install/adgendbc.txt.

DBC file Parameters

Verify dbc file exists and is in the right location. $FND_TOP/secure//_.dbc. Verify db_host using %uname -aVerify db_sid from v$instance or echo $ORACLE_SID.

Parameters:
APPL_SERVER_ID APPS_JDBC_DRIVER_TYPE=THIN DB_PORT <> DB_HOST GWYUID FNDNAM <> TWO_TASK GUEST_USER_PWD. this is application account and should exists in applications with out any responsibility.
Note:Make sure environment value specified for DB_HOST is db host not application host.
Optional parameters:

FND_MAX_JDBC_CONNECTIONS
Maximum number of open connections in the JDBC connection cache. This number is dependent on the amount of memory available, the number of processes specified in the init.ora file of the database.

FND_IN_USE_CONNECTION_TIMEOUT
Maximum number of seconds a connection can be in use. In order to avoid connections being locked up for too long, the connection cache uses this parameter to forcibly close connections that have been locked for over this time. If this parameter is unspecified,connections in use will not be cleaned up. This should be set to a number larger than the time taken to complete the largest transaction.It is difficult to estimate and recommendation is not to use this.

FND_UNUSED_CONNECTION_TIMEOUT
Maximum number of seconds an unused connection can remain in the cache. The connection cache will close and remove from the cache any connection that has been idle for longer than this specified limit.
Checking DBC file entries: Check Encrypted String for APPL_SERVER_ID parameter in the DBC file with entry in db using following sql stmt.These should be same.
Log in as apps/
Select server_id,server_address from FND_APPLICATION_SERVERS;

The output server_id should match APPL_SERVER_ID and server_address should match IPADDRESS of db host.

%nslookup Address: xxx.xx.xxx.xx Name: Address:
verify hostname above with db_host parameter in dbc file.

Checking db connectivity using DBC file :


syntax:

jre -v oracle.apps.fnd.security.AdminAppServer apps/ STATUS dbc=

Output :
Database Server
---------------
DATABASE_ID: *********
AUTHENTICATION: OFF

Application Server
------------------
APPL_SERVER_STATUS: VALID
APPL_SERVER_ID: 2CF3A427AB3AE01EE0439C143428E01E24739190873060609592242102215611


Status return's APPL_SERVER_ID and other db related info. This verifies DBC setup.

Yellow bar

                    Yellow bar Issue in R12

Yellow Warning Bar

The Yellow Warning Bar is a warning that your applet is not running in a trusted mode

1. Create the digital certificate.
1a.Go to the master web server and set up your environment pointing to the web server’s APPL_TOP.
1b.Enter the following command:
adjkey -initialize
You are prompted for an entity name and an organization name.
adjkey takes the following actions:
- Creates a certificate (.cer file) in the admin directory under your APPL_TOP.
- Imports this certificate into the identitydb.obj file, which is located in the
user’s home directory
- Creates adsign.txt in the admin directory of your APPL_TOP.
This file is used to pass arguments to JRI for signing jar files.



NOTE: If you have multiple web servers in your Release 11i environment, you must copy identitydb.obj and adsign.txt to the appropriate directories on all other web servers.
DO NOT re-run the adjkey command on the other web servers. All Applications Java code should be signed using one digital certificate, unique to your site.Running adjkey multiple times will produce multiple certificates, causing each web server to have JAR files with different signatures.


2. Repackage JInitiator with the new digital certificate.
This step modifies JInitiator so that it recognizes your digital signature as a trusted entity.  This must be done each time you create a new digital certificate.
During this step you run the adjbuild.sh script. Please follow the instructions on how to do this in the  “Repackage JInitiator with your digital certificate” section of Chapter 6 in Installing Oracle Applications,Release 11i.


NOTE: If you have multiple web servers in your Release 11i environment, you must copy the resulting oajinit.exe
file from the $OA_HTML (%OA_HTML% if on Windows NT) directory to the $OA_HTML (or %OA_HTML%) directory of all your other Release 11i web servers.

3. Regenerate jar files
3a.  Run AD Administration on each one of your Release 11i web servers
3b.  Select “Maintain Applications Files” from the main menu
3c.  Select “Generate product jar files” from the next menu.
This will regenerate and sign all the jar files using your new digital certificate, which your newly repackaged JInitiator client software will recognize.

NOTE: At this point, if your users attempt to connect to the Applications,they will see the yellow warning banner in their Applications windows indicating that the Java security authorization has failed.
This is because none of the clients have yet received the new certificate bundled with JInitiator. Continue to the next step to correct this.

4. Install the new JInitiator on your client PCs.
The oajinit.exe file is the file users will download to install and configure the newly repackaged JInitiator.
Before installing the new JInitiator, the users should deinstall their current JInitiator.
This is a two step process:
- Close all browser sessions and windows.
- Deinstall JInitiator using the Windows Control Panel,Add/Remove Programs applet.
a) Jinitiator needs to be completely removed from the machine using Control
Panel -> Add/Remove programs -> Remove Jinitiator  1.1.7.27 Export
b) Make sure the browser is completely shutdown – e.g. for Netscape, check the Taskbar to make sure all netscape.exe processes finish
c) Delete the whole Jinitiator directory from c:\ Program Files\Oracle\ to make sure all files are removed
d) Start Apps client and download a fresh version of Jinitiator

These are located on the Middle Tier, webserver  -  should be owned by APPLMGR
ADCERT.txt     (certificate directive file)

UNIX    :     $APPL_TOP/admin/adcert.txt
ADSIGN.txt     (used to pass arguments to JRI for signing JAR files.)

UNIX    :     $APPL_TOP/admin/adsign.txt
APPLTOP.cer    (Certificate file that gets imported into the identitydb.obj

UNIX    :     $APPL_TOP/admin/appltop.cer
OAJINIT.exe    (Repackaged Jinitiator executeable that includes identitydb.obj)

UNIX    :     $OA_HTML/oajinit.exe
IDENTITYDB.obj (Identity Database File that holds trusted digital certificates)

UNIX    :     $HOME/identitydb.obj

Finding fragmentation at table level and tablespace level in Oracle and steps to remove them




Use this query :-


select owner,table_name,blocks,num_rows,avg_row_len,round(((blocks*8/1024)),2)||'MB' "TOTAL_SIZE",
    round((num_rows*avg_row_len/1024/1024),2)||'Mb' "ACTUAL_SIZE",
    round(((blocks*8/1024)-(num_rows*avg_row_len/1024/1024)),2) ||'MB' "FRAGMENTED_SPACE"
    from all_tables  WHERE Owner NOT IN (
       'SYS', 'OUTLN', 'SYSTEM', 'CTXSYS', 'DBSNMP',
       'LOGSTDBY_ADMINISTRATOR', 'ORDSYS',
       'ORDPLUGINS', 'OEM_MONITOR', 'WKSYS', 'WKPROXY',
       'WK_TEST', 'WKUSER', 'MDSYS', 'LBACSYS', 'DMSYS',
       'WMSYS', 'OLAPDBA', 'OLAPSVR', 'OLAP_USER',
       'OLAPSYS', 'EXFSYS', 'SYSMAN', 'MDDATA',
       'SI_INFORMTN_SCHEMA', 'XDB', 'ODM');

Or This one :- It will collect the data which are having more than 100MB fragmentation.


select owner,table_name,blocks,num_rows,avg_row_len,round(((blocks*8/1024)),2)||'MB' "TOTAL_SIZE", round((num_rows*avg_row_len
/1024/1024),2)||'Mb' "ACTUAL_SIZE", round(((blocks*8/1024)-(num_rows*avg_row_len/1024/1024)),2) ||'MB' "FRAGMENTED_SPACE" from
dba_tables where owner in('a','b','c','d') and round(((blocks*8/1024)-(num_rows*avg_row_len/1024/1024)),2)
> 100 order by 8 desc;


========================================================================

Description

This script lists details of the extents within a tablespace. This will help you determine if a tablespace is fragmented or not. A tablespace with little or no fragmentation the biggest, smallest and average will be similar (e.g. as in a LOCALLY MANAGED tablespace of UNIFORM SIZE)

Parameters

None.

SQL Source


set pages 50

PROMPT
PROMPT Tablespace Freespace Fragmentation Report
PROMPT

column "Blocks" format 999999
column "Free" format 999999
column "Pieces" format 99999
column "Biggest" format 999999
column "Smallest" format 999999
column "Average" format 999999
column "Dead" format 9999
select substr(ts.tablespace_name,1,12) "Tspace",
       tf.blocks "Blocks",
       sum(f.blocks) "Free",
       count(*) "Pieces",
       max(f.blocks) "Biggest",
       min(f.blocks) "Smallest",
       round(avg(f.blocks)) "Average",
       sum(decode(sign(f.blocks-5),-1,f.blocks,0)) "Dead"
from   dba_free_space f,
       dba_data_files tf,
       dba_tablespaces ts
where  ts.tablespace_name=f.tablespace_name
and    ts.tablespace_name = tf.tablespace_name
group by ts.tablespace_name,tf.blocks
/

exit


Description

This script lists details how chained or migrated rows there are within a table. It may help you determine if a table needs to be rebuilt. In order for this script to be effective, you must analyze your tables regularly.

Parameters

None.

SQL Source

CLEAR
SET HEAD ON
SET VERIFY OFF
set pages 100
set lines 79

PROMPT
PROMPT Table Fragmentation Report
PROMPT

col owner form a12
col table_name form a20
col empty_blocks form 999,999 heading "Empty Blks"
col blocks form 999,999 heading "Blks"
col pct form 99

select owner, table_name, num_rows, chain_cnt, (chain_cnt*100/num_rows) pct, empty_blocks, blocks
from dba_tables
where chain_cnt > 0
and owner not in ('SYS','SYSTEM')
/

exit

================================================================

select table_name,round((blocks*8),2) "size (kb)" ,
                            round((num_rows*avg_row_len/1024),2) "actual_data (kb)",
                            (round((blocks*8),2) - round((num_rows*avg_row_len/1024),2)) "wasted_space (kb)"
from user_tab_partitions
where (round((blocks*8),2) > round((num_rows*avg_row_len/1024),2))
order by 4 desc;

===============================================================
steps to remove them :-


If you find reclaimable space % value more than 20% then we can expect fragmentation in the table. To remove this use the following options:

1. Export and import the table (difficult to implement in production environment)
2. Move table in to different or same tablespace (Depends upon the free space available in the tablespace)

Here for the 2nd  option:

1. Collect status of all the indexes on the table.
select index_name,status from user_indexes where table_name like 'table_name';

status may be valid or unusable.

2. Command to move in to new tablespace:

alter table <tb_name> enable row movement;---- Run this command before moving table
alter table table_name move tablespace new_tablespace_name

3. Command to move in to old tablespace

alter table table_name move tablespace old_tablespace_name

If we have free space available  in the tablespace which contain the table. Then we can replace step 2 and 3 by

alter table table_name move ;
alter table <tb_name> disable row movement;---- Run this command after moving table

4. rebuild all indexes
We need to rebuild all the indexes on the table because of move command all the index goes into unusable state.
select index_name from user_indexes where table_name like 'table_name';
alter index index name rebuild online;

5. check status of all the indexes
select index_name,status from user_indexes where table_name like 'table_name';
here value in status field must be valid.

6. Crosscheck space is reclaimed in tablespace

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

Above query will show increase in value of Free Size MB field of tablespce which owns fragmented table.

7. Gather table states:
exec dbms_stats.gather_table_stats('schema_name','table_name');

Comparing Between 2 schema

We can compare two schema with the help  of the below queries:

 compare the two users in terms of tables


SELECT TABLE_NAME FROM ALL_TABLES
WHERE TABLE_NAME NOT IN
(SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER='EMP1')
AND OWNER='EMP2';


compare the two users in terms of objects 


SELECT OBJECT_NAME||' '||OBJECT_TYPE FROM ALL_OBJECTS
WHERE OBJECT_NAME NOT IN
(SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE OWNER='EMP1')
AND OWNER='EMP2';

when we transfer data from one schema to other schema and we want to verify them after successful transfer.

Trace Files

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

To find the trace file for your current session:
  • Submit the following query:
    SELECT VALUE FROM V$DIAG_INFO WHERE NAME = 'Default Trace File';
    
    The full path to the trace file is returned.
To find all trace files for the current instance:
  • Submit the following query:
    SELECT VALUE FROM V$DIAG_INFO WHERE NAME = 'Diag Trace';
    
    The path to the ADR trace directory for the current instance is returned.
To determine the trace file for each Oracle Database process:
  • Submit the following query:
    SELECT PID, PROGRAM, TRACEFILE FROM V$PROCESS;
    
    
    In oracle10g, we find trace files under below directory->

    /oracle/<SID>/saptrace/usertrace

    but in oracle11g

    /oracle/<SID>/saptrace/diag/rdbms/qas/<SID>/trace. Although usertrace folder is present in oracle11g-> /oracle/<SID>/saptrace/usertrace..

     TRACE Utility

    The Oracle TRACE utility is used to measure timing statistics for a given query, a batch process, or an entire system. It is a fast method of finding where potential bottlenecks on the system reside. TRACE has the following functionality:
    • TRACE runs the query and generates statistics about an Oracle query that is executed.
    • TRACE helps developers analyze every section of a query.

    Simple Steps for TRACE with a Simple Query

    The steps for setting up and running Oracle's TRACE utility are as follows:
    1. Set the following init.ora parameters:
        TIMED.STATISTICS = TRUE
        MAX_DUMP_FILE_SIZE = 2000000 (Not 2M)
        USER_DUMP_DEST = /oracle8/rich_trc
        
      In Oracle7, the database must be shut down and restarted for these parameters to take effect. In Oracle8, the TIMED_STATISTICS parameter may be set via an ALTER SESSION (for an individual session) or ALTER SYSTEM (for the entire system) command. The USER_DUMP_DEST specifies the location to put the files and the MAX_DUMP_FILE_SIZE specifies the maximum file size.

    2. Enable TRACE for a SQL*Plus session (this starts TRACing for an individual session):
        alter session set SQL_TRACE true;
        
    3. Run the query to be TRACEd:
        select    table_name,
                  owner, 
                  initial_extent,
                  uniqueness
        from	    ind2
        where	    owner || '' = 'SCOTT';
        --    (Note: An index on "OWNER" is suppressed)
        
    4. Disable TRACE for the SQL*Plus session:
        alter session set SQL_TRACE false;
        
    5. You can also enable TRACE for all sessions by setting the SQLTRACE parameter in the init.ora. You must shut down and restart the database for this to take effect. This is not suggested!
        SQL_TRACE = TRUE
        
      After running TRACE, your output file will look something like the following:
        5_19554.trc
        
      TIP Setting TIMED_STATISTICS=TRUE in the init.ora will begin TRACing upon the user's command. But, be careful; setting SQLTRACE=TRUE in the init.ora will cause the entire system and all queries to be TRACEd and could cause performance degradations.

    6. Run TKPROF to put the TRACE file into readable format:
        tkprof 5_19554.trc rich2.prf explain=system/manager
        
      The TKPROF utility translates the TRACE file generated by the SQLTRACE facility to a readable format. You can run TKPROF against a TRACE file that you have previously created, or you can run it while the program that is creating the TRACE file is still running. Options for TKPROF are listed next.
        tkprof tracefile output_file [sort = parameters]
        [print =number] [explain=username/password@sid]
        
      Command-Line Options:
      TRACEfile
      The name of the TRACE file containing the statistics by SQL_TRACE.
      output_file
      The name of the file where TKPROF writes its output.
      SORT= parameters
      The order in which to display the statements in the output. There are about 20 different options for sorting the output-you can even combine these options.
      PRINT=number
      The number of statements to include in the output. included, TKPROF will list all statements in the output.
      EXPLAIN=username/password@sid
      Run the EXPLAIN PLAN on the user's SQL statements in the TRACE file. This option will create a PLAN_TABLE of its own, so the user will need to have privileges to create the table and space in which to create it. When TKPROF is finished, this table is dropped.

      New options in 7.3+:
      INSERT= filename
      This option creates a script to create a table and store the TRACE file statistics for each SQL statement TRACEd.
      RECORD= filename
      This option will produce a file of all the user's SQL statements.
      SYS= YES/NO
      This option allows the user to request the recursive SQL statements not be displayed in the output. The default is set to YES.
      SORT= parameters
      There is a tremendous number of sorting options that are available. My favorites are FCHCPU (CPU time of fetch), FCHDSK (disk reads for fetch), FCHCU and FCHQRY (memory reads for fetch), FCH ROW (number of rows fetched), EXEDSK (disk reads during execute), EXECU and EXEQRY (memory reads during execute), EXEROW (rows processed during execute), EXECPU (execute CPU time), and PRSCNT (times parsed).
      TIP
      The TKPROF utility puts a TRACEd output into a readable format. Without running TKPROF, it would be difficult to read the output of a TRACE. By specifying "explain=username/password" (noted earlier), we are able to get the EXPLAIN PLAN execution path in addition to the execution statistics of the query.
    7. The output of the file rich2.prf (query with the index suppressed):
    8.   select    table_name,
                  owner,
                  initial_extent,
                  uniqueness
        from      ind2
        where     owner = 'SCOTT';
      
      	count	cpu	elap	disk	query	current	  rows
      
      Parse:	    1     1        2       0        0         0
      Execute:    1     0        0       0        0         2      0
      Fetch:	    2    69      113     142      430         0     36
        
      Execution Plan (no index used):
      TABLE ACCESS (FULL) OF 'IND2'
        
      The output shows 142 disk reads and 430 memory reads (query + current). Having such a high number of disk reads compared to physical reads is certainly a potential problem. The execution path shows a full table scan confirming that we may have a potential problem.TIP A TRACEd query with a large number of physical reads usually indicates a missing index. The disk column indicates the physical reads (usually where an index is not used) and the query added to the current columns indicates the memory reads (usually reads where an index is being used).

    9. Here's what happens when I rerun the query (after restarting the system) to be TRACEd, now using an index on the owner table:
        select    table_name,
                  owner,
                  initial_extent,
                  uniqueness
        from      ind2
        where     owner = 'SCOTT';
        (The index on "OWNER" is not suppressed)
      
      	count	cpu	elap	disk	query	current	  rows
      
      Parse:	    2     0        0       0        0         0
      Execute:    2     0        0       0        0         0      0
      Fetch:	    4     6        6       0      148         0     72 
        
      Execution Plan (index used):
      TABLE ACCESS (BY ROWID) OF 'IND2'
        INDEX (RANGE SCAN) OF 'IND2_1' (NON-UNIQUE)
        
      TIPA TRACEd query output with only memory reads (query-consistent reads) indicates that an index is being used.

    The Sections of a TRACE Output

    The TRACE utility has multiple sections including the SQL statements, statistics, information, and the EXPLAIN PLAN. Each of these different topics are discussed in the following sections.
    The SQL Statement
    The first section of a TKPROF statement is the SQL statement. This statement will be the exact same as the statement that was executed. If there were any hints or comments in the statement, they would be retained in this output. This can be helpful when you are reviewing the output from multiple sessions. If you find a statement causing problems, you would be able to search for the exact statement. Remember, some of the statements from Oracle forms are generated dynamically.
    The Statistics Section
    This section contains all the statistics for this SQL statement and all the recursive SQL statements generated to satisfy this statement. In this section there are eight columns, the first being the type of call to the database. There are three types of calls, parse, execute, and fetch. Each type of call will generate a separate line of statistics. The other seven columns are the statistics for each type of call.
    count
    The number of times this type of call was made.
    cpu
    The total CPU time for all of the calls of this type for this statement. If the TIMED_STATISTICS parameter in the init.ora is not set to TRUE, this statistic and the elapsed statistic will be 0.
    elapsed
    The total elapsed time for this call.
    disk
    The total number of data blocks retrieved from disk to satisfy this call.
    query
    The total number of data buffers retrieved from memory for this type SELECT statements usually retrieve buffers in this mode.
    current
    The total number of data buffers retrieved from memory for this type of call. UPDATE, INSERT, or DELETE the usual access buffers in this mode.
    rows
    The total number of rows processed by this statement. The rows statements will appear in the row of Fetch statistics. INSERTS, UPDATES, and DELETES will appear in the execute row.

ERROR 1396 (HY000): Operation ALTER USER failed for 'Mysql'@'%'

 This MySQL error — ERROR 1396 (HY000): Operation ALTER USER failed for 'Mysql'@'%' — means that MySQL cannot find the user ...