Oracle Net Services -- Listeners and Service Names In EM from Home Database Page click on the Listener link and then Related LinksNet Service AdministrationAdminister drop down list and choose ListenersGoCreate (if you already saved your credentials for “oracle” and “password”, otherwise you must provide them on the Login Page) Enter LISTENER2 as Listener Name and click on Add for the Address, then provide the following 3 components for Protool, Port# and Host Name TCP/IP 1522 localhost Then click on the Static Database Registration link and then on Add for the Service Name and then provide the following 3 components for Service Name, Oracle Home Directory and Oracle SID and click OK dborcl /opt/oracle/11.2.0.0.0/ dborcl Then go to the Net Service AdministrationAdminister drop down list and choose Local Naming GoCreate (if you already saved your credentials for “oracle” and “password”, otherwise you must provide them on the Login Page) Enter TEST as Net Service Name (Alias), choose Use Service Name option and enter dborcl, then choose Dedicated Server option and click Add for the Address, then provide the following 3 components for Protool, Port# and Host Name and click OK TCP/IP 1521 localhost Finally,choose only Load Balancing option, but NOT Failover (Button # 3) and click OK You should have a situation like shown on the picture below Create Net Service Name General Advanced * Net Service Name TEST Database Information To identify the database or service, you must provide either its service name (recommended) or the Oracle System Identifer (SID). The service name is normally its global database name, a name comprising the database name and domain name. Use Service Name Service Name dborcl Use SID SID Choose if you want a shared or dedicated server database connection. Database Default Requests will be served by whatever database default is. Dedicated Server Requests will be served by dedicated server. Shared Server Request will be served by shared server. Addresses / Reorder Select Protocol TCP/IP Move To Top Protocol Details Host localhost Port 1521 Connect-time Failover and Client Load Balancing Configure whether addresses are tried randomly or sequentially during connections to the service. This setting is applicable only if there are more than one addresses configured. Try each address, in order, until one succeeds Try each address randomly, until one succeeds Try one address, selected at random Use each address in order until destination is reached Use only the first address * In Linux check that Net Configuration Files have been updated: for Listener actions is listener.ora and for Local Naming is tnsnames.ora * oracle@localhost:~> pwd /home/oracle oracle@localhost:~> cd $ORACLE_HOME/network/admin * This is place to hold Net Configuration files * oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> ls -l total 32 -rw-r--r-- 1 oracle oinstall 299 2011-02-17 13:59 listener1102171PM5953.bak -rw-r--r-- 1 oracle oinstall -rw-r--r-- 1 oracle oinstall -rw-r--r-- 1 oracle oinstall -rw-r--r-- 1 oracle oinstall -rw-r--r-- 1 oracle oinstall -rw-r----- 1 oracle oinstall 299 2011-02-17 14:00 listener1102172PM0035.bak 700 2011-02-17 14:15 listener.ora 187 2007-05-09 14:59 shrept.lst 315 2011-02-17 13:59 tnsnames1102171PM5953.bak 315 2011-02-17 14:00 tnsnames1102172PM0035.bak 546 2011-02-17 14:42 tnsnames.ora * Observe how the content of these two files has changed related to your work in EM * oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> cat listener.ora # listener.ora Network Configuration File: /opt/oracle/11.2.0.0.0/network/admin/listener.ora # Generated by Oracle configuration tools. TRACE_LEVEL_LISTENER2 = OFF LISTENER2 = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) ) ) ) LOGGING_MY_LISTENER = OFF SID_LIST_LISTENER2 = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = dborcl) (SID_NAME = dborcl) (ORACLE_HOME = /opt/oracle/11.2.0.0.0/) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /opt/oracle oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> cat tnsnames.ora # tnsnames.ora Network Configuration File: /opt/oracle/11.2.0.0.0/network/admin/tnsnames.ora # Generated by Oracle configuration tools. TEST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (LOAD_BALANCE = yes) (FAILOVER = false) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dborcl) ) ) DBORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dborcl) ) ) oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> lsnrctl LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 22-FEB-2011 13:34:05 Copyright (c) 1991, 2009, Oracle. All rights reserved. Welcome to LSNRCTL, type "help" for information. LSNRCTL> set cur listener2 This command declares default listener for command line Current Listener is my_listener LSNRCTL> start Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=15 31))) STATUS of the LISTENER -----------------------Alias LISTENER2 Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 17-FEB-2011 14:15:40 Uptime 0 days 0 hr. 0 min. 2 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /opt/oracle/11.2.0.0.0/network/admin/listener.ora Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1522))) Services Summary... Service "dborcl" has 1 instance(s). Instance "dborcl", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully LSNRCTL> exit oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on Tue Feb 22 13:34:55 2011 Copyright (c) 1982, 2009, Oracle. All rights reserved. SQL> conn sys as sysdba Enter password: Connected. SQL> SET PAGESIZE 200 SQL> SELECT instance_name, host_name FROM V$INSTANCE; INSTANCE_NAME ---------------HOST_NAME ---------------------------------------------------------------dborcl localhost.localdomain SQL> CONN SCOTT/TIGER; Password is case sensitive ERROR: ORA-01017: invalid username/password; logon denied Warning: You are no longer connected to ORACLE. SQL> CONN scott/tiger; Connected. * This connection is over the default protocol TCP and default Port 1521-- it uses LISTENER* SQL> conn scott/tiger@localhost:1521/dborcl Connected. SQL> conn scott/tiger@localhost/dborcl Connected. * Both these connections were with EASY METHOD, where we must submit HOST NAME and SERVICE NAME, but Port# may be skipped (if it is default value 1521) * SQL> conn scott/tiger@localhost ERROR: ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA * We did NOT provide SERVICE NAME, which is mandatory with EASY METHOD * SQL> conn scott/tiger@localhost:1522/dborcl ERROR: ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Linux Error: 2: No such file or directory Process ID: 0 Session ID: 0 Serial number: 0 * Easy method did NOT work -- it should use LISTENER2 on Port 1522. It is explained later how can we use different Port# than the default one * SQL> conn scott/tiger@test Connected. * So, our TEST alias for Service dborcl works – it uses LISTENER * SQL> host oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> lsnrctl LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 22-FEB-2011 13:42:17 Copyright (c) 1991, 2009, Oracle. All rights reserved. Welcome to LSNRCTL, type "help" for information. LSNRCTL> stop listener Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))) The command completed successfully LSNRCTL> status listener Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 111: Connection refused LSNRCTL> exit oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> exit exit SQL> conn scott/tiger ERROR: ORA-12541: TNS:no listener SQL> conn scott/tiger@test ERROR: ORA-12541: TNS:no listener * Well, without LISTENER running, we can NOT use Default connection or TEST alias * LSNRCTL> host lsnrctl start listener Starting /opt/oracle/11.2.0.0.0/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.1.0 - Production System parameter file is /opt/oracle/11.2.0.0.0/network/admin/listener.ora Log messages written to /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=152 1))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))) STATUS of the LISTENER -----------------------Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 17-FEB-2011 14:25:28 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /opt/oracle/11.2.0.0.0/network/admin/listener.ora Listener Log File /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=152 1))) The listener supports no services The command completed successfully Then go to the Net Service AdministrationAdminister drop down list and choose Local Naming GoCreate (if you already saved your credentials for “oracle” and “password”, otherwise you must provide them on the Login Page) Enter LEMON as Net Service Name (Alias), choose Use Service Name option and enter dborcl, then choose Dedicated Server option and click Add for the Address, and provide the following 3 components for Protool,Port# and Host Name and click OK TCP/IP 1522 localhost Then ,choose both Load Balancing and Failover options (Button # 2) and click OK Finally, click on Local Naming link,choose TEST alias and click on Edit and then Add for the Address, and provide the following 3 components for Protool,Port# and Host Name and click OK TCP/IP 1522 localhost and again OK. * Inspect how your client (local) networking configuration file has changed * SQL> host oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> cat tnsnames.ora # tnsnames.ora Network Configuration File: /opt/oracle/11.2.0.0.0/network/admin/tnsnames.ora # Generated by Oracle configuration tools. LEMON = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) (LOAD_BALANCE = yes) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dborcl) ) ) TEST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) (LOAD_BALANCE = yes) (FAILOVER = false) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dborcl) ) ) DBORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dborcl) ) ) oracle@localhost:/opt/oracle/11.2.0.0.0/network/admin> exit exit SQL> CONN scott/tiger@test ERROR: ORA-12154: TNS:could not resolve the connect identifier specified Warning: You are no longer connected to ORACLE. * We have two options to fix this problem related to our tnsnames.ora file 1) Remove the SECOND address with non-default Port# from the TEST entry OR 2) Go with just FAILOVER option (Button #1) or Both FAILOVER and LOAD BALANCE options (Button #2), because it uses currently just randomly LB option (Button #3) and fails when it tries to go over Port# 1522. Let’s switch to Button #1 – just FAILOVER option.* In EM click on Local Naming link,choose TEST alias and click on Edit and then choose only Failover option (Button # 1) and click OK You should have a situation like shown on the picture below Edit Net Service Name: test General Advanced * Net Service Name test Database Information To identify the database or service, you must provide either its service name (recommended) or the Oracle System Identifer (SID). The service name is normally its global database name, a name comprising the database name and domain name. Use Service Name Service Name dborcl Use SID SID Choose if you want a shared or dedicated server database connection. Database Default Requests will be served by whatever database default is. Dedicated Server Requests will be served by dedicated server. Shared Server Addresses Reorder Move To Top Select Protocol TCP/IP TCP/IP Host Port Host Port Protocol Details localhost 1521 localhost 1522 Connect-time Failover and Client Load Balancing Configure whether addresses are tried randomly or sequentially during connections to the service. This setting is applicable only if there are more than one addresses configured. Try each address, in order, until one succeeds Try each address randomly, until one succeeds Try one address, selected at random Use each address in order until destination is reached Use only the first address * Inspect how your client networking configuration file has changed for TEST entry * TEST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dborcl) ) ) SQL> conn scott/tiger@test Connected. * Well, we fixed the problem for the TEST alias * SQL> conn scott/tiger@lemon ERROR: ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Linux Error: 2: No such file or directory Process ID: 0 Session ID: 0 Serial number: 0 * Well, listening on non-default Port# 1522 does NOT work and can NOT resolve Service Name LEMON into Connect Descriptor. So, we need to fix the parameter called LOCAL_LISTENER to point to that Port * SQL> CONN SYS AS SYSDBA Enter password: Connected. SQL> show parameter local NAME TYPE VALUE ------------------------------------ ----------- -----------------------------local_listener string log_archive_local_first boolean TRUE parallel_force_local boolean FALSE SQL> ALTER SYSTEM SET LOCAL_LISTENER='listener2'; ALTER SYSTEM SET LOCAL_LISTENER='listener2' 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 'listener2' * In some LINUX versions this command will NOT work, although recommended by Oracle. But, we may specify the THREE DIRECT values for this parameter * SQL> ALTER SYSTEM SET LOCAL_LISTENER='(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))'; System altered. SQL> ALTER SYSTEM REGISTER; System altered. SQL> conn scott/tiger@lemon Connected. SQL> conn scott/tiger@localhost:1522/dborcl Connected. SQL> SELECT * FROM TAB; TNAME TABTYPE CLUSTERID ------------------------------ ------------ --------------------- BONUS DEPT EMP SALGRADE TABLE TABLE TABLE TABLE * Well, we fixed our problem of listening on non-default Port# 1522. So, both LEMON alias (that uses only that Port) and EASY METHOD with that Port will work now * SQL> conn scott/tiger@test Connected. * It uses now the SECOND address with Port# 1522 for the TEST entry * SQL> conn scott/tiger Connected. * Default connection over TCP and Port# 1521 always works if the Client shares the machine with the Server (so called Loopback connection) SQL> conn scott/tiger@dborcl ERROR: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor Warning: You are no longer connected to ORACLE. * It can NOT use the FIRST address with Port# 1521 for the DBORCL entry. Let’s revert to our REGULAR listening situation on Port# 1521 * SQL> conn sys as sysdba Enter password: Connected. SQL> ALTER SYSTEM SET LOCAL_LISTENER='(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))'; System altered. SQL> ALTER SYSTEM REGISTER; System altered. SQL> SHOW PARAMETER LOCAL NAME TYPE VALUE ------------------------------------ ----------- -----------------------------local_listener string (ADDRESS = (PROTOCOL = TCP) (HOST = localhost)(PORT = 1521)) log_archive_local_first boolean TRUE parallel_force_local boolean FALSE SQL> conn scott/tiger@dborcl Connected. * Our revert to default Port# 1521 was Success * SQL> conn scott/tiger@lemon ERROR: ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Linux Error: 2: No such file or directory Process ID: 0 Session ID: 0 Serial number: 0 Warning: You are no longer connected to ORACLE. SQL> conn scott/tiger@localhost:1522/dborcl ERROR: ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Linux Error: 2: No such file or directory Process ID: 0 Session ID: 0 Serial number: 0 * After reverting to the default listening Port# 1521, resolving the Service Name into Connect Descriptor can NOT work over Port# 1522 anymore *