共计 6105 个字符,预计需要花费 16 分钟才能阅读完成。
这篇文章主要介绍了 oracle 12 DBCA 如何创建 pdb,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让丸趣 TV 小编带着大家一起了解一下。
12c 新推出的 pdb 是一种全新的数据库管理模式,有别于传统的数据库。今天的实验室是使用 dbca 图形界面创建一个 pdb,再用 dbca 的静默方式创建一个 pdb。
pdb 是可插拔数据库,当然也就离不开 cdb。c 就是 container, 容器。
环境变量如下
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1
export ORACLE_SID=CDB
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
在这里如果有报错 Error in Process:/u01/app/oracle/product/12.1.0/db_1/perl/bin/perl
可参见我的另一篇博客 http://blog.itpub.net/29047826/viewspace-1434056/
[oracle@snow ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Sun Feb 8 16:11:18 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
查看 pdb 状态,已经是 open(read write)
SQL
SQL show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
图形安装后包含了根库 CDB$ROOT,con_id 为 1,包含种子库 PDB$SEED,con_id 为 2,还包含本次创建的可插拔库 pdb1,con_id 为 3
SQL select con_id,name from v$containers;
CON_ID NAME
———- ——————————
1 CDB$ROOT
2 PDB$SEED
3 PDB1
查看 cdb_data_files 数据字典可以看到 cdb 的数据文件和 pdb 的数据文件
SQL col file_name for a60
SQL set line 120
SQL select con_id,file_name from cdb_data_files order by 1;
CON_ID FILE_NAME
———- ————————————————————
1 /u01/app/oracle/oradata/CDB/system01.dbf
1 /u01/app/oracle/oradata/CDB/users01.dbf
1 /u01/app/oracle/oradata/CDB/undotbs01.dbf
1 /u01/app/oracle/oradata/CDB/sysaux01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/sysaux01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/system01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/sysaux01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/pdb1_users01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/system01.dbf
如果切换到 pdb,就只能看到属于自己的数据文件
SQL alter session set container=pdb1;
SQL col name for a60
SQL select con_id,name from v$datafile;
CON_ID NAME
———- ————————————————————
0 /u01/app/oracle/oradata/CDB/undotbs01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/system01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/sysaux01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/pdb1_users01.dbf
由于我的虚拟机空间较小,先用 dbca 删除刚才创建的 cdb 和 pdb 再执行下面的脚本。注意 dbca 删除数据库后并不清理磁盘上的物理文件,需要手动删除比如 rm -rf $ORACLE_BASE/oradata/CDB,这个命令只是一个事例请勿模仿。
下面这条 dbca – silent … 语句是一条完整的语句,不换行。里面的关键字是 createAsContainerDatabase true, 如果没有该关键字创建出来的就是一个普通的数据库,而不是我们此次需要的 CDB。
该命令执行后,输出 Copying database files ..1% complete
[oracle@snow ~]$ dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname CDB -sid CDB -responseFile NO_VALUE -characterSet AL32UTF8 -memoryPercentage 30 -emConfiguration LOCAL -createAsContainerDatabase true -sysPassword oracle -systemPassword oracle
Copying database files
1% complete
3% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
46% complete
47% complete
52% complete
57% complete
58% complete
59% complete
62% complete
Completing Database Creation
66% complete
70% complete
74% complete
85% complete
96% complete
100% complete
Look at the log file /u01/app/oracle/cfgtoollogs/dbca/CDB/CDB.log for further details.
到此为止 CDB 创建完成,通过下面的 sql 语句查看其内容。
[oracle@snow ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Sun Feb 8 16:51:36 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
SQL
SQL select con_id,name from v$containers;
CON_ID NAME
———- ——————————
1 CDB$ROOT
2 PDB$SEED
SQL col file_name for a60
SQL select con_id,file_name from cdb_data_files order by 1;
CON_ID FILE_NAME
———- ————————————————————
1 /u01/app/oracle/oradata/CDB/system01.dbf
1 /u01/app/oracle/oradata/CDB/users01.dbf
1 /u01/app/oracle/oradata/CDB/undotbs01.dbf
1 /u01/app/oracle/oradata/CDB/sysaux01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/sysaux01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/system01.dbf
下面通过种子容器创建 pdb
[oracle@snow ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Sun Feb 8 16:59:03 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL create pluggable database pdb1 admin user pdb1adm identified by oracle file_name_convert=(/u01/app/oracle/oradata/CDB/pdbseed , /u01/app/oracle/oradata/CDB/pdb1
Pluggable database created.
此时 pdb 的状态是 mounted
SQL show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED
下面的额查询语句只有跟库的信息,无法显示 pdb 的信息
SQL select con_id,file_name from cdb_data_files order by 1;
CON_ID FILE_NAME
———- ————————————————–
1 /u01/app/oracle/oradata/CDB/system01.dbf
1 /u01/app/oracle/oradata/CDB/sysaux01.dbf
1 /u01/app/oracle/oradata/CDB/undotbs01.dbf
1 /u01/app/oracle/oradata/CDB/users01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/sysaux01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/system01.dbf
通过下面的命令将所有的 pdb 库 open
SQL alter pluggable database all open;
Pluggable database altered.
此时 pdb 的状态有 mount 变成了 read write
SQL show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
再次执行下面的查询就可以看到 pdb 的数据文件了
SQL select con_id,file_name from cdb_data_files order by 1;
CON_ID FILE_NAME
———- ————————————————–
1 /u01/app/oracle/oradata/CDB/system01.dbf
1 /u01/app/oracle/oradata/CDB/users01.dbf
1 /u01/app/oracle/oradata/CDB/undotbs01.dbf
1 /u01/app/oracle/oradata/CDB/sysaux01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/system01.dbf
2 /u01/app/oracle/oradata/CDB/pdbseed/sysaux01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/system01.dbf
3 /u01/app/oracle/oradata/CDB/pdb1/sysaux01.dbf
感谢你能够认真阅读完这篇文章,希望丸趣 TV 小编分享的“oracle 12 DBCA 如何创建 pdb”这篇文章对大家有帮助,同时也希望大家多多支持丸趣 TV,关注丸趣 TV 行业资讯频道,更多相关知识等着你来学习!