DBCA静默删除数据库

使用DBCA静默方式安装了几次数据库后,才感觉到这种方式安装数据库的便利之处,并且对于DBCA静默安装的方式越发喜欢了起来。还记得之前通过GUI模式进行配置,总是免不了需要配置好几分钟,并且安装过程少不了30分钟,而现在2~3分钟简单配置好dbca的响应文件后,不到10分钟一个数据库就可以安装出来。

正式因为使用DBCA静默的方式中感受到了方便,而删除数据库也是同样的道理。通过DBCA静默方式,无需再借一些图形化工具辅助打开GUI界面,完全可以在终端上完成对数据库的删除工作,极大便利了日常对数据库的安装及删除操作。

DBCA

DBCA是Oracle软件包中用来安装/卸载/配置数据库的一个工具,其提供了两种方式对数据库进行安装或卸载,分别是 GUI界面静默模式

图形化安装的方式相对来说比较简单,容易上手,但是不具备重复利用性。每次重新安装数据库的时候都可能需要进行相同的配置,而这无疑会消耗工作者的精力。相比来说,静默模式则可以将创建数据的配置参数持久化到文件中,以便下一次重新安装数据库时再次调用,但因为需要配置相关参数,需要额外一部分成本了解各项参数的含义。不过,总体感觉吧,利大于弊。

  • DBCA命令行帮助信息

如果你直接在终端命令行下执行 dbca -help,那么很可能你会遇到 DISPLAY not set 这样的一个提示。这是因为Oracle启动DBCA工具时,需要使用到 DISPLAY 的环境变量,而当前用户并未设置改环境变量导致的。

# dbca -help
DISPLAY not set.
Set DISPLAY environment variable, then re-run.

解决方式通过在终端执行 export DISPLAY={local_ip}:{port} 即可。

# export DISPLAY=172.16.xx.xx:1

再次执行 dbca -help 即可看到DBCA工具提供的一些功能。

# dbca -help
Usage:  dbca [<flag>] [<command> <option>]
Following are the possible flags:
    -help
        -contextId <RAC | SI>
    -ignorePreReqs - Ignore prerequisite checks for current operation.
    -ignorePrereqFailure  - Ignore all prerequisites failures.
    -silent - This flag allows you to carry on configuration in silent mode.
        -<command>

Following are the possible commands:
    -addInstance - Command to Add an instance to an admin managed cluster database.
    -configureDatabase - Command to Configure a database.
    -configurePluggableDatabase - Command to Configure a pluggable database.
    -createCloneTemplate - Command to Create a clone template from an existing database.
    -createDatabase - Command to Create a database.
    -createDuplicateDB - Command to Duplicate a database.
    -createPluggableDatabase - Command to Create a pluggable database.
    -createTemplateFromDB - Command to Create a template from an existing database.
    -createTemplateFromTemplate - Command to Create a template from an existing template.
    -deleteDatabase - Command to Delete a database.
    -deleteInstance - Command to Delete an instance from an admin managed cluster database.
    -deletePluggableDatabase - Command to Delete a pluggable database.
    -deleteTemplate - Command to delete a template.
    -executePrereqs - Command to execute prerequisite checks.
    -generateScripts - Command to Generate scripts which can be used to create database.
    -relocatePDB - Command to Relocate a pluggable database.
    -unplugDatabase - Command to Unplug a pluggable database.

工具提示包含两部分的内容,分别为 flagscommandsflags 部分提供了安装时可选的一些参数,例如,-silent 指定安装时使用静默模式安装;-ignorePreReqs 则会在安装数据库前跳过数据库依赖的检查;-ignorePrereqFailure 同理,只是针对安装前检查失败的依赖项结果忽略处理。

commands 部分就是DBCA可以使用的功能了。例如 -addInstance 为当前集群添加一个数据库实例;-configureDatabase 配置数据库的一些选项;-createDatabase 功能则可以用来创建数据库;-deleteDatabase 功能则可以用来删除数据库。

删除数据库

这里主要使用 dbca -silent 模式在终端下删除数据库。删除数据库时,也可以通过制作dbca响应文件的方式进行删除数据库的操作。不过,通常情况下,删除数据库需要指定的参数并不会像创建数据库那么多,因此,也可以直接在终端通过 命令+参数 的方式进行删除。

删除数据库的具体参数如下

# dbca -silent -deleteDatabase -help
    -deleteDatabase - Command to Delete a database.
        -sourceDB <Database unique name for RAC database or SID for Single Instance database>
        [-useWalletForDBCredentials <true | false> Specify true to load database credentials from wallet]
            -dbCredentialsWalletLocation <Path of the directory containing the wallet files>
            [-dbCredentialsWalletPassword <Password to open wallet with auto login disabled>]
        [-unregisterWithDirService <true | false>]
            -dirServiceUserName <User name for directory service>
            [-dirServicePassword <Password for directory service>]
            [-walletPassword <Password for database wallet>]
        [-deRegisterEMCloudControl ]
            -emUser <EM Admin username to add or modify targets>
            -omsHost <EM management server host name>
            -omsPort <EM management server port number>
            [-emPassword <EM Admin user password>]
        [-sysDBAUserName <User name  with SYSDBA privileges>]
        [-forceArchiveLogDeletion <To delete archive logs of a database>]
        [-sysDBAPassword <Password for sysDBAUserName user name>]
        [-sid <Database system identifier>]
  • sourceDB: 数据库名称。必须指定

  • useWalletForDBCredentials: 是否使用wallet作为数据库凭证。默认为false。

  • unregisterWithDirService: 是否使用DirService服务注销数据库。

  • deRegisterEMCloudControl: 企业版功能。将注册的数据库服务从EM云控制服务中注销。

  • sysDBAUserName: 删除数据库需要指定系统管理员用户。推荐配置

  • forceArchiveLogDeletion: 删除数据库强制删除归档日志。

  • sysDBAPassword: 删除数据库的系统管理员认证密码。推荐配置

  • sid: 数据库实例标识符。

删除数据库

# dbca -silent -deleteDatabase -sourceDB test -sysDBAUserName sys -sysDBAPassword oracle
[WARNING] [DBT-19202] The Database Configuration Assistant will delete the Oracle instances and datafiles for your database. All information in the database will be destroyed.
Prepare for db operation
32% complete
Connecting to database
39% complete
42% complete
45% complete
48% complete
52% complete
55% complete
58% complete
65% complete
Updating network configuration files
68% complete
Deleting instances and datafiles
77% complete
87% complete
97% complete
100% complete
Database deletion completed.
Look at the log file "/xxxx/cfgtoollogs/dbca/test/test0.log" for further details.

使用DBCA静默删除的方式删除数据库很快,执行结束后,操作系统上的数据库就没了,如果需要将数据库对应的日志文件也一并删除,可以手动进行删除。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容