[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
475 0
|
6月前
|
分布式计算 大数据 数据处理
MaxCompute操作报错合集之在本地用tunnel命令上传excel表格到mc遇到报错: tunnel upload C:\Users***\Desktop\a.xlsx mc里的非分区表名 -s false;该怎么办
MaxCompute是阿里云提供的大规模离线数据处理服务,用于大数据分析、挖掘和报表生成等场景。在使用MaxCompute进行数据处理时,可能会遇到各种操作报错。以下是一些常见的MaxCompute操作报错及其可能的原因与解决措施的合集。
|
Windows
windows批量修改文件、文件夹名工具:Bulk Rename Utility批量改名演示
windows批量修改文件、文件夹名工具:Bulk Rename Utility批量改名演示
574 0
windows批量修改文件、文件夹名工具:Bulk Rename Utility批量改名演示
|
SQL 测试技术 数据库
[20180529]克隆数据库与dblinks注意.txt
[20180529]克隆数据库与dblinks注意.txt --//在做数据库克隆,一般情况下给开发做测试,要注意一个细节问题,就是数据库内建立的dblink. --//有可能导致一些异常情况,特别是国内环境生产数据库与测试数据库没有分开的情况下,很有可能导致 --//无意中窜改生产系统的数据.
1164 0
|
SQL Shell 测试技术
[20161023]为什么以前可以这样的表.txt
[20161023]为什么以前可以这样的表.txt --上午看https://oracleblog.org/working-case/ora-01401-impdp-same-character/ CREATE TABLE ASS_ACC...
796 0
|
监控 Oracle 关系型数据库
[20161002]impdp导入很慢.txt
[20161002]impdp导入很慢.txt --如果在导入前表以及对应索引已经存在,impdp导入(使用参数TABLE_EXISTS_ACTION=append)要维护索引,这样在导入时产生大量日志,比 --没有表存在的情况下慢很多,通过例子来说明.
1679 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种就是利用交换分区的方法。
842 0