Oracle Database Connectivity

Published on July 2016 | Categories: Documents | Downloads: 35 | Comments: 0 | Views: 105
of 8
Download PDF   Embed   Report

Comments

Content

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

Oracle Connectivity
Oracle provides Oracle Net Services which is a suite of components that provides a connectivity solution. Oracle Net Service consist of Oracle Net - software component that initiates, establishes and maintains connections between client and servers, it contains two components responsible for establishing and maintaining connections - responsible for mapping Transparent Network Substrate (TNS) Oracle Net Listener - Listens for incoming requests from users Oracle Connection Manager - GUI based utility Oracle Net Configuration Assistant - GUI based utility , configure network components Oracle Net Manager - GUI based utility, configures various naming methods and listeners Oracle Enterprise Manager - can do everything Database Service Name Databases logically appear as services, you identify each database in your system by its service name. The database instance name refers to the SGA and processes that make up the instance, this is commonly referred as the Oracle System Identifier (SID), normally a database is only associated with one instance apart from when using a RAC environment. You can uniquely identify each database by using a global database name which is in the format of database_name.database_domain (sales.us.acme.com). Connection You need two pieces of information to connect to a database Name of the database server - name of the service that oracle is supplying Location of the address - need to supply the protocol type (default TCP) , hostname and the port number (default 1521) Oracle supports a number of protocols TCP, SDP, TCP with secure sockets and named pipes. There are two ways to connect to oracle dedicated or Shared Server, both could be running at the same time on the same server. There are 4 connection types Dedicated - direct handoff (client and server are on the same computer) Dedicated - redirect (client and server are on different computers) Shared server - direct handoff (client and server are on the same computer) Shared server - redirect (client and server are on different computers)

1 of 8

02/03/2013 4:58 PM

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

To connect to a oracle service you would use a connect string
connect scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sales)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=sales.us.acme.com))) connect scott/tiger@sales

Connect String

Listener Oracle listener only runs on the server and listens for incoming client connections, a utility called role is is used to manage the listener process. The listeners

The database registers information about the services, instances and service handlers with the listener The client makes the initial connection with the listener The listener receives and verifies the connection and forwards it to the service handler, once the listener hands off the request, the listener is out of the picture. The listener.ora file contains the listener configuration details, with oracle 10g the listener can automatically register itself with the database, The PMON process updates the listener.ora file with any new databases.
1. Register the default listener to the instance

Dynamically register the default listener

# alter system set instance_name = P01; # alter system set service_name = P01; Note: port 1521 is assumed, you do not need to update the listener.ora file

1. Create the listener (use Net Manager) 2. Create the Net Service name (Use Net Configuration Assistant) 3. Register the service with the instance

Dynamically register a non-default listener

# alter system set local_listener = 'P01_1522'; # alter system register; Note: you need to update the listener.ora and tnsnames.ora files

The listener utility
starting

can be used to manage the listener
lsnrctl start

2 of 8

02/03/2013 4:58 PM

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

stopping status Reloading configuration Display Services Save the configuration Set tracing ON Help

lsnrctl stop lsnrctl status lsnrctl reload lsnrctl services lsnrctl save_config lsnrctl trace lsnrctl help current_listener displaymode inbound_connection_timeout logstatus log_file log_directory trc_level trc_file trc_directory password

Number of set/show commands

An example listener.ora file
# listener.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = C:\oracle\product\10.2.0\db_1) (PROGRAM = extproc) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = laptop)(PORT = 1521)) ) )

listener.ora

Naming and Connectivity

3 of 8

02/03/2013 4:58 PM

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

Oracle also several types of naming services - uses a file called tnsnames.ora on the client uses host file or DNS to resolve hostname, you must use TCP. can supply the service information on the command line Use third party naming services to resolve service names i.e. NIS centralized LDAP-compliant directory server to resolve service names
c:\> sqlplus vallep/secret@laptop

Host Naming
Note: DNS will resolve the laptop name

Easy Connect

c:\> sqlplus vallep/secret@laptop:1522/P01 c:\> sqlplus vallep/secret@//laptop/P01 Add an entry in the tnsnames.ora file P01 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = laptop)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = P01) ) ) Note:can use the TNS_ADMIN environment variable to point to different tnsnames.ora files

Local Naming

The sqlnet.ora file specifies which order to try (bit like the nsswitch.conf file in unix)
sqlnet.ora
NAMES.DIRECTORY_PATH=(TNSNAMES,EZCONNECT,HOSTNAME) NAMES.DEFAULT_DOMAIN=DATADISK.CO.UK

File locations
adaptors listener tnsnames sqlnet $oracle_home/bin/adapters $oracle_home/network/admin/listener.ora $oracle_home/network/admin/tnsnames.ora $oracle_home/network/admin/sqlnet.ora

4 of 8

02/03/2013 4:58 PM

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

listener log server tracing

$oracle_home/network/log.listener.log $oracle_home/network/trace/listener.trc

Dedicated Connection Oracle will create a new process when you log on, this is commonly know as the dedicated server process, the process will exists as long as the connection exists. For every session a new dedicated server process will be created. This process will receive SQL and execute it, read data files and look in the database cache for data. It will also perform update statements and run any PL/SQL code. The flow of this process is seen below:

Shared Server Connection The big difference between dedicated and shared server is that the client process never talks directly to the shared server process. Oracle employs a process called dispatcher which will put clients requests into a request queue in the SGA (1), the first shared server process that is not busy will pick up the request and process it (2), upon completion the shared server will place the response in the response queue (3). The dispatcher process is monitoring this queue and upon seeing a result, will transmit it to the client (4), the flow of this action is seen below:

Normally one shared server process should be able to handle between 10-20 users. A dispatcher should be able to handle about 100 shared server processes. A good rule to thumb when setting the parameter values (pfile or spfile) should be the following:

5 of 8

02/03/2013 4:58 PM

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

SHARED_SERVERS

should be set for slightly greater than the expected number of shared servers that will be needed when the database is at an average load. should be set for slightly greater than the expected number of shared servers that will be needed when the database is at an peak load

MAX_SHARED_SERVERS

Add dispatcher processes while Oracle is running with the SET option of the ALTER SYSTEM statement to increase the value for the DISPATCHERS initialization parameter. The total number of dispatcher processes is limited by the value of the initialization parameter MAX_DISPATCHERS. You might need to increase this value before adding dispatcher processes. The default value of this parameter is five, and the maximum value varies depending on your operating system The big picture The following diagram details what we have seen before, connection via shared server and dedicated server. It also shows that an Oracle instance may use both connections type simultaneously:

A circuit is a piece of shared memory that the client connections are bound to during communications it is called a virtual circuit. The background process PMON notifies the listener as to which dispatcher is responsible for servicing each virtual circuit. This information is supplied when you run "lsnrctl services" and has 4 values and .
Connectivity Setup
# alter system set dispatchers="(protocol=TCP)(dispatchers=2)"; # alter system set dispatchers="(protocol=IPC)(dispatchers=2)"; # alter system set dispatchers="(protocol=TCP)(dispatchers=2)(pool=on)(tick=1)(connections=500)(sessions=1000)"; # alter system set max_dispatchers = 10; pool - provides connection pooling

Setup Dispatchers

6 of 8

02/03/2013 4:58 PM

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

tick - number of 10 minute intervals of inactivity for a connection to be considered idle connections - maximum number of concurrent sessions sessions - maximum number of sessions per dispatcher listener - address of listener to which PMON sends info to when listener is non-local and the

is not set

# alter system set shared_servers = 5; # alter system set shared_server_sessions = 2; # alter system set max_shared_server = 20;

Shared Server

shared_servers - the system will initially start this many (default = 1) shared_server_sessions - maximum number of shared server sessions max_shared_server - shared servers will grow to this limit Note: If at anytime you get ORA-00018 errors (Logging in or EM reports this error) this is because "shared_server_sessions" has been set too low

Circuits V$DISPATCHER V$DISPATCHER_CONFIG V$DISPATCHER_RATE V$QUEUE V$SHARED_SERVER V$CIRCUIT V$SESSION

# alter system set circuit = 300;

Useful Views displays information about the dispatcher processes displays information about the dispatcher configurations and their attributes displays rate statistics for a number of activities performed by the dispatcher processes contains information on the shared server message queues contains information on the shared server processes contains information about virtual circuits, which are user connections to the database through dispatchers and servers lists session information for each current session Useful SQL Code
select a.spid dedicated_server, b.process clientpid from v$process a, v$session b where a.addr = b.paddr and b.audsid = userenv('sessionid') Note: remove the last line for all dedicated processes

V$SHARED_SERVER_MONITOR contains information for tuning the shared server

List the dedicated server processes

List the dispatchers List the shared server processes

Select * from v$dispatcher; select count(*) "Shared Server processes" from v$shared_server where status != 'QUIT'; SELECT DECODE(TOTALQ, 0, 'No Requests',WAIT/TOTALQ || ' HUNDREDTHS OF SECONDS')

Display average wait time per "AVERAGE WAIT TIME PER REQUESTS" FROM V$QUEUE WHERE TYPE = 'COMMON'; request

7 of 8

02/03/2013 4:58 PM

Oracle Database Connectivity

http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm

Display levels and maximum levels

select 'session count from v$session', count(*) from v$session union select 'session utilization from v$resource_limit', current_utilization from v$resource_limit where resource_name = 'sessions';

Best Practices When using shared server make sure that transactions are short in duration, they can be frequent but short, otherwise it will appear to be a total system slowdown due to the shared resources being monopolized by a few processes. So shared server is highly appropriate for an OLTP system (short, frequent transactions). Do not used shared server for data warehousing. So shared server does 3 things for us: Reduces the number of O/S process/threads Allow you to artificially limit the degree of concurrency Reduces the memory needed on the system Unless your system is overloaded, or you need to use shared server ( if you want to talk to a EJB database) then a dedicated server will serve best.

8 of 8

02/03/2013 4:58 PM

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close