Oracle表空间管理,数据迁移,

拆迁术:

    赶人:delete

    扒房:truncate

     拆楼:drop

drop table xxx 时如果删除不掉,主要是因为约束,需添加cascade constraints

 analyze table 表名 compute statistics for table

设计术:

         设计大楼外形和空闲空间管理方式extent管理

         设计物业管理segement管理

         设计大小户型---非标准块的表空间

         extend管理(空闲区的管理方式)

         

数据字典管理:select *  from uet$,select * from fet$

本地管理:

               

段空间的管理方式:

           

设置非标准块的表空间需要添加blocksize参数,并且分配相应的缓冲区,比如db_4k_cache_size

施工术:

       拿地:quota

               如果用户只有create table权限,并不能盖楼,还要设置配额:alter user 用户名 10M on users;

               任何表空间无配额限制 分配unlimited tablespace 或connect ,resource角色

       盖楼:create 

       装修:offline和read only

迁移术:

         迁楼:move

             alter table 表名 move tablespace 表空间名称

         迁小区:transport tablespaces

  数据泵 导入导出
优点 字符集无需设定转换 通用
缺点 不通用,数据泵导入必须数据泵导出 需设定字符集

迁移表空间三步走:

一、创建目录,赋予权限

      cd /home/oracle ;

      mkdir dir;

      grant all on directory dir to public;

二、模拟环境

       create tablespace oltp datafile '/u01/app/oracle/oradata/PROD/disk4/oltp.dbf' size 50M;

       create tablespace olap datafile '/u01/app/oracle/oradata/PROD/disk5/olap.dbf' size 50M;

         create user oltp identified by oracle default tablespace oltp;

         create user olap identified by oracle default tablespace olap;

          grant connect,resource to oltp,olap;

          create table oltp.t_oltp tablespace oltp as select * from scott.emp;

          create table olap.t_olap tablespace olap as select * from scott.emp;

          alter table oltp.t_oltp add constraint pk_oltp primary key(empno);

           alter table olap.t_olap add constraint pk_olap primary key(empno);

           alter table oltp.t_oltp add constraint fk_oltp foreign key(deptno) references scott.dept(deptno);

           alter table olap_olap add constriant fk_olap foreign key(deptno) references scott.dept(deptno);

目标库创建对应用户赋予权限

     create user oltp identified by oracle; grant connect,resource to oltp;

检查自包含:

     execute dbms_tts.transport_set_check('oltp',true)

     select * from transport_set_violations;

      alter table oltp.t_oltp drop constraint fk_oltp cascade;

几字型迁移:

(只读)alter tablespace oltp readonly;

(导出)数据泵:expdp dumpfile=oltp.dmp directory=dir transport_tablespaces=oltp(system用户迁移)

(传输)拷贝: scp 本地目录 远程目录

(导入)拷贝数据文件

impdp dumpfile=oltp.dump directory-dir transport_tablespaces='数据文件所在目录';

(读写)alter tablespace oltp read write;

导入导出方式:

设置字符集

        export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

         export ORACLE_SID=xxx

alter tablespace olap read only;

exp file=olap.dmp tablespace=olap transport_tablespace=y

scp 本地目录 远程目录

拷贝数据文件:

imp file=olap.dmp tablespaces=olap transport_tablespace=y datafiles='文件'

alter tablespace olap read write;

原文地址:https://www.cnblogs.com/yangyanhao/p/7840493.html