目录
- 1. tnsnames.ora
- 2. Demo
- 3. 实战
1. tnsnames.ora
Oracle 数据库网络配置文件,用于配置客户端与数据库服务器之间的连接
定义网络服务名称,客户端可以使用这些名称连接到数据库实例
基本的路径如下:
- Windows:
ORACLE_HOME\network\admin
- Unix/Linux:
$ORACLE_HOME/network/admin
基本的结构如下:
net_service_name =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = protocol)(HOST = hostname)(PORT = port)))(CONNECT_DATA =(SERVICE_NAME = service_name)))
-
net_service_name
:客户端连接时使用的服务名称 (ORCL, SALESDB) -
DESCRIPTION
:描述网络连接信息的主要部分(ADDRESS_LIST, CONNECT_DATA) -
ADDRESS_LIST
:(包含一个或多个 ADDRESS,用于定义主机和端口信息,提供故障转移和负载均衡)
(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost1)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost2)(PORT = 1521))
)
ADDRESS
:指定数据库服务器的网络地址
PROTOCOL
:通信协议,常见的是 TCPHOST
:数据库服务器的主机名或 IP 地址PORT
:数据库监听程序的端口号
CONNECT_DATA
: 指定连接到数据库实例的相关信息
SERVICE_NAME
:数据库服务名,通常是数据库实例的全局名。SID
:系统标识符,数据库实例的唯一标识。INSTANCE_NAME
:实例名称,通常用于 RAC(Real Application Clusters)环境SERVER
: 服务器类型,可以是 DEDICATED(专用服务器)或 SHARED(共享服务器)
2. Demo
更多的Demo可以参考官网:tnsnames.ora 参数设置
以下给一些示例:
示例 1: 简单连接
ORCL =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost)(PORT = 1521))(CONNECT_DATA =(SERVICE_NAME = orcl.example.com)))
示例 2: 带有负载均衡和故障转移的连接
SALESDB =(DESCRIPTION =(ADDRESS_LIST =(LOAD_BALANCE = ON)(FAILOVER = ON)(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost1)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost2)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = sales.example.com)))
示例3:使用多个描述符
DBSERVICE =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost1)(PORT = 1521))(CONNECT_DATA =(SERVICE_NAME = dbservice.example.com)))(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost2)(PORT = 1522))(CONNECT_DATA =(SERVICE_NAME = dbservice.example.com)))
示例4:动态注册和连接池
SHAREDSERVICE =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = dbhost)(PORT = 1521))(CONNECT_DATA =(SERVICE_NAME = shared.example.com)(SERVER = SHARED)))
3. 实战
具体的修改路径如下:
配置好相应的数据之后,打开PLSQL会有相应的缓存信息
除了上述的登录方式外,还可以直接使用ip地址进行登录:
如果无法使用IP登录(保证账号密码等安全),查看configure-》preferences,是否下面没有监测识别到