Upload
mrnbd
View
214
Download
0
Embed Size (px)
Citation preview
7/28/2019 Oracle Database Connectivity
1/8
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 listenersOracle 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)
Oracle Database Connectivity http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm
1 of 8 02/03/2013 4:58 PM
7/28/2019 Oracle Database Connectivity
2/8
To connect to a oracle service you would use a connect string
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
Listener
Oracle listener only runs on the server and listens for incoming client connections, a utility called is used to manage the listener process. The listeners
role is
The database registers information about the services, instances and service handlers with the listenerThe 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.
Dynamically register the defaultlistener
1. Register the default listener to the instance
# 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
Dynamically register a non-defaultlistener
1. Create the listener (use Net Manager)
2. Create the Net Service name (Use Net Configuration Assistant)3. Register the service with the instance
# 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 can be used to manage the listener
starting lsnrctl start
Oracle Database Connectivity http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm
2 of 8 02/03/2013 4:58 PM
7/28/2019 Oracle Database Connectivity
3/8
stopping lsnrctl stop
status lsnrctl status
Reloading configuration lsnrctl reload
Display Services lsnrctl services
Save the configuration lsnrctl save_configSet tracing ON lsnrctl trace
Help lsnrctl help
Number of set/showcommands
current_listener
displaymode
inbound_connection_timeout
logstatus
log_file
log_directory
trc_leveltrc_file
trc_directory
password
An example listener.ora file
listener.ora
# 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))
)
)
Naming and Connectivity
Oracle Database Connectivity http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm
3 of 8 02/03/2013 4:58 PM
O l D b C i i h // d di k k/h l d / l / i i h
7/28/2019 Oracle Database Connectivity
4/8
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 lineUse third party naming services to resolve service names i.e. NIS
centralized LDAP-compliant directory server to resolve service names
Host Namingc:\> sqlplus vallep/secret@laptop
Note: DNS will resolve the laptop name
Easy Connectc:\> sqlplus vallep/secret@laptop:1522/P01
c:\> sqlplus vallep/secret@//laptop/P01
Local Naming
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
The sqlnet.ora file specifies which order to try (bit like the nsswitch.conf file in unix)
sqlnet.oraNAMES.DIRECTORY_PATH=(TNSNAMES,EZCONNECT,HOSTNAME)
NAMES.DEFAULT_DOMAIN=DATADISK.CO.UK
File locations
adaptors $oracle_home/bin/adapters
listener $oracle_home/network/admin/listener.ora
tnsnames $oracle_home/network/admin/tnsnames.ora
sqlnet $oracle_home/network/admin/sqlnet.ora
Oracle Database Connectivity http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm
4 of 8 02/03/2013 4:58 PM
Oracle Database Connectivity http://www datadisk co uk/html docs/oracle/connectivity htm
7/28/2019 Oracle Database Connectivity
5/8
listener log $oracle_home/network/log.listener.log
server tracing $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:
Oracle Database Connectivity http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm
5 of 8 02/03/2013 4:58 PM
Oracle Database Connectivity http://www datadisk co uk/html docs/oracle/connectivity htm
7/28/2019 Oracle Database Connectivity
6/8
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.
MAX_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 peak load
Add dispatcher processes while Oracle is running with the SET option of the ALTERSYSTEM 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
Setup Dispatchers
# 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
Oracle Database Connectivity http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm
6 of 8 02/03/2013 4:58 PM
Oracle Database Connectivity http://www datadisk co uk/html docs/oracle/connectivity htm
7/28/2019 Oracle Database Connectivity
7/8
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
Shared Server
# alter system set shared_servers = 5;# alter system set shared_server_sessions = 2;
# alter system set max_shared_server = 20;
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 # alter system set circuit = 300;Useful Views
V$DISPATCHER displays information about the dispatcher processes
V$DISPATCHER_CONFIG displays information about the dispatcher configurations and their attributes
V$DISPATCHER_RATE displays rate statistics for a number of activities performed by the dispatcher processes
V$QUEUE contains information on the shared server message queues
V$SHARED_SERVER contains information on the shared server processes
V$SHARED_SERVER_MONITORcontains information for tuning the shared server
V$CIRCUIT contains information about virtual circuits, which are user connections to the database through dispatchers and servers
V$SESSION lists session information for each current session
Useful SQL Code
List the dedicated serverprocesses
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
List the dispatchers Select * from v$dispatcher;
List the shared serverprocesses
select count(*) "Shared Server processes"
from v$shared_server
where status != 'QUIT';
Display average wait time per
request
SELECT DECODE(TOTALQ, 0, 'No Requests',WAIT/TOTALQ || ' HUNDREDTHS OF SECONDS')
"AVERAGE WAIT TIME PER REQUESTS" FROM V$QUEUE WHERE TYPE = 'COMMON';
Oracle Database Connectivity http://www.datadisk.co.uk/html_docs/oracle/connectivity.htm
7 of 8 02/03/2013 4:58 PM
Oracle Database Connectivity http://www.datadisk.co.uk/html docs/oracle/connectivity.htm
7/28/2019 Oracle Database Connectivity
8/8
Display levels and maximumlevels
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.
O ac e atabase Co ect v ty ttp://www.datad s .co.u / t _docs/o ac e/co ect v ty. t
8 of 8 02/03/2013 4:58 PM