在Oracle的网络结构中解决连接问题
最近看到好多人说到tns或者数据库不能登录等问题,就索性总结了下面的文档。 首先来说Oracle的网络结构,往复杂处说能加上加密、LDAP等等。。这里不做讨论,重点放在基本的网络结构也就是我们最常用的这种情况 三个配置文件listener.ora、sqlnet.ora、tnsnam
最近看到好多人说到tns或者数据库不能登录等问题,就索性总结了下面的文档。
首先来说Oracle的网络结构,往复杂处说能加上加密、LDAP等等。。这里不做讨论,重点放在基本的网络结构也就是我们最常用的这种情况
三个配置文件listener.ora、sqlnet.ora、tnsnames.ora ,都是放在$ORACLE_HOME\network\admin目录下。
重点:三个文件的作用和使用
sqlnet.ora-----作用类似于linux或者其他unix的nsswitch.conf文件,通过这个文件来决定怎么样找一个连接中出现的连接字符串,
例如我们客户端输入
sqlplus
假如我的sqlnet.ora是下面这个样子
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES,HOSTNAME)
那么,客户端就会首先在tnsnames.ora文件中找orcl的记录.如果没有相应的记录则尝试把orcl当作一个主机名,通过网络的途径去解析它的ip地址然后去连接这个ip上GLOBAL_DBNAME=orcl这个实例,当然我这里orcl并不是一个主机名
如果我是这个样子
NAMES.DIRECTORY_PATH= (TNSNAMES)
那么客户端就只会从tnsnames.ora查找orcl的记录
括号中还有其他选项,如LDAP等并不常用。
#------------------------
Tnsnames.ora------这个文件类似于unix 的hosts文件,提供的tnsname到主机名或者ip的对应,只有当sqlnet.ora中类似
NAMES.DIRECTORY_PATH= (TNSNAMES) 这样,也就是客户端解析连接字符串的顺序中有TNSNAMES是,才会尝试使用这个文件。
例子中有两个,ORCL 对应的本机,SALES对应的另外一个IP地址,里边还定义了使用主用服务器还是共享服务器模式进行连接,一句一句说
#你所要连接的时候输入得TNSNAME
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
#下面是这个TNSNAME对应的主机,端口,协议
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
#使用专用服务器模式去连接需要跟服务器的模式匹配,如果没有就根据服务器的模式
#自动调节
(SERVER = DEDICATED)
#对应service_name,
SQLPLUS>show parameter service_name;
#进行查看
(SERVICE_NAME = orcl)
)
)
#下面这个类似
SALES =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.188.219)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = sales)
)
)
#----------------------
客户端完了我们来看服务器端
listener.ora------listener监听器进程的配置文件
关于listener进程就不多说了,接受远程对数据库的接入申请并转交给oracle的服务器进程。所以如果不是使用的远程的连接,listener进程就不是必需的,同样的如果关闭listener进程并不会影响已经存在的数据库连接。Listener.ora文件的例子
#listener.ora Network Configuration File: #E:\oracle\product\10.1.0\Db_2\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
#下面定义LISTENER进程为哪个实例提供服务
#这里是ORCL,并且它对应的ORACLE_HOME和GLOBAL_DBNAME
#其中GLOBAL_DBNAME不是必需的除非使用HOSTNAME做数据库连接
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = boway)
(ORACLE_HOME = E:\oracle\product\10.1.0\Db_2)
(SID_NAME = ORCL)
)
)
#监听器的名字,一台数据库可以有不止一个监听器
#再向下面是监听器监听的协议,ip,端口等,这里使用的tcp1521端口,并且使#用的是主机名
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = boway)(PORT = 1521))
)
上面的例子是一个最简单的例子,但也是最普遍的。一个listener进程为一个instance(SID)提供服务。
监听器的操作命令
$ORACLE_HOME/bin/lsnrctl start,其他诸如stop,status等。具体敲完一个lsnrctl后看帮助。
上面说到的三个文件都可以通过图形的配置工具来完成配置
$ORACLE_HOME/netca 向导形式的
$ORACLE_HOME/netmgr
本人比较习惯netmgr,
profile 配置的是sqlnet.ora也就是名称解析的方式
service name 配置的是tnsnames.ora文件
listeners配置的是listener.ora文件,即监听器进程
具体的配置可以尝试一下然后来看一下配置文件。
这样一来总体结构就有了,是当你输入sqlplus 的时候
1. 查询sqlnet.ora看看名称的解析方式,发现是TNSNAME
2. 则查询tnsnames.ora文件,从里边找orcl的记录,并且找到主机名,端口和service_name
3. 如果listener进程没有问题的话,建立与listener进程的连接。
4. 根据不同的服务器模式如专用服务器模式或者共享服务器模式,listener采取接下去的动作。默认是专用服务器模式,没有问题的话客户端就连接上了数据库的server process。
5. 这时候网络连接已经建立,listener进程的历史使命也就完成了。
#---------------
几种连接用到的命令形式
1.sqlplus / as sysdba 这是典型的操作系统认证,不需要listener进程
2.sqlplus sys/oracle 这种连接方式只能连接本机数据库,同样不需要listener进程
3.sqlplus 这种方式需要listener进程处于可用状态。最普遍的通过网络连接。
以上连接方式使用sys用户或者其他通过密码文件验证的用户都不需要数据库处于可用状态,操作系统认证也不需要数据库可用,普通用户因为是数据库认证,所以数据库必需处于open状态。
然后就是
#-------------
平时排错可能会用到的
1.lsnrctl status查看服务器端listener进程的状态
LSNRCTL> help
The following operations are available
An asterisk (*) denotes a modifier or extended command:
start stop status
services version reload
save_config trace change_password
quit exit set*
show*
LSNRCTL> status
2.tnsping 查看客户端sqlnet.ora和tnsname.ora文件的配置正确与否,及对应的服务器的listener进程的状态。C:\>tnsping orcl
TNS Ping Utility for 32-bit Windows: Version 10.1.0.2.0 - Production on 16-8月 -
2005 09:36:08
Copyright (c) 1997, 2003, Oracle. All rights reserved.
Used parameter files:
E:\oracle\product\10.1.0\Db_2\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 127.0.0.1)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_
NAME = orcl)))
OK (20 msec)
3.
SQL>show sga 查看instance是否已经启动
SQL> select open_mode from v$database; 查看数据库是打开还是mount状态。
OPEN_MODE
READ WRITE
#-----------------
使用hostname访问数据库而不是tnsname的例子
使用tnsname访问数据库是默认的方式,但是也带来点问题,那就是客户端都是需要配置tnsnames.ora文件的。如果你的数据库服务器地址发生改变,就需要重新编辑客户端这个文件。通过hostname访问数据库就没有了这个麻烦。
需要修改
服务器端listener.ora
#监听器的配置文件listener.ora
#使用host naming则不再需要tnsname.ora文件做本地解析
# listener.ora Network Configuration File: d:\oracle\product\10.1.0\db_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
# (SID_NAME = PLSExtProc)
(SID_NAME = orcl)
参考:http://wap.thea.cn/zl_846419.html
在Oracle的网络结构中解决连接问题 谷歌

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment