Professional Documents
Culture Documents
Basic and Important Oracle Views V
Basic and Important Oracle Views V
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.
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.
Types of Processes
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.
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.
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.
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").
The checkpoint process (CKPT) updates the control file and data file headers with
checkpoint information and signals DBWn to write blocks to disk.
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.
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.
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
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;
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.
More:
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.
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#;
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
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.
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)
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
from gv$session s;
where
p.addr=s.paddr and
s.status='INACTIVE';
SESSIONS WHICH ARE IN INACTIVE STATUS FROM MORE THAN 1HOUR
where
p.addr=s.paddr and
s.status='INACTIVE';
where
p.addr=s.paddr and
s.status='ACTIVE';
where p.addr=s.paddr
group by s.program;
where p.addr=s.paddr
group by s.module;
where p.addr=s.paddr
group by s.action;
INACTIVE SESSIONS
where
p.addr=s.paddr and
s.status='INACTIVE';
INACTIVE
p.addr=s.paddr and
s.status='INACTIVE';
INACTIVE PROGRAMS
col module for a40
s.status='INACTIVE';
p.addr=s.paddr and
s.status='INACTIVE'
GROUP BY S.PROGRAM;
s.status='INACTIVE'
group by s.program
order by 2 desc;
s.status='INACTIVE'
group by s.program
order by 2 desc;
s.status='INACTIVE'
group by s.module;
set pagesize 40
set pagesize 80
p.addr=s.paddr and
s.status='INACTIVE'
order by last_call_et;
p.addr=s.paddr and
s.status='INACTIVE'
And s.program='&PROGRAM_NAME'
order by last_call_et;
INACTIVE MODULES --ANY--
p.addr=s.paddr
order by last_call_et;
set pagesize 40
set pagesize 80
p.addr=s.paddr and
s.status='INACTIVE'
order by last_call_et;
SELECT COUNT(P.SPID)
p.addr=s.paddr and
s.status='INACTIVE'
order by last_call_et;
FORMS
p.addr=s.paddr and
order by spid;
S.ACTION,s.process Client_Process,s.machine
p.addr=s.paddr and
order by 4;
p.addr=s.paddr and
s.status='INACTIVE'
UNIQUE SPID
select unique(p.spid)
p.addr=s.paddr and
s.status='INACTIVE'
COUNT FORMS
select COUNT(p.spid)
p.addr=s.paddr and
s.status='INACTIVE'
select COUNT(p.spid)
where
p.addr=s.paddr and
s.status='INACTIVE'
AND S.SQL_HASH_VALUE=0;
AND S.STATUS='INACTIVE';
GROUP BY ACTION
group by s.action;
d.user_form_name "FORM_NAME"
apps.fnd_form_tl d
where
a.login_id=b.login_id
and a.user_id=c.user_id
and b.form_id=d.form_id
and d.language='US';
INACTIVE FORM
set pagesize 40
set pagesize 80
p.addr=s.paddr and
s.status='INACTIVE'
order by last_call_et;
SELECT
FROM apps.fnd_user fu
) user_name,vs.status,
vs.last_call_et/3600 last_call_et,
FROM apps.fnd_form_tl ft
), 1, 40 ) form_name
gv$process vp,
apps.fnd_login_resp_forms rf,
gv$session vs
and vs.status='INACTIVE'
ORDER BY
vs.process,
fl.process_spid;
ACTIVE
s.status='ACTIVE';
MODULE
set pagesize 40
set pagesize 80
p.addr=s.paddr
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
p.addr=s.paddr
Order by last_call_et;
TOAD SESSIONS
s.status,s.action,s.module,s.program
where
p.addr=s.paddr
Order by last_call_et;
and s.status='INACTIVE';
hash value=0
AND S.SQL_HASH_VALUE=0
Unique Actions
p.addr=s.paddr and
s.status='INACTIVE';
GROUP BY program
p.addr=s.paddr AND
s.status='INACTIVE'
group by s.program;