Oracle启动的三个步骤

张彤 2022年07月11日 182次浏览

Oracle启动的三个步骤

startup nomount阶段

在此阶段,Oracle必须读到数据库的参数文件,pfile或者spfile

如果读不到参数文件,则nomount失败。

读取到参数文件后,Oracle会按照参数文件中的内存分配策略进行内存分配,启动相应的后台进程。创建实例Instance

为了保证可以动态修改参数,从oralce9i开始,Oracle引入了spfile来替代单一的pfile。具体在数据库开启后,可以执行如下命令来了解

show parameter spfile

首先找spfile,查找不到,就找init.ora文件,再找不到文件,就报错,nomount失败。

startup mount阶段

实例创建后,Oracle会根据参数文件中描述的控制文件名称及路径,去查找控制文件

一旦找到控制文件,立即锁定。控制文件内包含了数据文件日志文件检查点信息等非常重要的信息。

锁定控制文件成功,就表示数据库mount成功。实例和数据库之间桥梁搭建成功。

alter database open阶段

根据控制文件记录的信息,定位到数据库文件、日志文件等,从而正式打通了实例和数据库之间的桥梁。


具体的流程如下图

flowchart LR a[参数文件/spfile] --> b[创建实例] -->c([nomount成功]) -->|锁定| d[控制文件] --> e([mount成功])-->|查找|f[数据文件]-->|必备|i([数据库开启]) e-->|查找|g[日志文件] e-->|查找|h[归档日志] g-.-|安全需要|i h-.-|安全需要|i

数据库的关闭

数据库的关闭,是数据库开启三个过程的逆过程

这个过程可以合并为一个语句执行,shutdown immediate

可以使用如下命令观察数据库开启和关闭后,内存段的情况。

[oracle@oel7 ~]$ ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x00005feb 1          root       666        12000      1                       
0x00000000 10         oracle     600        9142272    116                     
0x00000000 11         oracle     600        3422552064 58                      
0x00000000 12         oracle     600        7634944    58                      
0x0b67239c 13         oracle     600        20480      58                      
0x00eb7941 25         postgres   600        56         6  

ORACLE 参数位置

# 参数文件位置
SQL> show parameter spfile

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
spfile				     string	 /ora01/app/oracle/product/19.3
						 .0.0/db_1/dbs/spfileORA19C.ora
# 控制文件位置
SQL> show parameter control 

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time	     integer	 7
control_files			     string	 /ora01/app/oracle/oradata/ORA1
						 9C/control01.ctl, /ora01/app/o
						 racle/flash_recovery_area/ORA1
						 9C/control02.ctl
control_management_pack_access	     string	 DIAGNOSTIC+TUNING

# 数据文件位置
SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/ora01/app/oracle/oradata/ORA19C/system01.dbf
/ora01/app/oracle/oradata/ORA19C/sysaux01.dbf
/ora01/app/oracle/oradata/ORA19C/undotbs01.dbf
/ora01/app/oracle/oradata/ORA19C/users01.dbf

# 日志文件位置
SQL> select group#,member from v$logfile;

    GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
	 3
/ora01/app/oracle/oradata/ORA19C/redo03.log

	 2
/ora01/app/oracle/oradata/ORA19C/redo02.log

	 1
/ora01/app/oracle/oradata/ORA19C/redo01.log

# 归档文件位置
SQL> show parameter recovery;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest		     string	 /ora01/app/oracle/flash_recovery_area
db_recovery_file_dest_size	     big integer 12732M
recovery_parallelism		     integer	 0
remote_recovery_file_dest	     string

# 告警日志文件
SQL> set linesize 1000;
SQL> show parameter dump;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
background_core_dump		     string	 partial
background_dump_dest		     string	 /ora01/app/oracle/product/19.3.0.0/db_1/rdbms/log
core_dump_dest			     string	 /ora01/app/oracle/diag/rdbms/ora19c/ORA19C/cdump
max_dump_file_size		     string	 unlimited
shadow_core_dump		     string	 partial
user_dump_dest			     string	 /ora01/app/oracle/product/19.3.0.0/db_1/rdbms/log



Oracle 监听

[oracle@oel7 ~]$ lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 11-JUL-2022 16:31:57

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oel7.dbaora.com)(PORT=11521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                21-FEB-2022 17:50:08
Uptime                    139 days 22 hr. 41 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /ora01/app/oracle/product/19.3.0.0/db_1/network/admin/listener.ora
Listener Log File         /ora01/app/oracle/diag/tnslsnr/oel7/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oel7)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=oel7)(PORT=5510))(Security=(my_wallet_directory=/ora01/app/oracle/admin/ORA19C/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "ORA19C.dbaora.com" has 1 instance(s).
  Instance "ORA19C", status READY, has 1 handler(s) for this service...
Service "ORA19CXDB.dbaora.com" has 1 instance(s).
  Instance "ORA19C", status READY, has 1 handler(s) for this service...
Service "d4ceba978a4010b6e0530804000afb68.dbaora.com" has 1 instance(s).
  Instance "ORA19C", status READY, has 1 handler(s) for this service...
Service "pora19c1.dbaora.com" has 1 instance(s).
  Instance "ORA19C", status READY, has 1 handler(s) for this service...
The command completed successfully

  • 监听命令lsnrctl是在oracle用户环境下执行。