Oracle Tips

ORA-12154 TNS:could not resolve service name

Posted on 21 June 2008

ORA-12154 TNS:could not resolve service name

You might have come accross this error when connecting to an Oracle server from an Oracle client. Oracle client will throw this error if it is unable to connect to the server by using the service name specified. This error actually means that Sql * Net is  unable to recognize the host/service name specified in the connection Parameters.

Explanation about how sql * net client connects to the server:

The parameters that are required to connect to an Oracle server.

1. Username
2. Password
3. Service name/connection String

sqlplus- tnsnames-ora

What is a service name ?

Service name specifies an entry in the tnsname.ora file. Each service name consists of  hostname/ip address of the Oracle database server you want to connect, Port at which Oracle listener is working, the database instance you want to connect to, and the protocol you are using for the connection.

  Continue Reading

Comments (0)

Oracle Articles

Undo Tablespace Oracle

Posted on 20 June 2008

Every Oracle database requires a mechanism to undo transactional changes. All the changes made by the dml transactions can be done undone using rollback segments until oracle 8i.  Oracle has introduced an  advanced feature called Automatic undo tablespace management from oracle version 9.0.0.   In contrast to the Roll back segment management, Oracle automatically manages all the operations like adding the segments, shrinking the segments, naming the segments, managing them, making the best possible use of undo space.

All the operations specified below involves an undo tablespace.

1. Revert back changes done with a rollback command.
2. Providing read consistency to Oracle sessions.
3. analyzing or retrieving the data at an earlier point of time using a flash back query.
4. Recover the database.

Creation of Undo tablespace :

You can create an undo tablespace at the time of creation of the database with ‘CREATE DATABASE’ command or later on you can add an UNDO tablespace with ‘CREATE UNDO TABLESPACE’ COMMAND. If Automatic undo management is enabled, and if  no Single undo tablespace available, Oracle makes use of  SYSTEM tablespace for undo management which is not recommended. Oracle also creates a warning in alert.log file, if it uses the system tablespace for UNDO management.

For automatic undo tablespace management by oracle, there should be atleast one active UNDO tablespace per instance.

Undo tablespace creation example  by using the create database command.

CREATE database strinix
 controlfile reuse
 datafile ‘/u01/oradata/strinix/system_01.dbf’ size 300M
undo tablespace undo_tbs_`
 datafile ‘/u02/oradata/strinix/undo_tbs_01.dbf’ size 600M
logfile
   group 1
    (’/u10/oradata/strinix/redo_g1m1.log’) size 25M,
    . . . . . . . . . . . . . . . .
   
;

When creating A new database, if Undo TS is specified but no ‘undo tablespace’ in ‘CREATE DATABASE’ command, the database creation fails with the following errors.

ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-30045: No undo tablespace name specified

Undo tablespace creation example by using the create undo tablespace command.

CREATE undo tablespace undo_tbs
 datafile ‘/u02/oradata/strinix/undo_tbs_01.dbf’ size 600M;

Drop UNDO TABLESPACE:

You can drop an undo tablespace similar to other tablespaces.

Drop undo tablespace example :

DROP TABLESPACE undotbs_01;

The above statement would work only if your undo tablespace is not being used by the system currently. If an UNDO TABLESPACE consists of pending transactions, DROP TABLESPACE statement will fail.

You can force undo tablespace to be dropped by the following command :

DROP TABLESPACE …..INCLUDING CONTENTS

 Undo tablespace Characteristics:

  • No Permanent objects can be created in UNDO TABLESPACE (ORACLE WILL THROW ORA-30022) error.
  • You can change the data file size , add data files to the undo tablespace similiar like other tablespaces.
  • Changes are permitted in data file properties.
  • You can alter the tablespace for online Backups.
  • You cannot offline an active undo tablespace.
  • You cannot change extent sizes of an undo tablespace.

Automatic Undo segments:

The names of Automatic Undo segments are system generated. They are in the form of _SYSSMUn$  (n is the undo segment number,  usn). The number of Initial undo segments created depends upon the SESSIONS parameter.  More automatic undo segments can be  brought online, or created, as needed, provided undo space is available. One transaction per undo segment is desired reach.

Dynamic Extents Transfer:: Reusing expired (or unexpired) undo extents from other undo segments

Shrinking of Undo Segments: Every 12 hours SMON shrinks idled undo segments.Foreground processes signal SMON to shrink undo segments when more undo space is needed

UNDO RETENTION :

 UNDO RETENTION specifies the duration of undo information to be held in the undo tablespace before overwriting. if a transaction is committed, there is no need to hold the undo information, but to provide the read consistency oracle tries to hold the undo information atleast for the specified duration. But holding of the undo information is not guranteed. If sufficient space is not available in undo tablespace, Oracle can overwrite the undo information.If any of this overwritten undo information is required for consistent read in a current long-running query, the query could fail with the ora-01555 : snapshot too old error message.

UNDO RETENTION period is specified in seconds. The default value for undo retention period is 900 seconds. Maximum value for  Undo retention is 4294967295 SECONDS. For a fixed size undo tablespace the parameter “undo_retention“  is ignored. Obviously  it would not be a best practice to keep an undo tablespace in an unlimited size. The other way is to fix the maximum size of a tablespace and enable the autoextend option.

An example of autoextending a tablespace fixing the maximum size

CREATE undo tablespace undo_tbs
 datafile ‘/u02/oradata/strinix/undo_tbs_01.dbf’ AUTOEXTEND ON NEXT 10M  maxsize 800M;

You can also change UNDO_RETENTION PERIOD immediately by using the following command.

ALTER SYSTEM SET UNDO_RETENTION = 3600;

 
Initilization parameters required for Automatic undo management:

UNDO_MANAGEMENT = <auto|manual>.

If UNDO_MANAGEMENT is specified as auto in initilizatin file, Oracle automatic undo management is enabled. if Manual is specified  for this parameter , then the traditional Rollback segment are used for undo management.  If Manual is specified for UNDO_MANAGEMENT ,below undo parameters will be ignored.

UNDO_TABLESPACE = <ts_name>

UNDO_TABLESPACE specifies the tablespace name which should be used as undo tablespace.

UNDO_RETENTION = <seconds|900>

UNDO RETENTION period is specfied in seconds.

UNDO_SUPPRESS_ERRORS = <false|true>

The defualt value for UNDO_SUPPRESS_ERRORS  is false. It Reports an error if  any manual management operation is done related to automatic undo segments. TRUE: Reports success for all such operations without actually carrying them out.

Switching of Undo tablespace:

An undo tablespace can be changed dynamically by using the following command:

alter system set undo_tablespace = <New Undo TS Name>;

 

 

Comments (0)

Oracle Tips

Differences between automatic undo management and Manual undo management

Posted on 19 June 2008

Differences between automatic undo management and Manual undo management

Traditionally until Oracle 8i you have been using Manaul undo management which deals with roll back segments. Typically undo information is stored in rollback segments until a rollback or commit statement is issued.But now with Oracle 9i all your troubles are gone with Manual undo management. Oracle has introduced auto undo management.

Terminology differences :

In automatic undo management we call undo segment rather than rollback segment.

Automatic undo Management can be abbrevated as AUM oR sYSTEM MANAGED UNDO (SMU).

Manual undo management is usually abbrevated as MUM OR ROLLBACK UNOD (RBU).

COMPATIBILITY differences :

Automatic undo management is possible and compatible in Oracle versions 9.0.0 and higher.

Automatic Undo Management is enable by default if the database is created using database configuration assistant.

Manual undo management is not obseleted. it is even supported in the latest versions of Oracle. If you are flexible with Manual undo management ,you can even use it in Oracle version 9.x or 8.x.

You can even upgrade from Manaul undo management to Automatic undo Management.

Continue Reading

Comments (0)

Oracle Tips

Ora-01555 : Snapshot too old error

Posted on 17 June 2008

Ora-01555 : Snapshot too old error

By this time you might have come accross this ora-01555 error lot of times. Before learning about the causes of the Ora-01555 error, you need to understand about Read Consistency and dirty reads in Oracle.

Read Consistency : Let us take an example of Reading a 1 million records from a table emp through a cursor.
While fetching the data from the cursor in session A, if another session B updates the data simultaneously in the table emp by which 10000 records has been affected in the set of 1 million records. if these 10000 rows are not yet read by the cursor in session A, then

 Whether the Oracle would read the updated records to Session A ? NO.

  Continue Reading

Comments (0)

Oracle Tips

Oracle and Xml : query the data into xml format

Posted on 09 June 2008

Oracle Application Server provides a powerful utility to help you generate XML straight from data in your Oracle database — the XSQL processor. XML style sheets allows you to manipulate XML into various usable forms.

 What is xml ?

xml stands for eXtensible Markup language.

eXtensible” - Information in a neutral way,stored in a neutral form, independent of systems, devices and applications

Markup” - Adding information to a document relating to its structure and/or format

Language” - A standard methodology with formal syntax.

Reasons behind xml Popularity

Platform independent

Ease of data exchange

License-Free and well supported

Big players (Oracle and Microsoft) are backing the W3C XML standard

  Continue Reading

Comments (0)

Oracle Tips

Index HINT IN Oracle

Posted on 05 June 2008

An index hint instructs the optimizer to consider the use of an indexed table scan for a specified table. You can optionally specify one or more indexes in the hint. If no indexes names are specified in the hint, Oracle optimizer evaluates the cost of all indexes for a table and uses the most efficient.

 
Instructing the optmizer to use an  index is just a hint, it’s Oracle optimizer decision to make use of an index or not. If the Oracle optimizer recognizes that the cost of full table scan is cheaper than using an index, your index hint will be ignored. And there are more factors that optimizer  may favor the use of full table scan rather than using an index.one among them is db_file_multiblock_read_count  initiliazation parameter.

db_file_multiblock_read_count is a parameter which specifies the number of blocks than can be read by Oracle simultaneously.

If you increase the value in the db_file_multiblock_read_count rather than the default value, then Oracle favours more of full table scan’s rather than index usage. If you decrease the value in the db_file_multiblock_read_count  , then Oracle favours more of index usage rather than full table scans.

Continue Reading

Comments (0)

Oracle Tips

All_Rows Hint Oracle

Posted on 04 June 2008

All_rows hint is used in an opposite view to first_rows hint. This hint is mainly used in datawarehouse environments. if You want to instruct the optimizer to choose the best plan in getting all the rows of the query by the minimum resources of the machine.

This hint is designed mainly  to consume less machine resources like CPU, MEMORY as well as DISK I/O.

All_rows mainly targets on througput of the query rather than response time. So this hint is mainly used in dataware house environments rather then transactional environments.

The result of using an All_rows hint on optimizer Plans:

All_rows hint favours more of full table scans rather than index usage.

All_rows hint favour more of Sort_merge or Hash Joins rather than nested loops.

Synatx of ALL_ROWS HINT:

SELECT /*+ ALL_ROWS */ ….. FROM ……

 

Comments (0)

Oracle Tips

Incorrect Usage Of Oracle Hints result in hint being ignored

Posted on 04 June 2008

Why your hint is Ignored ? Know the correct Usage of Hints

Usually a hint is specified as  a comment to the sql statement. But the job of Oracle optimizer is to differentiate between a hint and a comment. If the Oracle hint is not specified correctly in  an sql statement, there is 100% chance of your hint being ignored by the Oracle optimizer. If an incorrect hint is specified or a hint is mispelled, Optimizer ignores the hint instead of specifying an error. As the name specifies it is a “hint” to OPtimizer to choose the best path, not to report an error because of wrong hint.

I will list some of the cases where people go wrong in specifying a hint

Table aliases :

Let us have a look at the below query

SELECT /*+ INDEX(emp emp_PK) */ emp_name
FROM emp a
WHERE a.emp_no = 32322

In the above query you are instructing the oracle optimizer to use index hint. But Oracle definitely ignores your specification, it may or may not use the index based on the statistics available on the table EMP.This means that if the table is referenced via an alias within the SQL statement, the hint must also reference it via the alias .

Correct Placement of Hints:

Always Place an hint immediately after the first sql verb. if you place the oracle hint anywhere else your hint will be ignored.

Let us see the following query

SELECT emp_name
FROM /*+ INDEX(a emp_pk) */ emp a

Oracle does not report an error, but will definitely ignore your specification of hint.

The correct way of using a hint is

SELECT /*+ INDEX(a emp_pk) */ emp_name
FROM EMP a

INSERT /*+ APPEND */

First three consecutive letters of  your hint should be “/” ,”*”,”+” and the last two letters should be “*”, “/”.

Comments (1)

Oracle Tips

Oracle Performance Tuning Exam General tips

Posted on 03 June 2008

Oracle Performance Tuning Exam

 

This exam focuses on the skills that you use to tune all components of an Oracle database application system. Expect to answer ~65 multiple-choice questions in 90 minutes or less. To pass the exam, you need to answer at least 46 questions correctly (70%). In general, the exam tests you about the following categories of information:

 the fundamental goals and strategies for Oracle database system and application tuning
 the components that you can tune to affect overall performance
 the roles that application designers, developers, database administrators, system administrators, and application end users play in the tuning process
 the steps in SQL statement processing (e.g., open a cursor, parse)
 registering application information in the data dictionary with the DBMS_APPLICATION_INFO package
 techniques for using shared SQL and maximizing application performance
 gathering optimizer statistics to ensure optimal execution plans
 revealing SQL statement execution plans with the SQL command EXPLAIN PLAN and the SQL*Plus    AUTOTRACE feature
 controlling optimizer behavior with initialization parameters, hints, and stored outlines
 monitoring SQL statement performance statistics in the dynamic performance views
 monitoring SQL statements using SQL tracing and TKPROF
 designing transactions
 controlling and monitoring data locks (e.g., table locks, row locks)
 avoiding deadlocks
 setting isolation levels and extending read consistency
 minimizing disk I/O with indexes (normal, bitmap, and function-based), index-organized tables, and clusters (indexed and hash)
 tuning host operating system memory and disk I/O
 tuning a database instance’s buffer cache
 configuring multiple buffer pools (default, keep, and recycle pools) in the buffer cache
 measuring dictionary cache and library cache hit ratios
 Oracle tuning a database instance’s shared pool for general use
 Oracle tuning a database instance’s shared pool for shared server sessions
 preventing fragmentation of shared pool memory
 monitoring database I/O using dynamic performance views
 using tablespaces and data files to reduce contention for database data
 tuning the database writer background process(es)
 tuning database checkpoints
 tuning temporary (sort) space allocations
 tuning redo log I/O with online log members and the redo log buffer
 using the UTLBSTAT and UTLESTAT utilities to gather tuning statistics
 using Oracle Expert to tune an Oracle database system

Comments (0)

Oracle Tips

Oracle exam # 1Z0-032 TIPS- BACKUP, RECOVERY,NET CONFIGURATION

Posted on 02 June 2008

Specific tips for the exam 1Z0-0032:-

 

Although you are not expected to understand how to configure and make use of advanced Oracle Net features, you should be able to explain their function in an Oracle Net design. Such topics include the Oracle Internet Directory (OID, Oracle’s LDAP-compliant directory service), Oracle Names, Oracle Connection Manager, Oracle Advanced Security, the Oracle Net Application Proxy Kit, and Oracle Heterogeneous Services.

 
Do you understand the OSI model and how various Oracle Net software layers with different types of connections fit into this model? Expect several questions about this subject.

You must understand how to configure the two basic naming methods (name resolution methods) for Oracle Net: host naming and local naming.

Continue Reading

Comments (1)







Page 1 of 6123456»