Wednesday, May 26, 2010
Listener Configuration
Listener Configuration:
The listener is a separate process that resides on the server. It receives incoming client connection requests and manages the traffic of these requests to the server. A listener is configured with one or more listening protocol addresses and service information about the destination service.
Protocol addresses are configured in the listener configuration file, $ORACLE_HOME/network/admin/listener.ora.
The sample listener configuration is
LIWIPVA2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cof1s071)(PORT = 1546))
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.153.231.90) (PORT = 1546))
)
)
SID_LIST_LIWIPVA2 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = WIPVA2)
(ORACLE_HOME = /pkg/COBL/COBLpo05/home/oracle/product/10.2.0/Db_1)
(SID_NAME = WIPVA2)
)
)
SUBSCRIBE_FOR_NODE_DOWN_EVENT_LIWIPVA2=OFF
TNSNAMES Configuration:
The tnsnames.ora file contains client side network configuration parameters. It can be found in the ORACLE_HOME/network/admin or ORACLE_HOME/net80/admin directory on the client.
Here is an example of a tnsnames.ora file
WIPVA2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cof1s071)(PORT = 1546))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = WIPVA2)
)
)
Sqlnet.ora Configuration:
The sqlnet.ora file contains client side network configuration parameters. It can be found in the ORACLE_HOME/network/admin or ORACLE_HOME/net80/admin directory on the client. This file will also be present on the server if client style connections are used on the server itself.
Here is an example of an sqlnet.ora file
# SQLNET.ORA Network Configuration File: C:\Oracle\817\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)
NAMES.DEFAULT_DOMAIN = WORLD
Undo Parameter Optimization
________________________________________
Overview
Starting in Oracle9i, rollback segments are re-named undo logs. Traditionally transaction undo information was stored in Rollback Segments until a commit or rollback statement was issued, at which point it was made available for overlaying.
Best of all, automatic undo management allows the DBA to specify how long undo information should be retained after commit, preventing "snapshot too old" errors on long running queries.
This is done by setting the UNDO_RETENTION parameter. The default is 900 seconds (5 minutes), and you can set this parameter to guarantee that Oracle keeps undo logs for extended periods of time.
Rather than having to define and manage rollback segments, you can simply define an Undo tablespace and let Oracle take care of the rest. Turning on automatic undo management is easy. All you need to do is create an undo tablespace and set UNDO_MANAGEMENT = AUTO.
However it is worth to tune the following important parameters
1. The size of the UNDO tablespace
2. The UNDO_RETENTION parameter
Calculate UNDO_RETENTION for given UNDO Tabespace
You can choose to allocate a specific size for the UNDO tablespace and then set the UNDO_RETENTION parameter to an optimal value according to the UNDO size and the database activity. If your disk space is limited and you do not want to allocate more space than necessary to the UNDO tablespace, this is the way to proceed. The following query will help you to optimize the UNDO_RETENTION parameter:
Because these following queries use the V$UNDOSTAT statistics, run the queries only after the database has been running with UNDO for a significant and representative time!
Actual Undo Size
SELECT SUM(a.bytes) "UNDO_SIZE"
FROM v$datafile a,
v$tablespace b,
dba_tablespaces c
WHERE c.contents = 'UNDO'
AND c.status = 'ONLINE'
AND b.name = c.tablespace_name
AND a.ts# = b.ts#;
UNDO_SIZE
----------
209715200
Undo Blocks per Second
SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
"UNDO_BLOCK_PER_SEC"
FROM v$undostat;
UNDO_BLOCK_PER_SEC
------------------
3.12166667
DB Block Size
SELECT TO_NUMBER(value) "DB_BLOCK_SIZE [KByte]"
FROM v$parameter
WHERE name = 'db_block_size';
DB_BLOCK_SIZE [Byte]
--------------------
4096
Optimal Undo Retention
209'715'200 / (3.12166667 * 4'096) = 16'401 [Sec]
Using Inline Views, you can do all in one query!
SELECT d.undo_size/(1024*1024) "ACTUAL UNDO SIZE [MByte]",
SUBSTR(e.value,1,25) "UNDO RETENTION [Sec]",
ROUND((d.undo_size / (to_number(f.value) *
g.undo_block_per_sec))) "OPTIMAL UNDO RETENTION [Sec]"
FROM (
SELECT SUM(a.bytes) undo_size
FROM v$datafile a,
v$tablespace b,
dba_tablespaces c
WHERE c.contents = 'UNDO'
AND c.status = 'ONLINE'
AND b.name = c.tablespace_name
AND a.ts# = b.ts#
) d,
v$parameter e,
v$parameter f,
(
SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
undo_block_per_sec
FROM v$undostat
) g
WHERE e.name = 'undo_retention'
AND f.name = 'db_block_size'
/
ACTUAL UNDO SIZE [MByte]
------------------------
200
UNDO RETENTION [Sec]
--------------------
10800
OPTIMAL UNDO RETENTION [Sec]
----------------------------
16401
Calculate Needed UNDO Size for given Database Activity
If you are not limited by disk space, then it would be better to choose the UNDO_RETENTION time that is best for you (for FLASHBACK, etc.). Allocate the appropriate size to the UNDO tablespace according to the database activity:
Again, all in one query:
SELECT d.undo_size/(1024*1024) "ACTUAL UNDO SIZE [MByte]",
SUBSTR(e.value,1,25) "UNDO RETENTION [Sec]",
(TO_NUMBER(e.value) * TO_NUMBER(f.value) *
g.undo_block_per_sec) / (1024*1024)
"NEEDED UNDO SIZE [MByte]"
FROM (
SELECT SUM(a.bytes) undo_size
FROM v$datafile a,
v$tablespace b,
dba_tablespaces c
WHERE c.contents = 'UNDO'
AND c.status = 'ONLINE'
AND b.name = c.tablespace_name
AND a.ts# = b.ts#
) d,
v$parameter e,
v$parameter f,
(
SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
undo_block_per_sec
FROM v$undostat
) g
WHERE e.name = 'undo_retention'
AND f.name = 'db_block_size'
/
ACTUAL UNDO SIZE [MByte]
------------------------
200
UNDO RETENTION [Sec]
--------------------
10800
NEEDED UNDO SIZE [MByte]
------------------------
131.695313
The previous query may return a "NEEDED UNDO SIZE" that is less than the "ACTUAL UNDO SIZE". If this is the case, you may be wasting space. You can choose to resize your UNDO tablespace to a lesser value or increase your UNDO_RETENTION parameter to use the additional space.
Sunday, May 9, 2010
Explain plan and TKPROF to tune databases and applications
Summary:
EXPLAIN PLAN overview
TKPROF overview
Why???
Reading execution plans
Reading TKPROF reports
Execution Plans and EXPLAIN PLAN
An execution plan is a list of steps that Oracle will follow in order to execute
a SQL statement. Each step is one of a finite number of basic operations
known to the database server. Even the most complex SQL statement can
be broken down into a series of basic operations.
EXPLAIN PLAN is a statement that allows you to have Oracle generate the
execution plan for any SQL statement without actually executing it. You will
be able to examine the execution plan by querying the plan table.
The Plan Table
A plan table holds execution plans generated by the EXPLAIN PLAN
statement.
The typical name for a plan table is plan_table, but you may use any name
you wish.
Create the plan table by running utlxplan.sql, located in
$ORACLE_HOME/rdbms/admin.
Important Columns in the Plan Table
statement_id Unique identifier for each execution plan
timestamp When the execution plan was generated
operation The operation performed in one step of the execution plan, such as
“table access”
options Additional information about the operation, such as “by index
ROWID”
object_name Name of table, index, view, etc. accessed
optimizer Optimizer goal used when creating execution plan
id Step number in execution plan
parent_id Step number of parent step
EXPLAIN PLAN Prerequisites
INSERT privilege on a plan table
All necessary privileges to execute the statement being explained
SELECT privileges on underlying tables of views, if the statement being
explained involves views
EXPLAIN PLAN Syntax
EXPLAIN PLAN
[SET STATEMENT_ID =
[INTO
FOR
Use EXPLAIN PLAN and TKPROF To Tune Your Applications i
Querying an Execution Plan from the Plan Table
Use a CONNECT BY clause to trace the hierarchy
Use LPAD function to indent rows, making the hierarchy easier to follow
Put statement_id in WHERE clause to retrieve only one execution plan at a
time
Sample script on next slide shows the most important information
You can also try utlxpls.sql or utlxplp.sql in $ORACLE_HOME/rdbms/admin
A Simple Query to Display Execution Plans
SET VERIFY OFF
ACCEPT stmt_id CHAR PROMPT "Enter statement_id: "
COL id FORMAT 999
COL parent_id FORMAT 999 HEADING "PARENT"
COL operation FORMAT a35 TRUNCATE
COL object_name FORMAT a30
SELECT id, parent_id, LPAD (' ', LEVEL - 1) ||
operation || ' ' || options operation,
object_name
FROM plan_table
WHERE statement_id = '&stmt_id'
START WITH id = 0
AND statement_id = '&stmt_id'
CONNECT BY PRIOR id = parent_id
AND statement_id = '&stmt_id';
A Sample Execution Plan
SQL> EXPLAIN PLAN SET statement_id = 'demo' FOR
2 SELECT a.customer_name, a.customer_number, b.invoice_number,
3 b.invoice_type, b.invoice_date, b.total_amount,
4 c.line_number, c.part_number, c.quantity, c.unit_cost
5 FROM customers a, invoices b, invoice_items c
6 WHERE c.invoice_id = :b1
7 AND c.line_number = :b2
8 AND b.invoice_id = c.invoice_id
9 AND a.customer_id = b.customer_id;
Explained.
SQL> @explain.sql
Enter statement_id: demo
ID PARENT OPERATION OBJECT_NAME
---- ------ ----------------------------------- -----------------
0 SELECT STATEMENT
1 0 NESTED LOOPS
2 1 NESTED LOOPS
3 2 TABLE ACCESS BY INDEX ROWID INVOICE_ITEMS
4 3 INDEX UNIQUE SCAN INVOICE_ITEMS_PK
5 2 TABLE ACCESS BY INDEX ROWID INVOICES
6 5 INDEX UNIQUE SCAN INVOICES_PK
7 1 TABLE ACCESS BY INDEX ROWID CUSTOMERS
8 7 INDEX UNIQUE SCAN CUSTOMERS_PK
Other Ways to View Execution Plans
Use EXPLAIN PLAN and TKPROF To Tune Your Applications ii
The autotrace feature in SQL*Plus
Performance tuning tools
Sample Autotrace Output in SQL*Plus
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=1 Bytes=39)
1 0 NESTED LOOPS (Cost=4 Card=1 Bytes=39)
2 1 NESTED LOOPS (Cost=3 Card=1 Bytes=27)
3 2 TABLE ACCESS (BY INDEX ROWID) OF 'INVOICE_ITEMS' (Cost
=2 Card=1 Bytes=15)
4 3 INDEX (UNIQUE SCAN) OF 'INVOICE_ITEMS_PK' (UNIQUE) (
Cost=1 Card=2)
5 2 TABLE ACCESS (BY INDEX ROWID) OF 'INVOICES' (Cost=1 Ca
rd=2 Bytes=24)
6 5 INDEX (UNIQUE SCAN) OF 'INVOICES_PK' (UNIQUE)
7 1 TABLE ACCESS (BY INDEX ROWID) OF 'CUSTOMERS' (Cost=1 Car
d=100 Bytes=1200)
8 7 INDEX (UNIQUE SCAN) OF 'CUSTOMERS_PK' (UNIQUE)
EXPLAIN PLAN Limitations
The EXPLAIN PLAN statement provides a good faith estimate of the
execution plan that Oracle would use. The real plan that gets used may
differ from what EXPLAIN PLAN tells you for many reasons:
– Optimizer stats, cursor sharing, bind variable peeking, dynamic
instance parameters make plans less stable.
– EXPLAIN PLAN does not peek at bind variables.
– EXPLAIN PLAN does not check the library cache to see if the
statement has already been parsed.
EXPLAIN PLAN does not work for some queries:
ORA-22905: cannot access rows from a non-nested table item
Viewing Actual Execution Plans
The v$sql view shows statements in the library cache. Here you can find the
address, hash value, and child number for a statement of interest.
The v$sql_plan view shows the actual execution plan for each statement,
given its address, hash value, and child number. The columns are similar to
the plan table.
The v$sql_plan_statistics view shows actual statistics (rows, buffer gets,
elapsed time, etc.) for each operation of the execution plan.
The v$sql_plan and v$sql_plan_statistics views are available starting in
Oracle 9i. v$sql_plan_statistics is not populated by default.
A Simple Query to Display Actual Execution Plans
SET VERIFY OFF
COL id FORMAT 999
COL parent_id FORMAT 999 HEADING "PARENT"
COL operation FORMAT a35 TRUNCATE
COL object_name FORMAT a30
Use EXPLAIN PLAN and TKPROF To Tune Your Applications iii
SELECT id, parent_id, LPAD (' ', LEVEL - 1) ||
operation || ' ' || options operation, object_name
FROM (
SELECT id, parent_id, operation, options, object_name
FROM v$sql_plan
WHERE address = '&address'
AND hash_value = &hash_value
AND child_number = &child_number
)
START WITH id = 0
CONNECT BY PRIOR id = parent_id;
Trace Files and TKPROF
The Oracle server process managing a database session writes a verbose
trace file when SQL trace is enabled for the session.
TKPROF is a utility provided by Oracle that formats SQL trace files into very
helpful and readable reports. TKPROF is installed automatically when the
database server software is installed. You invoke TKPROF from the operating
system command line; there is no graphical interface for TKPROF. Starting in
Oracle 9i TKPROF can read extended SQL trace files and report on wait
events statistics.
Enabling SQL Trace
At the instance level:
sql_trace = true
timed_statistics = true (optional)
In your own session:
ALTER SESSION SET sql_trace = TRUE;
ALTER SESSION SET timed_statistics = TRUE; (optional)
In another session:
SYS.dbms_system.set_sql_trace_in_session
(
Finding the Trace File
Look in the user dump destination. On OFA compliant systems this will be
$ORACLE_BASE/admin/$ORACLE_SID/udump
Check timestamps and file contents to see which trace file is yours
If non-DBAs need access to trace files, add _trace_files_public = true to the
parameter file to avoid permissions problems on Unix platforms
Use a dedicated server connection when tracing, if possible.
Formatting a Trace File with TKPROF
Invoke TKPROF from the operating system prompt like this:
tkprof
Thursday, May 6, 2010
Oracle Editions
Oracle
Enterprise Edition is the full (top of the range) version or the Oracle Database Server. Options like RAC, Partitioning, Spatial, etc. can be purchased separately to enhance the functionality of the database.
Oracle Standard Edition:
Standard Edition is designed for smaller businesses and enterprises. It offers a subset of the features/ functionality implemented in Enterprise Edition. Database options like Data Guard, Partitioning, Spatial, etc. is not available with Standard Edition (from 10g one can use RAC with Standard Edition). Standard Edition can only be licensed on servers with a maximum capacity of four processors.
Oracle Standard Edition One:
Standard Edition One is a low cost, entry-level version of the Oracle Standard Edition database server. Standard Edition One can only be licensed on small servers with a maximum capacity of two processors.
Oracle Personal Edition:
Personal Oracle is a single user version of the database server. It is mostly the same as Enterprise Edition, but doesn't support advanced options like RAC, Streams, XMLDB, etc.
Oracle Lite:
Oracle Light is a database engine that can be used on mobile platforms like cell phones and PDA's.
Oracle XE: