(修改版)
环境:redhat linux 5企业版
创建时需要指定enable pluggable database,不加为non-CDB
seed file_name_convert 指定如何通过root的文件来生成seed的文件,做的是目录转换。
pdb_file_name_convert 指定pdb文件和seed文件的转换路径关系
手工建库:
1 参数:
vi initnewcdb.ora
*.control_files='/u01/app/oracle/oradata/newcdb/control01.ctl','/u01/app/oracle/oradata/newcdb/control02.ctl'
*.db_block_size=16384
*.db_name='newcdb'
*.diagnostic_dest='/u01/app/oracle'
*.enable_pluggable_database=true --新参数
*.memory_target=800m
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
2 创建目录,口令文件
cd $ORACLE_HOME/dbs
orapwd file=orapwnewcdb password=oracle entries=30 format=12
cd $ORACLE_BASE/oradata
mkdir -p newcdb/pdbseed
3 执行建库语句 ,捎带解释一下
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 10M BLOCKSIZE 512,
GROUP 2 ('/u01/app/oracle/oradata/newcdb/redo02a.log','/u01/app/oracle/oradata/newcdb/redo02b.log')
SIZE 10M BLOCKSIZE 512,
GROUP 3 ('/u01/app/oracle/oradata/newcdb/redo03a.log','/u01/app/oracle/oradata/newcdb/redo03b.log')
SIZE 10M BLOCKSIZE 512
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
CHARACTER SET ZHS16GBK
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 deftbs DATAFILE '/u01/app/oracle/oradata/newcdb/deftbs01.dbf' SIZE 50M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
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 20M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
ENABLE PLUGGABLE DATABASE --这个必须有,要不创建是的non-CDB
SEED --cdb的数据库包括root,seed,pdb,我们跑完这个脚本,创建的是root,seed
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/newcdb/', --seed的文件参照cdb的产生,所以这里需要对应root和cdb文件目录的对应关系
'/u01/app/oracle/oradata/newcdb/pdbseed/')
SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
SYSAUX DATAFILES SIZE 100M
USER_DATA TABLESPACE usertbs
DATAFILE '/u01/app/oracle/oradata/newcdb/pdbseed/usertbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
-执行成功,看看生成的文件:
oracle@linux12c:/u01/app/oracle/oradata/newcdb$ls
control01.ctl deftbs01.dbf redo01a.log redo02a.log redo03a.log sysaux01.dbf temp01.dbf
control02.ctl pdbseed redo01b.log redo02b.log redo03b.log system01.dbf undotbs01.dbf
oracle@linux12c:/u01/app/oracle/oradata/newcdb$
oracle@linux12c:/u01/app/oracle/oradata/newcdb$
oracle@linux12c:/u01/app/oracle/oradata/newcdb$
oracle@linux12c:/u01/app/oracle/oradata/newcdb$cd pdbseed
oracle@linux12c:/u01/app/oracle/oradata/newcdb/pdbseed$ls
deftbs01.dbf sysaux01.dbf system01.dbf temp01.dbf usertbs01.dbf
oracle@linux12c:/u01/app/oracle/oradata/newcdb/pdbseed$
oracle@linux12c:/u01/app/oracle/oradata/newcdb$du -sm
1899 .
oracle@linux12c:/u01/app/oracle/oradata/newcdb$
-运行脚本
用sysdba权限用户执行
conn /as sysdba
@?/rdbms/admin/catcdb.sql --发现此脚本竟然没有,难道是官档bug
@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
--发现上面两个脚本的执行比9、10、11版本的执行要多很多东西
system用户执行
conn system/oracle
@?/sqlplus/admin/pupbld.sql
在/etc/oratab中添加如下行:
newcdb:/u01/app/oracle/product/12.1.0/dbhome_1:N
4 配置EM EXPRESS for CDB
--发现使用https://192.168.11.20:1158/em可以访问,但使用system和密码不能登录:
如果手工设定端口,存在两个协议:
如果为http,使用
conn /as sysdba
exec DBMS_XDB_CONFIG.SETHTTPPORT(http_port_number);
如果为https,使用
conn /as sysdba
exec DBMS_XDB_CONFIG.SETHTTPSPORT(http_port_number);
SQL> conn /as sysdba
Connected.
SQL> exec DBMS_XDB_CONFIG.SETHTTPSPORT(1158);
PL/SQL procedure successfully completed.
SQL>
SQL>
--但是通过https://192.168.11.20:1158/em还是无法访问
重启cdb,依旧不能访问
重启os,不能访问
此问题留给以后处理吧
5 之后配置
--现在数据库只有CDB和SEED,如果需要添加PDB,需要自己添加
--这个内容在后面章节
遗憾的是em express没有成功打开。
虽然手工创建cdb成功了,但是发现在cdb下创建pdb的时候说缺包,可能是哪块还是少了
下面摘录了一份dbca下创建cdb的脚本,写的比较全,大家可以适当参考如下的脚本,特别是创建系统必须的数据字典的部分。
======================================================================================================
Oracle 12c使用dbca创建cdb保存的脚本
oracle@linux12c:/home/oracle$cd/u01/app/oracle/admin/newcdb/scripts/
oracle@linux12c:/u01/app/oracle/admin/newcdb/scripts$ll
total 72
-rw-r----- 1 oracle oinstall 378 Dec 3 00:56 apex.sql
-rw-r----- 1 oracle oinstall 978 Dec 3 00:56 context.sql
-rw-r----- 1 oracle oinstall 540 Dec 3 00:56 CreateClustDBViews.sql
-rw-r----- 1 oracle oinstall 1823 Dec 3 00:56 CreateDBCatalog.sql
-rw-r----- 1 oracle oinstall 404 Dec 3 00:56 CreateDBFiles.sql
-rw-r----- 1 oracle oinstall 1677 Dec 3 00:56 CreateDB.sql
-rw-r----- 1 oracle oinstall 345 Dec 3 00:56 cwmlite.sql
-rw-r----- 1 oracle oinstall 357 Dec 3 00:56 datavault.sql
-rw-r----- 1 oracle oinstall 1957 Dec 3 00:56 init.ora
-rw-r----- 1 oracle oinstall 334 Dec 3 00:56 interMedia.sql
-rw-r----- 1 oracle oinstall 1139 Dec 3 00:56 JServer.sql
-rw-r----- 1 oracle oinstall 336 Dec 3 00:56 labelSecurity.sql
-rw-r----- 1 oracle oinstall 1153 Dec 3 00:56 lockAccount.sql
-rwxr-xr-x 1 oracle oinstall 855 Dec 3 00:56 newcdb.sh
-rwxr-xr-x 1 oracle oinstall 1085 Dec 3 00:56 newcdb.sql
-rw-r----- 1 oracle oinstall 352 Dec 3 00:56 ordinst.sql
-rw-r----- 1 oracle oinstall 845 Dec 3 00:56 postDBCreation.sql
-rw-r----- 1 oracle oinstall 327 Dec 3 00:56 spatial.sql
oracle@linux12c:/u01/app/oracle/admin/newcdb/scripts$
oracle@linux12c:/u01/app/oracle/admin/newcdb/scripts$morenewcdb.sql
set verify off
ACCEPT sysPassword CHAR PROMPT 'Enter newpassword for SYS: ' HIDE
ACCEPT systemPassword CHAR PROMPT 'Enternew password for SYSTEM: ' HIDE
host/u01/app/oracle/product/12.1.0/dbhome_1/bin/orapwdfile=/u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwnewcdb force=y format=12
@/u01/app/oracle/admin/newcdb/scripts/CreateDB.sql
@/u01/app/oracle/admin/newcdb/scripts/CreateDBFiles.sql
@/u01/app/oracle/admin/newcdb/scripts/CreateDBCatalog.sql
@/u01/app/oracle/admin/newcdb/scripts/JServer.sql
@/u01/app/oracle/admin/newcdb/scripts/context.sql
@/u01/app/oracle/admin/newcdb/scripts/ordinst.sql
@/u01/app/oracle/admin/newcdb/scripts/interMedia.sql
@/u01/app/oracle/admin/newcdb/scripts/cwmlite.sql
@/u01/app/oracle/admin/newcdb/scripts/spatial.sql
@/u01/app/oracle/admin/newcdb/scripts/labelSecurity.sql
@/u01/app/oracle/admin/newcdb/scripts/apex.sql
@/u01/app/oracle/admin/newcdb/scripts/datavault.sql
@/u01/app/oracle/admin/newcdb/scripts/CreateClustDBViews.sql
@/u01/app/oracle/admin/newcdb/scripts/lockAccount.sql
@/u01/app/oracle/admin/newcdb/scripts/postDBCreation.sql
oracle@linux12c:/u01/app/oracle/admin/newcdb/scripts$
oracle@linux12c:/home/oracle$more/u01/app/oracle/admin/newcdb/scripts/CreateDB.sql
SET VERIFY OFF
connect"SYS"/"&&sysPassword" as SYSDBA
set echo on
spool/u01/app/oracle/admin/newcdb/scripts/CreateDB.log append
startup nomountpfile="/u01/app/oracle/admin/newcdb/scripts/init.ora";
CREATE DATABASE "newcdb"
MAXINSTANCES 8
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
DATAFILE'/u01/app/oracle/oradata/newcdb/system01.dbf' SIZE 700M REUSE AUTOEXTEND ONNEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE'/u01/app/oracle/oradata/newcdb/sysaux01.dbf' SIZE 550M REUSE AUTOEXTEND ONNEXT 10240K MAXSIZE UNLIMITED
SMALLFILE DEFAULT TEMPORARY TABLESPACE TEMPTEMPFILE '/u01/app/oracle/oradata/newcdb/temp01.dbf' SIZE 20M REUSE AUTOEXTENDON NEXT 640K MAXSIZE UNLIMITED
SMALLFILE UNDO TABLESPACE"UNDOTBS1" DATAFILE '/u01/app/oracle/oradata/newcdb/undotbs01.dbf' SIZE 200M REUSEAUTOEXTEND ON NEXT 5120K MAXSIZEUNLIMITED
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
LOGFILE GROUP 1('/u01/app/oracle/oradata/newcdb/redo01.log') SIZE 50M,
GROUP 2('/u01/app/oracle/oradata/newcdb/redo02.log') SIZE 50M,
GROUP 3('/u01/app/oracle/oradata/newcdb/redo03.log') SIZE 50M
USER SYS IDENTIFIED BY"&&sysPassword" USER SYSTEM IDENTIFIED BY"&&systemPassword"
enable pluggable database
seedfile_name_convert=('/u01/app/oracle/oradata/newcdb/system01.dbf','/u01/app/oracle/oradata/newcdb/pdbseed/system01.dbf','/u01/app/oracle/oradata/newcdb/sysaux01.dbf','/u01/a
pp/oracle/oradata/newcdb/pdbseed/sysaux01.dbf','/u01/app/oracle/oradata/newcdb/temp01.dbf','/u01/app/oracle/oradata/newcdb/pdbseed/temp01.dbf','/u01/app/oracle/oradata/newcdb/un
dotbs01.dbf','/u01/app/oracle/oradata/newcdb/pdbseed/undotbs01.dbf');
spool off
oracle@linux12c:/home/oracle$
oracle@linux12c:/home/oracle$more/u01/app/oracle/admin/newcdb/scripts/CreateDBFiles.sql
SET VERIFY OFF
connect"SYS"/"&&sysPassword" as SYSDBA
set echo on
spool /u01/app/oracle/admin/newcdb/scripts/CreateDBFiles.logappend
CREATE SMALLFILE TABLESPACE"USERS" LOGGING DATAFILE '/u01/app/oracle/oradata/newcdb/users01.dbf'SIZE 5M REUSE AUTOEXTEND ON NEXT 1280KMAXSIZE UNLIMITED EXTENT MANAGEMENT
LOCAL SEGMENT SPACE MANAGEMENT AUTO;
ALTER DATABASE DEFAULT TABLESPACE"USERS";
spool off
oracle@linux12c:/home/oracle$
oracle@linux12c:/home/oracle$more/u01/app/oracle/admin/newcdb/scripts/CreateDBCatalog.sql
SET VERIFY OFF
connect"SYS"/"&&sysPassword" as SYSDBA
set echo on
spool/u01/app/oracle/admin/newcdb/scripts/CreateDBCatalog.log append
alter session set"_oracle_script"=true;
alter pluggable database pdb$seed close;
alter pluggable database pdb$seed open;
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b catalog/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/adm
in/catalog.sql;
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b catblock/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/ad
min/catblock.sql;
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b catproc/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/adm
in/catproc.sql;
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b catoctk/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/adm
in/catoctk.sql;
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b owminst/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/adm
in/owminst.plb;
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b pupbld -uSYSTEM/&&systemPassword /u01/app/oracle/product
/12.1.0/dbhome_1/sqlplus/admin/pupbld.sql;
connect"SYSTEM"/"&&systemPassword"
set echo on
spool/u01/app/oracle/admin/newcdb/scripts/sqlPlusHelp.log append
host perl /u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl-n 1 -l /u01/app/oracle/admin/newcdb/scripts -b hlpbld -uSYSTEM/&&systemPassword -a 1 /u01/app/oracle/p
roduct/12.1.0/dbhome_1/sqlplus/admin/help/hlpbld.sql1helpus.sql;
spool off
spool off
oracle@linux12c:/home/oracle$
oracle@linux12c:/home/oracle$more/u01/app/oracle/admin/newcdb/scripts/lockAccount.sql
SET VERIFY OFF
connect"SYS"/"&&sysPassword" as SYSDBA
set echo on
spool/u01/app/oracle/admin/newcdb/scripts/lockAccount.log append
alter session set"_oracle_script"=true;
alter pluggable database pdb$seed close;
alter pluggable database pdb$seed open;
BEGIN
FORitem IN ( SELECT USERNAME FROM DBA_USERS WHERE ACCOUNT_STATUS IN ('OPEN','LOCKED', 'EXPIRED') AND USERNAME NOT IN (
'SYS','SYSTEM') )
LOOP
dbms_output.put_line('Locking and Expiring: ' || item.USERNAME);
execute immediate 'alter user ' ||
sys.dbms_assert.enquote_name(
sys.dbms_assert.schema_name(
item.USERNAME),false) || ' password expire account lock' ;
ENDLOOP;
END;
/
alter session set container=pdb$seed;
BEGIN
FORitem IN ( SELECT USERNAME FROM DBA_USERS WHERE ACCOUNT_STATUS IN ('OPEN','LOCKED', 'EXPIRED') AND USERNAME NOT IN (
'SYS','SYSTEM') )
LOOP
dbms_output.put_line('Locking and Expiring: ' || item.USERNAME);
execute immediate 'alter user ' ||
sys.dbms_assert.enquote_name(
sys.dbms_assert.schema_name(
item.USERNAME),false) || ' password expire account lock' ;
ENDLOOP;
END;
/
alter session set container=cdb$root;
spool off
oracle@linux12c:/home/oracle$
oracle@linux12c:/home/oracle$more/u01/app/oracle/admin/newcdb/scripts/postDBCreation.sql
SET VERIFY OFF
spool/u01/app/oracle/admin/newcdb/scripts/postDBCreation.log append
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b catbundle -a 1 /u01/app/oracle/product/12.1.0/dbhome_1/r
dbms/admin/catbundle.sql 1psu 1apply;
connect"SYS"/"&&sysPassword" as SYSDBA
set echo on
createspfile='/u01/app/oracle/product/12.1.0/dbhome_1/dbs/spfilenewcdb.ora' FROMpfile='/u01/app/oracle/admin/newcdb/scripts/init.ora';
connect"SYS"/"&&sysPassword" as SYSDBA
host perl/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin/catcon.pl -n 1 -l/u01/app/oracle/admin/newcdb/scripts -b utlrp/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/admin
/utlrp.sql;
select comp_id, status from dba_registry;
shutdown immediate;
connect"SYS"/"&&sysPassword" as SYSDBA
startup ;
spool off
exit;
oracle@linux12c:/home/oracle$