12c 使用SQL命令手工建立CDB數

snowdba發表於2015-02-16
在工作環境中我們可能沒有機會使用SQL命令手工建立12c CDB,但是學習一下手工建庫對熟悉其安裝步驟和所需條件還是有幫助的。下面開始手工建庫。

1,配置環境變數
[oracle@snow ~]$ cat /home/oracle/.bash_profile

export ORACLE_SID=CDB
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1
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

2,配置初始換引數檔案,只需要兩個引數就可以。一個是必要引數db_name,另一個是針對插拔資料庫。如果建立不同的資料庫就不需要第二個引數enable_pluggable_database

[oracle@snow ~]$ cat $ORACLE_HOME/dbs/initCDB.ora
db_name='CDB'
enable_pluggable_database=true

3,建立建庫指令碼createdb.sql
建立語句參考12c官方文件,文件路徑為
Database Administrator's Guide --&gt
2 Creating and Configuring an Oracle Database —>
Creating a Database with the CREATE DATABASE Statement —>
Step 9: Issue the CREATE DATABASE Statement


注意指令碼最後才會用到“;“前面的都是”,“號。
[oracle@snow ~]$ cat /home/oracle/createdb.sql
CREATE DATABASE CDB
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
LOGFILE GROUP 1 ('/u01/app/oracle/oradata/CDB/redo01a.log','/u02/app/oracle/oradata/CDB/redo01b.log') SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/u01/app/oracle/oradata/CDB/redo02a.log','/u02/app/oracle/oradata/CDB/redo02b.log') SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/u01/app/oracle/oradata/CDB/redo03a.log','/u02/app/oracle/oradata/CDB/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/CDB/system01.dbf'
SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE '/u01/app/oracle/oradata/CDB/sysaux01.dbf'
SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
DEFAULT TABLESPACE users
DATAFILE '/u01/app/oracle/oradata/CDB/users01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/u01/app/oracle/oradata/CDB/temp01.dbf'
SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED1
UNDO TABLESPACE undotbs1
DATAFILE '/u01/app/oracle/oradata/CDB/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
USER_DATA TABLESPACE usertbs
DATAFILE '/u01/app/oracle/oradata/CDB/usertbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
ENABLE PLUGGABLE DATABASE
SEED FILE_NAME_CONVERT=('/u01/app/oracle/oradata/CDB','/u01/app/oracle/oradata/CDB/pdbseed');

4,確保建立資料庫涉及到的目錄都存在
[oracle@snow oradata]$ pwd
/u01/app/oracle/oradata
[oracle@snow oradata]$ mkdir -p CDB/pdbseed

5,啟動資料庫到nomount狀態下,執行建庫指令碼
[oracle@snow ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Sun Feb 8 20:00:49 2015

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 217157632 bytes
Fixed Size 2286656 bytes
Variable Size 159386560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5152768 bytes
SQL> @/home/oracle/createdb.sql

Database created.

6,為CDB建立資料字典,根據官方文件提示執行下面的3個sql語句
使用sys使用者執行下面兩個sql語句,執行時間會很長
SQL> @?/rdbms/admin/catalog.sql
SQL> @?/rdbms/admin/catproc.sql

切換到system使用者下執行下面的語句
SQL> conn system/oracle
Connected.
SQL> @?/sqlplus/admin/pupbld.sql


所有指令碼執行完後,CDB資料庫正式建立完成。
SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED MOUNTED

SQL> col file_name for a60
SQL> select con_id,file_name from cdb_data_files;

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


全文完。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29047826/viewspace-1437483/,如需轉載,請註明出處,否則將追究法律責任。

相關文章