You are on page 1of 46

05 - Configuring the Oracle Network Environment

By Muhammad Asghar Khan


Reference: OCA Oracle Database 11g - Admin I Exam Guide by John Watson

1/1

Agenda

Configure and Manage the Oracle Network


Oracle Net Establishing a Session Methods of Name Resolution Listener Net Manager TNS Ping Database Links EXERCISE 5-1 Configure Oracle Net EXERCISE 5-2: Set Up a Shared Server Environment
http://asghars.blogspot.com

Use the Oracle Shared Server Architecture

1/23

Configure and Manage the Oracle Network

Oracle calls its set of connectivity solutions Oracle Net Oracle Net

In the Oracle environment, no user has direct access to the database A user interacts with a user process (e.g. SQL *Plus) The server process is a process running on the database server machine that executes the SQL it receives from the user process The execution of a SQL statement goes through four stages: parse, bind, execute, and fetch
http://asghars.blogspot.com

2/23

Configure and Manage the Oracle Network

Parse Phase

Server process works out what the statement actually means, and how best to execute it Any variables used in SQL statement are expanded to literal values Data in the database buffer cache will be read or updated and changes written to the redo log buffer If the relevant blocks are not in the database buffer cache, server process will read them from the datafiles This is the only point in the execution of a statement where the database itself is involved
http://asghars.blogspot.com

Bind Phase

Execute Phase

3/23

Configure and Manage the Oracle Network

Fetch Phase

The server process sends the result set generated by the statements execution back to the user process, which should then format it for display

Oracle Net provides the mechanism for launching a server process to execute code on behalf of a user process, this mechanism is called establishing a session A user interacts with a user process; a user process interacts with a server process, via Oracle Net; a server process interacts with the instance; and the instance, via its background processes, interacts with the database
http://asghars.blogspot.com

4/23

Configure and Manage the Oracle Network

Oracle Net is a layered protocol: it runs on top of whatever communications protocol is supported by your operating system These protocols may include TCP, TCP with secure sockets, Windows Named Pipes (or NMP), and the newer Sockets Direct Protocol (or SDP) over Infiniband high-speed networks For local connections where the user process is on the same machine as the server Oracle Net uses the Inter Process Communication (or IPC) protocol Oracle Net maps on to layers five, six, and seven: the session, presentation, and application layers of OSI model
http://asghars.blogspot.com

5/23

Configure and Manage the Oracle Network

Establishing a Session

When a user, through his user process, wishes to establish a session against an instance, he will issue a command something like
CONNECT SCOTT/TIGER@ORCL

The database user name (SCOTT), and password (TIGER) are separated by a / as a delimiter The @ symbol is followed by a connect string ORCL The @ symbol is an indication to the user process that a network connection is required to an instance on a remote machine
http://asghars.blogspot.com

6/23

Configure and Manage the Oracle Network

If the @ and the connect string are omitted, then the user process will assume that the instance you wish to connect to is running on the local machine, and that the always-available IPC protocol can be used Local instance connection does not require a database listener; indeed, local connections do not require any configuration at all The only information needed is to tell your user process which instance you want to connect to You give the process this information through an environment variable
http://asghars.blogspot.com

7/23

Configure and Manage the Oracle Network

If your connect statement includes the connect string @orcl, Oracle Net has to work out what is meant by orcl, this is calle name resolution This means that the string has to be resolved into certain pieces of information:

Protocol you want to use, IP address/Host name on which the database listener is running, Port that the listener is monitoring for incoming connection requests, and the Name of the instance /service
http://asghars.blogspot.com

8/23

Configure and Manage the Oracle Network

Methods of Name Resolution

Oracle provides four methods of name resolution: easy connect, local naming, directory naming, and external naming Easy Connect
It is limited to one protocol: TCP Easy Connect cannot be used with any of Oracle Nets more advanced capabilities such as load balancing or connect-time failover across different network routes DBA find it very handy to use, but it is not a method of much use for your end users You invoke it with a syntax such as this as your connect string:

10

http://asghars.blogspot.com

9/23

Configure and Manage the Oracle Network


connect scott/tiger@pwr.financekpp.gov.pk:1522/orcl

SQL*Plus will use TCP to go to port 1522 on the IP address to which the hostname resolves Then if there is a listener running on that port and address, it will ask the listener to spawn a server process against an instance that is part of the service called orcl

Local Naming
With local naming the user supplies Oracle Net service alias for the connect string, and the alias is resolved by a local file (tnsnames.ora) into the full network address (protocol, address, port, and service or instance name) The tnsnames.ora file is a client-side Consider this example of a tnsnames.ora file:

11

http://asghars.blogspot.com

10/23

Configure and Manage the Oracle Network


orcl = (DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP) (HOST = pwr.financekpp.gov.pk) (PORT = 1522)) ) (CONNECT_DATA = service_name = orcl) ) )

The alias orcl what your users will provide in their connect statements Local naming supports all protocols and all the advanced features of Oracle Net, but maintaining tnsnames.ora files on all your client machines can be an extremely time-consuming task

12 http://asghars.blogspot.com

11/23

Configure and Manage the Oracle Network

Directory Naming
Directory naming points the user toward an LDAP directory server to resolve aliases Oracle provides an LDAP server (the Oracle Internet Directory) as part of the Oracle Application Server, but you do not have to use thatif you already have a Microsoft Active Directory Directory naming supports all Oracle Net features

External Naming

It is conceptually similar to directory naming, but it uses thirdparty naming services such as Suns Network Information Services (NIS+) or the Cell Directory Services (CDS)

13

http://asghars.blogspot.com

12/23

Configure and Manage the Oracle Network

Listener

When a client request reached the listener, the listener selects an appropriate service handler (a dispatcher or dedicated server) to service the clients request and forwards the clients request to it The listener configuration is stored in a configuration file named listener.ora. Whose default location is the $ORACLE_HOME/network/admin directory A listener spawn server processes against an instance In order to do this, it needs to know what instances are available on the computer on which it is running A listener finds out about instances by the process of registration
http://asghars.blogspot.com

14

13/23

Configure and Manage the Oracle Network

There are two methods for registering an instance with a database: static and dynamic Static Registeration

For static registration, you hard-code a list of instances in the listener.ora file If you have older databases (prior to 8i) that your listener must connect users to, you will have to register them statically Also some applications may require static registration: typically management tools To register an instance statically, add an appropriate entry to the listener.ora file:
http://asghars.blogspot.com

15

14/23

Configure and Manage the Oracle Network


SID_LIST_LIST2 = (SID_LIST = ( SID_DESC = (ORACLE_HOME = /u01/oracle/app/product/11.2.0/db_1) (SID_NAME = orcl)) )

This entry configure the listener called LIST2 to accept connection requests for an instance called orcl The directive ORACLE_HOME is only required if the database listener is not running from the same Oracle Home as the instance This directive will let the listener find the executable file that it must run to launch a server process
http://asghars.blogspot.com

16

15/23

Configure and Manage the Oracle Network

Dynamic Registration

This is the preferred method by which an instance will register with a listener Dynamic registration requires no configuration at all if your listener is running on the default port, 1521 The initialization parameter local_listener, tells the instance the network address that it should contact to find a listener with which to register At instance startup time, the PMON process will use this parameter to locate a listener, and inform it of the instances name and the names of the service(s) that the instance is offering
http://asghars.blogspot.com

17

16/23

Configure and Manage the Oracle Network

The instance name is defined by the instance_name parameter, and the service_names parameter will have defaulted to this suffixed by the db_domain parameter You will need to register your instance with the listener with alter system register if you have restarted the listener, or if you started the database instance before starting the listener If your listener is not running on the default port on the address identified by the hostname, you must specify where the listener is by setting the parameter local_listener and reregistering
http://asghars.blogspot.com

18

17/23

Configure and Manage the Oracle Network


alter system set local_listener=list2; alter system register;

You can start and stop listeners through Database Control, but there is also a command-line utility lsnrctl
lsnrctl start [listener name]

The STATUS command provides basic status information about a listener


lsnrctl status [listener name]

The SERVICES command provides detailed information about the services and instances registered with a listener and the service handlers allocated to each instance
lsnrctl services [listener name]

19

http://asghars.blogspot.com

18/23

Configure and Manage the Oracle Network

Net Manager

It is a stand-alone Java utility, shipped with all the Oracle client-side products Use the net manager, to configure the clients to use the desired name resolution method To launch the net manager run netmgr from an OS prompt The net manager navigation tree has three branches:

20

http://asghars.blogspot.com

19/23

Configure and Manage the Oracle Network

Profile

It is used to set options that may apply to both the client and server sides of Oracle Net and can be used to influence the behavior of all Oracle Net connections When you take the Profile branch you are in fact configuring a file called sqlnet.ora Sqlnet.ora contains settings that apply to all connections and listeners, such as security rules and encryption There are defaults for every sqlnet.ora directivebut you will usually configure it if only to select the name resolution method
http://asghars.blogspot.com

21

20/23

Configure and Manage the Oracle Network

Service Naming

It is used to configure client-side name resolution It edits the Local Naming tnsnames.ora file This file exists in your ORACLE_HOME/network/admin directory Listeners branch is used to configure database listeners

Listeners

22

http://asghars.blogspot.com

21/23

Configure and Manage the Oracle Network

TNS Ping

To test a connect string, use the TNSPING utility


tnsping orcl

This will accept a connect string, locate the Oracle Net files, resolve the string, and send a message to the listener If the listener is running and does know about the service requested, the test will return successfully

23

http://asghars.blogspot.com

22/23

Configure and Manage the Oracle Network

Database Links

Oracle Net can also be used for communications between databases A user session against one database can execute SQL statements against another database This is done through a database link Simple example of database link creation is:
create database link prodscott

connect to scott identified by tiger using 'prod';

24

http://asghars.blogspot.com

23/23

Configure and Manage the Oracle Network

This defines a database link from the current database to a remote database identified by the connect string PROD You can issue statement through a link as
select * from emp@prodscott;

25

http://asghars.blogspot.com

1/10

EXERCISE 5-1 Configure Oracle Net


1.

Create a directory to be used for the Oracle Net configuration files, and set the TNS_ADMIN variable to point to this Start the Net Manager. The top line of the Net Manager window will show the location of the Oracle Net files. If this is not the new directory, then the TNS_ADMIN variable has not been set correctly

2.

3.

Create a new listener: expand the Local branch of the navigation tree, highlight Listeners, and click the +
http://asghars.blogspot.com

26

2/10

EXERCISE 5-1 Configure Oracle Net


4. 5. 6.

Enter a listener name, NEWLIST, and click OK Click Add Address For Address 1, choose TCP/IP as the protocol and enter 127.0.0.1 as the host, 2521 as the port

27

http://asghars.blogspot.com

3/10

EXERCISE 5-1 Configure Oracle Net


7.

Create a new service name: highlight Service Naming in the navigation tree, and click the + Enter NEW as the net service name, and click Next Select TCP/IP as the protocol, and click Next

8. 9.

10.

Enter 127.0.0.1 as the host name and 2521 as the port and click Next
Enter SERV1 as the Service Name, and click Next. Click Finish

11.

28

http://asghars.blogspot.com

4/10

EXERCISE 5-1 Configure Oracle Net

12.

Save the configuration by clicking File and Save Network Configuration. This will create the listener.ora and tnsnames.ora files in the TNS_ADMIN directory
http://asghars.blogspot.com

29

5/10

EXERCISE 5-1 Configure Oracle Net


13.

Use an editor to check the two files

30

http://asghars.blogspot.com

6/10

EXERCISE 5-1 Configure Oracle Net


14.

Start the listener with lsnrctl

31

http://asghars.blogspot.com

7/10

EXERCISE 5-1 Configure Oracle Net


15.

From an operating system prompt, test the connect string with tnsping new

16.

Connect to your database using operating system authentication, bypassing any listener

32

http://asghars.blogspot.com

8/10

EXERCISE 5-1 Configure Oracle Net


17.

Set the service_names and local_listener parameters for the running instance and register the new service name with the new listener

33

http://asghars.blogspot.com

9/10

EXERCISE 5-1 Configure Oracle Net


18.

From an operating system prompt, confirm that the new service has registered with the new listener

34

http://asghars.blogspot.com

10/10

EXERCISE 5-1 Configure Oracle Net


19.

Confirm that the new network environment is functional by logging on


system/oracle@new

35

http://asghars.blogspot.com

1/8

Use the Oracle Shared Server Architecture


As more users log on to your instance, more server processes get launched The database listener can launch as many processes as required If you have a large number of concurrent connection requests, your listener will have to queue them up You can avoid this by running multiple listeners on different ports, and load-balancing between them
36 http://asghars.blogspot.com

2/8

Use the Oracle Shared Server Architecture

But your operating system may well have limits on the number of processes that it can support, limits to do with context switches and with memory A computer can only do one thing at once unless it is an SMP machine, in which case each CPU can only do one thing at once The operating system simulates concurrent processing by using an algorithm, often referred to as a time slicing or time-sharing algorithm Context switches are very expensive
37 http://asghars.blogspot.com

3/8

Use the Oracle Shared Server Architecture

As more users connect to the instance, the operating system has to context-switch between more and more server processes There may also be memory problems that occur as more sessions are established The PGA is a block of memory associated with each server process, to maintain the state of the session and as a work area for operations such as sorting rows This is why your system may begin to swap as more users log on
38 http://asghars.blogspot.com

4/8

Use the Oracle Shared Server Architecture

There comes a point, performance begins to degrade because of operating system inefficiencies in managing context switches and paging These are not Oracles problems, but to overcome them Oracle offers the option of the shared server architecture Shared server is implemented by additional processes that are a part of the instance There are two new process types: dispatchers and shared servers
39 http://asghars.blogspot.com

5/8

Use the Oracle Shared Server Architecture


The dispatchers run on a unique TCP port When a user process contacts a listener the listener passes back the address of a dispatcher When a user process issues a SQL statement, it is sent to the dispatcher The dispatcher puts all the statements it receives onto a queue This queue is called the common queue, because all dispatchers share it All the shared server processes monitor the common queue
40 http://asghars.blogspot.com

6/8

Use the Oracle Shared Server Architecture

From then execution proceeds through the usual parse-bind-execute cycle, but when it comes to the fetch phase the shared server puts the result set onto a response queue that is specific to the dispatcher that received the job Each dispatcher monitors its own response queue, and whenever any results are put on it, the dispatcher will pick them up and fetch them back to the user process that originally issued the statement The state of the session is maintained in SGA
41 http://asghars.blogspot.com

7/8

Use the Oracle Shared Server Architecture

The memory used in the SGA for each shared server session is known as the user global area (UGA) and includes all of what would have been in a PGA with the exception of the sessions stack space Shared server configuration needs two set dispatchers and shared_servers parameters shared_servers controls the number of shared servers that will be launched at instance startup time
42 http://asghars.blogspot.com

8/8

Use the Oracle Shared Server Architecture

The dispatchers parameter controls how many dispatcher processes to launch at instance startup time, and how they will behave To enable the shared server architecture, adjust the two critical parameters as follows:
alter system set dispatchers='(dispatchers=2)(protocol=tcp)'; alter system set shared_servers=20;

43

http://asghars.blogspot.com

1/3

EXERCISE 5-2: Set Up a Shared Server Environment


1. 2.

Continues from Exercise 5-1 Set the dispatchers and shared_servers parameters and register with the listener as follows

44

http://asghars.blogspot.com

2/3

EXERCISE 5-2: Set Up a Shared Server Environment


3.

Confirm that the dispatchers and shared servers have started by querying the view V$PROCESS. Look for processes named S000, S001, S002, S003, D000, and D001: From an operating system prompt, confirm that the dispatchers have registered with the listener

4.

45

http://asghars.blogspot.com

3/3

EXERCISE 5-2: Set Up a Shared Server Environment

46

http://asghars.blogspot.com

You might also like