Oracle 12c: Create a Container Database manually

Oracle 12c: Create a Container Database (CDB) manually with CREATE DATABASE script

Note:
Oracle strongly recommends using the Database Configuration Assistant (DBCA) instead of the CREATE DATABASE SQL statement to create a CDB, because using DBCA is a more automated approach, and your CDB is ready to use when DBCA completes.

1. Setup Database environment
Set the ORACLE_SID and ORACLE_HOME environment variable and include the ORACLE_HOME/bin directory to the PATH variable.

export ORACLE_SID=newcdb
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH

 

CREATE CDB MANUALLY 01

 

NOTE: You must choose a Database Administrator authentication method
– You must be authenticated and granted appropriate system privileges in order to create a database.
– You can be authenticated as an administrator with the required privileges in the following ways:
a. With a password file (sqlplus sys as sysdba)
Example: orapwd FILE=’/u01/app/oracle/product/12.1.0/db_1/dbs/orapwnewcdb’ ENTRIES=10 FORMAT=12

CREATE CDB MANUALLY 02 ORAPWD

b. With operating system authentication (sqlplus / as sysdba)
Ensure that you log in to the host computer with a user account that is a member of the appropriate operating system user group (typically the dba user group).

 

2. Create the Initialization Parameter File
cd $ORACLE_HOME/dbs
vi initnewcdb.ora
cat initnewcdb.ora

sga_target=500M
pga_aggregate_target=260M
audit_file_dest="/u01/app/oracle/admin/newcdb/adump"
audit_trail=db
compatible=12.1.0.2.0
control_files=("/u01/app/oracle/oradata/newcdb/control01.ctl","/u01/app/oracle/fast_recovery_area/newcdb/control02.ctl")
db_block_size=8192
db_domain=localdomain
db_name="newcdb"
db_recovery_file_dest="/u01/app/oracle/fast_recovery_area"
db_recovery_file_dest_size=4560m
diagnostic_dest=/u01/app/oracle
dispatchers="(PROTOCOL=TCP) (SERVICE=newcdbXDB)"
enable_pluggable_database=true
open_cursors=300
processes=300
remote_login_passwordfile=EXCLUSIVE
undo_tablespace=UNDOTBS1

 

CREATE CDB MANUALLY 03 INIT

CREATE CDB MANUALLY 03 INIT 2

 

3. Create needed directories
CONTROL FILES:
mkdir -p /u01/app/oracle/oradata/newcdb
mkdir -p /u01/app/oracle/fast_recovery_area/newcdb
DATA FILES:
# mkdir -p /u01/app/oracle/oradata/newcdb
mkdir -p /u01/app/oracle/oradata/newcdb/pdbseed
REDO LOG FILES:
# mkdir -p /u01/app/oracle/oradata/newcdb
mkdir -p /u02/app/oracle/oradata/newcdb
ADUMP:
mkdir -p /u01/app/oracle/admin/newcdb/adump

 

CREATE CDB MANUALLY 04 MKDIR

 

4. Create Database script
To create a CDB, the ENABLE_PLUGGABLE_DATABASE initialization parameter must be set to TRUE.
Note: /home/oracle/bin exists in my environment
vi /home/oracle/bin/create_db_newcdb.sql

CREATE DATABASE newcdb
 USER SYS IDENTIFIED BY sys_password
 USER SYSTEM IDENTIFIED BY system_password
 LOGFILE GROUP 1 ('/u01/app/oracle/oradata/newcdb/redo01a.log','/u02/app/oracle/oradata/newcdb/redo01b.log')
 SIZE 100M BLOCKSIZE 512,
 GROUP 2 ('/u01/app/oracle/oradata/newcdb/redo02a.log','/u02/app/oracle/oradata/newcdb/redo02b.log')
 SIZE 100M BLOCKSIZE 512,
 GROUP 3 ('/u01/app/oracle/oradata/newcdb/redo03a.log','/u02/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/')
 SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
 SYSAUX DATAFILES SIZE 100M
;

 

CREATE CDB MANUALLY 05 CREATE DB SCRIPT

 

5. Login to the Database

$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Mon Oct 9 13:15:24 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to an idle instance.
SQL>

6. Create a Server Parameter File

SQL> create spfile from pfile='/u01/app/oracle/product/12.1.0/db_1/dbs/initnewcdb.ora';
File created.

7. Start the Instance

SQL> startup nomount;
ORACLE instance started.
Total System Global Area 524288000 bytes
Fixed Size 2926320 bytes
Variable Size 268437776 bytes
Database Buffers 247463936 bytes
Redo Buffers 5459968 bytes
SQL>

 

CREATE CDB MANUALLY 06 SPFILE

 

8. Use the CREATE DATABASE statement to create the new CDB.

SQL> set echo on
SQL> set timing on
SQL> @/home/oracle/bin/create_db_newcdb.sql
SQL> CREATE DATABASE newcdb
 2 USER SYS IDENTIFIED BY oracle3
 3 USER SYSTEM IDENTIFIED BY oracle3
 4 LOGFILE GROUP 1 ('/u01/app/oracle/oradata/newcdb/redo01a.log','/u02/app/oracle/oradata/newcdb/redo01b.log')
 5 SIZE 100M BLOCKSIZE 512,
 6 GROUP 2 ('/u01/app/oracle/oradata/newcdb/redo02a.log','/u02/app/oracle/oradata/newcdb/redo02b.log')
 7 SIZE 100M BLOCKSIZE 512,
 8 GROUP 3 ('/u01/app/oracle/oradata/newcdb/redo03a.log','/u02/app/oracle/oradata/newcdb/redo03b.log')
 9 SIZE 100M BLOCKSIZE 512
 10 MAXLOGHISTORY 1
 11 MAXLOGFILES 16
 12 MAXLOGMEMBERS 3
 13 MAXDATAFILES 1024
 14 CHARACTER SET AL32UTF8
 15 NATIONAL CHARACTER SET AL16UTF16
 16 EXTENT MANAGEMENT LOCAL
 17 DATAFILE '/u01/app/oracle/oradata/newcdb/system01.dbf'
 18 SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
 19 SYSAUX DATAFILE '/u01/app/oracle/oradata/newcdb/sysaux01.dbf'
 20 SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
 21 DEFAULT TABLESPACE USERS
 22 DATAFILE '/u01/app/oracle/oradata/newcdb/users01.dbf'
 23 SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
 24 DEFAULT TEMPORARY TABLESPACE TEMP
 25 TEMPFILE '/u01/app/oracle/oradata/newcdb/temp01.dbf'
 26 SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
 27 UNDO TABLESPACE UNDOTBS1
 28 DATAFILE '/u01/app/oracle/oradata/newcdb/undotbs01.dbf'
 29 SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
 30 ENABLE PLUGGABLE DATABASE
 31 SEED
 32 FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/newcdb/',
 33 '/u01/app/oracle/oradata/newcdb/pdbseed/')
 34 SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
 35 SYSAUX DATAFILES SIZE 100M
 36 ;
Database created.
Elapsed: 00:01:15.92

 

CREATE CDB MANUALLY 07 CREATE DB RUN

 

— Validate if the database created is a CDB

SQL> SELECT dbid, name, created, log_mode, open_mode, cdb, con_id FROM v$database;
 DBID NAME CREATED LOG_MODE OPEN_MODE CDB CON_ID
---------- --------- --------- ------------ -------------------- --- ----------
 46140884 NEWCDB 10-OCT-17 NOARCHIVELOG READ WRITE YES 0

— Validate if the seed database is created

SQL> SELECT con_id, dbid, name, open_mode, restricted, TO_CHAR(open_time, 'DD-MON-YY HH:MI:SS AM') OPEN_TIME FROM v$containers;
 CON_ID DBID NAME OPEN_MODE RES OPEN_TIME
---------- ---------- -------- ---------- --- ------------------------------
 1 46140884 CDB$ROOT READ WRITE NO 10-OCT-17 10:36:54 AM
 2 3138122242 PDB$SEED READ ONLY NO 10-OCT-17 10:36:54 AM

 

CREATE CDB MANUALLY 08 VALIDATE

 

— Query CDB/PDB name, tablespace name, datafile location, size, and status

SELECT c.name DB_NAME, a.name TABLESPACE_NAME, b.name DATA_FILE_NAME, b.bytes/1024/1024 SIZE_MB, b.status
 -- c.name DB_NAME, a.con_id, a.ts#, a.name TABLESPACE_NAME, b.name DATA_FILE_NAME, b.file#, b.blocks, b.bytes/1024/1024 SIZE_MB, b.status, b.enabled, b.creation_time
 FROM v$tablespace a, v$datafile b, v$containers c
 WHERE a.con_id = b.con_id
 AND a.con_id = c.con_id
 AND a.ts# = b.ts#
 ORDER BY a.con_id, a.TS#;

 

CREATE CDB MANUALLY 09 TBS

 

— Check Control files

SQL> show parameter control_files
NAME TYPE VALUE
-------------- -------- ------------------------------
control_files string /u01/app/oracle/oradata/newcdb/control01.ctl, /u01/app/oracle/fast_recovery_area/newcdb/control02.ctl

— Check Redo log files

SQL> SELECT a.group#, a.members, a.bytes/1024/1024 SIZE_MB, a.status, b.member
 FROM v$log a, v$logfile b
 WHERE a.group# = b.group#;
 GROUP# MEMBERS SIZE_MB STATUS MEMBER
---------- ---------- ---------- ---------- ----------------------------------------
 1 2 100 CURRENT /u01/app/oracle/oradata/newcdb/redo01a.log
 1 2 100 CURRENT /u02/app/oracle/oradata/newcdb/redo01b.log
 2 2 100 UNUSED /u01/app/oracle/oradata/newcdb/redo02a.log
 2 2 100 UNUSED /u02/app/oracle/oradata/newcdb/redo02b.log
 3 2 100 UNUSED /u01/app/oracle/oradata/newcdb/redo03a.log
 3 2 100 UNUSED /u02/app/oracle/oradata/newcdb/redo03b.log

 

CREATE CDB MANUALLY 10 Ctl redo

 

— Check if the NLS parameters are set as per the response file

SQL> SELECT * FROM v$nls_parameters WHERE parameter LIKE '%CHARACTERSET%';
PARAMETER VALUE CON_ID
------------------------- --------------- ------
NLS_CHARACTERSET AL32UTF8 0
NLS_NCHAR_CHARACTERSET AL16UTF16 0

 

CREATE CDB MANUALLY 11 NLS

 

9. Data Dictionary views

We need to run the Oracle supplied dictionary scripts like catalog.sql, catproc.sql, pupbld.sql to populate the necessary dictionary views when we create a Oracle database manually using CREATE DATABASE statement.

But it’s different for a container database, because we have multiple container databases such as CDB$ROOT and PDB$SEED, we need to run these scripts against each of these containers. To simplify the creation of dictionary views in a CDB, Oracle provides a script called catcdb.sql located under $ORACLE_HOME/rdbms/admin directory.

However, when we run the catcdb.sql script, it creates all the database components like the way DBCA does, it will create database components like Spatial, Oracle Text, XDK, etc, even if we wouldn’t use them. So we would use the catcon.pl located under $ORACLE_HOME/rdbms/admin to run the Oracle supplied scripts (catalog.sql, catproc.sql, etc) against our container databases.

# running catalog.sql script against CDB containers
$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u sys -d $ORACLE_HOME/rdbms/admin -b catalog_output -e -l /home/oracle catalog.sql

# running catproc.sql script against CDB containers
$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u sys -d $ORACLE_HOME/rdbms/admin -b catproc_output -e -l /home/oracle catproc.sql

# running pupbld.sql script against CDB containers
$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -u system -d $ORACLE_HOME/sqlplus/admin -b pupbld_output -e -l /home/oracle pupbld.sql

NOTE: We used sys, sys, and system account here

 

CREATE CDB MANUALLY 12 catcon 1

 

— Query the status of database components

col comp_name for a40
col version for a15
col status for a10
SELECT name, comp_name, version, status FROM v$database, dba_registry;
NAME COMP_NAME VERSION STATUS
--------- ---------------------------------------- --------------- ----------
newcdb Oracle XML Database 12.1.0.2.0 VALID
newcdb Oracle Database Catalog Views 12.1.0.2.0 INVALID
newcdb Oracle Database Packages and Types 12.1.0.2.0 INVALID

 

CREATE CDB MANUALLY 13 dba_registry

 

— Recompile all the INVALID objects

@?/rdbms/admin/utlrp.sql

 

CREATE CDB MANUALLY 13 dba_registry 2

 

— Query the status of database components again

col comp_name for a40
col version for a15
col status for a10
SELECT name, comp_name, version, status FROM v$database, dba_registry;
NAME COMP_NAME VERSION STATUS
--------- ---------------------------------------- --------------- ----------
newcdb Oracle XML Database 12.1.0.2.0 VALID
newcdb Oracle Database Catalog Views 12.1.0.2.0 VALID
newcdb Oracle Database Packages and Types 12.1.0.2.0 VALID

 

CREATE CDB MANUALLY 13 dba_registry 3

 

10. Create a PDB

-- Creating PDB mypdb_01 using seed database (PDB$SEED)
CREATE PLUGGABLE DATABASE newpdb1 ADMIN USER pdbadmin IDENTIFIED BY oracle
FILE_NAME_CONVERT=('/u01/app/oracle/oradata/newcdb/pdbseed/','/u01/app/oracle/oradata/newcdb/newpdb1/');
Pluggable database created.

— Open the PDB for READ-WRITE

ALTER PLUGGABLE DATABASE newpdb1 OPEN;
Pluggable database altered.

— Validate the PDB

SELECT name, open_mode, restricted FROM v$pdbs;
NAME OPEN_MODE RES
------------------------------ ---------- ---
PDB$SEED READ ONLY NO
PDB1 READ WRITE NO

 

CREATE CDB MANUALLY 14 NEWPDB

 

— Validate list of datafiles from each of the containers

-- Query CDB/PDB name, con_id, tablespace name, datafile location, size, and status
SELECT c.name DB_NAME, b.name DATA_FILE_NAME
 -- a.con_id, a.ts#, a.name TABLESPACE_NAME, b.name DATA_FILE_NAME, b.file#, b.blocks, b.bytes/1024/1024 SIZE_MB, b.status, b.enabled, b.creation_time
 FROM v$tablespace a, v$datafile b, v$containers c
 WHERE a.con_id = b.con_id
 AND a.con_id = c.con_id
 AND a.ts# = b.ts#
 ORDER BY a.con_id, a.TS#;

DB_NAME DATA_FILE_NAME
---------- --------------------------------------------------
CDB$ROOT /u01/app/oracle/oradata/newcdb/system01.dbf
CDB$ROOT /u01/app/oracle/oradata/newcdb/sysaux01.dbf
CDB$ROOT /u01/app/oracle/oradata/newcdb/undotbs01.dbf
CDB$ROOT /u01/app/oracle/oradata/newcdb/users01.dbf
PDB$SEED /u01/app/oracle/oradata/newcdb/pdbseed/system01.dbf
PDB$SEED /u01/app/oracle/oradata/newcdb/pdbseed/sysaux01.dbf
PDB$SEED /u01/app/oracle/oradata/newcdb/pdbseed/users01.dbf
PDB1 /u01/app/oracle/oradata/newcdb/pdb1/system01.dbf
PDB1 /u01/app/oracle/oradata/newcdb/pdb1/sysaux01.dbf
PDB1 /u01/app/oracle/oradata/newcdb/pdb1/users01.dbf

NOTE: Because we created the CDB manually, if we did not create an entry for it on /etc/oratab, we wouldn’t see its entry on DBCA (let’s say you wanted to delete it).

This is my personal notes and I hope you learned something from it!

Like Loading…

Measure

Measure

Read more

How to migrate Raspberry Pi 5 OS from micro SD to NVME m.2 SSD

首先我買了Raspberry Pi CM5後來買了Raspberry Pi CM5 I/O board來當個人電腦使用,系統是安裝在256GB SD卡上運行的很好。用久了在開啟較肥的程式像Web Browser或LiberOffice會有慢半拍的反應,而有了升級NVME m.2 SSD念頭。 因為Raspberry Pi 5支援的最快PCIe gen3 x 4就不去考慮快的Gen4 or Gen5 m.2 SSD。找了ADATA出的 LEGEND 710入門級的產品,會利用HMB(Host Memory Buffer)來加速I/O速度,因為是Raspberry Pi OS kernel會認不得而無法正常使用 事先在SD卡的/boot/firmware/cmdline.txt 加入 kernel command line參數如下,然後重開機m.

By Phillips Hsieh

How to document Home Lab and Network

運維機房和跨域的網路,會遇到各式需求與問題,用對工具才能分析問題,個人覺得最重要的是使用能處理問題的工具。 推薦目前想學和正在使用的平台與軟體,協助將公司/家用機房文件化 佈告欄任務管理 Focalboard 白板可管理任務指派 網路架構文件編寫 netbox 精細管理網路設備與連接線路 IP 資源管理 phpipam 專注網路IP分配 邏輯塊文件編寫 draw.io 視覺化概念圖 機房設備管理 ITDB 管理設備生命週期與使用者

By Phillips Hsieh

如何在Raspberry Pi4上安裝Proxmox for ARM64

第一步 準備好Raspberry Pi 4 / CM4 4GB RAM,這裡要留意CM4如果是買有內建eMMC storage會限制不能使用SD卡開機而限制本地空間容量,如果沒有NAS外接空間或使用USB開機的話,建議買CM4 Lite插上大容量SD卡 第二步 去Armbian官網下載最小化Debian bookworm image https://www.armbian.com/rpi4b/ Armbian 25.2.2 Bookworm Minimal / IOT 然後寫入SD/USB開機碟,寫入方法參考官方文件 https://github.com/raspberrypi/usbboot/blob/master/Readme.md Note: 官方提供的預先設定系統方法,可以在Armbian初次啟動自動化完成系統設定。連結在此 https://docs.armbian.com/User-Guide_Autoconfig/

By Phillips Hsieh

世界越快心越慢

在晚飯後的休息時間,我特別享受在客廳瀏灠youtube上各樣各式創作者的影音作品。很大不同於傳統媒體,節目多是針對大多數族群喜好挑選的,在youtube上我會依心情看無腦的動畫、一些旅拍記錄、新聞時事談論。 尤其在看了大量的Youtube的分享後,我真的感受到會限制我的是我的無知,特別是那些我想都沒想過的實際應用,在學習後大大幫助到我的生活和工作層面。 休息在家時,我喜歡想一些沒做過的菜,動手去設計生活和工作上的解決方案,自己是真的很難閒著沒事做。 如創作文章,陪養新的習慣都能感覺到成長的喜悅,是不同於吃喝玩樂的快樂的。 創作不去限制固定的形式,文字是創作、影像聲音也是創作,記錄生活也是創作,我想留下的就是創造—》實現—》回憶,這樣子的循環過程,在留下的足跡面看到自己一路上的成長、失敗、絕望、重新再來。 雖然大部份的時候去做這些創作也不明白有什麼特別的意義,但不去做也不會留下什麼,所以呀不如反事都去試試看,也許能有不一樣的水花也許有意想不到的結果,投資自己永遠不會是失敗的決定,不是嗎?先問問自己再開始計畫下一步,未來沒人說得準。 像最近看youtube仍大一群人在為DOS開

By Phillips Hsieh