DBA必备神器Oracle关库

脚本的功能

这个脚本就像是一个"数据库关闭管家",它考虑了以下场景:

  1. 既能关单库,也能关全库(就像一键关灯和一键关所有灯的区别)
  2. 多库关闭时可以并行处理(就是传说中的"分身术")
  3. 通过ckpt进程智能识别ORACLE_HOME环境(不用手动设置环境变量,懒人福音!)
  4. 根据输入的实例名精准关闭(不会误伤其他数据库,很有礼貌的脚本)
  5. 多实例关闭时互不影响(一个实例出问题,其他实例表示:关我啥事?)
  6. 所有操作都会生成SQL脚本后再执行(方便debug,就像留下作案现场一样)

关闭过程主要包含三个步骤:

  1. 日志切换(如果是备库就跳过,毕竟备库也要面子)
  2. 杀进程(温柔或暴力,由你选择)
  3. 关闭数据库(最后的最后)

关闭模式有两种:

  1. shutdown abort模式:简单粗暴,不切换日志,不杀进程,直接关!(就像拔电源一样干脆)
  2. shutdown immediate模式:温柔优雅,该切换切换,该清理清理(讲究人用的模式)

默认采用shutdown immediate模式,并使用操作系统kill命令(保持优雅的同时又不失效率)

脚本的参数说明

脚本的使用方法简单得像点外卖一样,来看看这个"数据库外卖菜单":

yihan:shutdown yihan$ ./shutdown --h   

Usage: shutdown [-s htz1] [-h help] [-d] [-ec ORA-12345] [-ic ORA-00060] [-f mode]
Options: 
the script encounters an error, please contact: 18081072613 (same number for phone and WeChat).
Shutdown modes (-f):
    a: Abort mode - Uses shutdown abort without session termination
    k: Kill mode - Uses OS kill for LOCAL=NO sessions before shutdown immediate
    n: Normal mode - Uses alter system kill session before shutdown immediate
    
  -d    Enable script debugging
  -ec string
        Manual input error code,Comma-spaced multiple values
  -f string
        Shutdown mode: a (abort), k (os kill), n (normal kill) (default "k")
  -h    display help information
  -ic string
        Manual input ignore code,Comma-spaced multiple values
  -s string
        instance name you will shutdown,0 will shutdown all instance (default "htz")

参数说明(通俗版):

-d  开启调试模式,就像打开显微镜一样,让你看清每一步操作(所有命令都会乖乖记录在log文件里)
-ec 遇到这些ORA错误就立刻停止(就像遇到红灯要停车一样)
-ic 遇到这些ORA错误就装作没看见(就像对某些bug睁一只眼闭一只眼 )
-s  要关闭哪个数据库?输入0就是包场,全部关掉!(默认只关名叫htz的库)
-f  选择关闭模式:
    a - 暴力模式(就像拔电源)
    k - 温柔模式,用操作系统方式请走用户
    n - 绅士模式,用数据库命令优雅地请走用户

你可能感兴趣的:(技术分享,dba,oracle,数据库)