A) 파라미터 파일 생성
인스턴스 생성을 위해 pfile을 vi 편집기로 생성합니다. 파일이 있어야 할 디렉토리는 $ORACLE_HOME/dbs입니다.
cd $ORACLE_HOME/dbs vi initorcl.ora
db_name='orcl' enable_pluggable_database=true audit_trail='db' control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl' db_block_size=8192 db_domain='' memory_target=800M open_cursors=300 processes=300 remote_login_passwordfile='EXCLUSIVE' undo_tablespace='UNDOTBS1'
B) 디렉토리 생성
데이터 파일을 저장할 디렉토리와 Fast Recovery Area 디렉토리를 생성합니다. container database, seed pluggable database, pluggable database의 데이터 파일을 저장할 위치를 각각 생성합니다.
mkdir -p /u01/app/oracle/oradata/orcl mkdir -p /u01/app/oracle/oradata/orcl/pdbseed mkdir -p /u01/app/oracle/oradata/orcl/salespdb mkdir -p /u01/app/oracle/oradata/orcl/hrpdb mkdir -p /u01/app/oracle/fast_recovery_area/orcl
C) 데이터베이스 생성
sysdba 권한으로 접속하여 nomount에서 데이터베이스 생성 스크립트를 실행합니다.
sqlplus / as sysdba
startup nomount create spfile from pfile; CREATE DATABASE orcl CONTROLFILE REUSE USER sys IDENTIFIED BY oracle USER system IDENTIFIED BY oracle LOGFILE GROUP 1 ('/u01/app/oracle/oradata/orcl/redo01.log') SIZE 50M, GROUP 2 ('/u01/app/oracle/oradata/orcl/redo02.log') SIZE 50M, GROUP 3 ('/u01/app/oracle/oradata/orcl/redo03.log') SIZE 50M MAXLOGFILES 16 MAXLOGMEMBERS 4 MAXDATAFILES 1024 MAXINSTANCES 1 MAXLOGHISTORY 680 CHARACTER SET AL32UTF8 NATIONAL CHARACTER SET AL16UTF16 DATAFILE '/u01/app/oracle/oradata/orcl/system01.dbf' SIZE 500M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE 1000M EXTENT MANAGEMENT LOCAL SYSAUX DATAFILE '/u01/app/oracle/oradata/orcl/sysaux01.dbf' SIZE 500M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE 1000M UNDO TABLESPACE undotbs1 DATAFILE '/u01/app/oracle/oradata/orcl/undotbs01.dbf' SIZE 500M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE 1000M DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' SIZE 100M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE 1000M DEFAULT TABLESPACE USERS DATAFILE '/u01/app/oracle/oradata/orcl/users01.dbf' SIZE 100M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE 1000M USER_DATA TABLESPACE userstbs DATAFILE '/u01/app/oracle/oradata/orcl/pdbseed/userstbsp01.dbf' SIZE 500M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE 1000M ENABLE PLUGGABLE DATABASE SEED FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl', '/u01/app/oracle/oradata/orcl/pdbseed');
D) 시스템 뷰, 딕셔너리 테이블 생성
시스템 뷰와 딕셔너리 테이블 생성을 위한 스크립트를 실행합니다. 12c에서는 perl 스크립트를 이용해서 생성하는 것을 권장하고 있습니다.
cd $ORACLE_HOME/rdbms/admin perl catcon.pl -u sys/oracle -s -e -d $ORACLE_HOME/rdbms/admin -b catalog1 catalog.sql > catcon-catalog.log perl catcon.pl -u sys/oracle -s -e -d $ORACLE_HOME/rdbms/admin -b catproc1 catproc.sql > catcon-catproc.log perl catcon.pl -u system/oracle -s -e -d $ORACLE_HOME/sqlplus/admin -b pupbld1 pupbld.sql > catcon-pupbld.log
E) PDB 생성
sysdba 권한으로 pluggable database(이하 PDB)를 create pluggable database 문을 이용해서 생성합니다.
CREATE PLUGGABLE DATABASE salespdb ADMIN USER salesadm IDENTIFIED BY oracle FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/pdbseed', '/u01/app/oracle/oradata/orcl/salespdb'); CREATE PLUGGABLE DATABASE hrpdb ADMIN USER hradm IDENTIFIED BY oracle FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/pdbseed', '/u01/app/oracle/oradata/orcl/hrpdb');
F) 리스너 생성
$ORACLE_HOME/network/admin 디렉토리에 listener.ora 파일을 생성합니다.
cd $ORACLE_HOME/network/admin vi listener.ora
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c.localdomain)(PORT = 1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = salespdb) (ORACLE_HOME = /u01/app/oracle/product/12.1.0/db_1) ) (SID_DESC = (SID_NAME = hrpdb) (ORACLE_HOME = /u01/app/oracle/product/12.1.0/db_1) ) )
원격 접속을 위한 tnsnames.ora 파일은 아래와 같습니다.
ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c.localdomain)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) SALESPDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c.localdomain)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = salespdb) ) ) HRPDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c.localdomain)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = hrpdb) ) )
G) PDB 복제
create pluggable database ... from 문을 이용해서 PDB를 복제할 수 있습니다.
CREATE PLUGGABLE DATABASE salespdb2 FROM salespdb FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/salespdb', '/u01/app/oracle/oradata/orcl/salespb2') STORAGE (MAXSIZE 6G MAX_SHARED_TEMP_SIZE 100M);
H) 데이터베이스 정지
PDB를 close한 후에 전체 인스턴스를 shutdown 합니다.
shutdown
alter pluggable database all close immediate; select con_id, name, open_mode from v$pdbs;
CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 SALESPDB MOUNTED 4 HRPDB MOUNTED
shutdown immediate;
I) 데이터베이스 기동
Container Database를 startup 명령을 이용해 open한 후에 PDB를 open합니다.
startup
startup;
alter pluggable database all open;
Pluggable database altered.
select con_id, name, open_mode from v$pdbs;
CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 SALESPDB READ WRITE 4 HRPDB READ WRITE