oracle 动态监听例子,oracle动态监听和静态监听的区别

一、什么是注册

注册就是将数据库作为一个服务注册到监听程序。

客户端不需要知道数据库名和实例名,只需要知道该数据库对外提供的服务名就可以申请连接到数据库。

这个服务名可能与实例名一样,也有可能不一样。

在数据库服务器启动过程中,数据库服务器会向监听程序注册相应的服务(无论何时启动一个数据库,默认地都有两条信息注册到监听器中:数据库服务器对应的实例和服务)

相当于是这样:在数据库服务器和客户端之间有一监听程序(Listener),在监听程序中,会记录相应数据库对应的服务名(一个数据库可能对应有多个服务名),当客户端需要连接数据库时,只需要提供服务名,就可以建立客户端和服务器之间的连接.

1.1、数据库关闭的状态下,只有sys用户可连入数据库,其他用户不可连入。

数据库关闭状态:SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 12 16:12:15 2018

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> select open_mode from v$database;

select open_mode from v$database

*

ERROR at line 1:

ORA-01034: ORACLE not available

Process ID: 15430

Session ID: 13 Serial number: 39

1.2、sys用户可以连入数据库,提示接入空实例$ sqlplus sys/123 as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 12 16:14:28 2018

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to an idle instance.

SQL>

1.3、除sys用户的其他用户连接不进数据库$ sqlplus system/123

SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 12 16:15:02 2018

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

ERROR:

ORA-01034: ORACLE not available

ORA-27101: shared memory realm does not exist

Linux-x86_64 Error: 2: No such file or directory

Process ID: 0

Session ID: 0 Serial number: 0

二、如何查询某服务是静态监听注册还是动态监听注册

可以使用命令lsnrctl status来查看某服务是静态注册还是动态注册。

实例状态为UNKNOWN值时表明此服务是静态注册的设置。

这时监听器用来表明它不知道关于该实例的任何信息,只有当客户发出连接请求时,它才检查该实例是否存在。

动态监听的状态是READY。

三、动态注册

3.1、动态注册不需要显示的配置listener.ora文件,实例MOUNT时,PMON进程就会根据instance_name,service_name参数将实例和服务动态注册到listerer中。

配置listener.ora文件为空:

4b38bc4096244ac7e2849a0e6f7780be.png

动态监听状态:

ca653f1d710be7b434e529fac63c88f3.png

数据库关闭$ sqlplus sys/justsoft123 as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 12 16:21:41 2018

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

此时在查询监听状态

729469f7b98253f4510572bef0503461.png

此时数据库是完全关闭的,这时定是无法远程连接数据库的

3e54f2c469286d3ff477b2280f4f479e.png

启动数据库到nomount状及查看监听情况,并测试过在nomount状态,客户端同样无法用sys用户进行远程连接数据库的

b280e42c32007db7091e55928cceb7ac.png

10311f4c244150b1991b6804cebac5df.png

启动数据库到mount状态,查看监听状态并测试数据库连接是成功的

654344c13fd69475e724ddc0647fdcc5.png

6086ff9ae5dd06dcf73389e2c9de0045.png*********************************************************************************************************************************************************************************************

四、静态监听

静态注册指实例启动时读取listener.ora配置文件,将实例和服务注册到监听程序。

优点:

无论何时启动一个数据库,默认都有两条信息注册到监听器中:实例和服务。

在数据库未open状态中(前提是已经在nomount或mount状态),就可以远程连接到数据库,对数据库进行操作--当然了要配置密码文件。

4.1、接下来改为静态监听#cat /opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

# Generated by Oracle configuration tools.

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = orcl)

(ORACLE_HOME = /opt/oracle/product/11.2.0/dbhome_1)

(SID_NAME = orcl)

)

)

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = in)(PORT = 1521))

)

)

ADR_BASE_LISTENER = /opt/oracle

重新启动监听及数据库,查看静态监听状态:

e274dee00a71fff502d5e11ac4e4aca4.png

数据库关闭后:

4283a7440b26641d87418756fb400c3c.png

静态监听时远程数据库处于关闭状态,是需要启动到nomount或者mount状,客户端(sys用户)都可以连接上,可以在客户进行操作启动到mount或是open状态。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值