怎么检查oracle数据库服务有没有启动?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么检查oracle数据库服务有没有启动?相关的知识,希望对你有一定的参考价值。

检查oracle数据库服务有没有启动,然后怎么再检查监听配置是不是正常,然后怎么再检查,是否有scott用户 服务启动后怎么在关掉?

Oracle数据库实例启动时,分成nomount、mount和open的三个阶段,下面的实例分析来展示不同阶段时,系统到底做了哪些工作

1、nomout阶段,该阶段启动的前提是有参数文件,若没有参数文件,系统无法启动,在该过程中,系统分配内存、开启后台进程,同时更新alter日志文件

实例nomount之前的状态:

--无实例进程
[oracle@secdb1 admin]$ echo $ORACLE_SID
PROD
[oracle@secdb1 admin]$ ps -ef|grep PROD
oracle 14890 6310 0 21:12 pts/1 00:00:00 grep PROD
--alter日志信息
[oracle@secdb1 bdump]$ ls -lrt
total 48
-rw-r----- 1 oracle oinstall 1113 Mar 4 23:15 prod_lgwr_7319.trc
-rw-r----- 1 oracle oinstall 779 Mar 5 19:42 prod_mmnl_7329.trc
-rw-r--r-- 1 oracle oinstall 40910 Mar 5 21:08 alert_PROD.log

此时启动实例到nomount状态
[oracle@secdb1 admin]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 5 21:15:50 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 100664720 bytes
Database Buffers 209715200 bytes
Redo Buffers 2973696 bytes
SQL>

此时查看进程和日志信息
[oracle@secdb1 bdump]$ ls -lrt
total 52
-rw-r----- 1 oracle oinstall 1113 Mar 4 23:15 prod_lgwr_7319.trc
-rw-r----- 1 oracle oinstall 779 Mar 5 19:42 prod_mmnl_7329.trc
-rw-r--r-- 1 oracle oinstall 42513 Mar 5 21:15 alert_PROD.log ----------------日志文件已经更新

[oracle@secdb1 bdump]$ ps -ef|grep PROD ----------------------------系统中出现后台进程
oracle 14946 1 0 21:15 ? 00:00:00 ora_pmon_PROD
oracle 14948 1 0 21:15 ? 00:00:00 ora_psp0_PROD
oracle 14950 1 0 21:15 ? 00:00:00 ora_mman_PROD
oracle 14952 1 0 21:15 ? 00:00:00 ora_dbw0_PROD
oracle 14954 1 0 21:15 ? 00:00:00 ora_lgwr_PROD
oracle 14956 1 0 21:15 ? 00:00:00 ora_ckpt_PROD
oracle 14958 1 0 21:15 ? 00:00:00 ora_smon_PROD
oracle 14960 1 0 21:15 ? 00:00:00 ora_reco_PROD
oracle 14962 1 0 21:15 ? 00:00:00 ora_mmon_PROD
oracle 14964 1 0 21:15 ? 00:00:00 ora_mmnl_PROD
oracle 14965 14942 0 21:15 ? 00:00:00 oraclePROD (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 14988 5989 0 21:17 pts/3 00:00:00 grep PROD
如果在$ORACLE_HOME/dbs目录下无参数文件,启动实例是现象如下:
[oracle@secdb1 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 5 21:21:19 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initPROD.ora'
SQL> quit

参数寻找的优先级 spfileSID.ora----initSID.ora

在该阶段,可以进行数据库的创建、控制文件的创建

2、mount,在该阶段,启动条件是需要有控制文件,如果控制文件丢失或者损坏,启动将会报错。此时系统会打开控制文件、检查数据文件、日志文件的名称和位置,
但此时不检查文件到底是否存在不存在

mount之前:
SQL> select * from v$controlfile;
no rows selected

SQL> select * from v$datafile;
select * from v$datafile
*
ERROR at line 1:
ORA-01507: database not mounted
mount之后

SQL> alter database mount;
Database altered.
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/PROD/disk1/control01.ctl
/u01/app/oracle/oradata/PROD/disk2/control02.ctl

SQL> select file#,name from v$datafile;

FILE# name
--------------------------------------------------------------------------------
1 /u01/app/oracle/oradata/PROD/disk1/system01.dbf
2 /u01/app/oracle/oradata/PROD/disk1/undotbs01.dbf
3 /u01/app/oracle/oradata/PROD/disk1/sysaux01.dbf
在该阶段,可以进行数据库的完全恢复、修改数据库的归档模式、移动和重命令数据文件
SQL> archive log list ---查看数据库归档模式
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/oracle/product/10.2.0/db_1/dbs/arch
Oldest online log sequence 3
Current log sequence 5

SQL> alter database archivelog; ---修改成归档模式
SQL> alter database noarchivelog;---修改成非归档模式

如果控制文件丢失,系统报错,现象如下:

SQL> startup mount
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 100664720 bytes
Database Buffers 209715200 bytes
Redo Buffers 2973696 bytes
ORA-00205: error in identifying control file, check alert log for more info
3、open阶段,该阶段主要是打开数据文件、日志文件,在打开的过程中对数据文件和日志文件进行一致性检查,如果不一致,则SMON进程继续实例恢复,如果文件丢失,打开失败。
SQL> alter database open;
Database altered.

--如何数据文件丢下,打开失败
SQL> startup mount;
ORACLE instance started.
Total System Global Area 314572800 bytes
Fixed Size 1219184 bytes
Variable Size 79693200 bytes
Database Buffers 230686720 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/PROD/disk1/system01.dbf'

4、小结

启动时分成三个步骤,1、nomount阶段,该阶段是实例启动,根据参数文件进行系统分配内存,启动后台进程。mount阶段,根据控制文件来进行数据文件和日志文件的名称和位置检查,把实例和数据库连接起来。open阶段,就是数据库打开阶段,打开是就需要检查文件是否正常,有没有发生文件丢失或者不一致的情况,丢失则报错,不一致则进行实例恢复。
参考技术A 检查数据库是否启动,linux下可以用ipcs查看,windows下可以查看服务、也可以进到数据库里面看数据库当前状态 select status from v$instance;如果status = open 就说明oracle服务正常。
查看监听,执行lsnrctl status,就可以看监听所对应的实例。
是否有scott用户,可以查看dba_users这个表的用户状态。

服务启动后 使用 shutdown immediate关闭服务
参考技术B 不管是windows还是linxu下你能用数据库的用户(比如说sys,system用户)通过命令或者工具连上数据库并且执行查询之类的操作,都是证明服务和监听正常的最可靠的办法。

使用sql*plus连接oracle数据库时,输入口令提示协议适配器错误,当初安装时口令不符合它的规范,怎么解决?

如果安装没有问题的话那就是没有启动服务,或者你没有安装数据库实例,当然也就没有服务了。
你可以右键“我的电脑”-管理-服务和应用程序-服务,找一下OracleServiceORCL这个服务,ORCL是默认安装的数据库服务,如果安装了其他服务这个名称不一样,如果没有类似的服务那就是没有了,需要重新配置个服务(新建一个数据库实例)
参考技术A 没关系,oracle装本地不再密码也可以登录 sqlplus / as sysdba 进去后即可改密码 参考技术B 检查一下你的监听程序

以上是关于怎么检查oracle数据库服务有没有启动?的主要内容,如果未能解决你的问题,请参考以下文章

怎么恢复oracle 中被drop掉的分区

linux下安装好oracle12c,然后sqlplus启动出现如下问题ORA-01034、ORA-27101,求高手,linux如何启动orac

启动oracle监听服务报错。

如何查看和开启oracle监听和服务

如何查看和开启oracle监听和服务

修改 oracle 数据库的 sys 账号密码,alter user sys identified by Aa123456@#_# * ERROR at line 1: ORA-01034: ORAC