Oracle复制数据库(单个oracle用户对应的数据库)基本操作

这里以数据库仓库34复制到数据库仓库36为例

1.分配权限

在linux界面oracle账号下执行

sqlplus / as sysdba;

oracle数据库中执行:

create or replace directory DUMP_DIR as  '/backup/zqw/dump';
grant read,write on directory DUMP_DIR to wmwhse34,wmwhse36;

2.导出(/仓库34)

linux界面oracle账户下执行

expdp wmwhse34/WMwhSql34  DIRECTORY=DUMP_DIR  DUMPFILE=wmwhse34.DMP schemas=wmwhse34  logfile=exp_wmwhse34.log;

3.备份(/仓库36)

linux界面oracle账户下执行

expdp wmwhse36/WMwhSql36 DIRECTORY=DUMP_DIR  DUMPFILE=wmwhse36.DMP schemas=wmwhse36 logfile=exp_wmwhse36.log;

4.停WMS应用

5.删除原有仓库用户

删除原有仓库用户(/仓库36) --删除整个仓库数据,用户所有的数据(包括在表空间中的数据),谨慎操作!!
进入sqlplus / as sysdba里面操作,需要等待,不要动任何操作!

drop user wmwhse36 cascade;

如果删除过程出现如下错误:
ORA-01940: cannot drop a user that is currently connected
则需要判断应用是否停止,是否有开发在连接使用数据库等等。
强制杀死进程即可删除仓库

SELECT SID,SERIAL# FROM V$SESSION WHERE USERNAME='WMWHSE1';查询数据中用户WMWHSE1是否在使用
//select username,default_tablespace,TEMPORARY_TABLESPACE from dba_users where username = 'ENTERPRISE';查询表空间名字

alter system kill session '1922,39146,@1';//杀死进程。如果是单台,不需要@1

在这里插入图片描述

6.创建用户

进入sqlplus / as sysdba里面操作

create user wmwhse36 PROFILE SCEUSER identified by WMwhSql36 DEFAULT TABLESPACE wmwhse36_DATA TEMPORARY TABLESPACE wmwhse36_TEMPDATA;

授权

grant create any table to  wmwhse36;
grant dba to wmwhse36;
grant execute on DBMS_LOCK to wmwhse36;
grant select on DBA_OBJECTS to wmwhse36;
grant create any sequence to wmwhse36;
grant read,write on directory DUMP_DIR to wmwhse36;

7.导入仓库数据

注意:在oracle账号界面执行!

impdp wmwhse36/WMwhSql36 DIRECTORY=DUMP_DIR DUMPFILE=wmwhse34.DMP REMAP_SCHEMA=wmwhse34:wmwhse36 remap_tablespace=wmwhse34_DATA:wmwhse36_DATA  TRANSFORM=segment_attributes:n,OID:n EXCLUDE=STATISTICS logfile=imp_wmwhse36.log;

8.回收权限

数据库中执行

--revoke exp_full_database from wmwhse36;

如果没有表空间,创建表空间如下

1.1.创建表空间
create tablespace WMWHSE36_DATA datafile '+DATADG' size 3424m autoextend on next 512m maxsize unlimited extent management local segment space management auto;
1.2.创建临时表空间
create temporary tablespace WMWHSE36_TEMPDATA tempfile '+DATADG' size 512m reuse autoextend on next 256m maxsize unlimited extent management local uniform size 1m;

猜你喜欢

转载自blog.csdn.net/jike11231/article/details/107187721