1. 检查、准备必要的环境变量
# su - oracle
$ cat .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/dbhome_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH:$HOME/.local/bin:$HOME/bin
如果没有以上环境变量需要加入。在命令行定义要创建的CDB数据库的SID。
$ export ORACLE_SID=cdb1
2. 编辑pfile文件
必须增加的参数:
- db_name
- enable_pluggable_database
建议增加的参数:
- db_block_size
- control_files
可选的参数:
- db_create_file_dest 此参数的值是指定在创建数据库时,控制文件、redolog文件、数据文件存储路径。如果使用ASM时,该值形如“+DATA”即可。
$ cd $ORACLE_HOME/dbs
$ cp init.ora initcdb1.ora
$ vim initcdb1.ora
$ cat initcdb1.ora
db_name='cdb1'
db_block_size=8192
control_files=(cdb1_control1, cdb1_control2, cdb1_control3)
enable_pluggable_database=TRUE
3. 编辑“创建数据库”脚本
从Oracle官网,复制创建脚本,并根据自己的定义进行修改。
$ vim createcdb.sql
$ cat createcdb.sql
CREATE DATABASE cdb1
USER SYS IDENTIFIED BY Oracle123
USER SYSTEM IDENTIFIED BY Oracle123
LOGFILE GROUP 1 ('/oradata/cdb1/logdisk1/redo01a.log','/oradata/cdb1/logdisk2/redo01b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/oradata/cdb1/logdisk1/redo02a.log','/oradata/cdb1/logdisk2/redo02b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/oradata/cdb1/logdisk1/redo03a.log','/oradata/cdb1/logdisk2/redo03b.log')
SIZE 100M BLOCKSIZE 512
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '/oradata/cdb1/system01.dbf'
SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE '/oradata/cdb1/sysaux01.dbf'
SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
DEFAULT TABLESPACE deftbs
DATAFILE '/oradata/cdb1/deftbs01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/oradata/cdb1/temp01.dbf'
SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE undotbs1
DATAFILE '/oradata/cdb1/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
ENABLE PLUGGABLE DATABASE
SEED
FILE_NAME_CONVERT = ('/oradata/cdb1/',
'/oradata/cdb1/pdbseed/')
SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
SYSAUX DATAFILES SIZE 100M
USER_DATA TABLESPACE usertbs
DATAFILE '/oradata/cdb1/pdbseed/usertbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
注意:路径的创建。
$ mkdir -p /oradata/cdb1/{logdisk1,logdisk2,pdbseed}
如果参数文件中配置了DB_CREATE_FILE_DEST 参数,可以使用下面的创建语句。
CREATE DATABASE cdb2
USER SYS IDENTIFIED BY Oracle123
USER SYSTEM IDENTIFIED BY Oracle123
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DEFAULT TABLESPACE users
DEFAULT TEMPORARY TABLESPACE temp
UNDO TABLESPACE undotbs1
ENABLE PLUGGABLE DATABASE
SEED
SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
SYSAUX DATAFILES SIZE 100M;
4. 执行脚本创建CDB
$ export ORACLE_SID=cdb1
$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri May 5 11:54:34 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 318767104 bytes
Fixed Size 8792152 bytes
Variable Size 251660200 bytes
Database Buffers 50331648 bytes
Redo Buffers 7983104 bytes
SQL> @/home/oracle/createcdb.sql
Database created.
5. 执行以下数据库系统提供的脚本。
- 数据字典等等,执行时间比较长。
SQL> @?/rdbms/admin/catalog.sql
SQL> @?/rdbms/admin/catblock.sql
SQL> @?/rdbms/admin/catproc.sql
SQL> @?/rdbms/admin/catoctk.sql
SQL> @?/rdbms/admin/owminst.plb
- 安装CDB的所有组件。
SQL> @?/rdbms/admin/catcdb.sql
- 切换到system用户,执行pupbld.sql。
SQL> conn system
Enter password:
Connected.
SQL> @?/sqlplus/admin/pupbld.sql
6. 检查
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
1 row selected.
SQL> col file_name for a60
SQL> select con_id,file_name from cdb_data_files;
CON_ID FILE_NAME
---------- ------------------------------------------------------------
1 /oradata/cdb1/system01.dbf
1 /oradata/cdb1/sysaux01.dbf
1 /oradata/cdb1/undotbs01.dbf
1 /oradata/cdb1/deftbs01.dbf
4 rows selected.
网友评论