手工创建cdb数据库(create database语句)


1. 创建newcdb的参数文件

[oracle@12cr2 ~]$ cd $ORACLE_HOME/dbs
[oracle@12cr2 dbs]$ cat initnewcdb.ora 
db_create_file_dest='/u01/app/oracle/oradata/newcdb'
sga_target=800M
db_name=newcdb
enable_pluggable_database=true

2. 创建存放数据文件的目录

[oracle@12cr2 dbs]$ mkdir /u01/app/oracle/oradata/newcdb

3. 创建CREATE DATABASE的SQL语句脚本

[oracle@12cr2 ~]$ cat create_omfdb.sql 
CREATE DATABASE newcdb
USER SYS IDENTIFIED BY newcdb
USER SYSTEM IDENTIFIED BY newcdb
EXTENT MANAGEMENT LOCAL
DEFAULT TABLESPACE users
DEFAULT TEMPORARY TABLESPACE temp
UNDO TABLESPACE undotbs1
ENABLE PLUGGABLE DATABASE
  SEED
  SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
  SYSAUX DATAFILES SIZE 100M;

4. 指定SID,生成spfile,启动数据库到nomount状态

[oracle@12cr2 dbs]$ export ORACLE_SID=newcdb            
[oracle@12cr2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Mon May 15 21:26:10 2017
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> create spfile from pfile;
File created.

SQL> startup nomount force;      
ORACLE instance started.
Total System Global Area  838860800 bytes
Fixed Size                  8798312 bytes
Variable Size             226496408 bytes
Database Buffers          599785472 bytes
Redo Buffers                3780608 bytes

5. 创建数据库

SQL> set echo on
SQL> set timing on
SQL> @create_omfdb.sql
SQL> CREATE DATABASE newcdb
  2  USER SYS IDENTIFIED BY newcdb
  3  USER SYSTEM IDENTIFIED BY newcdb
  4  EXTENT MANAGEMENT LOCAL
  5  DEFAULT TABLESPACE users
  6  DEFAULT TEMPORARY TABLESPACE temp
  7  UNDO TABLESPACE undotbs1
  8  ENABLE PLUGGABLE DATABASE
  9    SEED
 10    SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
 11    SYSAUX DATAFILES SIZE 100M;

Database created.

Elapsed: 00:00:45.29
SQL> set timing off
SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

6. 执行catcdb.sql脚本

修改oracle用户的环境变量,在PATH中加入$ORACLE_HOME/perl/bin

[oracle@12cr2 ~]$ vi .bash_profile 
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/perl/bin:$PATH:$HOME/bin
[oracle@12cr2 ~]$ export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/perl/bin:$PATH:$HOME/bin
执行catcdb.sql,会报如下错误:
SQL> @?/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/db_1/rdbms/admin
Enter value for 2: /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl
Can't locate util.pm in @INC (you may need to install the util module) (@INC contains: /u01/app/oracle/product/12.2.0/db_1/rdbms/admin /u01/app/oracle/product/12.2.0/db_1/perl/lib/site_perl/5.22.0/x86_64-linux-thread-multi /u01/app/oracle/product/12.2.0/db_1/perl/lib/site_perl/5.22.0 /u01/app/oracle/product/12.2.0/db_1/perl/lib/5.22.0/x86_64-linux-thread-multi /u01/app/oracle/product/12.2.0/db_1/perl/lib/5.22.0 .) at /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl line 35.
BEGIN failed--compilation aborted at /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl line 35.
上面报错的解决方法,修改catcdb.pl文件,到$ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash下面执行catcdb.sql
[oracle@12cr2 Hash]$ vi $ORACLE_HOME/rdbms/admin/catcdb.pl
修改use util qw(trim, splitToArray);为use Util qw(trim, splitToArray);

[oracle@12cr2 ~]$ cd $ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash
[oracle@12cr2 Hash]$ ll
total 28
drwxr-xr-x 2 oracle oinstall  4096 May  9 00:02 Util
-rwxr-x--- 1 oracle oinstall 23392 May 12  2016 Util.pm

[oracle@12cr2 Hash]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Mon May 15 21:56:50 2017
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> @?/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/db_1/rdbms/admin
Enter value for 2: /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl
Enter new password for SYS: newcdb
Enter new password for SYSTEM: newcdb
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.0/db_1/rdbms/admin/catalog_catcon_3304.lst]
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catalog*.log] files for output generated by scripts
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catalog_*.lst] files for spool files, if any

… …

    SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
  ] end of output produced in exec_DB_script
catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catclust_catcon_4806.lst]
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catclust*.log] files for output generated by scripts
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catclust_*.lst] files for spool files, if any
catcon.pl: completed successfully
catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catfinal_catcon_5175.lst]
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catfinal*.log] files for output generated by scripts
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catfinal_*.lst] files for spool files, if any
catcon.pl: completed successfully
catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catbundleapply_catcon_5259.lst]
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catbundleapply*.log] files for output generated by scripts
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catbundleapply_*.lst] files for spool files, if any
catcon.pl: completed successfully
catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/utlrp_catcon_5343.lst]
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/utlrp*.log] files for output generated by scripts
catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/utlrp_*.lst] files for spool files, if any
catcon.pl: completed successfully

你可能感兴趣的:(oracle12c)