在Oracle 19c中,若要创建CDB容器数据库环境,可以使用如下几种办法:
1、DBCA静默创建CDB2、DBCA图形化界面创建CDB3、手动创建CDB,即使用create database来创建CDB4、duplicate a CDB5、Using DBCA to Duplicate a CDB
在OCP的课件中,Oracle给我们提供了如下图的几种方式:
从本节开始,麦老师将依次讲解使用DBCA静默创建CDB 、DBCA图形化界面创建CDB、手动创建CDB,即使用create database来创建CDB 、duplicate a CDB、Using DBCA to Duplicate a CDB这5种方式来创建CDB。
麦老师觉得,这种方式创建数据库,是一个DBA必须要会的技能。想起曾几何时,领导让我创建一个数据库,而我还傻傻的向领导去申请Xmanager Enterprise软件,还告诉领导,有这个软件才能把图形界面调出来,进而才能创建数据库,哎,,,
静默删库:
1dbca -silent -deleteDatabase -sourceDB lhr19cdb -sysDBAUserName sys -sysDBAPassword lhr -forceArchiveLogDeletion
创建存储为磁盘组的CDB单实例数据库:
1dbca -silent -ignorePreReqs -ignorePrereqFailure -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname lhr19cdb -sid lhr19cdb \
3-createAsContainerDatabase TRUE \
4-sysPassword lhr -systemPassword lhr -pdbAdminPassword lhr -dbsnmpPassword lhr \
5-datafileDestination '+DATA' -recoveryAreaDestination '+FRA' \
6-redoLogFileSize 50 \
7-storageType ASM \
8-characterset AL32UTF8 \
9-sampleSchema true \
10-totalMemory 1024 \
11-databaseType MULTIPURPOSE \
12-emConfiguration NONE
创建rac类型的CDB数据库:
1dbca -silent -ignorePreReqs -ignorePrereqFailure -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname rac19c -sid rac19c \
3-createAsContainerDatabase TRUE \
4-sysPassword lhr -systemPassword lhr -pdbAdminPassword lhr -dbsnmpPassword lhr \
5-datafileDestination '+DATA' -recoveryAreaDestination '+FRA' \
6-redoLogFileSize 50 \
7-storageType ASM \
8-characterset AL32UTF8 \
9-sampleSchema true \
10-totalMemory 1024 \
11-databaseType MULTIPURPOSE \
12-emConfiguration none \
13-nodeinfo raclhr-19c-n1,raclhr-19c-n2
创建FS存储方式的单实例(不含PDB)数据库:
1dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname CDBLHR -sid CDBLHR \
3-createAsContainerDatabase TRUE \
4-sysPassword lhr -systemPassword lhr \
5-datafileDestination '/u01/app/oracle/oradata' \
6-recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
7-redoLogFileSize 50 \
8-storageType FS \
9-characterset ZHS16GBK -nationalCharacterSet AL16UTF16 \
10-sampleSchema true \
11-totalMemory 1024 \
12-databaseType OLTP \
13-emConfiguration NONE
创建FS存储方式的单实例(含一个PDB)数据库:
1dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname CDBLHR3 -sid CDBLHR3 \
3-createAsContainerDatabase TRUE \
4-numberOfPDBs 1 \
5-pdbName pdb2 \
6-pdbAdminPassword lhr \
7-sysPassword lhr -systemPassword lhr \
8-datafileDestination '/u01/app/oracle/oradata' \
9-recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
10-redoLogFileSize 50 \
11-storageType FS \
12-characterset ZHS16GBK -nationalCharacterSet AL16UTF16 \
13-sampleSchema true \
14-totalMemory 1024 \
15-databaseType OLTP \
16-emConfiguration NONE
静默方式创建一个非CDB数据库:
1dbca -silent -ignorePreReqs -ignorePrereqFailure -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname lhrdb -sid lhrdb \
3-createAsContainerDatabase FALSE \
4-sysPassword lhr -systemPassword lhr -dbsnmpPassword lhr \
5-datafileDestination '/u01/app/oracle/oradata' -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
6-storageType FS \
7-characterset ZHS16GBK \
8-sampleSchema true \
9-totalMemory 600 \
10-databaseType MULTIPURPOSE \
11-emConfiguration NONE
创建CDB数据库示例
麦老师不能把所有情况都演示一次,我这里只演示其中的一种,其它情况大家自行测试。
接下来创建的是一个文件系统存储的CDB数据库,默认包含一个PDB,脚本如下所示:
1dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname CDBLHR -sid CDBLHR \
3-createAsContainerDatabase TRUE \
4-numberOfPDBs 1 \
5-pdbName pdb2 \
6-pdbAdminPassword lhr \
7-sysPassword lhr -systemPassword lhr \
8-datafileDestination '/u01/app/oracle/oradata' \
9-recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
10-redoLogFileSize 50 \
11-storageType FS \
12-characterset AL32UTF8 -nationalCharacterSet AL16UTF16 \
13-sampleSchema true \
14-totalMemory 1024 \
15-databaseType OLTP \
16-emConfiguration NONE
执行过程:
1[oracle@lhrora19c ~]$ sqlplus -v
2
3SQL*Plus: Release 19.0.0.0.0 - Production
4Version 19.3.0.0.0
5
6[oracle@lhrora19c ~]$ dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
7> -gdbname CDBLHR -sid CDBLHR \
8> -createAsContainerDatabase TRUE \
9> -numberOfPDBs 1 \
10> -pdbName pdb2 \
11> -pdbAdminPassword lhr \
12> -sysPassword lhr -systemPassword lhr \
13> -datafileDestination '/u01/app/oracle/oradata' \
14> -recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
15> -redoLogFileSize 50 \
16> -storageType FS \
17> -characterset AL32UTF8 -nationalCharacterSet AL16UTF16 \
18> -sampleSchema true \
19> -totalMemory 1024 \
20> -databaseType OLTP \
21> -emConfiguration NONE
22[WARNING] [DBT-06208] The 'SYS' password entered does not conform to the Oracle recommended standards.
23 CAUSE:
24a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
25b.The password entered is a keyword that Oracle does not recommend to be used as password
26 ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
27[WARNING] [DBT-06208] The 'SYSTEM' password entered does not conform to the Oracle recommended standards.
28 CAUSE:
29a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
30b.The password entered is a keyword that Oracle does not recommend to be used as password
31 ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
32[WARNING] [DBT-06208] The 'PDBADMIN' password entered does not conform to the Oracle recommended standards.
33 CAUSE:
34a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
35b.The password entered is a keyword that Oracle does not recommend to be used as password
36 ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
37Prepare for db operation
388% complete
39Copying database files
4031% complete
41Creating and starting Oracle instance
4232% complete
4336% complete
4440% complete
4543% complete
4646% complete
47Completing Database Creation
4851% complete
4953% complete
5054% complete
51Creating Pluggable Databases
5258% complete
5377% complete
54Executing Post Configuration Actions
55100% complete
56Database creation complete. For details check the logfiles at:
57 /opt/oracle/cfgtoollogs/dbca/CDBLHR.
58Database Information:
59Global Database Name:CDBLHR
60System Identifier(SID):CDBLHR
61Look at the log file "/opt/oracle/cfgtoollogs/dbca/CDBLHR/CDBLHR.log" for further details.
这样我们就创建完一个CDB数据库,不用做其他交互式操作,是不是非常简单?我们进入数据库就可以做基本的操作了。
1[oracle@lhrora19c ~]$ ORACLE_SID=CDBLHR
2[oracle@lhrora19c ~]$ sas
3
4SQL*Plus: Release 19.0.0.0.0 - Production on Fri Oct 23 16:20:12 2020
5Version 19.3.0.0.0
6
7Copyright (c) 1982, 2019, Oracle. All rights reserved.
8
9
10Connected to:
11Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
12Version 19.3.0.0.0
13
14SYS@CDBLHR> show pdbs
15
16 CON_ID CON_NAME OPEN MODE RESTRICTED
17---------- ------------------------------ ---------- ----------
18 2 PDB$SEED READ ONLY NO
19 3 PDB2 READ WRITE NO
有关每个参数的详细含义和静默建库的常见故障处理请参考:【DB笔试面试852】在Oracle中,什么是静默建库?
DBCA静默建库如何创建归档模式的数据库DBCA静默建库默认创建的是一个非归档的数据库,这是由配置文件$ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc决定的,如下:
1[oracle@lhrora19c ~]$ strings $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc | grep -i arch
2 <archiveLogMode>false</archiveLogMode>
3[oracle@lhrora19c ~]$
所以,若想创建一个归档模式的数据库,可以将该值修改为true,后续所有DBCA创建的数据库都是一个归档模式的数据库。
DBCA静默建库的日志在哪里?111g开始:$ORACLE_BASE/cfgtoollogs/dbca
210g:$ORACLE_HOME/cfgtoollogs/dbca
从该日志中可以找到DBCA静默建库的详细过程,值得我们深入分析。
本文结束。