官术网_书友最值得收藏!

Local database connections

Establishing a connection locally means running the SQL command-line utility on the same computer where Oracle Database 11g XE is installed, and initiating a database connection command using the valid database credentials.

The following screenshot is taken from Oracle Database 11g XE on Windows, and demonstrates establishing a local database connection to the database:

Local database connections

Navigate to the Oracle Database 11g XE database home and start the sqlplus session with the /nolog option. Using the connect statement establish a connection to the database by supplying the valid database username and password. As shown in the preceding screenshot, connect as SYSTEM user with the password entered while installing Oracle Database 11g XE.

ORA_DBA is a local Windows group that gets automatically created when you install Oracle Database XE and your Windows username automatically gets added to this group. Members of ORA_DBA can connect to the Oracle Database XE without a password, as shown in the following screenshot:

Local database connections

Oracle Net Listener

To connect to the database remotely, we should have Oracle Net Listener running on the host where Oracle Database 11g XE is installed. When a remote client initiates a database connection request, this connection request is received by Oracle Net Listener. The job of the listener is to listen to these incoming database connection requests and hand over the connection requests to the appropriate databases.

Thereafter the remote-client connection directly communicates with the database without the need of the listener. Without the listener service running we cannot connect to the database remotely. There may be more than one database running on the host server; however, you will only have one database listener for all incoming requests. Based on the incoming request, Oracle Net Listener will hand over the connection request to the appropriate database.

Oracle Net Listener and the tnsnames.ora files are configured by default when we install Oracle Database 11g XE. The listener's configuration file is located under $ORACLE_HOME\network\admin\listener.ora. Oracle Database XE automatically creates a Windows service for Oracle Net Listener (OracleXETNSListener).

Configuring Oracle Net Listener

listener.ora is the name of the Oracle Net Listener configuration file and it resides under $ORACLE_HOME\network\admin.

The content of a sample listener.ora file in its simplest form is as follows:

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = XE)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = amomen-PC)(PORT = 1521))
)
)

The description of the parameters is as follows:

  • LISTENER: The name of the listener
  • SID_NAME: The Oracle Database name
  • ORACLE_HOME: The Oracle software installation home directory
  • HOST: The name of the host where Oracle Net Listener is running
  • PORT: The port on which Oracle Net Listener is listening to the incoming requests

Make the necessary changes to the preceding parameters, save the file, and restart the Windows Oracle Listener service OracleXETNSListener.

Viewing the status of Oracle Net Listener

Navigate to Oracle home ($ORACLE_HOME\bin), start the listener utility (lsnrctl), enter status as shown in the following screenshot, and hit Enter.

If the listener is not started, the command displays an error message, as shown in the following screenshot:

Viewing the status of Oracle Net Listener

If the listener is running, the command displays detailed listener information as shown in the following screenshot:

Viewing the status of Oracle Net Listener

Starting and stopping the listener

The listener is automatically configured when we install Oracle Database 11g XE.

  • To stop the listener on Windows, launch the Services window by navigating to Start | Control Panel | Administrative Tools | Services and stop the OracleXETNSListener service, or launch the listener utility (lsnrctl) and enter the LSNRCTL> stop command. To stop the listener on Linux, within the listener utility (lsnrctl) enter the stop command as we did in the Windows environment.
  • To start the listener on Windows, launch the Services window by navigating to Start | Control Panel | Administrative Tools | Services and start the OracleXETNSListener service, or launch the listener utility (lsnrctl) and enter the LSNRCTL> start command. To start the listener on Linux, within the listener utility (lsnrctl) enter the start command as we did in Windows environment.

Configuring the tnsnames.ora file

Transparent Network Susbstrate (TNS) handles all remote database connections. Oracle software reads the TNS connection string to understand how to connect to the remote databases. Every Oracle database and the Oracle Client software will have this file. By default the tnsnames.ora file is located under $ORACLE_HOME\network\admin. A sample alias entry from the tnsnames.ora file is as follows:

MY_XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = amomen-PC)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = XE)
)
)

In the preceding code:

  • MY_XE is an alias name. You can name it anything you like.
  • HOST is the hostname or IP-Address where database is running.
  • PORT is the port number on which Oracle Net Listener is listening.
  • SID is the Oracle database name.

When connecting to the remote database, we will use my_xe as a connect string.

主站蜘蛛池模板: 隆德县| 山东省| 崇州市| 雷州市| 辰溪县| 颍上县| 上栗县| 木里| 四子王旗| 柳州市| 会昌县| 塘沽区| 梓潼县| 靖西县| 怀仁县| 宁南县| 绍兴市| 江油市| 右玉县| 广州市| 通海县| 邢台县| 安乡县| 师宗县| 龙江县| 吉首市| 呼图壁县| 彭水| 祁门县| 佛山市| 武威市| 蛟河市| 刚察县| 长沙县| 贵阳市| 鹤庆县| 巴彦县| 庆阳市| 德钦县| 旬阳县| 武邑县|