今天试验表空间传输,从一个库PROD 传输表空间到repos
假定表employees 在tbs4表空间里
SQL> select table_name,tablespace_name from user_tables where tablespace_name='TBS4';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
EMPLOYEES TBS4
当然employees 表里有一些constaints什么的。
表空间传输,可以用dbms_tts.transport_set_check('TBS4',TRUE);
然后用transport_set_violations来查询传输是否有可行。
发现有一些关联的constraint(外键等)的影响
spool 如下脚本
SQL> select 'alter table employees disable constraint '||constraint_name ||' CASCADE;' from user_constraints where table_name='EMPLOYEES';
'ALTERTABLEEMPLOYEESDISABLECONSTRAINT'||CONSTRAINT_NAME||'CASCADE;'
--------------------------------------------------------------------------------
alter table employees disable constraint EMP_LAST_NAME_NN CASCADE;
alter table employees disable constraint EMP_EMAIL_NN CASCADE;
alter table employees disable constraint EMP_HIRE_DATE_NN CASCADE;
alter table employees disable constraint EMP_JOB_NN CASCADE;
alter table employees disable constraint EMP_SALARY_MIN CASCADE;
alter table employees disable constraint EMP_EMAIL_UK CASCADE;
alter table employees disable constraint EMP_EMP_ID_PK CASCADE;
alter table employees disable constraint EMP_MANAGER_FK CASCADE;
alter table employees disable constraint EMP_JOB_FK CASCADE;
alter table employees disable constraint EMP_DEPT_FK CASCADE;
alter table employees disable constraint SYS_C003327 CASCADE;
'ALTERTABLEEMPLOYEESDISABLECONSTRAINT'||CONSTRAINT_NAME||'CASCADE;'
--------------------------------------------------------------------------------
alter table employees disable constraint SYS_C003328 CASCADE;
alter table employees disable constraint SYS_C003329 CASCADE;
13 rows selected.
运行就可以去除constraint的问题了。
检查没问题就可以传输了。
首先把tbs4置为只读状态
alter tablespace tbs4 read only;
exp \'sys/oracle@PROD as sysdba\' file=hr_PROD.dmp transport_tablespace=y
tablespaces=tbs4
然后scp到目标库的机器上,数据文件tbs04.db也拷贝到对应的目录下
在目标库上运行
imp \'sys/oracle123@repos as sysdba\' file=hr_PROD.dmp transport_tablespace=y tablespaces=tbs4 datafiles=/u01/app/db/oradata/repos/tbs04.dbf
运行过后,似乎一切都ok了,新建一个分区表,结构和employees一摸一样。
SQL> create table emp_part partition by range(hire_date)
(
PARTITION p1 VALUES LESS THAN(TO_DATE('01/01/1980','DD/MM/YYYY')) tablespace tbs1,
PARTITION p2 VALUES LESS THAN(TO_DATE('01/01/1990','DD/MM/YYYY')) tablespace tbs2,
PARTITION p3 VALUES LESS THAN(TO_DATE('01/01/2000','DD/MM/YYYY')) tablespace tbs3,
PARTITION p4 VALUES LESS THAN(TO_DATE('01/01/2010','DD/MM/YYYY')) tablespace tbs4,
PARTITION p5 VALUES LESS THAN(maxvalue) tablespace tbs1
)
as select * from employees where rownum<1; 2 3 4 5 6 7 8 9
as select * from employees where rownum<1
*
ERROR at line 9:
ORA-28110: policy function or package HR.RLS_F has error
这个表中可能还有原来的函数
--检查一下是否存在
SQL> SELECT OBJECT_NAME FROM DBA_OBJECTS WHERE OBJECT_TYPE='FUNCTION' AND OBJECT_NAME ='RLS_F';
OBJECT_NAME
--------------------------------------------------------------------------------
RLS_F
--重新编译一下就可以了。
SQL> alter function HR.RLS_F compile;
Function altered.
阅读(1199) | 评论(0) | 转发(0) |