首页 > 数据库 >normal数据库关闭hang的问题

normal数据库关闭hang的问题

时间:2023-06-19 13:02:23浏览次数:41  
标签:22 normal process hang 数据库 Jun Mon shutdown 2015


今晚办公楼停电维护,需要提前关闭服务器,为防止异常关闭导致的各种问题,有个测试库,使用shutdown normal停库,结果就是很常见的hang住了。


操作顺序:


1. shutdown normal,然后关闭了当前sqlplus窗口。

从alert日志中看:

Mon Jun 22 16:50:22 2015

Shutting down instance (normal)

Stopping background process SMCO

Shutting down instance: further logons disabled

这里涉及到shutdown normal的原理,稍后引述。



2. 此时重新登录,sqlplus / as sysdba,执行startup或shutdown immediate命令都提示失败,

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 22 17:03:06 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected.
SQL> startup
ORA-01012: not logged on
SQL> shutdown immediate
ORA-24324: service handle not initialized
ORA-24323: value not allowed
ORA-01090: shutdown in progress - connection is not permitted
Mon Jun 22 16:50:24 2015
Stopping background process CJQ0
Stopping background process QMNC
Stopping background process MMNL
Stopping background process MMON
License high water mark = 125

ORA-01090提示说正在执行关闭操作,不允许其他连接的操作。3. 其实这涉及到normal关闭的原理,他需要等待所有已连接用户中断连接,换句话说,如果仍有连接到库的用户,shutdown的操作就一直等待。这是最完全的关闭方式,但同时是变数最大的,因为可能你不知其他用户什么时候中断。首先尝试查找出所有连接用户,用kill -9直接杀进程。可以使用ps -ef查找所有(LOCAL=NO)的进程,LOCAL=NO表示连接不是本地,而是远程。

ps -ef|grep ora|grep -v grep|grep -v ora_|grep LOCAL=NO|awk '{print $2}',然后kill -9 进程号
或者
ps -ef|grep ora|grep -v grep|grep -v ora_|grep LOCAL=NO|awk '{print $2}'|xargs kill

从alert日志看:

Mon Jun 22 16:55:26 2015
Active process 27446 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 27402 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 27555 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 11697 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 14942 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 27559 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 27513 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 26911 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 31993 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 30810 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 27557 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 11684 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 11666 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 27510 user 'oracle11g' program 'oracle@dcsopenNode1'
Active process 11688 user 'oracle11g' program 'oracle@dcsopenNode1'
SHUTDOWN: waiting for logins to complete.
Mon Jun 22 17:01:29 2015
All dispatchers and shared servers shutdown

是提示了所有dispatcher和共享服务关闭,但sqlplus登录后仍是上面的提示。


4. 尝试关闭监听服务,lsnrctl stop。

问题依旧。


5. 重登陆执行shutdown abort,强制关闭。

从alert日志看:

USER (ospid: 28558): terminating the instance

Instance terminated by USER, pid = 28558

看样子是关闭了实例。

重新执行sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 22 17:43:25 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to an idle instance.

再次执行startup-shutdown normal,

SQL> startup
ORACLE instance started.

Total System Global Area 3290345472 bytes
Fixed Size                  2217832 bytes
Variable Size            2499807384 bytes
Database Buffers          771751936 bytes
Redo Buffers               16568320 bytes
Database mounted.
Database opened.
SQL> shutdown normal
Database closed.
Database dismounted.
ORACLE instance shut down.

由于现在已经没有连接的用户了,正常启动,正常关闭了。

从alert日志看,

Mon Jun 22 17:46:01 2015
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 3
Using LOG_ARCHIVE_DEST_1 parameter default value as /oracle/ora11gR2/product/11.2.0/dbhome_1/dbs/arch
Autotune of undo retention is turned on. 
IMODE=BR
ILAT =27
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options.
Using parameter settings in server-side spfile /oracle/ora11gR2/product/11.2.0/dbhome_1/dbs/spfiledcsopen.ora
System parameters with non-default values:
  processes                = 150
  memory_target            = 3152M
  control_files            = "/oracle/ora11gR2/oradata/dcsopen/control01.ctl"
  control_files            = "/oracle/ora11gR2/oradata/dcsopen/control02.ctl"
  db_block_size            = 8192
  compatible               = "11.2.0.0.0"
  undo_tablespace          = "UNDOTBS1"
  remote_login_passwordfile= "EXCLUSIVE"
  db_domain                = ""
  dispatchers              = "(PROTOCOL=TCP) (SERVICE=dcsopenXDB)"
  audit_file_dest          = "/oracle/ora11gR2/admin/dcsopen/adump"
  audit_trail              = "DB"
  db_name                  = "dcsopen"
  open_cursors             = 300
  diagnostic_dest          = "/oracle/ora11gR2"
Mon Jun 22 17:46:03 2015
PMON started with pid=2, OS id=30699 
Mon Jun 22 17:46:03 2015
VKTM started with pid=3, OS id=30701 at elevated priority
VKTM running at (10)millisec precision with DBRM quantum (100)ms
Mon Jun 22 17:46:03 2015
GEN0 started with pid=4, OS id=30705 
Mon Jun 22 17:46:03 2015
DIAG started with pid=5, OS id=30707 
Mon Jun 22 17:46:03 2015
DBRM started with pid=6, OS id=30709 
Mon Jun 22 17:46:03 2015
PSP0 started with pid=7, OS id=30711 
Mon Jun 22 17:46:03 2015
DIA0 started with pid=8, OS id=30713 
Mon Jun 22 17:46:03 2015
MMAN started with pid=9, OS id=30715 
Mon Jun 22 17:46:03 2015
DBW0 started with pid=10, OS id=30717 
Mon Jun 22 17:46:03 2015
LGWR started with pid=11, OS id=30721 
Mon Jun 22 17:46:03 2015
CKPT started with pid=12, OS id=30723 
Mon Jun 22 17:46:03 2015
SMON started with pid=13, OS id=30725 
Mon Jun 22 17:46:03 2015
RECO started with pid=14, OS id=30727 
Mon Jun 22 17:46:03 2015
MMON started with pid=15, OS id=30729 
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
Mon Jun 22 17:46:03 2015
MMNL started with pid=16, OS id=30731 
starting up 1 shared server(s) ...
ORACLE_BASE from environment = /oracle/ora11gR2
Mon Jun 22 17:46:04 2015
ALTER DATABASE   MOUNT
Successful mount of redo thread 1, with mount id 2809595100
Database mounted in Exclusive Mode
Lost write protection disabled
Completed: ALTER DATABASE   MOUNT
Mon Jun 22 17:46:08 2015
ALTER DATABASE OPEN
Thread 1 opened at log sequence 1279
  Current log# 1 seq# 1279 mem# 0: /oracle/ora11gR2/oradata/dcsopen/redo01.log
Successful open of redo thread 1
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
SMON: enabling cache recovery
Successfully onlined Undo Tablespace 2.
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Database Characterset is ZHS16GBK
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Mon Jun 22 17:46:09 2015
QMNC started with pid=20, OS id=30789 
Completed: ALTER DATABASE OPEN
Starting background process CJQ0
Mon Jun 22 17:46:11 2015
CJQ0 started with pid=22, OS id=30806 
Mon Jun 22 17:46:18 2015
Shutting down instance (normal)
Shutting down instance: further logons disabled
Stopping background process QMNC
Stopping background process CJQ0
Stopping background process MMNL
Stopping background process MMON
License high water mark = 5
All dispatchers and shared servers shutdown
ALTER DATABASE CLOSE NORMAL
Mon Jun 22 17:46:22 2015
SMON: disabling tx recovery
SMON: disabling cache recovery
Mon Jun 22 17:46:22 2015
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
Thread 1 closed at log sequence 1279
Successful close of redo thread 1
Completed: ALTER DATABASE CLOSE NORMAL
ALTER DATABASE DISMOUNT
Completed: ALTER DATABASE DISMOUNT
ARCH: Archival disabled due to shutdown: 1090
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
Mon Jun 22 17:46:23 2015
Stopping background process VKTM: 
ARCH: Archival disabled due to shutdown: 1090
Shutting down archive processes
Archiving is disabled
Archive process shutdown avoided: 0 active
Mon Jun 22 17:46:25 2015
Instance shutdown complete


借鉴《Concept》,一些知识点:

1. 如果用户试图访问一个正在关闭的数据库,会得到错误提示:ORA-01090: shutdown in progress - connection is not permitted.

2. 关闭数据库,必须用SYSOPER或SYSDBA的角色。

3. 关闭数据库,是有超时时间的,如果用户未中断连接,或者交易未完成,超过一小时,则shutdown命令会取消,提示错误:ORA-01013: user requested cancel of current operation.

4. 几种关闭库的参数,

shutdown normal:

默认的关闭参数,需要两个条件:

(1) 执行语句后,不允许新的连接。

(2) 数据库关闭之前,数据库会等待所有已连接用户中断连接。

下一次启动时不需要实例恢复。

shutdown immediate:

使用场景:

(1) 初始化一个自动,无人值守的备份。

(2) 马上就要断电。

(3) 数据库或应用工作不正常,你不能马上联系到用户退出登录或他们无法退出登录。

条件:

(1) 不允许新的连接,不允许新的交易。

(2) 任何未提交的事务会回滚(如果此时有个长交易,未提交,那么不会像这种关闭名称immediate那样迅速地关闭)。

(3) 不会等待已连接用户退出登录。数据库会隐式回滚活动事务,中断连接用户。

下一次启动时不需要实例恢复。

shutdown transactional:

适用于计划停机,允许活动交易处理完成后再停止实例的场景。

条件:

(1) 不允许新的连接,不允许新的交易。

(2) 所有交易完成后,会中断所有和库的连接。

(3) 在这个时间点,关闭实例就像执行了shutdown immediate。

下一次启动时不需要实例恢复。

transactional参数主要会防止用户丢失交易,同时不需要所有用户退出登录。

shutdown abort:

适用场景:

数据库或应用不能正常工作,并且没有其它类型的关闭操作正在进行。

(1) 需要立即关闭数据库(例如,一分钟后电源会被关闭)。

(2) 启动实例时碰到了问题。

条件:

(1) 不允许新的连接,不允许新的交易。

(2) 正在被Oracle处理的客户端SQL语句会被立即中断。

(3) 未提交事务不会回滚。

(4) Oracle不会等待正保持连接的客户端退出登录。数据库会隐式地中断所有连接。

下一次启动时需要进行实例恢复。

总结:

以上四种参数会适合于不同的场景,简单讲,shutdown normal是默认的关闭方式,最完整的关闭方式,缺点是需要被动等待所有交易完成,所有用户退出登录。shutdown immediate只要不存在较长的需要回滚的事务,其关闭时间会快。shutdown transactional会最大限度地保证交易的完成。前三种都不需要实例恢复。shutdown abort则是最暴力的关闭,关闭时间最快,但代价是启动需要实例恢复,因为关闭时存在未回滚未提交的事务。

标签:22,normal,process,hang,数据库,Jun,Mon,shutdown,2015
From: https://blog.51cto.com/u_13950417/6512496

相关文章

  • 克隆数据库,速度至上
    《Linux7安装Oracle11g打怪经历》完成了数据库软件的初始安装,如果要同步复制到多套相同的环境,选择克隆数据库,是个好的选择。原始数据库首先,将数据库软件的$ORACLE_HOME路径进行打包,但是要注意,如果使用root打包,会提示错误,[root@bisal]$tarzcvf11g.tar11.2.0.4tar:Exitingwi......
  • .net 数据库开发的时候的一些错误
    (.netC#)今天找到了一个错误,就是在数据库记录用程序插入的时候,竟然没有检查数据库的列和插入列有没有匹配,找出错误。 ......
  • 非Oracle Linux下Oracle 19c CDB数据库安装
    《非OracleLinux下安装Oracle19c》我们安装了non-cdb的19c数据库,通过这个脚本,还可以搭建cdb的数据库。1.修改安装脚本cp/etc/init.d/oracledb_ORCLCDB-19c/etc/init.d/oracledb_pdbisal-19c其中要改几处,ORACLE_SID改成新的,LISTENER_NAME改成新的,CREATE_AS_CDB之前我写的false,......
  • 代码如何连接数据库?常用的方式有几种?
    在现代应用程序开发中,与数据库的交互是非常重要的一步。要想使用数据库,我们需要对应的编程语言提供的库或框架来实现数据库的连接和交互。本文将从几个方面介绍代码如何连接数据库,并详细介绍常用的方式。一、什么是数据库连接?数据库连接是指应用程序通过特定的接口与一个或多个数据......
  • mybatis-plus 数据库日志仅打印SQL
     一、项目背景:springboot、web组件、Mysql8、java8+; 二、开发环境打印SQL及执行结果日志,便于调试接口;mybatis-plus配置文件的configuration节点添加以下配置2、效果   三、生产环境仅打印SQL,避免打印过多的查询结果影响系统性能    1、pom中增加sl4j的......
  • 三种数据库架构的介绍
    从数据库架构设计的角度,主要有三种,SharedEverything、SharedDisk以及SharedNothing。1. SharedEverything一般指的是单个主机的环境,完全透明共享的CPU/内存/硬盘,并行处理能力是最差的,典型代表就是SQLServer、单机版Oracle和MySQL,一般不考虑大规模的并发需求,架构比较简单,一般......
  • android连接本地数据库sqlite,实现增删改查
    前言Android应用数据存储简单来说有这么几种:文件存储、SharedPreference存储、SQLite数据库存储、网络服务器存储、ContentProvider等。如果需要存储的数据量大的时候,那么使用文件存储会有很大的弊端,例如:你想修改其中很微小的项就要先读取整个文件的内容,修改后再全部保存,非常耗时。......
  • Android 架构之 MVI 完全体 | 重新审视 MVVM 之殇,PartialChange & Reducer 来拯救
    作者:唐子玄MVI架构有三大关键词:“唯一可信数据源”+“单向数据流”+“响应式编程”,以及一些关键概念,比如Intent,State。理解这些概念之后,能更轻松地阅读本文。(强烈建议从第一篇开始阅读)引子在上一篇中,用MVI重构了“新闻流”这个业务场景。本篇在此基础上进一步拓展,引入MVI中......
  • Windows调试Oracle数据库问题的一些手段
    最近需要在Windows的跳板机上访问远程的Oracle数据库进行调试。Windows中只有个精简版OracleClient,以及PLSQLDeveloper客户端。如果用惯了Linux,再用Windows,确实不知所措。但这就是个从生疏到熟练的事儿,最近看的一本书中描述得很恰当,Themosteffectivewaytodealwithaworry......
  • 20230423 15. 抽象工厂模式 - 数据库
    介绍工厂方法模式是定义一个用于创建对象的接口,让子类决定实例化哪一个类。抽象工厂模式(AbstractFactory),提供一个创建一系列相关或相互依赖对象的接口,而无须指定它们具体的类。AbstractProductA和AbstractProductB是两个抽象产品,之所以为抽象,是因为它们都有可能有两种不同......