Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

Basic and Important Oracle Views V$ View List

Oracle v$ View List

These views are owned by SYS. The V$ views are actually public synonyms for
corresponding SYS.V_$ views
To list all the V$ views on your system look in V$FIXED_VIEW_DEFINITION, or Select
name from V$FIXED_TABLEwhere name like 'V$%';
To use these views, ensure that timed_statistics is set in the init.ora file
(TIMED_STATISTICS=TRUE). This has minimal effect on performance.
GV$ views are dynamic performance views in a parallel server environment. There
is a GV$ view for almost every V$ view. These have an additional column INST_ID
(instance number)

V$ACCESS
This view displays objects in the database that are currently locked and the sessions
that are accessing them.

V$ACTIVE_INSTANCES
This view maps instance names to instance numbers for all instances that have the
database currently mounted.

V$BGPROCESS
This view describes the background processes.

V$CONTROLFILE
This view lists the names of the control files.

V$DATABASE
This view contains database information from the control file.

V$DATAFILE
This view contains datafile information from the control file. See also the
"V$DATAFILE_HEADER" view which displays information from datafile headers.

V$DBFILE
This view lists all datafiles making up the database. This view is retained for
historical compatibility. Use of V$DATAFILE is recommended instead. For more
information, see "V$DATAFILE"

V$INSTANCE
This view displays the state of the current instance. This version of V$INSTANCE is
not compatible with earlier versions of V$INSTANCE.

V$LIBRARYCACHE
This view contains statistics about library cache performance and activity.
V$LOADTSTAT
SQL*Loader statistics compiled during the execution of a direct load. These statistics
apply to the current table. Any SELECT against this table results in "no rows
returned" since you cannot load data and do a query at the same time.

V$LOCK
This view lists the locks currently held by the Oracle Server and outstanding
requests for a lock or latch.

V$LOG
This view contains log file information from the control files.

V$MYSTAT
This view contains statistics on the current session.

V$NLS_PARAMETERS
This view contains current values of NLS parameters.

V$PARAMETER
This view lists information about initialization parameters.

V$PQ_SESSTAT
This view lists session statistics for parallel queries.

V$PROCESS
This view contains information about the currently active processes. While the
LATCHWAIT column indicates what latch a process is waiting for, the LATCHSPIN
column indicates what latch a process is spinning on. On multi-processor machines,
Oracle processes will spin on a latch before waiting on it.

V$SESSION
This view lists session information for each current session.

V$SGA
This view contains summary information on the System Global Area.

V$SGASTAT
This view contains detailed information on the System Global Area.

V$SQL
This view lists statistics on shared SQL area without the GROUP BY clause and
contains one row for each child of the original SQL text entered.

V$SQL_SHARED_MEMORY
This view displays information about the cursor shared memory snapshot. Each SQL
statement stored in the shared pool has one or more child objects associated with
it. Each child object has a number of parts, one of which is the context heap, which
holds, among other things, the query plan.

V$SQLTEXT
This view contains the text of SQL statements belonging to shared SQL cursors in
the SGA.

V$SYSTEM_PARAMETER
This view contains information on system parameters.

V$TABLESPACE
This view displays tablespace information from the controlfile.

V$VERSION
Version numbers of core library components in the Oracle Server. There is one row
for each component.

V$WAITSTAT
This view lists block contention statistics. This table is only updated when timed
statistics are enabled.
Basic Architecture of Oracle Database and Basic Components -11g

Database Architecture:
A database is a collection of data treated as a unit. The purpose of a database is to
store and retrieve related information. Oracle Database is the first database
designed for enterprise grid computing, the most flexible and cost-effective way to
manage information and applications.

The database has Physical Components , Background Process and Logical


Compoents. Because the physical and logical structures are separate, the physical
storage of data can be managed without affecting access to logical storage
structures.

A. Physical Components:
a. Data File
b. Redo Log Files
c. Control Files
d. Init Parameter
e. Archive
f. Password File
g. Listener & TNS Files

B. Logical Components
a. SGA
b. PGA
C. Background Process
a. SMON
b. PMON
c. DataBase Writer
d. Log Writer
e. Archival Process
f. Checkpoint

Below Diagram will give you more idea on the Structure part of the Database.

I will take all the components description one by one:

Types of Processes

A database instance contains or interacts with the following types of processes:


Client processes run the application or Oracle tool code.
Oracle processes run the Oracle database code. Oracle processes including the
following

Subtypes:

o Background processes start with the database instance and perform maintenance
tasks such as performing instance recovery, cleaning up processes, writing redo
buffers to disk, and so on.
o Server processes perform work based on a client request.

Overview of Server Processes:

Oracle Database creates server processes to handle the requests of client processes
connected to the instance. A client process always communicates with a database
through a separate server process.

Mandatory Background Processes

The mandatory background processes are present in all typical database


configurations. These processes run by default in a database instance started with a
minimally configured initialization parameter file

This section describes the following mandatory background processes:

Process Monitor Process (PMON)

The process monitor (PMON) monitors the other background processes and
performs process recovery when a server or dispatcher process terminates
abnormally. PMON is responsible for cleaning up the database buffer cache and
freeing resources that the client process was using. For example, PMON resets the
status of the active transaction table, releases locks that are no longer required, and
removes the process ID from the list of active processes.

System Monitor Process (SMON)

The system monitor process (SMON) is in charge of a variety of system-level


cleanup duties. The duties assigned to SMON include:
Performing instance recovery, if necessary, at instance startup. In an Oracle RAC
database, the SMON process of one database instance can perform instance
recovery for a failed instance.
Recovering terminated transactions that were skipped during instance recovery
because of file-read or tablespace offline errors. SMON recovers the transactions
when the tablespace or file is brought back online.

Database Writer Process (DBWn)

The database writer process (DBWn) writes the contents of database buffers to data
files. DBWn processes write modified buffers in the database buffer cache to disk
(see "Database Buffer Cache").

Log Writer Process (LGWR)


The log writer process (LGWR) manages the redo log buffer
Checkpoint Process (CKPT)

The checkpoint process (CKPT) updates the control file and data file headers with
checkpoint information and signals DBWn to write blocks to disk.

Archiver Processes (ARCn)


The archiver processes (ARCn) copy online redo log files to offline storage after a
redo log switch occurs

Basic Memory Structures

The basic memory structures associated with Oracle Database include:

System global area (SGA)


The SGA is a group of shared memory structures, known as SGA components, that
contain data and control information for one Oracle Database instance. The SGA is
shared by all server and background processes. Examples of data stored in the SGA
include cached data blocks and shared SQL areas.

Program global area (PGA)


A PGA is a nonshared memory region that contains data and control information
exclusively for use by an Oracle process. The PGA is created by Oracle Database
when an Oracle process is started.
One PGA exists for each server process and background process. The collection of
individual PGAs is the total instance PGA, or instance PGA. Database initialization
parameters set the size of the instance PGA, not individual PGAs.

User Global Area (UGA)


The UGA is memory associated with a user session.

Database Buffer Cache


The database buffer cache, also called the buffer cache, is the memory area that
stores copies of data blocks read from data files. A buffer is a main memory address
in which the buffer manager temporarily caches a currently or recently used data
block. All users concurrently connected to a database instance share access to the
buffer cache.

Buffer States
The database uses internal algorithms to manage buffers in the cache. A buffer can
be in any of the following mutually exclusive states:
Unused
The buffer is available for use because it has never been used or is currently
unused. This type of buffer is the easiest for the database to use.
Clean
This buffer was used earlier and now contains a read-consistent version of a block
as of a point in time. The block contains data but is "clean" so it does not need to be
checkpointed. The database can pin the block and reuse it.
Dirty
The buffer contain modified data that has not yet been written to disk. The
database must checkpoint the block before reusing it.

Every buffer has an access mode: pinned or free (unpinned). A buffer is "pinned" in
the cache so that it does not age out of memory while a user session accesses it.
Multiple sessions cannot modify a pinned buffer at the same time.

Redo Log Buffer

The redo log buffer is a circular buffer in the SGA that stores redo entries describing
changes made to the database. Redo entries contain the information necessary to
reconstruct, or redo, changes made to the database by DML or DDL operations.
Database recovery applies redo entries to data files to reconstruct lost changes.
Oracle Database processes copy redo entries from the user memory space to the
redo log buffer in the SGA. The redo entries take up continuous, sequential space in
the buffer. The background process log writer (LGWR) writes the redo log buffer to
the active online redo log group on disk

Shared Pool
The shared pool caches various types of program data. For example, the shared
pool stores parsed SQL, PL/SQL code, system parameters, and data dictionary
information. The shared pool is involved in almost every operation that occurs in the
database. For example, if a user executes a SQL statement, then Oracle Database
accesses the shared pool.
The shared pool is divided into several subcomponents

Library Cache
The library cache is a shared pool memory structure that stores executable SQL and
PL/SQL code. This cache contains the shared SQL and PL/SQL areas and control
structures such as locks and library cache handles. In a shared server architecture,
the library cache also contains private SQL areas.
When a SQL statement is executed, the database attempts to reuse previously
executed code. If a parsed representation of a SQL statement exists in the library
cache and can be shared, then the database reuses the code, known as a soft parse
or a library cache hit. Otherwise, the database must build a new executable version
of the application code, known as a hard parse or alibrary cache miss.

Shared SQL Areas


The database represents each SQL statement that it runs in the following SQL areas:
Shared SQL area
The database uses the shared SQL area to process the first occurrence of a SQL
statement. This area is accessible to all users and contains the statement parse tree
and execution plan. Only one shared SQL area exists for a unique statement.
Private SQL area

Data Dictionary Cache


The data dictionary is a collection of database tables and views containing reference
information about the database, its structures, and its users. Oracle Database
accesses the data dictionary frequently during SQL statement parsing.
The data dictionary is accessed so often by Oracle Database that the following
special memory locations are designated to hold dictionary data:
Data dictionary cache
This cache holds information about database objects. The cache is also known as
the row cache because it holds data as rows instead of buffers.
Library cache
All server processes share these caches for access to data dictionary information.

Differences between pfile and spfile

PROBLEM
What is the differences between pfile and spfile?

SOLUTION
Oracle provides two parameter files that you can use: PFILE or SPFILE.

PFILE

1. The PFILE is a text-based file usually called initSID.ora, meaning the file will use the
ORACLE_SID you defined when you created the database. If your SID is called TESTDB, the
resulting PFILE should be called initTESTDB.ora
2. Inside the PFILE there are database settings called parameters. These parameters help the
Oracle programs know how to start.
3. The parameters tell the Oracle programs how much memory to allocate, where to put files
related to the database and where certain database files already exist.
4. As the PFILE is text based, one can edit it in an editor like notepad or vi.
5. Depending on which operating system you are running on, your PFILE is located by default in
the ORACLE_HOME\database (usually the case on Windows) or ORACLE_HOME\dbs directory for
most other platforms.
SPFILE
1. The SPFILE is different from the PFILE in that it can not be directly edited. This is because it
has a header and footer that contains binary values.
2. Since you can not change a SPFILE directly, Oracle allows you to manage the SPFILE via the
alter system command.
3. For using an SPFILE, you can reap great benefits. It can be backed up by RMAN (Oracles backup
and recovery software) every time a change is made or when the database is backed up, which
means its easier to recover.
4. SPFILES allow you to make dynamic changes to parameters that are persistent. For example
o Alter system set db_recovery_file_dest_size=10g;
5. If we were using SPFILES the parameter would keep the same value, even after a database
restart. This means you only have to change the parameter value in one place, and that you
can forget having to change it in the PFILE of the database.
6. One of the most important benefits of the SPFILE is that Oracle has introduced many automatic
tuning features into the core of the database. Without an SPFILE, Oracle can not autotune
your database.
7. An SPFILE uses the same formatting for its file name as the PFILE, except the word spfile
replaces init. For instance, if your ORACLE_SID is TESTDB, the resulting spfile would be called
spfileTESTDB.ora.
PFILE and SPFILE Backup
1. As a DBA the main thing you need to worry about with the SPFILE and PFILES are backing them
up. You can use RMAN to backup an SPFILE, or back them up yourself.
2. PFILE is simply a text based file, which means you can copy it to another directory without
affecting the Oracle instance. This is the easiest way to backup a PFILE.
3. To back up an SPFILE, you will first want to convert it to a PFILE. This will create a PFILE
named initSID.ora in your $ORACLE_HOME/database (Windows) or $ORACLE_HOME/dbs
(Linux/Unix) directory. You can do this with the following syntax
o create pfile from spfile;
4. In addition, you can back up the file directly to the preferred location with the command
o create pfile=/path/to/backup.ora from spfile;
5. If the time comes that you must put the SPFILE back into place, you can do so with this
command
o create spfile from pfile=/path/to/backup.ora
6. You can use the V$PARAMETER dynamic view to see the current setting of the different
database parameters
o select name, value from v$parameter where name ='control_files';
The Parameter File at Startup Time
Oracle prefers the use of an SPFILE to a PFILE. When you startup your Oracle database, Oracle will
scan the contents of your parameter directory ($ORACLE_HOME/database on Windows or the Linux
directory name $ORACLE_HOME/dbs), searching in the following order:
1. spfileSID.ora
2. spfile.ora
3. initSID.ora
4. init.ora
If the directory contains none of the above, then the startup will fail.
Alternatively, you can tell Oracle where to find a PFILE if you store it in a different location.

startup

Oracle Database Performance Tuning

Application user is complaining the database is slow.How would you find the
performance issue of SQL queries?

High performance is common expectation for end user, in fact the database is never
slow or fast in most of the case session connected to the database slow down when
they receives unexpected hit. Thus to solve this issue you need to find those
unexpected hit. To know exactly what the session is doing join your query v$session
with v$session_wait.
SELECT NVL(s.username,'(oracle)') as username,s.sid,s.serial#,sw.event,sw.wait_time,
sw.seconds_in_wait, sw.state FROM v$session_wait sw,v$session s
WHERE s.sid=sw.sid and s.username= '&username'ORDER BY sw.seconds_in_wait
DESC;

1.Check the events that are waiting for something.

2.Try to find out the objects locks for that particular session.

3.Locking is not only the cause to effects the performance. Disk I/O contention is
another case. When a session retrieves data from the database datafiles on disk to the
buffer cache, it has to wait until the disk sends the data. The wait event shows up for the
session as "db file sequential read" (for index scan) or "db file scattered read" (for full
table scan).When you see the event, you know that the session is waiting for I/O from
the disk to complete. To improve session performance, you have to reduce that waiting
period. The exact step depends on specific situation, but the first technique reducing
the number of blocks retrieved by a SQL statement almost always works.Reduce the
number of blocks retrieved by the SQL statement. Examine the SQL statement to see if
it is doing a full-table scan when it should be using an index, if it is using a wrong index,
or if it can be rewritten to reduce the amount of data it retrieves.

4.Run SQL Tuning Advisor (@$ORACLE_HOME/rdbms/admin/sqltrpt.sql) by providing


SQL_ID as the input for generating the findings and recommendations.
SQL Tuning Advisor seems to be doing logical optimization mainly by checking your
SQL structure and statistics.
SQL Tuning Advisor suggests indexes that might be very useful.
SQL Tuning Advisor suggests query rewrites.
SQL Tuning Advisor suggests SQL profile.

More:

1.Run TOP command in Linux to check CPU usage.


2.Run VMSTAT, SAR, PRSTAT command to get more information on CPU, memory
usage and possible blocking.
3.Enable the trace file before running your queries,then check the trace file using tkprof
create output file.
According to explain plan check the elapsed time for each query,then tune them
respectively.

What is the use of iostat/vmstat/netstat command in Linux?


Iostat reports on terminal, disk and tape I/O activity.
Vmstat reports on virtual memory statistics for processes, disk, tape and CPU activity.
Netstat reports on the contents of network data structures.
If you are getting high Busy Buffer waits, how can you find the reason behind
it?
Buffer busy wait means that the queries are waiting for the blocks to be read into the db
cache. There could be the reason when the block may be busy in the cache and
session is waiting for it. It could be undo/data block or segment header wait.
Run the below two query to find out the P1, P2 and P3 of a session causing buffer busy
wait
then after another query by putting the above P1, P2 and P3 values.
SQL> Select p1 "File #",p2 "Block #",p3 "Reason Code" from v$session_wait Where
event = 'buffer busy waits';
SQL> Select owner, segment_name, segment_type from dba_extents
Where file_id = &P1 and &P2 between block_id and block_id + blocks -1;

What to Look for in AWR Report and STATSPACK Report?


Many DBAs already know how to use STATSPACK but are not always sure what to
check regularly.
Remember to separate OLTP and Batch activity when you run STATSPACK, since they
usually
generate different types of waits. The SQL script spauto.sql can be used to run
STATSPACK
every hour on the hour. See the script in $ORACLE_HOME/rdbms/admin/spauto.sql for
more
information (note that JOB_QUEUE_PROCESSES must be set > 0). Since every
system is different,
this is only a general list of things you should regularly check in your

STATSPACK output:
Top 5 wait events (timed events)
Load profile
Instance efficiency hit ratios
Wait events

Latch waits
Top SQL
Instance activity
File I/O and segment statistics
Memory allocation
Buffer waits

What is the difference between DB file sequential read and DB File Scattered
Read?
DB file sequential read is associated with index read where as DB File Scattered Read
has to do with full table scan.
The DB file sequential read, reads block into contiguous memory and DB File scattered
read gets from multiple block and scattered them into buffer cache.
Which factors are to be considered for creating index on Table? How to select
column for index?
Creation of index on table depends on size of table, volume of data. If size of table is
large and we need only few data for selecting or in report then we need to create index.
There are some basic reason of selecting column for indexing like cardinality and
frequent usage in where condition of select query. Business rule is also forcing to create
index like primary key, because configuring primary key or unique key automatically
create unique index.
It is important to note that creation of so many indexes would affect the performance of
DML on table because in single transaction should need to perform on various index
segments and table simultaneously.

Is creating index online possible?


YES. You can create and rebuild indexes online. This enables you to update base
tables at the same time you are building or rebuilding indexes on that table. You can
perform DML operations while the index building is taking place, but DDL operations are
not allowed. Parallel execution is not supported when creating or rebuilding an index
online.
CREATE INDEX emp_name ON emp (mgr, emp1, emp2, emp3) ONLINE;

How to recover password in oracle 10g?


You can query with the table user_history$. The password history is store in this table.

How can you track the password change for a user in oracle?
Oracle only tracks the date that the password will expire based on when it was latest
changed. Thus listing the view DBA_USERS.EXPIRY_DATE and subtracting
PASSWORD_LIFE_TIME you can determine when password was last changed. You
can also check the last password change time directly from the PTIME column in
USER$ table (on which DBA_USERS view is based). But If you have
PASSWORD_REUSE_TIME and/or PASSWORD_REUSE_MAX set in a profile
assigned to a user account then you can reference dictionary table USER_HISTORY$
for when the password was changed for this account.
SELECT user$.NAME, user$.PASSWORD, user$.ptime, user_history$.password_date
FROM SYS.user_history$, SYS.user$
WHERE user_history$.user# = user$.user#;

What is Secure External password Store (SEPS)?


Through the use of SEPS you can store password credentials for connecting to
database by using a client side oracle wallet, this wallet stores signing credentials. This
feature introduced since oracle 10g. Thus the application code, scheduled job, scripts
no longer needed embedded username and passwords. This reduces risk because the
passwords are no longer exposed and password management policies are more easily
enforced without changing application code whenever username and password change.
Why we need CASCADE option with DROP USER command whenever dropping a
user and why "DROP USER" commands fails when we don't use it?
If a user having any object then YES in that case you are not able to drop that user
without using CASCADE option. The DROP USER with CASCADE option command
drops user along with its all associated objects. Remember it is a DDL command after
the execution of this command rollback cannot be performed.

What is the difference between Redo,Rollback and Undo?


I find there is always some confusion when talking about Redo, Rollback and Undo.
They all sound like pretty much the same thing or at least pretty close.
Redo: Every Oracle database has a set of (two or more) redo log files. The redo log
records all changes made to data, including both uncommitted and committed changes.
In addition to the online redo logs Oracle also stores archive redo logs. All redo logs are
used in recovery situations.
Rollback: More specifically rollback segments. Rollback segments store the data as it
was before changes were made. This is in contrast to the redo log which is a record of
the insert/update/deletes.
Undo: Rollback segments. They both are really one in the same. Undo data is stored in
the undo tablespace. Undo is helpful in building a read consistent view of data.

You have more than 3 instances running on the Linux server? How can you
determine which shared memory and semaphores are associated with which
instance?
Oradebug is undocumented oracle supplied utility by oracle. The oradebug help
command list the command available with oracle.
SQL>oradebug setmypid
SQL>oradebug ipc
SQL>oradebug tracfile_name

Why drop table is not going into Recycle bin?


If you are using SYS user to drop any table then users object will not go to the
recyclebin as there is no recyclebin for SYSTEM tablespace, even we have already
SET recycle bin parameter TRUE.
Select * from v$parameter where name = 'recyclebin';
Show parameter recyclebin;

Temp Tablespace is 100% FULL and there is no space available to add datafiles to
increase temp tablespace. What can you do in that case to free up TEMP
tablespace?
Try to close some of the idle sessions connected to the database will help you to free
some TEMP space. Otherwise you can also use Alter Tablespace PCTINCREASE 1
followed by Alter Tablespace PCTINCREASE 0
Initialization Parameter files: PFILEs vs. SPFILEs

When an Oracle Instance is started, the characteristics of the Instance are established by
parameters specified within the initialization parameter file. These initialization parameters
are either stored in a PFILE or SPFILE. SPFILEs are available in Oracle 9i and above. All prior
releases of Oracle are using PFILEs.

SPFILEs provide the following advantages over PFILEs:

o An SPFILE can be backed-up with RMAN (RMAN cannot backup PFILEs)

o Reduce human errors. The SPFILE is maintained by the server. Parameters are checked
before changes are accepted.

o Eliminate configuration problems (no need to have a local PFILE if you want to start
Oracle from a remote machine)

o Easy to find - stored in a central location

What is the difference between a PFILE and SPFILE:

A PFILE is a static, client-side text file that must be updated with a standard text editor like
"notepad" or "vi". This file normally reside on the server, however, you need a local copy if you
want to start Oracle from a remote machine. DBA's commonly refer to this file as the INIT.ORA
file.

An SPFILE (Server Parameter File), on the other hand, is a persistent server-side binary file
that can only be modified with the "ALTER SYSTEM SET" command. This means you no longer
need a local copy of the pfile to start the database from a remote machine. Editing an SPFILE
will corrupt it, and you will not be able to start your database anymore.
Query to find Active Session, Inactive Session and Other Sessions in Oracle
Database
Total Count of sessions

select count(s.status) TOTAL_SESSIONS

from gv$session s;

Total Count of Inactive sessions

select count(s.status) INACTIVE_SESSIONS

from gv$session s, v$process p

where

p.addr=s.paddr and

s.status='INACTIVE';
SESSIONS WHICH ARE IN INACTIVE STATUS FROM MORE THAN 1HOUR

select count(s.status) "INACTIVE SESSIONS > 1HOUR "

from gv$session s, v$process p

where

p.addr=s.paddr and

s.last_call_et > 3600 and

s.status='INACTIVE';

COUNT OF ACTIVE SESSIONS

select count(s.status) ACTIVE_SESSIONS

from gv$session s, v$process p

where

p.addr=s.paddr and

s.status='ACTIVE';

TOTAL SESSIONS COUNT ORDERED BY PROGRAM

col program for a30

select s.program,count(s.program) Total_Sessions

from gv$session s, v$process p

where p.addr=s.paddr

group by s.program;

TOTAL COUNT OF SESSIONS ORDERED BY MODULE

col module for a30

prompt TOTAL SESSIONS

select s.module,count(s.sid) Total_Sessions

from gv$session s, v$process p

where p.addr=s.paddr
group by s.module;

TOTAL COUNT OF SESSIONS ORDERED BY ACTION

col action for a30

prompt TOTAL SESSIONS

select s.action,count(s.sid) Total_Sessions

from gv$session s, v$process p

where p.addr=s.paddr

group by s.action;

INACTIVE SESSIONS

prompt INACTIVE SESSIONS

select p.spid, s.sid,s.last_call_et/3600 last_call_et ,s.status,s.action,s.module,s.program

from gv$session s, v$process p

where

p.addr=s.paddr and

s.status='INACTIVE';

INACTIVE

prompt INACTIVE SESSIONS

select count(s.status) INACTIVE

from gv$session s, gv$sqlarea t,v$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE';

INACTIVE PROGRAMS
col module for a40

prompt INACTIVE SESSIONS

col INACTIVE_PROGRAMS FOR A40

select distinct (s.program) INACTIVE_PROGRAMS,s.module

from gv$session s, v$process p

where p.addr=s.paddr and

s.status='INACTIVE';

INACTIVE PROGRAMS with disk reads

prompt INACTIVE SESSIONS

select distinct (s.program) INACTIVE_PROGRAMS,SUM(T.DISK_READS)

from gv$session s, gv$sqlarea t,v$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

GROUP BY S.PROGRAM;

INACTIVE SESSIONS COUNT WITH PROGRAM

col program for a30

prompt TOTAL INACTIVE SESSIONS

col INACTIVE_PROGRAMS FOR A40

select s.program,count(s.program) Total_Inactive_Sessions

from gv$session s,v$process p

where p.addr=s.paddr AND

s.status='INACTIVE'

group by s.program

order by 2 desc;

TOTAL INACTIVE SESSIONS MORE THAN 1HOUR


col program for a30

col INACTIVE_PROGRAMS FOR A40

select s.program,count(s.program) Inactive_Sessions_from_1Hour

from gv$session s,v$process p

where p.addr=s.paddr AND

s.status='INACTIVE'

and s.last_call_et > (3600)

group by s.program

order by 2 desc;

TOTAL INACTIVE SESSIONS GROUP BY MODULE

col program for a60

COL MODULE FOR A30

prompt TOTAL SESSIONS

col INACTIVE_PROGRAMS FOR A40

select s.module,count(s.module) Total_Inactive_Sessions

from gv$session s,v$process p

where p.addr=s.paddr AND

s.status='INACTIVE'

group by s.module;

INACTIVE SESSION DETAILS MORE THAN 1 HOUR

set pagesize 40

col INST_ID for 99

col spid for a10

set linesize 150

col PROGRAM for a10

col action format a10

col logon_time format a16

col module format a13


col cli_process format a7

col cli_mach for a15

col status format a10

col username format a10

col last_call_et_Hrs for 9999.99

col sql_hash_value for 9999999999999col username for a10

set linesize 152

set pagesize 80

col "Last SQL" for a60

col elapsed_time for 999999999999

select p.spid, s.sid,s.last_call_et/3600 last_call_et_Hrs


,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

and s.last_call_et > (3600)

order by last_call_et;

INACTIVE PROGRAM --ANY--

select p.spid, s.sid,s.last_call_et/3600 last_call_et_Hrs


,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

And s.program='&PROGRAM_NAME'

order by last_call_et;
INACTIVE MODULES --ANY--

select p.spid, s.sid,s.last_call_et/3600 last_call_et_Hrs


,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr

And s.module like '%order_cleanup_hazmat_v3.sql'

order by last_call_et;

INACTIVE JDBC SESSIONS

set pagesize 40

col INST_ID for 99

col spid for a10

set linesize 150

col PROGRAM for a10

col action format a10

col logon_time format a16

col module format a13

col cli_process format a7

col cli_mach for a15

col status format a10

col username format a10

col last_call_et for 9999.99

col sql_hash_value for 9999999999999col username for a10

set linesize 152

set pagesize 80

col "Last SQL" for a60

col elapsed_time for 999999999999

select p.spid, s.sid,s.last_call_et/3600 last_call_et ,s.status,s.action,

s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"


from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

and s.program='JDBC Thin Client'

and s.last_call_et > 3600

order by last_call_et;

COUNT OF INACTIVE SESSIONS MORE THAN ONE HOUR

SELECT COUNT(P.SPID)

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

and s.program='JDBC Thin Client'

and s.last_call_et > 3600

order by last_call_et;

FORMS

TOTAL FORM SESSIONS

SELECT COUNT(S.SID) INACTIVE_FORM_SESSIONS FROM V$SESSION S

WHERE S.STATUS='INACTIVE' and

s.action like ('%FRM%');

FORMS SESSIONS DETAILS

col "Last SQL" for a30

select p.spid,s.sid,s.status,s.last_call_et/3600 last_call_et_hrs ,


s.sid,t.disk_reads, t.elapsed_time,lpad(t.sql_text,30) "Last SQL"

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.action like ('FRM%') and

s.last_call_et > 3600

order by spid;

col machine for a15

col "Last SQL" for a30

select p.spid,s.sid,s.status,s.last_call_et/3600 last_call_et_hrs ,

S.ACTION,s.process Client_Process,s.machine

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.action like ('FRM%') and

s.last_call_et > 3600;

order by 4;

INACTIVE FORMS SESSIONS DETAILS

col program for a15

col last_call_et for 999.99

select p.spid, s.sid, s.process,s.last_call_et/3600 last_call_et


,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and
s.status='INACTIVE'

and s.action like 'FRM:%'

and s.last_call_et > 3600

order by last_call_et desc;

UNIQUE SPID

select unique(p.spid)

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

and s.action like 'FRM:%'

and s.last_call_et > 3600;

COUNT FORMS

select COUNT(p.spid)

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

and s.action like 'FRM:%'

and s.last_call_et > 3600;

ZERO HASH VALUE

select COUNT(p.spid)

from gv$session s,gv$process p

where
p.addr=s.paddr and

s.status='INACTIVE'

and s.action like 'FRM:%'

and s.last_call_et > 3600

AND S.SQL_HASH_VALUE=0;

INACTIVE FORM BY NAME

select count(s.sid) from v$session S

where s.action like ('%&ACTION%')

AND S.STATUS='INACTIVE';

GROUP BY ACTION

SELECT S.ACTION,COUNT(S.SID) FROM V$SESSION S

WHERE S.STATUS='INACTIVE' and

s.action like ('%FRM%')

group by s.action;

FROM A SPECIFIC USERNAME

SET LINSIZE 152

col spid for a10

col process_spid for a10

col user_name for a20

col form_name for a20

select a.pid,a.spid,a.process_spid, c.user_name,to_char(a.start_time,'DD-MON-YYYY HH24:MI:SS')


"START_TIME" ,

d.user_form_name "FORM_NAME"

from apps.fnd_logins a, apps.fnd_login_resp_forms b, apps.fnd_user c,

apps.fnd_form_tl d

where
a.login_id=b.login_id

and c.user_name like 'JROMO'

and a.user_id=c.user_id

and trunc(b.start_time) >trunc(sysdate -11)

and trunc(b.end_time) is null

and b.form_id=d.form_id

and d.language='US';

INACTIVE FORM

set pagesize 40

col INST_ID for 99

col spid for a10

set linesize 150

col PROGRAM for a10

col action format a10

col logon_time format a16

col module format a13

col cli_process format a7

col cli_mach for a15

col status format a10

col username format a10

col last_call_et for 9999.99

col sql_hash_value for 9999999999999col username for a10

set linesize 152

set pagesize 80

col "Last SQL" for a30

col elapsed_time for 999999999999

select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,

s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and


s.sql_hash_value =t.hash_value and

p.addr=s.paddr and

s.status='INACTIVE'

and s.action like ('FRM%')

and s.last_call_et > (3600*3)

order by last_call_et;

INACTIVE FORM SESSIONS

col cli_proc for a9

COL AUDSID FOR A6

COL PID FOR A6

COL SID FOR A5

COL FORM_NAME FOR A25

COL USER_NAME FOR A15

col last_call_et for 9999.99

SELECT

-- /*+ ORDERED FULL(fl) FULL(vp) USE_HASH(fl vp) */

( SELECT SUBSTR ( fu.user_name, 1, 20 )

FROM apps.fnd_user fu

WHERE fu.user_id = fl.user_id

) user_name,vs.status,

TO_CHAR ( fl.start_time, 'DD-MON-YYYY HH24:MI' ) login_start_time,

TO_CHAR ( fl.end_time, 'DD-MON-YYYY HH24:MI' ) login_end_time,

vs.last_call_et/3600 last_call_et,

SUBSTR ( fl.process_spid, 1, 6 ) spid,

SUBSTR ( vs.process, 1, 8 ) cli_proc,

SUBSTR ( TO_CHAR ( vs.sid ), 1, 3 ) sid,

SUBSTR ( TO_CHAR ( vs.serial#), 1, 7 ) serial#,


SUBSTR ( TO_CHAR ( rf.audsid ), 1, 6 ) audsid,

SUBSTR ( TO_CHAR ( fl.pid ), 1, 3 ) pid,

SUBSTR ( vs.module || ' - ' ||

( SELECT SUBSTR ( ft.user_form_name, 1, 40 )

FROM apps.fnd_form_tl ft

WHERE ft.application_id = rf.form_appl_id

AND ft.form_id = rf.form_id

AND ft.language = USERENV('LANG')

), 1, 40 ) form_name

FROM apps.fnd_logins fl,

gv$process vp,

apps.fnd_login_resp_forms rf,

gv$session vs

WHERE fl.start_time > sysdate - 7 /* login within last 7 days */

AND fl.login_type = 'FORM'

AND fl.process_spid = vp.spid

AND fl.pid = vp.pid

AND fl.login_id = rf.login_id

AND rf.end_time IS NULL

AND rf.audsid = vs.audsid

and vs.status='INACTIVE'

ORDER BY

vs.process,

fl.process_spid;

ACTIVE

prompt ACTIVE SESSIONS

select count(s.status) ACTIVE

from gv$session s, gv$sqlarea t,v$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and


p.addr=s.paddr and

s.status='ACTIVE';

MODULE

set pagesize 40

col INST_ID for 99

col spid for a10

set linesize 150

col PROGRAM for a10

col action format a10

col logon_time format a16

col module format a13

col cli_process format a7

col cli_mach for a15

col status format a10

col username format a10

col last_call_et for 9999.99

col sql_hash_value for 9999999999999col username for a10

set linesize 152

set pagesize 80

col "Last SQL" for a30

col elapsed_time for 999999999999

select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,

s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr

and s.MODULE like ('&MODULE_NAME_1HR%')

and s.last_call_et > ('&TIME_HRS' * 3600)

order by last_call_et;
select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,

s.status,s.action,s.module,s.program

from gv$session s, gv$sqlarea t,gv$process p

where s.sql_address =t.address and

p.addr=s.paddr

and s.MODULE like ('%TOAD%')

Order by last_call_et;

TOAD SESSIONS

select p.spid, s.sid,s.process cli_process,s.last_call_et/3600 last_call_et ,

s.status,s.action,s.module,s.program

from gv$session s, gv$process p

where

p.addr=s.paddr

and s.MODULE like ('%TOAD%')

Order by last_call_et;

CLIENT MACHINE SESSIONS COUNT

select count(s.process) TOTAL from v$session S

where s.machine like ('%&CLIENT_MACHINE%');

select count(s.process) INACTIVE from v$session S

where s.machine like ('%&CLIENT_MACHINE%')

and s.status='INACTIVE';

hash value=0

select count(s.process) from v$session S

where s.machine like ('%&CLIENT_MACHINE%')


AND S.SQL_HASH_VALUE=0;

select count(s.process) from v$session S

where s.machine like ('%&CLIENT_MACHINE%')

AND S.SQL_HASH_VALUE=0

AND S.LAST_CALL_ET > 3600;

Unique Actions

col module for a40

prompt INACTIVE SESSIONS

col INACTIVE_PROGRAMS FOR A40

select distinct (s.program) INACTIVE_PROGRAMS,s.module

from gv$session s, gv$sqlarea t,v$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

s.machine like ('%&CLIENT_MACHINE%') AND

p.addr=s.paddr and

s.status='INACTIVE';

GROUP BY program

col program for a60

prompt TOTAL SESSIONS

col INACTIVE_PROGRAMS FOR A40

select s.program,count(s.program) Total_Inactive_Sessions

from gv$session s, gv$sqlarea t,v$process p

where s.sql_address =t.address and

s.sql_hash_value =t.hash_value and

p.addr=s.paddr AND

s.machine like ('%&CLIENT_MACHINE%') AND

s.status='INACTIVE'
group by s.program;

You might also like