好久没有写文章了,主要是最近太忙了,没有时间去总结一些东西,刚刚闲下来,记录了一下最近遇到的一些问题。希望大家能够喜欢!
环境:
操作系统:SUSE Linux9
数据库: oracle10gR2
1:更改主机host
[root@www ~]# hostname
linux
[root@www ~]# hostname test11
[root@www ~]# hostname
test11
[root@www ~]#
2:尝试重启监听
oracle@linux:/> lsnrctl stop
IXDBA.NET技术社区
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。
如果关闭数据库,此时监听日志中会有如下信息出现:
05-DEC-2006 10:32:24 * service_died * orcl * 12537
此时如果再次用服务名连接数据库,将出现问题,所以在oracle10g中,要想用网络服务名连接某台数据库,那么这台数据库必须是监听启动且数据库正常mount或者open。
5:下面用目录服务名连接数据库试试:
oracle@linux:/> sqlplus "sys/cicro@standby as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 11月 29 17:42:09 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>
可以连接了,由此可以知道,
一个完整的启动数据库顺序应该是先启动监听,然后启动数据库。
总结:
1:监听文件listener.ora tnsnames.ora中关于host的配置建议都用ip来表示,
2:如果监听不能启动或者启动后不能正常使用,
(1)首先确认你的OS的hostname,执行hostname命令,尝试ping "hostname",看是否能通,
(2)然后检查监听的listener.ora ,tnsnames.ora这两个配置文件中关于host的信息是否是用主机名表示的。
(3)如果是,更改到新的主机名,然后把新的主机名加入系统的hosts文件,linux下为/etc/hosts;
然后ping 新主机名,应该能通的。
(4)如果全部是用ip表示的,那么直接将新的主机名加入系统的hosts文件即可。
然后ping 新主机名,也应该能通的。
3:如果第二步还是解决不了问题,
(1)检查启动的oracle的instance信息,select * fromv$instance;
然后查看本级系统的主机名,两者应该是相等的。
(2)如果查询出来的是老的主机名,尝试"ping老主机名"应该不通,
通过listener也应该是连结不上;
(3)如果是新的主机名,如果"ping新主机名"不通,
请修改/etc/hosts文件增加新主机名,确认能ping通,然后重启oracle
4:注意tns和listener文件的设置。
具体操作步骤:
1)修改hostname为www.ixdba.net
2)修改/etc/hosts,去掉原来的主机名的行,增加该行
192.168.60.253 www.ixdba.net
3)重启数据库,查询instance信息
select * from v$instance;
得到新的HOST_NAME为www.ixdba.net
4)修改listener.ora,把HOST改成新的主机名
5)修改tnsname.ora,修改对应的HOST为新的主机名
6)重启listener
然后connect oracle/oracle@standby应该可以成功的。