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> ```

相关推荐
·薯条大王4 小时前
MySQL联合查询
数据库·mysql
morris1316 小时前
【redis】redis实现分布式锁
数据库·redis·缓存·分布式锁
hycccccch7 小时前
Canal+RabbitMQ实现MySQL数据增量同步
java·数据库·后端·rabbitmq
这个懒人7 小时前
深入解析Translog机制:Elasticsearch的数据守护者
数据库·elasticsearch·nosql·translog
Yan-英杰7 小时前
【百日精通JAVA | SQL篇 | 第二篇】数据库操作
服务器·数据库·sql
NineData8 小时前
NineData云原生智能数据管理平台新功能发布|2025年3月版
数据库
百代繁华一朝都-绮罗生9 小时前
检查是否存在占用内存过大的SQL
数据库·sql
吾日三省吾码9 小时前
Python 脚本:自动化你的日常任务
数据库·python·自动化
CZIDC9 小时前
win11 系统环境下 新安装 WSL ubuntu + ssh + gnome 桌面环境
数据库·ubuntu·ssh
直裾9 小时前
Mapreduce的使用
大数据·数据库·mapreduce