TNS and LISTENER Configuration in oracle

TNS-Transparent network substrate.
  • The transparent network substrate a proprietary oracle computer networkin technology,supports homogeneous peer-to-peer connectivity on top of other  networking technologies such as  tcp/ip and named pipes.
  • Tns operates mainly for connection to oracle databases.
  • Which is the responsible of connecctions establishment.
TNS ENTRY:-
[oracle@nijam]$netca
Step1:- To click the local net service name configuration and click next button.
Step2:-To  click the add and click next button.
Step3:-To add service name  and click next button.
Step4:-To  click the tcp  and click next button.
Step5:-To add  host name and click next button.
Step6:-To click the no  and click next button.
Step7:-To add net service name and click next button.
Step8:-To click the no and click the next button.
Step 9:-to click the finish button.

then check the information  os  level.
[oracle@nijam]$cd $ORACLE_HOME/network/admin/
[oracle@nijam admin]$vi tnsname.ora
#tnsnames.ora network  configuration file:/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
#generated by oracle configuration tools.
Nijam=(description=(address_list=(address=(protocol=tcp)(host=192.168.2.22)(port=1521))
)(connect_data=(service_name=nijam)
)
)
Save  the file.


[oracle@nijam admin]$tnsping nijam
[oracle@nijam]$ps –ef|grep –i tns
LISTENER:-
  • The oracle database listener is the server process that provides basic network connectivity for clients,application servers,and other databases to an oracle databases.
  • In addition to  database ,the listener can also be configured to  support  binary executables.
  • The listener listens on a  specific network port(default 1521) and forwards  network connections to the database.
  • The listener configuration,  stored in the listener.ora  file.
[oracle@nijam]$netca
Step1:-To click the listener  configuration  and click next button.
Step2:-To click the  add and click the next button
Step3:-To add listener name and click next button
Step4:-To click the tcp and click next button.
Step5:-To click the no and next button.
Step6:-To click the finish button.

[oracle@nijam]$cd $ORACLE_HOME/network/admin/
[oracle@nijam admin]$vi listener.ora
Listener=(description=
(address_list=
(address=(protocol=tcp)(host=192.168.0.200)(port=1521))
(address=(protocol=ipc)(key=extproc))))
Sid_list_listner=
(sid_list=
(sid_desc=
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(sid_name=nijam))
)
Then save the file.

[oracle@nijam admin]$lsnrctl
Lsnctl>start    —>a starts the listener with the name specified.will be used.
Lsnrctl>stop   —>a stop the listener.
Lsnrctl>status —>information about the listener.
Lsnrctl>reload —>a forces a read of the configuration file in orderfor new settings to take effect without stopping and starting the listener.
Lsnrctl>exit —>a the lsnrctl utility.

check whether port is available or not.
[oracle@nijam]$netstat  -tunlp|grep 1521.

TNS_ADMIN is an environment variable that points to the directory where the SQL*Net configuration files (like sqlnet.ora and tnsnames.ora) are located.

Windows:
set TNS_ADMIN=%ORACLE HOME%\network\admin

Unix/ Linux:
export TNS_ADMIN=$ORACLE HOME/network/admin

Create VLAN interface in linux

VLAN (virtual local area network) is very useful concept as you can easily separate device management from users by using appropriate network devices and configuration.

Preparations
Install user mode programs to enable VLANs on your ethernet devices:
$ sudo apt-get install vlan
Load 8021q module (IEEE 802.1Q):

$ sudo modprobe 8021q
To load 8021q module at the boot time add it to the /etc/modules file:

$ sudo echo 8021q >> /etc/modules
$ cat /etc/modules
# /etc/modules: kernel modules to load at boot time.

# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with “#” are ignored.
# Parameters can be specified after the module name.
oop
8021q



Solution For Temporary 
Create VLAN 700 on the eth0 device:
$ sudo vconfig add eth0 700

Add VLAN with VID == 700 to IF -:eth0:-
Set IP address (10.100.10.77 netmask 255.255.255.0 in this example):
$ sudo ifconfig eth0.700 10.100.10.77/24

Created interface is named as eth0.700:
$ sudo ifconfig -a
eth0      Link encap:Ethernet  HWaddr 84:8f:69:b0:fa:0a
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:49

eth0.700  Link encap:Ethernet  HWaddr 84:8f:69:b0:fa:0a
          inet addr:10.100.10.77  Bcast:10.100.10.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:11 errors:0 dropped:0 overruns:0 frame:0
          TX packets:53 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:884 (884.0 B)  TX bytes:3158 (3.0 KiB)

Now you can access other hosts available in VLAN 700:
$ ping -c 1 10.100.10.1
PING 10.100.10.1 (10.100.10.1) 56(84) bytes of data.
64 bytes from 10.100.10.1: icmp_req=1 ttl=64 time=1.28 ms

— 10.100.10.1 ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.282/1.282/1.282/0.000 ms
To remove VLAN 700 from the eth0 interface execute command:

$ sudo vconfig rem eth0.700

Removed VLAN -:eth0.700:-
Permanent solution
To create VLAN at the boot time you need to get familiar with /etc/network/interfaces configuration file (man interfaces, man vlan-interfaces).

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

To create VLAN 700 on the eth0 interface at the boot time just add similar configuration:
# add vlan 700 on eth0 – static IP address
auto eth0.700
iface eth0.700 inet static
 address 10.100.10.77
 netmask 255.255.255.0

linux related interview squestions and answwer– 1 in oracle

1) What’s the difference between soft link and hard link?

Ans:
A symbolic (soft) linked file and the targeted file can be located on the same or different file system while for a hard link they must be located on the same file system, because they share same inode number and an inode table is unique to a file system, both must be on the same file system.

2) How you will read a file from shell script?
Ans:
while read line
do
 echo $line
done < file_name

3) 3. What’s the use of umask?
ANS:
Will decide the default permissions for files.

4) What is crontab and what are the arguments?
Ans:
The entries have the following elements:
field             allowed values
—–             ————–
minute            0-59
hour                0-23
day of month   1-31
month             1-12
day of week     0-7 (both 0 and 7 are Sunday)
user                 Valid OS user
command         Valid command or script

? ? ? ? ? command
|  | |  | |_________day of the week (0-6, 0=Sunday)
|  | |  |___________month (1-12)
|  | |_____________day of the month (1-31)
|  |_______________hour (0-23)
|_________________minute (0-59)

5) How to find operating system (OS) version?
Ans:
uname –a

6)  How to find out the run level of the user?
Ans:
uname –r

7) How to delete 7 days old trace files?
Ans:
find ./trace –name *.trc –mtime +7 –exec rm {} \;

8) What is top command?
Ans:
top is a operating system command, it will display top processes which are taking high cpu and memory.

9) 8. How to get 10th line of a file (by using grep)?

tns and listener configure linux —oracle

Tns and Listener
Registering listener in oracle 11G

Error :
[oracle@oraclehost admin]$ sqlplus system/manager@test

SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 21 11:16:06 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor

Make sure the belo entry exists …

[oracle@oraclehost admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

ADR_BASE_LISTENER_TEST = /u01/app/oracle

LISTENER_TEST =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = oraclehost)(PORT = 1521))
    )
  )
[oracle@oraclehost admin]$ cat tnsnames.ora

test =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = oraclehost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = test)
    )
  )

You may get the below error when registering …

SQL> alter system set local_listener=’LISTENER_TEST’;
alter system set local_listener=’LISTENER_TEST’
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-00119: invalid specification for system parameter LOCAL_LISTENER
ORA-00132: syntax error or unresolved network name ‘LISTENER_TEST’
Solution :

SQL > alter system set LOCAL_LISTENER='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=oraclehost)(PORT=1521))))’ sid=’test’;

[oracle@oraclehost admin]$ sqlplus system/manager@test

SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 21 11:14:47 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> ==================================================

How will you connect a DB in linux from windows?
  First check the connectivity in OS(windows) level using
    ping -t 10.3.2.10(linux server)
 Then install Oracle Client in Windows and configure tnsnames.ora.
TNS can be configures using netca.

SSS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = sss)
    )
  )

Server side, Make sure that listener is configured in listener.ora and it is running.
  Listener consists of a header and body like

LISTENER =
 …

SID_LIST_LISTENER =


then use C:\> tnsping sss to check the response from listener. It is not mandatory that Database should be UP and running.

What is default location of listener.ora and tnsnames.ora ? Can this be changed?

The default location is $ORACLE_HOME/network/admin. This can be changed by using TNS_ADMIN parameter.

What is TNS?

TNS stands for TRANSPARENT NETWORK SUBSTRATE

How will you find how many listeners are running in my server?
$ps -ef|grep -i tns

Is it possible to have more than one listener for one database?
 Yes, You can have more than one listener for one database. It is configured as show below.
LISTENER_SSS =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = sss-oracle)(PORT = 1521))
    )
  )

SID_LIST_LISTENER_SSS =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = SSS)
      (ORACLE_HOME = /u01/product/10.2.0/db_1)
    )
  )
————————
LISTENER_SAKTHI =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = sss-oracle)(PORT = 1522))
    )
  )

SID_LIST_LISTENER_SAKTHI =
  (SID_LIST =
    (SID_DESC =
      (ORACLE_HOME = /u01/product/10.2.0/db_1)
      (SID_NAME = SSS)
    )
  )

Make sure that the port is different.  Start the listener using.

$lsnrctl start listener_sss
$lsnrctl start listener_sakthi

How will you find whether a port is available?
$ netstat -tunlp |grep portnumber.

Is it possible to have one listener for more than one database?

Yes, You can have one listener for more than one database. It is configured as show below.
LISTENER_SSS =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = sss-oracle)(PORT = 1521))
    )
  )

SID_LIST_LISTENER_SSS =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = SSS)
      (ORACLE_HOME = /u01/product/10.2.0/db_1)
    )
(SID_DESC =
      (SID_NAME = Sakthi)
      (ORACLE_HOME = /u01/product/10.2.0/db_1)
    )
(SID_DESC =
      (SID_NAME = SSS1)
      (ORACLE_HOME = /u01/product/10.2.0/db_1)
    )
  )

How will you configure single listener for multiple versions of databases?

Just change the ORACLE_HOME and then reload the listener using

$ lsnrctl reload LISTENER_SSS

LISTENER_SSS =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = sss-oracle)(PORT = 1521))
    )
  )

SID_LIST_LISTENER_SSS =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = SSS)
      (ORACLE_HOME = /u01/product/10.2.0/db_1)
    )
(SID_DESC =
      (SID_NAME = Sakthi)
      (ORACLE_HOME = /u01/product/9.2.0.4/db_1)
    )
(SID_DESC =
      (SID_NAME = SSS1)
      (ORACLE_HOME = /u01/product/10.1.0/db_1)
    )
  )
============================================

Error : Starting ORACLE instance (normal)
Wed Feb 20 12:00:52 2013
Process m000 died, see its trace file
Wed Feb 20 12:00:52 2013
ksvcreate: Process(m000) creation failed
Wed Feb 20 12:01:53 2013
Process m000 died, see its trace file
Wed Feb 20 12:01:53 2013
ksvcreate: Process(m000) creation failed
Wed Feb 20 12:02:54 2013
Process m000 died, see its trace file
Wed Feb 20 12:02:54 2013
ksvcreate: Process(m000) creation failed
Wed Feb 20 12:03:56 2013
Process m000 died, see its trace file
Wed Feb 20 12:03:56 2013
ksvcreate: Process(m000) creation failed
Wed Feb 20 12:04:57 2013

Ans :

Check you have sufficient resources in OS level, if yes , increase or
increase the processes parameter accordingly.

=================================================
WARNING: inbound connection timed out (ORA-3136)
Wed Feb 20 12:21:06 2013
WARNING: inbound connection timed out (ORA-3136)
Wed Feb 20 12:21:07 2013
WARNING: inbound connection timed out (ORA-3136)
Solution:

In sqlnet.ora set

SQLNET.INBOUND_CONNECT_TIMEOUT= 0 or more value > 120

default value is 60

also
set in listener.ora

INBOUND_CONNECT_TIMEOUT_ = 0 or > 120

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

PerformanceTuning oracledba -linux plateform

                                  One of the most and COMPLEX task is tuning the database. COMPLEX is not the correct word, if we understand the environment(ie. functionality)  and we know how to tune a query, then everything is simple. Advanced tuning can be learned only through experience and with good environment setup.

Actually 70% of the database is self tuned. Our job is just to do the remaining.

Scenario 1 ,  Lets have the problematic query , how will you tune it?
Eg.
  1  select e.empno,
  2        d.deptno
  3        from
  4        emp e,
  5        dept d
  6             where
  7*            e.deptno=d.deptno;

First you need to get the execution plan for the query. To get plan you can do the following.

Step 1:
———
First check all the tables in the query are RECENTLY analyzed using the below query.
(here it is emp and dept)

SQL> select last_analyzed from dba_tables where table_name in (‘EMP’,’DEPT’);

Like,

SQL> select last_analyzed from user_tables;

LAST_ANAL
————–

4 rows selected.

SQL>

   If the result is null or the date is not current then analyze the table.

SQL > ANALYZE TABLE

COMPUTE STATISTICS;

or use

SQL > exec dbms_stats.gather_table_stats(‘SCOTT’,’EMP’);

Note :  Lets discuss more about DBMS_STATS in another post.

SQL> select table_name,last_analyzed from user_tables;

TABLE_NAME                     LAST_ANAL
—————————— ———
DEPT
EMP
BONUS
SALGRADE

SQL> analyze table dept compute statistics;    

Table analyzed.

SQL> select table_name,last_analyzed from user_tables;

TABLE_NAME                     LAST_ANAL
—————————— ———
DEPT                           05-APR-12
EMP
BONUS
SALGRADE

SQL> exec dbms_stats.gather_table_stats(‘SCOTT’,’EMP’);

PL/SQL procedure successfully completed.

Step 2:
——-
   Check PLAN_TABLE exists in your schema else create using the below script.

SQL> @?/rdbms/admin/utlxplan.sql

SQL> set timing on time on

 To see the query elapsed time.

Step 3 :
———

  There are two ways to see the execution plan.

 1. set autotrace on
 2. using explain plan for …

1.

 SQL > set autotrace on

        Just execute the query , you will get 3 outputs.

  Query result
  execution plan
  Statistics

  1  select e.empno,
  2        d.deptno
  3        from
  4        emp e,
  5        dept d
  6             where
  7*            e.deptno=d.deptno
SQL> /

     EMPNO     DEPTNO
———- ———-
      7369         20
      7499         30
      7521         30
      7566         20
      7654         30
      7698         30
      7782         10
      7788         20
      7839         10
      7844         30
      7876         20

     EMPNO     DEPTNO
———- ———-
      7900         30
      7902         20
      7934         10

14 rows selected.

Execution Plan
———————————————————-
Plan hash value: 3074306753

——————————————————————————
| Id  | Operation          | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
——————————————————————————
|   0 | SELECT STATEMENT   |         |    14 |   546 |     2   (0)| 00:00:01 |
|   1 |  NESTED LOOPS      |         |    14 |   546 |     2   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| EMP     |    14 |   364 |     2   (0)| 00:00:01 |
|*  3 |   INDEX UNIQUE SCAN| PK_DEPT |     1 |    13 |     0   (0)| 00:00:01 |
——————————————————————————

Predicate Information (identified by operation id):
—————————————————

   3 – access(“E”.”DEPTNO”=”D”.”DEPTNO”)

Note
—–
   – dynamic sampling used for this statement

Statistics
———————————————————-
         32  recursive calls
          0  db block gets
         17  consistent gets
          0  physical reads
          0  redo size
        654  bytes sent via SQL*Net to client
        395  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
         14  rows processed

SQL>

If you want to see the statistics, Just give

 SQL > set autotrece traceonlyexplain

You can see the execution plan.

SQL> set autotrace traceonly explain
SQL>  select e.empno,
          d.deptno
          from
          emp e,
          dept d
               where
             e.deptno=d.deptno;

Execution Plan
———————————————————-
Plan hash value: 3074306753

——————————————————————————
| Id  | Operation          | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
——————————————————————————
|   0 | SELECT STATEMENT   |         |    14 |   546 |     2   (0)| 00:00:01 |
|   1 |  NESTED LOOPS      |         |    14 |   546 |     2   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| EMP     |    14 |   364 |     2   (0)| 00:00:01 |
|*  3 |   INDEX UNIQUE SCAN| PK_DEPT |     1 |    13 |     0   (0)| 00:00:01 |
——————————————————————————

Predicate Information (identified by operation id):
—————————————————

   3 – access(“E”.”DEPTNO”=”D”.”DEPTNO”)

Note
—–
   – dynamic sampling used for this statement

SQL>

You can stop the trace using.

 SQL> set autotrace off

2. USING EXPLAIN PLAN FOR …

SQL> explain plan for select e.empno,
          d.deptno
          from
          emp e,
          dept d
               where
             e.deptno=d.deptno;

SQL>

Explained.

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
———————————————————————————————————————————-
Plan hash value: 3074306753

——————————————————————————
| Id  | Operation          | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
——————————————————————————
|   0 | SELECT STATEMENT   |         |    14 |   546 |     2   (0)| 00:00:01 |
|   1 |  NESTED LOOPS      |         |    14 |   546 |     2   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| EMP     |    14 |   364 |     2   (0)| 00:00:01 |
|*  3 |   INDEX UNIQUE SCAN| PK_DEPT |     1 |    13 |     0   (0)| 00:00:01 |
——————————————————————————

PLAN_TABLE_OUTPUT
———————————————————————————————————————————-
Predicate Information (identified by operation id):
—————————————————

   3 – access(“E”.”DEPTNO”=”D”.”DEPTNO”)

Note
—–
   – dynamic sampling used for this statement

19 rows selected.

What is execution plan?
It the access path for a query execution.

When a query is executed from the client, it does three things.

1. Parsing
2. Exection
3. fetching

1. PARSING
Parsing has 6 stages, they are

1. systax checking
     – Just checks the syntax
2. Semantic checking
     – Checks the objects are available and accessible.
3. View Merging
     – rewrites the query so that it uses tables instead if views.
4. Statement transformation
     – Breaks the query to simple queries.
5. Optimization
     – Check the best access path with use of CBO or RBO.
6. Query Execution Plan Generation

 After taking the best access path, it is stored with the query in the library cache. Queries are stored in the

library cache by using a hash value.

 If a query is called again , it is hashed using hashing algorithm and checks in the library cache, if found it uses

the execution plan else it does the parsing(6 stages).


2. EXECUTION
   Query Execution Plan Execution

3. FETCHING

   Reads the data. It may be physical reads, logical reads and consistent reads.

How does oracle reads data?
There are two ways.
1. sigle blocks read
2. multi-block read

Blocks are read using the following techniqs.

Full tables scan
Index scan
Rowid

What is rowsource, predicate,tuples?
  Rowsource is a function that does some action and returns set of records.

  predicate is where clause from a query.

  tuples are rows from table.

What is driving table and probing table?
  Driving table is the one that will be scanned first and the key rows are retrieved. The result will be compared to  the probing table to get the exact result.

for example.

SQL> select e.empno,
          d.deptno
          from
          emp e,
          dept d
               where
             e.deptno=d.deptno;

if the table emp is scanned first by using the predicate e.deptno and the result is used to look for data in dept table using d.deptno.

Here emp is driving table and dept is probing table.

What are joining methods?

   There are three types of joining methods.
 
1. Sort merge
2. Nested loop
3. Hash join.

How will you interpret the execution plan?

Execution plan should be read from right most top.


What will you see in the execution plan?

We need to see the cost and bytes of accessing each table. Try to reduce the cost.

 Like,
Check any full table scans and force to use index etc.

How will you monitor the index creation?

 select OPNAME,SOFAR,TOTALWORK,TIME_REMAINING from v$session_longops
 where sofartotalwork;

How will you view the DML queries that are currently executing?

SQL> select
a.sql_text,
s.sql_id,
t.ubablk
from v$transaction t,
v$session s,
v$sqlarea a
where t.addr=s.taddr
and a.sql_id=s.sql_id;

Note : Since the above query is referring V$TANSACTION , it take only DML statements.

What is RBO?

RBO is Rule based optimizer that uses 15 set of rules to create the execution plan.

RBO Path 1: Single Row by Rowid

RBO Path 2: Single Row by Cluster Join

RBO Path 3: Single Row by Hash Cluster Key with Unique or Primary Key

RBO Path 4: Single Row by Unique or Primary Key

RBO Path 5: Clustered Join

RBO Path 6: Hash Cluster Key

RBO Path 7: Indexed Cluster Key

RBO Path 8: Composite Index

RBO Path 9: Single-Column Indexes

RBO Path 10: Bounded Range Search on Indexed Columns

RBO Path 11: Unbounded Range Search on Indexed Columns

RBO Path 12: Sort Merge Join

RBO Path 13: MAX or MIN of Indexed Column

RBO Path 14: ORDER BY on Indexed Column

RBO Path 15: Full Table Scan

SQL> conn scott/tiger

SQL> set autotrace on
SP2-0618: Cannot find the Session Identifier.  Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report

SQL> conn sys/sys as sysdba

@?/sqlplus/admin/plustrce.sql

SQL>
SQL> drop role plustrace;
drop role plustrace
          *
ERROR at line 1:
ORA-01919: role ‘PLUSTRACE’ does not exist

SQL> create role plustrace;

Role created.

SQL>
SQL> grant select on v_$sesstat to plustrace;
grant select on v_$sesstat to plustrace
                *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> grant select on v_$statname to plustrace;
grant select on v_$statname to plustrace
                *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> grant select on v_$mystat to plustrace;
grant select on v_$mystat to plustrace
                *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL>
SQL> set echo off
SQL> grant plustrace to scott;

Grant succeeded.

reconnect scott.

SQL> conn scott/tiger
Connected.
SQL> set autotrace on
SQL>

Scenario : My daily job has a update statement that normally runs every 10 mins. But today it takes more that 30 mins but still it hangs. How will i trouble shoot it. 

Answer :

Terminal one :

SQL> SELECT sys_context(‘USERENV’, ‘SID’) FROM DUAL
  2  /

SYS_CONTEXT(‘USERENV’,’SID’)
——————————————————————————–
39

SQL> c/ao/ao as
  1* create table ao as select * from all_objects
SQL> /

Table created.

SQL> update ao set owner=’S’;

9383 rows updated.

Terminal two :  

SQL> SELECT sys_context(‘USERENV’, ‘SID’) FROM DUAL
  2  /

SYS_CONTEXT(‘USERENV’,’SID’)
——————————————————————————–
25

SQL> update ao set owner=’H’ ;

It hangs …..

Terminal three :

SQL> l
  1*  select sid,EVENT,SECONDS_IN_WAIT from v$session_wait order by 3
SQL> /

       SID EVENT                                    SECONDS_IN_WAIT
———- —————————————- —————
        44 rdbms ipc message                                      0
        23 SQL*Net message to client                              0
        35 ARCH wait on ATTACH                                   72
        45 rdbms ipc message                                    252
        46 rdbms ipc message                                    255
        33 rdbms ipc message                                    261
        36 rdbms ipc message                                    270        25 enq: TX – row lock contention                        546
        39 SQL*Net message from client                          561
        42 rdbms ipc message                                    810
        26 Streams AQ: qmn slave idle wait                      822
        30 Streams AQ: qmn coordinator idle wait                849
        38 Streams AQ: waiting for time management              852
           or cleanup tasks

        48 rdbms ipc message                                    852
        41 rdbms ipc message                                    864
        40 rdbms ipc message                                    864
        49 pmon timer                                           867
        43 smon timer                                           867
        47 rdbms ipc message                                    868

19 rows selected.

  1* select * from v$locked_object
SQL> /

    XIDUSN    XIDSLOT     XIDSQN  OBJECT_ID SESSION_ID ORACLE_USE OS_USER_NA PROCESS      LOCKED_MODE
———- ———- ———- ———- ———- ———- ———- ———— ———–
         0          0          0       9766         25 SYS        oracle     5958                   3
         5         20         31       9766         39 SYS        oracle     5855                   3

Note : In first 3 columns you find values  0 0 0 and sid is 25, which means this session is hanging (waiting session) …, The session 39 is holding(lock holding) session.

SQL> select sid,serial# from v$session where sid=39;

       SID    SERIAL#
———- ———-
        39          3

To kill the sesison from database :

SQL> alter system kill session ‘39,3’;
Killing from OS level :

SQL> select PADDR from v$session where sid=39;

PADDR
——–
52522C34

SQL> select PID,SPID,ADDR from v$process where addr=’52522C34′;

       PID SPID         ADDR
———- ———— ——–
        12 5887         52522C34

[oracle@oraclehost ~]$ ps -ef|grep 5887|grep -v grep
oracle    5887  5855  0 06:33 ?        00:00:02 oraclekart581 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

[oracle@oraclehost ~]$ kill -9 5887

Also , You can use dba_blockers and dba_waiters.

SQL> @?/rdbms/admin/catblock.sql;

Note : This package will create two views

dba_blockers
dba_waiters

SQL>  select HOLDING_SESSION from dba_blockers;

HOLDING_SESSION
—————
             39

SQL> select * from dba_waiters;

WAITING_SESSION HOLDING_SESSION LOCK_TYPE    MODE_HELD       MODE_REQUE   LOCK_ID1   LOCK_ID2
————— ————— ———— ————— ———- ———- ———-
             25              39 Transaction  Exclusive       Exclusive      327700         31

How will you increase the performance of insert statement?
Ex  query is

insert into table1 select * from ext_table;

Ans :

First,
1. drop the indexes except primary key
2. Disable the foreign Keys
3. Use Hints like APPEND,NOLOGGING, PARALLEL

1.  Check whether you can disable your foreign keys (ie make sure that it is reliable data)

command to disable the constraint.

SQL > alter table tablename disable constraint constraint_name;

2. drop the indexes except primary key

  drop index index_name;

3. use nologging   and append hints

insert /*+ APPEND NOLOGGING */  into table1 select * from ext_table;

4.  Incase you are inserting into partition table

Note : check your total cpu count (total cpu count=CPU*Core) , In this case i have 4 CPU with QUAD core.(TCPU=4*4=16 CPUs).

So you can use 8 to 12 cpus for ur query. Don’t use all of them, because it may lead to CPU exhaust and the OS Server may get down.

SQL > insert /*+ APPEND NOLOGGING parallel(table1,4) */  into table1 select/*+ parallel(ptable,4) * from partition_table ptable;

Once Done. If you are confident about the data , you can enable the constraint using…

SQL > alter table tablename enable constraint constraint_name novalidate;

5. If you dropped the index , recreate the index using

SQL > create index index_name on table_name(column_name) nologging parallel(4) [local] ;

Design a site like this with WordPress.com
Get started