ora-12170:tns:连接超时
lsnrctl status 查看监听器是否启动
lsnrctl start启动监听(lsnrctl stop关闭监听)
启动监听后可以用sqlplus登录数据库,查看数据库信息:如sqlplus emcd/[email protected]:1521/orcl
以数据库管理员登录:sqlplus sys/oracle as sysdba 登录后可以执行关闭或启动数据库命令:
SQL> shutdown immediate (关闭数据库)
SQL> startup (启动数据库)
当数据库处于关闭状态时,要启动数据库:首先启动监听器 lsnrctl start;然后sqlplus sys/oracle as sysdba
回车后会显示Connected to an idle instance,并出现提示符SQL>,此时输入命令startup启动数据库,输入 shutdown immediate
则可关闭数据库;
关闭虚拟机的防火墙和SELinux后,就可以在本地访问了
如果在本机可以正常使用,可是到局域网中的其他机器就出现“ORA-12170:TNS:连接超时
解决方法:
1.cmd-----ping ip地址 查看网络问题,看能否ping通
2.cmd-----tnsping ip地址(或者是服务器的实例名SID)如果报“TNS-12535:操作超时”,可能是服务器端防火墙 没有关闭
3.cmd----netstat -na 查看1521端口是否关闭,如果关闭Windows XP中的防火墙设置中将1521端口设为例外
4.cmd----lsnrctl status lsnrctl是listener-control 监听器的缩写,查看监听的状态
在CentOS 6.3下安装完Oracle 10g R2,重开机之后,你会发现Oracle没有自行启动,这是正常的,因为在Linux下安装Oracle的确不会自行启动,必须要自行设定相关参数,首先先介绍一般而言如何启动oracle。
登录到linux,切换到oracle用户权限
一、在Linux下启动Oracle
登录到CentOS,切换到oracle用户权限
# su – oracle
接着输入:
$ sqlplus "/as sysdba"
原本的画面会变为
SQL>
接着请输入
SQL> startup
就可以正常的启动数据库了。
另外停止数据库的指令如下:
SQL> shutdown immediate
二、检查Oracle DB监听器是否正常
回到终端机模式,输入:
$ lsnrctl status
检查看看监听器是否有启动
如果没有启动,可以输入:
$ lsnrctl start
启动监听器
SQL> conn sys@orcl as sysdba
然后输入密码,sys以sysdba身份登入数据库。
三、启动emctl
另外也可以发现http://localhost.localdomain:1158/em 目前是没有反应的,这边要另外启动,启动的指令如下:
$ emctl start dbconsole
这个指令运行时间较长,执行完的画面如下:
手动启动Oracle数据库完毕,下面创建系统自行启动Oracle的脚本。
四、Oracle启动&停止脚本
1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。
# vi /etc/oratab
orcl:/opt/oracle/102:Y
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
2. 在 /etc/init.d/ 下创建文件oracle,内容如下:
#!/bin/sh
# chkconfig: 35 80 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/opt/oracle/102
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"
# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;
'restart')
$0 stop
$0 start
;;
esac
3. 改变文件权限
# chmod 755 /etc/init.d/oracle
4. 添加服务
# chkconfig --level 35 oracle on
5. 需要在关机或重启机器之前停止数据库,做一下操作
# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle //关机
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle //重启
6. 使用方法
# service oracle start //启动oracle
# service oracle stop //关闭oracle
# service oracle restart //重启oracle
7. 测试
a. 开机自启动
Last login: Mon Nov 26 19:57:06 2012 from 10.0.0.145
[root@ORS ~]# su - oracle
[oracle@ORS ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:07:33 2012
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> set linesize 300;
SQL> set pagesize 30;
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
SMITH CLERK 7902 17-DEC-80 800 20
ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
WARD SALESMAN 7698 22-FEB-81 1250 500 30
JONES MANAGER 7839 02-APR-81 2975 20
MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
BLAKE MANAGER 7839 01-MAY-81 2850 30
CLARK MANAGER 7839 09-JUN-81 2450 10
SCOTT ANALYST 7566 19-APR-87 3000 20
KING PRESIDENT 17-NOV-81 5000 10
TURNER SALESMAN 7698 08-SEP-81 1500 0 30
ADAMS CLERK 7788 23-MAY-87 1100 20
JAMES CLERK 7698 03-DEC-81 950 30
FORD ANALYST 7566 03-DEC-81 3000 20
MILLER CLERK 7782 23-JAN-82 1300 10
rows selected.
SQL>
b. service oracle stop
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@ORS ~]$ logout
[root@ORS ~]# service oracle stop
Stoping Oracle Listeners ...
Done.
Stoping Oracle Databases ...
Done.
[root@ORS ~]# su - oracle
[oracle@ORS ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:17:20 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select * from scott.emp;
select * from scott.emp
*
ERROR at line 1:
ORA-01034: ORACLE not available
SQL>
c. service oracle start
SQL> Disconnected
[oracle@ORS ~]$ logout
[root@ORS ~]# service oracle start
Starting Oracle Databases ...
Done
Starting Oracle Listeners ...
Done.
[root@ORS ~]#
d. service oracle restart
[root@ORS ~]# service oracle restart
Stoping Oracle Listeners ...
Done.
Stoping Oracle Databases ...
Done.
Starting Oracle Databases ...
Done
Starting Oracle Listeners ...
Done.
[root@ORS ~]#
至此,Oracle服务启动&停止脚本与开机自启动设置完毕。
一、在Linux下启动Oracle
1、启动数据库:
# su – oracle
# sqlplus /nolog
SQL> connect /as sysdba
SQL> startup
ORACLE instance started.
Total System Global Area 135352820 bytes
Fixed Size 455156 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 679936 bytes
Database mounted.
2、关闭数据库:
# su – oracle
# sqlplus /nolog
SQL> connect /as sysdba
SQL> shutdwon abort
另外停止数据库的指令如下:
SQL> shutdown immediate
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务解决
问题:Oracle主服务和监听器服务已经启动,使用SQL Plus能够正常连接,使用PL SQL Developer连接报次错误:ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务。如图:
(1).遇到的问题:
在虚拟机的redhat 5上安装了Oracle10g 在本地的XP系统上,在配置好tnsnames.ora的情况下却无法访问虚拟机里面的Oracle,提示
不能解析链接串;但是本地命令行下tnsping 虚拟机又是可以ping通的,而在虚拟机里面用sqlplus访问远程主机的Oracle数据库也可以的;
后来发现:关闭虚拟机的防火墙和SELinux后,就可以在本地访问了,#chkconfig --list iptables 查看防火墙是否关闭,运行命令
#chkconfig iptables off关闭防火墙;
(2).在处理了(1)的问题后,在本地命令行用sqlplus链接远程Linux的Oracle:
C:\Documents and Settings\hawk>sqlplus emcd/[email protected]:1521/orcl,出现如下错误:
ERROR:
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
请输入用户名: emcd
输入口令:
ERROR:
ORA-12560: TNS: 协议适配器错误
这个问题经过一番折腾,在配置文件listener.ora里面添加SID_DESC后重启监听,问题得到解决;
配置文件所添加内容如下所示:
# listener.ora Network Configuration File: /home/oracle/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC = #为添加的内容:相应得数据库服务
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = oracle_IPC))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.120)(PORT = 1521))
)
)
重要的配置文件和参数文件:
/home/oracle/oracle/product/10.2.0/db_1/dbs/initorcl.ora
/home/oracle/oracle/product/10.2.0/db_1/dbs/initorcl.ora
/home/oracle/oracle/product/10.2.0/db_1/admin/orcl/bdump/alert_orcl.log警告日志信息
/home/oracle/oracle/product/10.2.0/db_1/dbs/spfileorcl.ora可读不可写,为启动参数文件,命令strings spfileorcl.ora可查看其内容;
重新配置监听器:netca,若果中文显示异常,则可以先运行命令export LC_ALL=C,再运行netca则可以英文显示窗口出现;
ORA-01219
问题解决(一般情况):
1:数据库未打开
2:数据文件问题
前几天误删除D:\DATA\PROD\PRODDATA\CUX_INDEX_X_1.DBF文件,后面一直提示ORA-01219错误。
解决:
1. 运行输入:sqlplus /nolog
2. 以sysdba的角色登录:connect sys/口令 as sysdba
3. 先执行”alter database open”,会出现如下的错误
第 1 行出现错误:
ORA-01157: 无法标识/锁定数据文件 6 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 6: D:\DATA\PROD\PRODDATA\CUX_INDEX_X_1.DBF
4. 执行“alter database create datafile 6;”
5. 执行“alter database datafile 6 offline drop
6. 执行“alter database open”