如何在 Oracle 中克隆可插拔数据库
How to clone a pluggable database in Oracle
我是 Oracle 的可插拔数据库的新手(我们仍然在工作中使用 Oracle 11.2)。为了测试分区和子分区,我需要创建几十个表空间。我想,我会快速克隆我当前的数据库,进行测试,然后删除数据库。
我能够克隆数据库:
CREATE PLUGGABLE DATABASE ora193p2 FROM ora193p1
FILE_NAME_CONVERT = (
'/opt/oracle/oradata/ORA193C/ORA193P1/',
'/opt/oracle/oradata/ORA193C/ORA193P2/');
Pluggable database ORA193P2 created.
但在尝试连接时出现错误 ORA-01109: database not open
。
我尝试打开它,但也收到错误消息(ora193c 是 cdb 的名称):
ALTER DATABASE ora193p2 OPEN;
ORA-01509: specified name 'ORA193P2' does not match actual 'ORA193C'
我使用了 vagrant-boxes 的数据库。
对于可插拔数据库,您需要添加关键字可插拔数据库,后跟 pdb 名称
SQL> create pluggable database pdbclone from orclpdb;
Pluggable database created.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE MOUNTED
SQL> alter pluggable database pdbclone open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE READ WRITE NO
SQL> alter pluggable database pdbclone save state;
Pluggable database altered.
从12.1.0.2
开始,您可以通过CDB重启保留PDB启动状态。 12.1.0.2 补丁集引入了 SAVE STATE
和 DISCARD STATE
选项:
ALTER PLUGGABLE DATABASE pdb_name OPEN;
ALTER PLUGGABLE DATABASE pdb_name SAVE STATE;
要放弃保存的状态:
ALTER PLUGGABLE DATABASE pdb_name DISCARD STATE;
对于 12.1.0.1
及之前的版本,您可以创建启动后触发器:
CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
/
它在 CDB 中创建一个启动后系统级触发器。
我是 Oracle 的可插拔数据库的新手(我们仍然在工作中使用 Oracle 11.2)。为了测试分区和子分区,我需要创建几十个表空间。我想,我会快速克隆我当前的数据库,进行测试,然后删除数据库。
我能够克隆数据库:
CREATE PLUGGABLE DATABASE ora193p2 FROM ora193p1
FILE_NAME_CONVERT = (
'/opt/oracle/oradata/ORA193C/ORA193P1/',
'/opt/oracle/oradata/ORA193C/ORA193P2/');
Pluggable database ORA193P2 created.
但在尝试连接时出现错误 ORA-01109: database not open
。
我尝试打开它,但也收到错误消息(ora193c 是 cdb 的名称):
ALTER DATABASE ora193p2 OPEN;
ORA-01509: specified name 'ORA193P2' does not match actual 'ORA193C'
我使用了 vagrant-boxes 的数据库。
对于可插拔数据库,您需要添加关键字可插拔数据库,后跟 pdb 名称
SQL> create pluggable database pdbclone from orclpdb;
Pluggable database created.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE MOUNTED
SQL> alter pluggable database pdbclone open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE READ WRITE NO
SQL> alter pluggable database pdbclone save state;
Pluggable database altered.
从12.1.0.2
开始,您可以通过CDB重启保留PDB启动状态。 12.1.0.2 补丁集引入了 SAVE STATE
和 DISCARD STATE
选项:
ALTER PLUGGABLE DATABASE pdb_name OPEN;
ALTER PLUGGABLE DATABASE pdb_name SAVE STATE;
要放弃保存的状态:
ALTER PLUGGABLE DATABASE pdb_name DISCARD STATE;
对于 12.1.0.1
及之前的版本,您可以创建启动后触发器:
CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
/
它在 CDB 中创建一个启动后系统级触发器。