首页 > 代码库 > 3.通过现有的PDB创建一个新的PDB
3.通过现有的PDB创建一个新的PDB
实验说明:创建PDB除了可以通过种子PDB创建外,现在测试通过一个现有的用户PDB克隆创建新的PDB数据库
实验步骤:
1.创建测试数据
SQL> alter session set container=emp;
Session altered.
SQL> conn dsg/dsg@emp
Connected.
SQL> create table test (id number(8));
Table created.
SQL> begin
2 for i in 1..100 loop
3 insert into test values(i);
4 end loop;
5 commit;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> select count(*) from test;
COUNT(*)
----------
100
Session altered.
SQL> conn dsg/dsg@emp
Connected.
SQL> create table test (id number(8));
Table created.
SQL> begin
2 for i in 1..100 loop
3 insert into test values(i);
4 end loop;
5 commit;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> select count(*) from test;
COUNT(*)
----------
100
2.通过现有PDB创建新的PDB EMPTEST
SQL> conn / as sysdba
Connected.
SQL> create pluggable database emptest from emp;
create pluggable database emptest from emp
*
ERROR at line 1:
ORA-65081: database or pluggable database is not open in read only mode
----源数据库必须在read only状态
SQL> alter pluggable database emp close;
Pluggable database altered.
SQL> alter pluggable database emp open read only;
Pluggable database altered.
SQL> create pluggable database emptest from emp;
Pluggable database created.
Connected.
SQL> create pluggable database emptest from emp;
create pluggable database emptest from emp
*
ERROR at line 1:
ORA-65081: database or pluggable database is not open in read only mode
----源数据库必须在read only状态
SQL> alter pluggable database emp close;
Pluggable database altered.
SQL> alter pluggable database emp open read only;
Pluggable database altered.
SQL> create pluggable database emptest from emp;
Pluggable database created.
3.在tnsnames.ora中添加下面的信息,这样就可以通过服务名连接数据库了
EMPTEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521)) (CONNECT_DATA =http://www.mamicode.com/ (SERVER = DEDICATED) (SERVICE_NAME = EMPTEST) ) ) |
新的PDB创建成功,查看alert日志:
create pluggable database emptest from emp Sun Jan 19 22:26:48 2014 **************************************************************** Pluggable Database EMPTEST with pdb id - 4 is created as UNUSABLE. If any errors are encountered before the pdb is marked as NEW, then the pdb must be dropped **************************************************************** Deleting old file#7 from file$ Deleting old file#8 from file$ Deleting old file#9 from file$ Adding new file#12 to file$(old file#7) Adding new file#13 to file$(old file#8) Adding new file#14 to file$(old file#9) Successfully created internal service emptest at open ALTER SYSTEM: Flushing buffer cache inst=0 container=4 local **************************************************************** Post plug operations are now complete. Pluggable database EMPTEST with pdb id - 4 is now marked as NEW. **************************************************************** Completed: create pluggable database emptest from emp |
新的PDB创建后数据库会自动监听
[oracle@localhost datafile]$ lsnrctl status LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 19-JAN-2014 22:31:31 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 12.1.0.1.0 - Production Start Date 14-JAN-2014 10:29:20 Uptime 5 days 12 hr. 2 min. 11 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost.localdomain)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=localhost.localdomain)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/ora12c/xdb_wallet))(Presentation=HTTP)(Session=RAW)) Services Summary... Service "emp" has 1 instance(s). Instance "ora12c", status READY, has 1 handler(s) for this service... Service "emptest" has 1 instance(s). Instance "ora12c", status READY, has 1 handler(s) for this service... Service "ora12c" has 1 instance(s). Instance "ora12c", status READY, has 1 handler(s) for this service... Service "ora12cXDB" has 1 instance(s). Instance "ora12c", status READY, has 1 handler(s) for this service... The command completed successfully |
说明:
PDB的一些更改操作不能在CDB级别更改,必须切换到PDB下,下面以修改GLOBAL_NAME为例:
SQL> select service_id,name,pdb from v$services;
SERVICE_ID NAME PDB
---------- ---------------------------------------------------------------- ------------------------------
0 emptest EMPTEST
6 emp EMP
3 ora12cXDB CDB$ROOT
4 ora12c CDB$ROOT
1 SYS$BACKGROUND CDB$ROOT
2 SYS$USERS CDB$ROOT
SQL> alter pluggable database emptest rename global_name to emp_test;
alter pluggable database emptest rename global_name to emp_test
*
ERROR at line 1:
ORA-65046: operation not allowed from outside a pluggable database
SQL> alter pluggable database emptest close;
alter pluggable database emptest close
*
ERROR at line 1:
ORA-65020: pluggable database EMPTEST already closed
下面以RESTRICTED 模式打开数据库
SQL> alter pluggable database emptest open restricted;
Pluggable database altered.
SQL> conn sys/oracle@emptest as sysdba
Connected.
SQL> alter pluggable database emptest rename global_name to emp_test;
Pluggable database altered.
SQL> select service_id,name,pdb from v$services;
SERVICE_ID NAME PDB
---------- ---------------------------------------------------------------- ------------------------------
1 emp_test EMP_TEST
SQL> conn / as sysdba
Connected.
SQL> select service_id,name,pdb from v$services;
SERVICE_ID NAME PDB
---------- ---------------------------------------------------------------- ------------------------------
1 emp_test EMP_TEST
6 emp EMP
3 ora12cXDB CDB$ROOT
4 ora12c CDB$ROOT
1 SYS$BACKGROUND CDB$ROOT
2 SYS$USERS CDB$ROOT
6 rows selected.
alter pluggable database emptest rename global_name to emp_test
*
ERROR at line 1:
ORA-65046: operation not allowed from outside a pluggable database
SQL> alter pluggable database emptest close;
alter pluggable database emptest close
*
ERROR at line 1:
ORA-65020: pluggable database EMPTEST already closed
下面以RESTRICTED 模式打开数据库
SQL> alter pluggable database emptest open restricted;
Pluggable database altered.
SQL> conn sys/oracle@emptest as sysdba
Connected.
SQL> alter pluggable database emptest rename global_name to emp_test;
Pluggable database altered.
SQL> select service_id,name,pdb from v$services;
SERVICE_ID NAME PDB
---------- ---------------------------------------------------------------- ------------------------------
1 emp_test EMP_TEST
SQL> conn / as sysdba
Connected.
SQL> select service_id,name,pdb from v$services;
SERVICE_ID NAME PDB
---------- ---------------------------------------------------------------- ------------------------------
1 emp_test EMP_TEST
6 emp EMP
3 ora12cXDB CDB$ROOT
4 ora12c CDB$ROOT
1 SYS$BACKGROUND CDB$ROOT
2 SYS$USERS CDB$ROOT
6 rows selected.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。