IMP数据到指定的表空间

来源:互联网 发布:scratch编程视频教程 编辑:程序博客网 时间:2024/05/17 23:44


一直以来,我都认为只要指定用户的默认表空间,向该用户导入数据时,会自动进入到默认表空间。后来发现从System导出的dmp文件在导入时,即使指定新用户的默认表空间,还是要往System表空间中导数据。

上网搜了一下,还是有解决方法的,常见的方法如下:

SQL> create user myhuang identified by myhuang default tablespace myhuang;

SQL> grant resource,connect to myhuang;

SQL> grant dba to myhuang;//赋DBA权限

SQL> revoke unlimited tablespace from myhuang;//撤销此权限

SQL> alter user myhuang quota 0 on system;//将用户在System表空间的配额置为0

SQL> alter user myhuang quota unlimited on myhuang;//设置在用户在myhuang表空间配额不受限。

 

经过上述设置后,就可以用imp导入数据,数据将会进入指定的myhuang表空间:

C:\Documents and Settings\myhuang>imp system/123456@vdb fromuser=lnxh tous

er=myhuang file=G:\myhuang\lnxh.dmp ignore=y grants=n

 

顺便说两个小问题:

(1)IMP-00003: 遇到 ORACLE 错误 1658

ORA-01658: 无法为表空间 MYHUANG 中的段创建 INITIAL 区

通常这个问题可以通过Resize增加表空间数据文件大小来解决。

 

1 查看表空间路径 select * from dba_data_files;

2 修改表空间大小 ALTER TABLESPACE MAXDATA ADD DATAFILE '/oradata/XX/MAXDATA02.DBF' SIZE 1000M;

(2)删除表空间

SQL> drop tablespace myhuang including contents and datafiles;

在10g中实验,drop表空间之后,仍然需要手动去删除数据文件。

 
//2008-08-24补充————————————————————————
另一种比较好的方法:

Create tablespace {tbs_name} datafile ‘{file_path}’ size 500M autoextend on next 10M;

Create user {u_name} identified by {u_pwd} default tablespace {tbs_name} quota unlimited on {tbs_name};

Grant connect,imp_full_database to {u_name};

Imp {u_name}/{u_pwd}@{local_svrname} fromuser={from_user} touser={u_name} file={dmp_file_path} ignore=y tablespaces={tbs_name};

此方法不需要授予新用户DBA权限。
此方法的存在的问题是:可能导致包含BLOB、CLOB字段的表导入失败,这种情况下可以先用sql脚本将表结构建立起来,再导入相应的数据。

 

 

SQL> create user atf_ygj identified by mas123 default tablespace ygj_atf_data temporary tablespace ygj_atf_temp quota unlimited on ygj_atf_data ;

用户已创建。

SQL> grant connect,imp_full_database to atf_ygj;

授权成功。

D:\>imp atf_ygj/mas123@orcl_192.168.6.19 fromuser=atf_back touser=atf_ygj file=d:/atf_back20090927.dmp ignore=y tablespaces=ygj_atf_data;

 

 

方法三 改变用户数据所在的表空间

以后以该用户登录,创建的任何数据库对象都属于test_temp 和test_data表空间,这就不用在每创建一个对象给其指定表空间了。

=============  移动数据到表空间  ================= 
查询需要移动的表所在的表空间
  select tt.table_name,tt.tablespace_name  from user_all_tables tt where tt.tablespace_name like '%YGJ%'
 移动表到指定表空间
 alter table employees move tablespace ygj_data;
查询要移动的索引所在的表空间
select ii.index_name,ii.table_name,ii.tablespace_name,ii.temporary from user_indexes ii where index_name like  '%EMP_PK%'
 移动(重建)索引到指定表空间
 alter index EMP_PK rebuild tablespace ygj_data;

 

原创粉丝点击