Oracle12c手工创建多租户容器数据库(手工建库CDB)

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>
相关推荐
时差95315 分钟前
【面试题】Hive 查询:如何查找用户连续三天登录的记录
大数据·数据库·hive·sql·面试·database
让学习成为一种生活方式17 分钟前
R包下载太慢安装中止的解决策略-R语言003
java·数据库·r语言
Mephisto.java23 分钟前
【大数据学习 | kafka高级部分】kafka的优化参数整理
大数据·sql·oracle·kafka·json·database
秋意钟43 分钟前
MySQL日期类型选择建议
数据库·mysql
Dxy12393102161 小时前
python下载pdf
数据库·python·pdf
桀桀桀桀桀桀2 小时前
数据库中的用户管理和权限管理
数据库·mysql
BearHan3 小时前
Sqlsugar调用Oracle的存储过程
oracle·存储过程·orm
superman超哥3 小时前
04 深入 Oracle 并发世界:MVCC、锁、闩锁、事务隔离与并发性能优化的探索
数据库·oracle·性能优化·dba
用户8007165452003 小时前
HTAP数据库国产化改造技术可行性方案分析
数据库
engchina4 小时前
Neo4j 和 Python 初学者指南:如何使用可选关系匹配优化 Cypher 查询
数据库·python·neo4j