一、Oracle数据库的四种状态
Oracle数据库有四种状态:SHUTDOWN、NOMOUNT、MOUNT、OPEN.
二、Oracle数据库的启动过程详解
Oracle数据库启动主要包括三个过程:
(1) shutdown状态 ;= 数据库没有启动
(2)启动数据库到 NOMOUNT 状态;=(只是启动instance实例,尚未打开控制文件)= 启动后台进程+分配了内存
(3)启动数据库到 MOUNT 状态;=(加载控制文件)加载了 controlfile
(4)启动数据库到 OPEN 状态;=(执行控制文件,打开数据文件和redo日志文件)
三、执行 startup 命令,Oracle数据库会依次完成这三个过程;
另外,也可以通过手工命令依次进行:
1、数据库启动到NOMOUNT 状态
该状态查询不到控制文件和数据文件
SQL> startup nomount
ORACLE instance started.Total System Global Area 3774873224 bytes
Fixed Size 9141896 bytes
Variable Size 788529152 bytes
Database Buffers 2969567232 bytes
Redo Buffers 7634944 bytes
SQL> select status from v$instance;STATUS
------------------------
STARTEDSQL> select status from v$controlfile;no rows selectedSQL> select status from v$datafile;
select status from v$datafile*
ERROR at line 1:
ORA-01507: database not mountedSQL> select status from v$log;
select status from v$log*
ERROR at line 1:
ORA-01507: database not mounted
已启动实例进程
[oracle@rhel dbs]$ ps -ef |grep sanshi
oracle 126788 1 0 17:28 ? 00:00:00 ora_pmon_sanshi
oracle 126790 1 0 17:28 ? 00:00:00 ora_clmn_sanshi
oracle 126792 1 0 17:28 ? 00:00:00 ora_psp0_sanshi
oracle 126795 1 0 17:28 ? 00:00:01 ora_vktm_sanshi
oracle 126799 1 0 17:28 ? 00:00:00 ora_gen0_sanshi
oracle 126801 1 0 17:28 ? 00:00:00 ora_mman_sanshi
oracle 126805 1 0 17:28 ? 00:00:00 ora_gen1_sanshi
oracle 126808 1 0 17:28 ? 00:00:00 ora_diag_sanshi
oracle 126810 1 0 17:28 ? 00:00:00 ora_ofsd_sanshi
oracle 126813 1 0 17:28 ? 00:00:00 ora_dbrm_sanshi
oracle 126815 1 0 17:28 ? 00:00:00 ora_vkrm_sanshi
oracle 126817 1 0 17:28 ? 00:00:00 ora_svcb_sanshi
oracle 126819 1 0 17:28 ? 00:00:00 ora_pman_sanshi
oracle 126821 1 0 17:28 ? 00:00:00 ora_dia0_sanshi
oracle 126823 1 0 17:28 ? 00:00:00 ora_dbw0_sanshi
oracle 126825 1 0 17:28 ? 00:00:00 ora_lgwr_sanshi
oracle 126827 1 0 17:28 ? 00:00:00 ora_ckpt_sanshi
oracle 126829 1 0 17:28 ? 00:00:00 ora_lg00_sanshi
oracle 126831 1 0 17:28 ? 00:00:00 ora_smon_sanshi
oracle 126833 1 0 17:28 ? 00:00:00 ora_lg01_sanshi
oracle 126835 1 0 17:28 ? 00:00:00 ora_smco_sanshi
oracle 126837 1 0 17:28 ? 00:00:00 ora_reco_sanshi
oracle 126839 1 0 17:28 ? 00:00:00 ora_w000_sanshi
oracle 126841 1 0 17:28 ? 00:00:00 ora_lreg_sanshi
oracle 126843 1 0 17:28 ? 00:00:00 ora_w001_sanshi
oracle 126845 1 0 17:28 ? 00:00:00 ora_pxmn_sanshi
oracle 126849 1 0 17:28 ? 00:00:00 ora_mmon_sanshi
oracle 126851 1 0 17:28 ? 00:00:00 ora_mmnl_sanshi
oracle 126853 1 0 17:28 ? 00:00:00 ora_d000_sanshi
oracle 126855 1 0 17:28 ? 00:00:00 ora_s000_sanshi
oracle 126857 1 0 17:28 ? 00:00:00 ora_tmon_sanshi
oracle 126862 1 0 17:28 ? 00:00:00 ora_m000_sanshi
oracle 127023 121945 0 17:31 pts/0 00:00:00 grep --color=auto sanshi
2 、数据库启动到MOUNT 状态
[oracle@rhel dbs]$ sqlplus / as sysdbaSQL*Plus: Release 19.0.0.0.0 - Production on Wed Jul 5 17:32:25 2023
Version 19.3.0.0.0Copyright (c) 1982, 2019, Oracle. All rights reserved.Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0SQL> alter database mount;Database altered.
实例处于mount状态,控制文件、数据文件已加载可查询
在这里插入代码片SQL> select status from v$controlfile;STATUS
--------------SQL> select status from v$instance;STATUS
------------------------
MOUNTEDSQL> select name from v$controlfile;NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/SANSHI/control01.ctl
/u01/app/oracle/fast_recovery_area/SANSHI/control02.ctlSQL> select name,status from v$controlfile;NAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/control01.ctl/u01/app/oracle/fast_recovery_area/SANSHI/control02.ctlSQL> select name,status from v$datafile;NAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/system01.dbf
SYSTEM/u01/app/oracle/oradata/SANSHI/sysaux01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/undotbs01.dbf
ONLINENAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/pdbseed/system01.dbf
SYSTEM/u01/app/oracle/oradata/SANSHI/pdbseed/sysaux01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/users01.dbf
ONLINENAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/pdbseed/undotbs01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/pdb1/system01.dbf
SYSTEM/u01/app/oracle/oradata/SANSHI/pdb1/sysaux01.dbf
ONLINENAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/pdb1/undotbs01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/pdb1/users01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/pdb2/system01.dbf
SYSTEMNAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/pdb2/sysaux01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/pdb2/undotbs01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/pdb2/users01.dbf
ONLINENAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/pdb3/system01.dbf
SYSTEM/u01/app/oracle/oradata/SANSHI/pdb3/sysaux01.dbf
ONLINE/u01/app/oracle/oradata/SANSHI/pdb3/undotbs01.dbf
ONLINENAME
--------------------------------------------------------------------------------
STATUS
--------------
/u01/app/oracle/oradata/SANSHI/pdb3/users01.dbf
ONLINE19 rows selected.SQL>
查看参数文件,存放在oracle_home目录
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@rhel dbs]$ cd $ORACLE_HOME/dbs
[oracle@rhel dbs]$ ls
hc_sanshi.dat init.ora lkSANSHI orapwsanshi snapcf_sanshi.f spfilesanshi.ora
[oracle@rhel dbs]$ ll
total 18308
-rw-rw---- 1 oracle oinstall 1544 Jul 5 17:33 hc_sanshi.dat
-rwxr-xr-x 1 oracle oinstall 3079 May 14 2015 init.ora
-rw-r----- 1 oracle oinstall 24 Jul 4 12:18 lkSANSHI
-rw-r----- 1 oracle oinstall 2048 Jul 4 12:20 orapwsanshi
-rw-r----- 1 oracle oinstall 18726912 Jul 4 12:49 snapcf_sanshi.f
-rw-r----- 1 oracle oinstall 3584 Jul 5 17:33 spfilesanshi.ora
[oracle@rhel dbs]$
查看控制文件,存放在oracle_base下的数据文件目录中
[oracle@rhel dbs]$ cd $ORACLE_BASE
[oracle@rhel oracle]$ LS
bash: LS: command not found...
Similar command is: 'ls'
[oracle@rhel oracle]$ ls
admin audit cfgtoollogs checkpoints diag fast_recovery_area oradata product
[oracle@rhel oracle]$ cd oradata/
[oracle@rhel oradata]$ ls
SANSHI
[oracle@rhel oradata]$ cd SANSHI/
[oracle@rhel SANSHI]$ kls
bash: kls: command not found...
[oracle@rhel SANSHI]$ ls
control01.ctl pdb2 pdbseed redo02.log sysaux01.dbf temp01.dbf users01.dbf
pdb1 pdb3 redo01.log redo03.log system01.dbf undotbs01.dbf
[oracle@rhel SANSHI]$ pwd
/u01/app/oracle/oradata/SANSHI
[oracle@rhel SANSHI]$ ll
total 2649240
-rw-r----- 1 oracle oinstall 18726912 Jul 5 17:39 control01.ctl
drwxr-x--- 2 oracle oinstall 104 Jul 4 12:40 pdb1
drwxr-x--- 2 oracle oinstall 104 Jul 4 12:40 pdb2
drwxr-x--- 2 oracle oinstall 104 Jul 4 12:40 pdb3
drwxr-x--- 2 oracle oinstall 111 Jul 4 12:25 pdbseed
-rw-r----- 1 oracle oinstall 209715712 Jul 5 16:43 redo01.log
-rw-r----- 1 oracle oinstall 209715712 Jul 5 16:20 redo02.log
-rw-r----- 1 oracle oinstall 209715712 Jul 5 16:20 redo03.log
-rw-r----- 1 oracle oinstall 629153792 Jul 5 16:43 sysaux01.dbf
-rw-r----- 1 oracle oinstall 954212352 Jul 5 16:43 system01.dbf
-rw-r----- 1 oracle oinstall 138420224 Jul 4 22:01 temp01.dbf
-rw-r----- 1 oracle oinstall 351281152 Jul 5 16:43 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Jul 5 16:43 users01.dbf
[oracle@rhel SANSHI]$
打开数据库
在状态mount下,无法查看表,数据库open状态可以查看表。
SQL> select status from v$instance;STATUS
------------------------
MOUNTEDSQL> desc tab;
ERROR:
ORA-01219: database or pluggable database not open: queries allowed on fixed
tables or views onlySQL> alter database open2 ;Database altered.SQL> desc tab;Name Null? Type----------------------------------------- -------- ----------------------------TNAME NOT NULL VARCHAR2(128)TABTYPE VARCHAR2(13)CLUSTERID NUMBERSQL>
shutdown关闭数据库
1、利用“shutdown immediate”命令执行某些清除工作后才关闭数据库;
SQL> shutdown immediate
ORA-01109: database not openDatabase dismounted.
ORACLE instance shut down.
2、利用“shutdown abort”命令直接关闭数据库,会话会被终止。
SQL> shutdown abort
ORACLE instance shut down.
SQL>
3、利用“shutdown normal”命令正常关闭数据库;
SQL> shutdown normal
4、shutdown transaction