DBCA创建CDB的过程



1. 使用DBCA静默安装生成脚本

[oracle@12cr2 ~]$ dbca -silent -templateName $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc -gdbname testdb1 -sid testdb1 -characterSet ZHS16GBK -sysPassword oracle -systemPassword Highgo123 -createAsContainerDatabase true -generateScripts
Database creation script generation
1% complete
2% complete
18% complete
33% complete
35% complete
40% complete
41% complete
42% complete
46% complete
51% complete
52% complete
55% complete
56% complete
60% complete
63% complete
66% complete
100% complete
Look at the log file "/u01/app/oracle/admin/testdb1/scripts/testdb1.log" for further details.
以下是生成的脚本
[oracle@12cr2 ~]$ cd /u01/app/oracle/admin/testdb1/scripts
[oracle@12cr2 scripts]$ ll
total 18348
-rw-r----- 1 oracle oinstall      841 May 20 07:52 CloneRmanRestore.sql
-rw-r----- 1 oracle oinstall     1921 May 20 07:52 cloneDBCreation.sql
-rw-r----- 1 oracle oinstall     1842 May 20 07:52 init.ora
-rw-r----- 1 oracle oinstall     1958 May 20 07:52 inittestdb1Temp.ora
-rw-r----- 1 oracle oinstall     1851 May 20 07:52 inittestdb1TempOMF.ora
-rw-r----- 1 oracle oinstall      550 May 20 07:52 lockAccount.sql
-rw-r----- 1 oracle oinstall     3657 May 20 07:52 plug_PDBSeed.sql
-rw-r----- 1 oracle oinstall      820 May 20 07:52 postDBCreation.sql
-rw-r----- 1 oracle oinstall     1862 May 20 07:52 postScripts.sql
-rw-r----- 1 oracle oinstall      101 May 20 07:52 rmanPDBCleanUpDatafiles.sql
-rw-r----- 1 oracle oinstall      383 May 20 07:52 rmanPDBRestoreDatafiles.sql
-rwxr-xr-x 1 oracle oinstall      568 May 20 07:52 rmanRestoreDatafiles.sql
-rw-r----- 1 oracle oinstall 18726912 May 20 07:52 tempControl.ctl
-rw-r----- 1 oracle oinstall      523 May 20 07:52 testdb1.log
-rwxr-xr-x 1 oracle oinstall      805 May 20 07:52 testdb1.sh
-rwxr-xr-x 1 oracle oinstall      626 May 20 07:52 testdb1.sql

[oracle@12cr2 scripts]$ cat testdb1.sh
#!/bin/sh

OLD_UMASK=`umask`
umask 0027
mkdir -p /u01/app/oracle
mkdir -p /u01/app/oracle/admin/testdb1/adump
mkdir -p /u01/app/oracle/admin/testdb1/dpdump
mkdir -p /u01/app/oracle/admin/testdb1/pfile
mkdir -p /u01/app/oracle/audit
mkdir -p /u01/app/oracle/cfgtoollogs/dbca/testdb1
mkdir -p /u01/app/oracle/oradata/testdb1
mkdir -p /u01/app/oracle/oradata/testdb1/pdbseed
mkdir -p /u01/app/oracle/product/12.2.0/db_1/dbs
umask ${OLD_UMASK}
PERL5LIB=$ORACLE_HOME/rdbms/admin:$PERL5LIB; export PERL5LIB
ORACLE_SID=testdb1; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$ORACLE_HOME/perl/bin:$PATH; export PATH
echo You should Add this entry in the /etc/oratab: testdb1:/u01/app/oracle/product/12.2.0/db_1:Y
/u01/app/oracle/product/12.2.0/db_1/bin/sqlplus /nolog @/u01/app/oracle/admin/testdb1/scripts/testdb1.sql

[oracle@12cr2 scripts]$ cat testdb1.sql
set verify off
ACCEPT sysPassword CHAR PROMPT 'Enter new password for SYS: ' HIDE
ACCEPT systemPassword CHAR PROMPT 'Enter new password for SYSTEM: ' HIDE
host /u01/app/oracle/product/12.2.0/db_1/bin/orapwd file=/u01/app/oracle/product/12.2.0/db_1/dbs/orapwtestdb1 force=y format=12
@/u01/app/oracle/admin/testdb1/scripts/CloneRmanRestore.sql
@/u01/app/oracle/admin/testdb1/scripts/cloneDBCreation.sql
@/u01/app/oracle/admin/testdb1/scripts/plug_PDBSeed.sql
@/u01/app/oracle/admin/testdb1/scripts/postScripts.sql
@/u01/app/oracle/admin/testdb1/scripts/lockAccount.sql
@/u01/app/oracle/admin/testdb1/scripts/postDBCreation.sql

[oracle@12cr2 scripts]$ cd /u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/
[oracle@12cr2 templates]$ ll
total 411616
-rw-r----- 1 oracle oinstall      4697 Jan 26 15:38 Data_Warehouse.dbc
-rw-r----- 1 oracle oinstall      4577 Jan 26 15:38 General_Purpose.dbc
-rw-r----- 1 oracle oinstall     10578 Jun 10  2016 New_Database.dbt
-rw-r----- 1 oracle oinstall  18726912 Jan 26 15:37 Seed_Database.ctl
-rw-r----- 1 oracle oinstall 281059328 Jan 26 15:37 Seed_Database.dfb
-rw-r----- 1 oracle oinstall 121667584 Jan 26 15:30 pdbseed.dfb
-rw-r----- 1 oracle oinstall      6685 Jan 26 15:30 pdbseed.xml
## dfb文件是RMAN的备份文件,ctl是控制文件,xml文件是注册信息

2. 设置initseeddata.ora参数

[oracle@12cr2 dbs]$ mkdir /u01/app/oracle/oradata/dbcadb
[oracle@12cr2 dbs]$ cat initseeddata.ora 
db_name=seeddata
control_files=/u01/app/oracle/oradata/dbcadb/control01.ctl
sga_target=800M
enable_pluggable_database=true

3. 复制控制文件

[oracle@12cr2 dbs]$ cd $ORACLE_HOME/assistants/dbca/templates/
[oracle@12cr2 templates]$ cp Seed_Database.ctl $ORACLE_BASE/oradata/dbcadb/control01.ctl

4. 启动数据库到mount状态

[oracle@12cr2 templates]$ export ORACLE_SID=seeddata
[oracle@12cr2 templates]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sat May 20 08:17:03 2017
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup nomount
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
SQL> alter database mount;
Database altered.

5. 修改REDO的路径

SQL> select member from v$logfile;

MEMBER
-------------------------------------------------------------------------------
/ade/b/2717506464/oracle/oradata/seeddata/redo01.log
/ade/b/2717506464/oracle/oradata/seeddata/redo02.log
/ade/b/2717506464/oracle/oradata/seeddata/redo03.log

SQL> alter database rename file '/ade/b/2717506464/oracle/oradata/seeddata/redo01.log' to '/u01/app/oracle/oradata/dbcadb/redo01.log';
Database altered.

SQL> alter database rename file '/ade/b/2717506464/oracle/oradata/seeddata/redo02.log' to '/u01/app/oracle/oradata/dbcadb/redo02.log';
Database altered.

SQL> alter database rename file '/ade/b/2717506464/oracle/oradata/seeddata/redo03.log' to '/u01/app/oracle/oradata/dbcadb/redo03.log';
Database altered.

SQL> select member from v$logfile;

MEMBER
-------------------------------------------------------------------------------
/u01/app/oracle/oradata/dbcadb/redo01.log
/u01/app/oracle/oradata/dbcadb/redo02.log
/u01/app/oracle/oradata/dbcadb/redo03.log

6. 使用RMAN还原恢复数据库

[oracle@12cr2 templates]$ rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Sat May 20 08:23:27 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.
connected to target database: SEEDDATA (DBID=4262971485, not open)
RMAN> catalog start with '/u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb';

using target database control file instead of recovery catalog
searching for all files that match the pattern /u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb

RMAN> run{
2> set newname for datafile 1 to '/u01/app/oracle/oradata/dbcadb/system01.dbf';
3> set newname for datafile 3 to '/u01/app/oracle/oradata/dbcadb/sysaux01.dbf';
4> set newname for datafile 4 to '/u01/app/oracle/oradata/dbcadb/undotbs01.dbf';
5> set newname for datafile 7 to '/u01/app/oracle/oradata/dbcadb/users01.dbf';
6> restore database;
7> switch datafile all;
8> recover database;
9> }

executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 20-MAY-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/dbcadb/system01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dbcadb/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dbcadb/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/dbcadb/users01.dbf
channel ORA_DISK_1: reading from backup piece /ade/aime_adc00jyz/oracle/oradata/Seed_Database.dfb
channel ORA_DISK_1: errors found reading piece handle=/ade/aime_adc00jyz/oracle/oradata/Seed_Database.dfb
channel ORA_DISK_1: failover to piece handle=/u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb tag=TAG20170126T153637
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:58
Finished restore at 20-MAY-17
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=944468874 file name=/u01/app/oracle/oradata/dbcadb/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=944468874 file name=/u01/app/oracle/oradata/dbcadb/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=944468874 file name=/u01/app/oracle/oradata/dbcadb/undotbs01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=944468874 file name=/u01/app/oracle/oradata/dbcadb/users01.dbf
Starting recover at 20-MAY-17
using channel ORA_DISK_1
starting media recovery
RMAN-08187: warning: media recovery until SCN 1408557 complete
Finished recover at 20-MAY-17

7. OPEN数据库

[oracle@12cr2 templates]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sat May 20 08:29:43 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> alter database open resetlogs;
Database altered.

SQL> select cdb from v$database;
CDB
---
YES
SQL> show pdbs;
SQL>

8. 修改temp表空间数据文件

SQL> select file_name from dba_temp_files;
select file_name from dba_temp_files
                      *
ERROR at line 1:
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201:
'/ade/b/2717506464/oracle/oradata/seeddata/temp01.dbf'

SQL> alter tablespace temp add tempfile '/u01/app/oracle/oradata/dbcadb/temp01.dbf' size 100M;
Tablespace altered.

SQL> alter tablespace temp drop tempfile '/ade/b/2717506464/oracle/oradata/seeddata/temp01.dbf';
Tablespace altered.

SQL> select file_name from dba_temp_files;

FILE_NAME
-------------------------------------------------------------------------------
/u01/app/oracle/oradata/dbcadb/temp01.dbf

9. 修改dbname

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
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
Database mounted.

[oracle@12cr2 templates]$ nid target=sys/Highgo123 dbname=dbcadb

DBNEWID: Release 12.2.0.1.0 - Production on Sat May 20 08:38:45 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.
Connected to database SEEDDATA (DBID=4262971485)
Connected to server version 12.2.0
Control Files in database:
    /u01/app/oracle/oradata/dbcadb/control01.ctl
Change database ID and database name SEEDDATA to DBCADB? (Y/[N]) => Y
Proceeding with operation
Changing database ID from 4262971485 to 3142198165
Changing database name from SEEDDATA to DBCADB
    Control File /u01/app/oracle/oradata/dbcadb/control01.ctl - modified
    Datafile /u01/app/oracle/oradata/dbcadb/system01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/dbcadb/sysaux01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/dbcadb/undotbs01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/dbcadb/users01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/dbcadb/temp01.db - dbid changed, wrote new name
    Control File /u01/app/oracle/oradata/dbcadb/control01.ctl - dbid changed, wrote new name
    Instance shut down
Database name changed to DBCADB.
Modify parameter file and generate a new password file before restarting.
Database ID for database DBCADB changed to 3142198165.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

10. 再次修改initdbcadb.ora参数文件

[oracle@12cr2 templates]$ cd $ORACLE_HOME/dbs
[oracle@12cr2 dbs]$ cat initdbcadb.ora 
db_name=dbcadb
control_files=/u01/app/oracle/oradata/dbcadb/control01.ctl
sga_target=800M
enable_pluggable_database=true

11. 启动dbcadb数据库

[oracle@12cr2 dbs]$ export ORACLE_SID=dbcadb
[oracle@12cr2 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sat May 20 09:21:09 2017
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup mount;
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
Database mounted.
SQL> alter database open resetlogs;
Database altered.

12. 初始化PDB

[oracle@12cr2 dbs]$ mkdir -p /u01/app/oracle/oradata/dbcadb/pdbseed
[oracle@12cr2 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sat May 20 09:27:52 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> alter system set "_catalog_foreign_restore"=TRUE;
System altered.

SQL> alter system set "_restore_create_directory"=TRUE;
System altered.

13. 还原PDB数据文件

[oracle@12cr2 dbs]$ rman target /
Recovery Manager: Release 12.2.0.1.0 - Production on Sat May 20 09:35:07 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.
connected to target database: DBCADB (DBID=3142198165)
RMAN> run
2> {
3> set command id to 'PDB$SEED';
4> RESTORE FOREIGN DATAFILE 2 FORMAT '/u01/app/oracle/oradata/dbcadb/pdbseed/system01.dbf',
5> 4 FORMAT '/u01/app/oracle/oradata/dbcadb/pdbseed/sysaux01.dbf',
6> 9 FORMAT '/u01/app/oracle/oradata/dbcadb/pdbseed/undotbs01.dbf' 
7> FROM BACKUPSET '/u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/pdbseed.dfb';
8> }

executing command: SET COMMAND ID
Starting restore at 20-MAY-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring foreign file 00002
channel ORA_DISK_1: restoring foreign file 00004
channel ORA_DISK_1: restoring foreign file 00009
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/pdbseed.dfb
channel ORA_DISK_1: restoring foreign file 2 to /u01/app/oracle/oradata/dbcadb/pdbseed/system01.dbf
channel ORA_DISK_1: restoring foreign file 4 to /u01/app/oracle/oradata/dbcadb/pdbseed/sysaux01.dbf
channel ORA_DISK_1: restoring foreign file 9 to /u01/app/oracle/oradata/dbcadb/pdbseed/undotbs01.dbf
channel ORA_DISK_1: foreign piece handle=/u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/pdbseed.dfb
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:26
Finished restore at 20-MAY-17

14. 创建PDB$SEED数据库

[oracle@12cr2 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sat May 20 09:41:07 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> show pdbs;
SQL> 
SQL> alter system set "_catalog_foreign_restore"=FALSE;
System altered.

SQL> alter system set "_restore_create_directory"=FALSE;
System altered.

SQL> alter session set "_oracle_script"=TRUE;
Session altered.

SQL> CREATE PLUGGABLE DATABASE PDB$SEED AS CLONE 
  2  USING '/u01/app/oracle/product/12.2.0/db_1/assistants/dbca/templates/pdbseed.xml' 
  3  source_file_name_convert =(
  4  '/ade/b/2717506464/oracle/oradata/seeddata/pdbseed/system01.dbf','/u01/app/oracle/oradata/dbcadb/pdbseed/system01.dbf',
  5  '/ade/b/2717506464/oracle/oradata/seeddata/pdbseed/sysaux01.dbf','/u01/app/oracle/oradata/dbcadb/pdbseed/sysaux01.dbf',
  6  '/ade/b/2717506464/oracle/oradata/seeddata/pdbseed/undotbs01.dbf','/u01/app/oracle/oradata/dbcadb/pdbseed/undotbs01.dbf',
  7  '/ade/b/2717506464/oracle/oradata/seeddata/pdbseed/temp01.dbf','/u01/app/oracle/oradata/dbcadb/pdbseed/temp012017-05-20_07-52-37-584-AM.dbf') 
  8  NOCOPY 
  9  STORAGE ( MAXSIZE UNLIMITED MAX_SHARED_TEMP_SIZE UNLIMITED);

Pluggable database created.

SQL>  show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       MOUNTED
##上面CREATE PLUGGABLE DATABASE的创建语句是从之前DBCA静默安装生成的脚本  /u01/app/oracle/admin/testdb1/scripts/plug_PDBSeed.sql中取得的。

15. 启动pdb$seed

SQL> alter pluggable database pdb$seed open;
Pluggable database altered.

SQL> alter session set container=pdb$seed;
Session altered.

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ WRITE NO
SQL> shutdown immediate
Pluggable Database closed.
SQL> alter database open read only;
Database altered.

SQL> show pdbs;
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO

16. 创建测试PDB数据库

SQL> conn / as sysdba
Connected.
SQL> CREATE PLUGGABLE DATABASE test_pdb ADMIN USER pdb_mgr IDENTIFIED BY oracle
  2  file_name_convert=('/u01/app/oracle/oradata/dbcadb','/u01/app/oracle/oradata/dbcadb/test_pdb');

Pluggable database created.

SQL> show pdbs;
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 TEST_PDB                       MOUNTED
SQL> alter pluggable database TEST_PDB open;

Pluggable database altered.

SQL> show pdbs;
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 TEST_PDB                       READ WRITE NO


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值