Oracle12c手工创建多租户容器数据库(手工建库CDB)
本文介绍如何在Oracle数据库12.2中手工创建CDB容器数据库
1、创建密码文件
bash
cd $ORACLE_HOME/dbs/
orapwd file=orapwnewcdb password=oracle format=12 entries=10
2、创建目录
bash
mkdir -p /u01/app/oracle/oradata/newcdb/pdbseed
3、创建静态参数文件
建议的最小初始化参数文件:db_name,control_files,memory_target
bash
cd $ORACLE_HOME/dbs/
vim initnewcdb.ora
bash
db_name=newcdb
control_files=('/u01/app/oracle/oradata/newcdb/control01.ctl','/u01/app/oracle/oradata/newcdb/control02.ctl','/u01/app/oracle/oradata/newcdb/control03.ctl')
memory_target=800m
enable_pluggable_database=TRUE
4、切换环境并启动到 nomount
bash
export ORACLE_SID=newcdb
sqlplus / as sysdba
create spfile from pfile;
startup nomount;
5、执行建库语句
bash
CREATE DATABASE newcdb
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
LOGFILE GROUP 1 ('/u01/app/oracle/oradata/newcdb/redo01a.log','/u01/app/oracle/oradata/newcdb/redo01b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/u01/app/oracle/oradata/newcdb/redo02a.log','/u01/app/oracle/oradata/newcdb/redo02b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/u01/app/oracle/oradata/newcdb/redo03a.log','/u01/app/oracle/oradata/newcdb/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 '/u01/app/oracle/oradata/newcdb/system01.dbf'
SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE '/u01/app/oracle/oradata/newcdb/sysaux01.dbf'
SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
DEFAULT TABLESPACE USERS
DATAFILE '/u01/app/oracle/oradata/newcdb/users01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE TEMP
TEMPFILE '/u01/app/oracle/oradata/newcdb/temp01.dbf'
SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE UNDOTBS1
DATAFILE '/u01/app/oracle/oradata/newcdb/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
ENABLE PLUGGABLE DATABASE
SEED
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/newcdb/',
'/u01/app/oracle/oradata/newcdb/pdbseed/')
LOCAL UNDO ON;
数据库创建完成,检查数据库的状态是:OPEN
bash
SYS@newcdb> select status from v$instance;
OPEN
6、后续工作,执行脚本:
6.1、第一步:修改$ORACLE_HOME/rdbms/admin/catcdb.pl
bash
[oracle@enmoedu1 admin]$vi $ORACLE_HOME/rdbms/admin/catcdb.pl
把util修改为Util
use Term::ReadKey; # to not echo password
use Getopt::Long;
use Cwd;
use File::Spec;
use Data::Dumper;
use Util qw(trim, splitToArray);
use catcon qw(catconSqlplus);
6.2、第二步:设置环境perl的环境变量:
bash
[oracle@enmoedu1 ~]$ vi .bash_profile
添加如下的环境变量:
bash
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/perl/bin:$ORACLE_HOME/jdk/bin:$PATH
oracle@enmoedu1 \~\]$ source .bash_profile #### 6.3、第三步:执行脚本: 首先切换到perl的目录下: ```bash [oracle@enmoedu1 ~]$cd $ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash [oracle@enmoedu1 ~]sqlplus / as sysdba SYS@newcdb>@?/rdbms/admin/catcdb.sql SQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --logFilename &&2 Enter value for 1: /u01/app/oracle/product/12.2.0/dbhome_1/rdbms/admin Enter value for 2: /u01/app/oracle/product/12.2.0/dbhome_1/rdbms/admin/catcdb.pl Enter new password for SYS: oracle Enter new password for SYSTEM: oracle Enter temporary tablespace name: temp No options to container mapping specified, no options will be installed in any containers catcon: ALL catcon-related output will be written to [/U01/app/oracle/product/12.2/rdbms/admin/catalog_catcon_46984.lst] catcon: See [/U01/app/oracle/product/12.2/rdbms/admin/catalog*.log] files for output generated by s catcon: See [/U01/app/oracle/product/12.2/rdbms/admin/catalog_*.lst] files for spool files, if any ``` 然后就是一段时间的等待,可以从日志看到会关联调用catalog.sql,catproc.sql等脚本文件。 #### 6.4、第四步:使用SYSTEM用户执行SQL\*Plus相关脚本 ```bash SYS@newcdb>conn system/oracle SYS@newcdb>@?/sqlplus/admin/pupbld.sql ``` #### 6.5、第五步:验证结果 ```bash SYS@newcdb> show parameter pluggable NAME TYPE VALUE enable_pluggable_database boolean TRUE SYS@newcdb> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED 2 PDB$SEED READ ONLY NO SYS@newcdb> select name from v$datafile where con_id=1; /u01/app/oracle/oradata/newcdb/system01.dbf /u01/app/oracle/oradata/newcdb/sysaux01.dbf /u01/app/oracle/oradata/newcdb/undotbs01.dbf /u01/app/oracle/oradata/newcdb/USERS01.dbf SYS@newcdb> select name from v$datafile where con_id=2; /u01/app/oracle/oradata/newcdb/pdbseed/system01.dbf /u01/app/oracle/oradata/newcdb/pdbseed/sysaux01.dbf /u01/app/oracle/oradata/newcdb/pdbseed/undotbs01.dbf /u01/app/oracle/oradata/newcdb/pdbseed/USERS01.dbf SYS@newcdb> select name from v$tempfile; /u01/app/oracle/oradata/newcdb/temp01.dbf /u01/app/oracle/oradata/newcdb/pdbseed/temp01.dbf SYS@newcdb> ```