环境:
操作系统:SUSE Linux9
数据库: oracle10gR2
1:更改主机host
[root@www ~]# hostname
linux
[root@www ~]# hostname test11
[root@www ~]# hostname
test11
[root@www ~]#
2:尝试重启监听
oracle@linux:/> lsnrctl stop
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 29-11月-2006 16:51:09
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully
oracle@linux:/> lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 29-11月-2006 16:51:32
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /free/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /free/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /free/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 29-11月-2006 16:51:32
Uptime 0 days 0 hr. 0 min. 42 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /free/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /free/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
可以看到,监听启动很慢,但是最后还是能启动成功,其实这是假象,我们即可得知。
其实监听在每次启动时刻会去读系统的主机名,然后根据主机名启动lsnrctl。
3:测试监听连接的有效性
下面的standby是本地目录服务名。
oracle@linux:> sqlplus "sys/cicro@standby as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 29 17:04:24 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12541: TNS:no listener
oracle@linux:> sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 29 17:07:32 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected.
SQL> shutdown immediate
ORA-24324: service handle not initialized
ORA-24323: value not allowed
ORA-00600: internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%s]
SQL>
SQL> select host_name from v$instance;
HOST_NAME
--------------------------------------------------------------------------------
linux
可以看到,此时关闭数据库也报错。数据库 v$instance中记录的hostname是linux,但是此时host name已经修改成了test11
5:增加 新的主机名到host中
linux:~ # vi /etc/hosts
#
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server.
# Syntax:
#
# IP-Address Full-Qualified-Hostname Short-Hostname
127.0.0.1 localhost
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts
127.0.0.1 linux
192.168.60.253 linux
192.168.60.253 test11
6:重启数据库和监听
oracle@linux:/> lsnrctl stop
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 29-11月-2006 17:20:02
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully
oracle@linux:/> lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 29-11月-2006 17:20:10
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /free/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 – Production System parameter file is /free/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /free/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.60.253)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 29-11月-2006 17:20:10
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /free/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /free/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.60.253)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
看到,监听很快启动完毕。
(1):查看监听日志:
[oracle@gaojf~]$
tail -f /free/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.60.144)(PORT=1521)))
Listener completed notification to CRS on start
TIMESTAMP * CONNECT DATA [* PROTOCOL INFO] * EVENT [* SID] * RETURN CODE
WARNING: Subscription for node down event still pending
05-DEC-2006 10:31:14 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=gaojf)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=169869568)) * status * 0
可以看到监听在启动的时候去读取了系统的主机名gaojf和登陆的用户oracle,因此这个主机名gaojf应该在/etc/hosts中唯一存在的,并且对oracle用户是可以使用的,
(2):试试用目录名连接登陆数据库试试:
oracle@linux:/> sqlplus "sys/cicro@standby as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 29 17:28:07 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
无法连接数据库,可能是监听刚刚启动,服务没有完全启动的原因,等上5分钟
oracle@linux:/> sqlplus "sys/cicro@standby as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 29 17:35:15 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
Descriptor
可以看到,还是无法用目录名连接数据库:
(3):下面继续启动数据库
oracle@linux:> sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 29 17:37:00 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
oracle@linux:> sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 29 17:39:32 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 62916852 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> select host_name from v$instance;
HOST_NAME
--------------------------------------------------------------------------------
test11
SQL>
看到,测试数据库中的host_name变成了test11,这个现象也说明了数据库在每次启动的时候都会读系统的主机名,然后记录到数据库中的v$instance中。
(4):查看此时的监听日志信息如下:
[oracle@gaojf~]$
tail -f /free/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.60.144)(PORT=1521)))
Listener completed notification to CRS on start
TIMESTAMP * CONNECT DATA [* PROTOCOL INFO] * EVENT [* SID] * RETURN CODE
WARNING: Subscription for node down event still pending
05-DEC-2006 10:31:14 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=gaojf)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=169869568)) * status * 0
05-DEC-2006 10:33:57 * service_register * orcl * 0
05-DEC-2006 10:34:03 * service_update * orcl * 0
05-DEC-2006 10:34:18 * service_update * orcl * 0
可以看到,比刚才多出了几行信息,因为上面是对数据库做的open操作,所以,对数据库nomount操作就是这里的service_register,mount数据库就是这里的第二个service_update,open对应的监听信息也是service_update。