Oracle Instant Client,tnsping,tnsnames.ora and Oracle_home

Source: Internet
Author: User
Tags echo command sqlplus

The previous time to connect to the Oracle database remotely, but do not want to complete the installation of OracleClient on their own computer, so to the Oracle website to download the lightweight Clientinstant client.

This thing does not have a graphical interface, all rely on sqlplus remote connection server, so does not occupy the place, just satisfies me to pursue "simple is good" the obsessive-compulsive patient demand.

However, it may be that the server did not open the monitoring port, I tried various configurations on my own machine, including Tnsnames.ora,sqlnet.ora, and so on, the remote connection failed. To troubleshoot the problem. I first ping the server's network address, found that no problem. Online said, light ping is not enough, but also to tnsping a bit.

Tnsping, just look at the name. It also seems to be one of the pings. However, this tool is only included in the complete Oracle client. Let's say you installed the instant client. You cannot use tnsping.

I just use the instant client, isn't it tragic? It's just that. After I went to the Otn community to stroll around. I find tnsping is not so magical. there is a post on the OTN community that tells Tnsping very thoroughly. I'm going to repeat it here. the original posts in https://community.oracle.com/thread/2434899?

Start=0&tstart=0, interested to be able to look down.

What tnsping can do is to open a socket connection by reading the host and port parameters from the TNS connection string. Then send a ping to the listener. The listener responds with a pong. Tnsping cannot allow the other parameters in the TNS connection string to take effect, and the availability of the DB instance and database service cannot be determined. It is also not possible to determine whether the parameters such as Sid, Service_Name, or instance_name are valid. Visible. Tnsping has never been such a high-end tool, so many people use it to test the TNS connection string, which is just rotten.

Instant client does not have tnsping tools? It doesn't matter. Because you can use Telnet

The front has been saying that Tnsping reads host and port parameters. Here's the question: Where are these numbers? To solve the problem, you have to mention a critical configuration file: Tnsnames.ora.

Tnsnames.ora is a configuration file that defines the various addresses that are required to establish a connection to a database.

Assuming you have installed the full OracleClient, the configuration file should be located under the Oracle_home\network\admin folder. Its forms such as the following:

<addressname> = (DESCRIPTION = (   address_list = (     ADDRESS = (PROTOCOL = TCP) (Host = 

a complete tnsnames.ora Demo sample is as follows:

ORA11 = (DESCRIPTION = (    address_list = (     ADDRESS = (PROTOCOL = TCP) (HOST = 127.0.0.1) (PORT = 1521))   (Conne Ct_data =   (service_name = ORA11)))

of course. Suppose you install the instant client, this file does not exist, but you can completely build a Tnsnames.ora in a specific folder. tNsnames.ora has one copy on both the client and server side. I took part in the Http://orafaq.com/wiki/Tnsnames.ora, which has more specific instructions. So, what did Tnsnames.ora do?

In fact. This configuration file is a bit like the hosts file inside our computer.

This file is actually a configuration file, the role is to use some of the domain name and its IP address frequently used to map, when you enter a Web address in the browser domain name, press ENTER, the system first voluntarily from the hosts file to look for the IP address of the domain name, find the address of the corresponding Web page If the corresponding IP address is not found, the system submits the URL to the DNS domain name resolution server and the server resolves the corresponding IP address .

The Hosts file resolves the memory-friendly URLs to IP addresses, and tnsnames.ora the easy-to-remember TNS aliases to the connection strings. The format of the connection string is typically "(discription= (address=<address details>) (Connect_data=<database details>)".

A sample of the tnsnames.ora shown above is compared to the example shown above. It can be seen that the Tnsnames.ora actually includes this so-called connection string. So, when you use the Sqlplus telnet database, you can have two ways.

One way is to completely write out the connection string, for example, as seen here:

Sqlplus Scott/[email protected] "(Description= (address= (protocol=tcp) (host=my-dev.mydomain.com) (port=1521)) ( Connect_data= (Sid=orcldev) (server=dedicated))) "

Another is to write the TNS alias directly, taking the Tnsnames.ora given above as an example:

Sqlplus Scott/[email protected]
Obviously, the other way is simpler. Especially when you need to log in to the database frequently. With the configuration file will undoubtedly make your efficiency greatly improved, this principle is like you to compile convenient and write makefile file is the same.

As I said earlier, suppose you installed the instant client without the Tnsping tool. It's okay, you just have to be clear about what tnsping is.

In fact, it only does three things: 1. Suppose you specify a TNS alias, which resolves the alias to a connection string (skip this step if you use the full connection string directly when you log in), 2. Based on the host parameter of the connection string, test the IP address of the listener you want to connect to. 3. based on the port parameter of the connection string, test the corresponding port of the listener you want to connect to.

Obviously, except for the 1th thing. 2nd, you can use Telnet

Instant client also has an inconvenient place, mentioned just now, that is, it does not bring the Tnsnames.ora file. Just as I said earlier, you can build a tnsnames.ora file yourself.

So. How does the Oracle client find this file? This will require you to add an environment variable named Tns_admin to save the Tnsnames.ora address. The system will find the corresponding Tnsnames.ora file according to the address given by this variable .

Finally, briefly oracle_home. This variable represents the installation folder of Oracle and can also represent an environment variable pointing to the Oracle installation folder.

Under Windows. If you want to see the current oracle_home, you can use the echo command. To add or set the ORFACLE_HOME environment variable, you can use the SET command. Of course, Oracle_home can also be found in the registration form, where the hkey_local_machine\software\oracle may be located.

More detailed content can be included in the Http://orafaq.com/wiki/ORACLE_HOME.

Oracle Instant Client,tnsping,tnsnames.ora and Oracle_home

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.