12C把non-CDB的单库导入到CDB里面当成PDB的方法

官方文档

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/admin/creating-and-removing-pdbs-with-sql-plus.html#GUID-EE58804F-A999-4F7C-93DE-D641B3C1047B

原理:

在non-CDB里面创建xml文件,这样non-CDB的xml文件和数据文件就组成了一个unplugged PDB,再在CDB里面执行create pluggable database orcl using创建这个PDB,切换到这个PDB执行脚本$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql,清除不属于这个PDB的object,就可以正常启动这个PDB了

结论1:所以没有办法在RMAN里面把non-CDB的备份restore成CDB里面的一个PDB,因为需要先把这个non-CDB变成一个unplugged PDB

结论2:该non-CDB的sys和system密码变成了和CDB一样,原来CDB的sys和system密码都是123456,non-CDB的sys和system密码都是666666,把该non-CDB当成PDB导入CDB后,该PDB的sys和system密码都是123456

结论3:该non-CDB的归档模式变成了和CDB一样,原来CDB是归档模式,non-CDB是非归档模式,把该non-CDB当成PDB导入CDB后,该PDB变成归档模式

结论4:该non-CDB当成PDB导入CDB后,每个文件的头部都会重写,文件号也会更改

同一台服务器上安装了两套实例,non-CDB实例名称为orcl,CDB实例名称为ocp,把orcl当成PDB导入到CDB

[oracle@ocp12c ~]$ lsnrctl status

Service “ocp” has 1 instance(s).

Instance “ocp”, status READY, has 1 handler(s) for this service…

Service “orcl” has 1 instance(s).

Instance “orcl”, status READY, has 1 handler(s) for this service…

Service “pocp1” has 1 instance(s).

Instance “ocp”, status READY, has 1 handler(s) for this service…

Service “pocp2” has 1 instance(s).

Instance “ocp”, status READY, has 1 handler(s) for this service…

The command completed successfully

1、登录non-CDB,创建用户user_orcl密码为666666,system密码为666666,创建表system.system2020

[oracle@ocp12c ~]$ ORACLE_SID=orcl

[oracle@ocp12c ~]$ sqlplus / as sysdba

SQL> show con_name;

CON_NAME


orcl

SQL> create user user_orcl identified by 666666;

SQL> grant dba to user_orcl;

SQL> conn system/666666

Connected.

SQL> create table system2020 as select * from dba_users;

2、关闭non-CDB数据库并重启至只读状态,再对non-CDB数据库创建一个xml文件

SQL> shutdown immediate;

SQL> startup open read only;

SQL> exec dbms_pdb.describe(pdb_descr_file=>’/home/oracle/orcl.xml’);

3、关闭non-CDB数据库

SQL> shutdown immediate;

4、登录CDB,必须要执行$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql,否则PDB启动会有报错

[oracle@ocp12c ~]$ ORACLE_SID=ocp

[oracle@ocp12c ~]$ sqlplus / as sysdba

SQL> show con_name

CON_NAME


CDB$ROOT

SQL> show pdbs

CON_ID CON_NAME                       OPEN MODE  RESTRICTED

     2 PDB$SEED                       READ ONLY  NO

     4 POCP2                          READ WRITE NO

     5 POCP1                          READ WRITE NO

SQL> create pluggable database orcl using ‘/home/oracle/orcl.xml’ nocopy tempfile reuse;

SQL> show pdbs

CON_ID CON_NAME                       OPEN MODE  RESTRICTED

     2 PDB$SEED                       READ ONLY  NO

     3 ORCL                           MOUNTED

     4 POCP2                          READ WRITE NO

     5 POCP1                          READ WRITE NO

SQL> select file_name from cdb_data_files a,cdb_pdbs b where a.con_id=b.con_id and b.pdb_name=‘ORCL’;

no rows selected

SQL> select name from v$datafile a,cdb_pdbs b where a.con_id=b.con_id and b.pdb_name=‘ORCL’;

NAME


/u01/app/oracle/oradata/orcl/system01.dbf

/u01/app/oracle/oradata/orcl/sysaux01.dbf

/u01/app/oracle/oradata/orcl/undotbs01.dbf

/u01/app/oracle/oradata/orcl/users01.dbf

SQL> alter session set container=ORCL;

Session altered.

SQL> startup

Warning: PDB altered with errors.

Pluggable Database opened.

SQL> shutdown immediate;

Pluggable Database closed.

SQL> startup

Warning: PDB altered with errors.

Pluggable Database opened.

SQL> shutdown immediate;

Pluggable Database closed.

SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

SQL> startup

Pluggable Database opened.

–使用CDB的sys和system密码才可以正常登录,原来non-CDB 的sys和system密码变成了和CDB一样

[oracle@ocp12c ~]$ sqlplus system/666666

ERROR:

ORA-01017: invalid username/password; logon denied

[oracle@ocp12c ~]$ sqlplus system/123456

SQL>

[oracle@ocp12c ~]$ sqlplus sys/666666@pocp1 as sysdba

ERROR:

ORA-01017: invalid username/password; logon denied

[oracle@ocp12c ~]$ sqlplus sys/123456@pocp1 as sysdba

SQL>

[oracle@ocp12c ~]$ lsnrctl status

Service “ocp” has 1 instance(s).

Instance “ocp”, status READY, has 1 handler(s) for this service…

Service “orcl” has 1 instance(s).

Instance “ocp”, status READY, has 1 handler(s) for this service…

Service “pocp1” has 1 instance(s).

Instance “ocp”, status READY, has 1 handler(s) for this service…

Service “pocp2” has 1 instance(s).

Instance “ocp”, status READY, has 1 handler(s) for this service…

The command completed successfully

原来的non-CDB可以启动到mount模式,再启动到open模式报错

ORA-01157: cannot identify/lock data file 1 - see DBWR trace file

ORA-01110: data file 1: ‘/u01/app/oracle/oradata/orcl/system01.dbf’

alert文件信息为

Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_38299.trc:

ORA-01157: cannot identify/lock data file 1 - see DBWR trace file

ORA-01110: data file 1: ‘/u01/app/oracle/oradata/orcl/system01.dbf’

ORA-1157 signalled during: ALTER DATABASE OPEN…

2020-02-19T18:57:28.276363+08:00

Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_38301.trc:

ORA-01110: data file 1: ‘/u01/app/oracle/oradata/orcl/system01.dbf’

ORA-01204: file number is 19 rather than 1 - wrong file

2020-02-19T18:57:30.142285+08:00

Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_38301.trc:

ORA-01110: data file 3: ‘/u01/app/oracle/oradata/orcl/sysaux01.dbf’

ORA-01204: file number is 20 rather than 3 - wrong file

2020-02-19T18:57:31.286909+08:00

Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_38301.trc:

ORA-01110: data file 4: ‘/u01/app/oracle/oradata/orcl/undotbs01.dbf’

ORA-01204: file number is 21 rather than 4 - wrong file

2020-02-19T18:57:31.649863+08:00

Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_m000_38301.trc:

ORA-01110: data file 7: ‘/u01/app/oracle/oradata/orcl/users01.dbf’

ORA-01204: file number is 22 rather than 7 - wrong file

你可能感兴趣的:(oracle,数据库)