[20170203]克隆schema.txt

简介: [20170203]克隆schema.txt --开发要求在原有数据库的基础上克隆schema(在相同的数据库上),仔细想一下很简单,采用impdp+dblink的模式可以完成.

[20170203]克隆schema.txt

--开发要求在原有数据库的基础上克隆schema(在相同的数据库上),仔细想一下很简单,采用impdp+dblink的模式可以完成.
--在测试环境测试看看.

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

--//建立一个loopback连接
CREATE PUBLIC DATABASE LINK LOOPBACK USING 'localhost:1521/book';

--//测试dblink
SCOTT@book> select sysdate from dual@loopback;
SYSDATE
-------------------
2017-02-03 16:19:48

2.克隆:
--//首先建立用户:
CREATE USER ztest IDENTIFIED BY ztest;
GRANT DBA TO ztest;

$ impdp system/oracle directory=DATA_PUMP_DIR network_link=loopback REMAP_SCHEMA=scott:ztest REMAP_TABLESPACE=users:users SCHEMAS=scott
--//注意后面一定要加SCHEMAS=scott!!
Import: Release 11.2.0.4.0 - Production on Fri Feb 3 16:42:21 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/a* directory=DATA_PUMP_DIR network_link=loopback REMAP_SCHEMA=scott:ztest REMAP_TABLESPACE=users:users SCHEMAS=scott
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 1.375 MB
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"ZTEST" already exists
--//不需要建立用户吗?
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
. . imported "ZTEST"."SESSION_WAIT_RECORD"                 8122 rows
. . imported "ZTEST"."LOCK_OBJECT_RECORD"                  8122 rows
. . imported "ZTEST"."DEPT"                                   4 rows
. . imported "ZTEST"."DEPTX"                                  4 rows
. . imported "ZTEST"."EMP"                                   14 rows
. . imported "ZTEST"."SALGRADE"                               5 rows
. . imported "ZTEST"."T1"                                     5 rows
. . imported "ZTEST"."T2"                                     5 rows
. . imported "ZTEST"."T3"                                     5 rows
. . imported "ZTEST"."BONUS"                                  0 rows
Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION
Processing object type SCHEMA_EXPORT/FUNCTION/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 21 error(s) at Fri Feb 3 16:42:41 2017 elapsed 0 00:00:19

ZTEST@book> select * from tab ;
TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
BONUS                          TABLE
DEPT                           TABLE
DEPTX                          TABLE
EMP                            TABLE
LOCK_OBJECT_RECORD             TABLE
SALGRADE                       TABLE
SESSION_WAIT_RECORD            TABLE
T1                             TABLE
T2                             TABLE
T3                             TABLE
10 rows selected.
--//OK,已经完成了克隆.

--不建立用户ztest,重复测试看看.
$ impdp system/oracle directory=DATA_PUMP_DIR network_link=loopback REMAP_SCHEMA=scott:ztest REMAP_TABLESPACE=users:users SCHEMAS=scott
Import: Release 11.2.0.4.0 - Production on Fri Feb 3 16:46:20 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/a** directory=DATA_PUMP_DIR network_link=loopback REMAP_SCHEMA=scott:ztest REMAP_TABLESPACE=users:users SCHEMAS=scott
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 1.375 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
. . imported "ZTEST"."SESSION_WAIT_RECORD"                 8122 rows
. . imported "ZTEST"."LOCK_OBJECT_RECORD"                  8122 rows
. . imported "ZTEST"."DEPT"                                   4 rows
. . imported "ZTEST"."DEPTX"                                  4 rows
. . imported "ZTEST"."EMP"                                   14 rows
. . imported "ZTEST"."SALGRADE"                               5 rows
. . imported "ZTEST"."T1"                                     5 rows
. . imported "ZTEST"."T2"                                     5 rows
. . imported "ZTEST"."T3"                                     5 rows
. . imported "ZTEST"."BONUS"                                  0 rows
Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION
Processing object type SCHEMA_EXPORT/FUNCTION/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Fri Feb 3 16:46:37 2017 elapsed 0 00:00:15

--//这样ztest用户的口令与scott的口令一样.

目录
相关文章
|
缓存 开发工具 git
报错:Git上传代码报错 will not add file alias already exists in index
报错:Git上传代码报错 will not add file alias already exists in index
389 0
|
开发者
最简单方法创建 README
最简单方法创建 README
456 0
最简单方法创建 README
|
SQL 测试技术 数据库
[20180529]克隆数据库与dblinks注意.txt
[20180529]克隆数据库与dblinks注意.txt --//在做数据库克隆,一般情况下给开发做测试,要注意一个细节问题,就是数据库内建立的dblink. --//有可能导致一些异常情况,特别是国内环境生产数据库与测试数据库没有分开的情况下,很有可能导致 --//无意中窜改生产系统的数据.
1133 0
|
SQL 关系型数据库 Oracle
[20180211]current_schema与dblink.txt
[20180211]current_schema与dblink.txt --//有时候调优sql语句,经常在回话设在alter session set current_schema=scott,然后执行sql语句.
1085 0
|
SQL 关系型数据库 数据库
|
Oracle 关系型数据库 Linux
[20171031]rman merge例子2.txt
[20171031]rman merge例子2.txt --//以前做的测试 [20170626]rman merge例子.txt --//链接 http://blog.
985 0
|
Oracle 关系型数据库 Linux
[20170626]rman merge例子.txt
[20170626]rman merge例子.txt 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER -----------------...
904 0
|
Oracle 关系型数据库 OLAP
[20161002]impdp导入空表.txt
[20161002]impdp导入空表.txt --业务需求要求建立新的测试库,由于磁盘空间有限,要求几个大表导入空表,11g支持段延迟提交,即使表init很大也不会出现空间问题.
1262 0
|
Oracle 关系型数据库 OLAP
[20160910]快速修改表的schema.txt
[20160910]快速修改表的schema.txt --以前也做过例子: http://blog.itpub.net/267265/viewspace-741154/ http://blog.itpub.net/267265/viewspace-744787/ --第1种就是修改数据字典的情况,但是这种存在一定的风险,我当时的测试版本11.2.0.1还有修改obj$的字段spare3. --第2种就是利用交换分区的方法。
828 0