0
点赞
收藏
分享

微信扫一扫

大库迁移#4进行切换

 

表结构检查 "

set linesize 1000 pagesize 1000

col owner for a20

col object_type for a30

col SYNONYM_NAME for a30

col CONSTRAINT_NAME for a40

col TABLE_NAME for a30

col COLUMN_NAME for a20

col GRANTEE for a15

col PRIVILEGE for a30

col GRANTED_ROLE for a15

col CONSTRAINT_TYPE for a5

col TRIGGER_NAME for a40

col TRIGGER_TYPE for a20

col SEQUENCE_NAME for a50

col username for a15

col host for a15

col db_link for a15

col object_name for a30


--对比对象数量和状态

select owner,status,object_type,count(*) from dba_objects@to_xxx where owner in ('username')   and object_name not like 'BIN$%'  
and object_name not in(select object_name from dba_recyclebin@to_xxx) group by owner,status,object_type order by 1,4 asc;  

select owner,status,object_type,count(*) from dba_objects where owner in ('username')   and object_name not like 'BIN$%'  
and object_name not in(select object_name from dba_recyclebin) group by owner,status,object_type order by 1,4 asc;




--对比表数量

with a as (select owner,table_name  from dba_tables where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin)),
 b as (select owner,table_name  from dba_tables@to_xxx where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin)) 
select *  from b  minus select *  from a;


with a as (select owner,table_name  from dba_tables where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin)), 
b as (select owner,table_name  from dba_tables@to_xxx where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin))
 select *  from a  minus select *  from b;





--对比表上索引数量

with a as (select table_name,count(*) cnt from dba_indexes where owner in  ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name),
b as (select table_name,count(*) cnt from dba_indexes@to_xxx where owner in ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name)
select *  from b  minus select *  from a;



with a as (select table_name,count(*) cnt from dba_indexes where owner in  ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name),
b as (select table_name,count(*) cnt from dba_indexes@to_xxx where owner in ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name)
select *  from a  minus select *  from b;



--对比同义词数量

with a as (select owner,SYNONYM_NAME from dba_synonyms where owner in ('username')),
b as (select owner,SYNONYM_NAME from dba_synonyms@to_xxx where owner in ('username'))
select *  from b  minus select *  from a;




--对比序列数量

with a as (select sequence_owner,SEQUENCE_NAME from dba_sequences where sequence_owner in ('username')),
b as (select sequence_owner,SEQUENCE_NAME from dba_sequences@to_xxx where sequence_owner in ('username'))
select *  from b  minus select *  from a;



--对比触发器数量

with a as (select owner,TRIGGER_NAME,TRIGGER_TYPE from dba_triggers where owner in ('username')),
b as (select owner,TRIGGER_NAME,TRIGGER_TYPE from dba_triggers@to_xxx where owner in ('username'))
select *  from b  minus select *  from a;



--对比约束数量

with a as (select  a.owner,a.CONSTRAINT_NAME,a.CONSTRAINT_TYPE,a.TABLE_NAME,b.column_name from dba_constraints a,dba_cons_columns b where a.owner=b.owner and a.CONSTRAINT_NAME=b.CONSTRAINT_NAME and a.table_name=b.table_name and a.owner in ('username') and a.CONSTRAINT_TYPE='R'),
b as (select  a.owner,a.CONSTRAINT_NAME,a.CONSTRAINT_TYPE,a.TABLE_NAME,b.column_name from dba_constraints@to_xxx a,dba_cons_columns@to_xxx b where a.owner=b.owner and a.CONSTRAINT_NAME=b.CONSTRAINT_NAME and a.table_name=b.table_name and a.owner in ('username') and a.CONSTRAINT_TYPE='R')
select *  from b  minus select *  from a;




--对比用户权限

select GRANTEE,PRIVILEGE from dba_sys_privs@to_xxx where GRANTEE in ('username')
minus
select GRANTEE,PRIVILEGE from dba_sys_privs where GRANTEE in ('username');



select GRANTEE,owner,table_name,PRIVILEGE from dba_tab_privs@to_xxx where GRANTEE in ('username')
minus
select GRANTEE,owner,table_name,PRIVILEGE from dba_tab_privs where GRANTEE in ('username');



select GRANTEE,GRANTED_ROLE from dba_role_privs@to_xxx where GRANTEE in ('username')
minus
select GRANTEE,GRANTED_ROLE from dba_role_privs where GRANTEE in ('username');


--查询库中dblink

select * from dba_db_links@to_xxx;


--查询原库DDL或者创建日期在导入表结构后发生的对象

select owner,object_name,object_type,LAST_DDL_TIME,CREATED from dba_objects@to_xxx where (LAST_DDL_TIME > to_date('20230701 10','yyyymmdd hh24') or CREATED > to_date('20230701 10','yyyymmdd hh24')) and owner in ('username') order by LAST_DDL_TIME asc;"

 

停止应用、改IP地址 见:应用端操作详情-停止应用;应用端操作详情-修改数据库IP地址

比对无问题后 应用切换前 将源库用户lock "

"

select 'alter user '||username||' account lock;' from dba_users where username in ('username');

alter user XXX account lock;

将数据库连接会话kill "

ps -ef|grep LOCAL=NO

kill进程号

ps -ef|grep LOCAL=NO|wc -l

"

源端数量对比 参考:数据验证


目标端外键enable "

select 'alter table '||owner||'.'||table_name||' enable constraint '|| CONSTRAINT_NAME||';' from dba_constraints where CONSTRAINT_TYPE='R' and owner in('username');

alter table INFA_DOMAIN.PC_NAMESPACE_SEQUENCE enable constraint FK_PC_NAMESPACE_SE;

"

目标端清理序列 "

select SEQUENCE_OWNER,count(*) from dba_sequences where SEQUENCE_OWNER in  ('username')

group by SEQUENCE_OWNER

order by 2 desc;

SEQUENCE_OWNER

----------  
 username COUNT(*)

----------  
       214

select 'drop sequence '||SEQUENCE_OWNER||'.'||SEQUENCE_NAME||';' from dba_sequences where SEQUENCE_OWNER in ('username');


drop sequence username.SEQ_STATEMENT_ID;



"

源端序列导入到目标端 "

expdp system/******* network_link=to_xxx dumpfile=20220919_seq.dmp directory=dmp logfile=20220919_seq.log schemas=username   include=sequence


导入序列

impdp system/******* directory=DMP dumpfile=20220919_seq.dmp logfile=20220922_imp_seq.log

  

select SEQUENCE_OWNER,count(*) from dba_sequences where SEQUENCE_OWNER in  ('username'

)

group by SEQUENCE_OWNER

order by 2 desc;

SEQUENCE_OWNER

----------  
 username COUNT(*)

----------  
       XXX

"

比对源端和目标端对象差异 "

set linesize 1000 pagesize 1000

col owner for a20

col object_type for a30

col SYNONYM_NAME for a30

col CONSTRAINT_NAME for a40

col TABLE_NAME for a30

col COLUMN_NAME for a20

col GRANTEE for a15

col PRIVILEGE for a30

col GRANTED_ROLE for a15

col CONSTRAINT_TYPE for a5

col TRIGGER_NAME for a40

col TRIGGER_TYPE for a20

col SEQUENCE_NAME for a50

col username for a15

col host for a15

col db_link for a15

col object_name for a30


--对比对象数量和状态

select owner,status,object_type,count(*) from dba_objects@to_xxx where owner in ('username')   and object_name not like 'BIN$%'  
and object_name not in(select object_name from dba_recyclebin@to_xxx) group by owner,status,object_type order by 1,4 asc;  

select owner,status,object_type,count(*) from dba_objects where owner in ('username')   and object_name not like 'BIN$%'  
and object_name not in(select object_name from dba_recyclebin) group by owner,status,object_type order by 1,4 asc;




--对比表数量

with a as (select owner,table_name  from dba_tables where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin)),

b as (select owner,table_name  from dba_tables@to_xxx where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin))

select *  from b  minus select *  from a;


with a as (select owner,table_name  from dba_tables where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin)),

b as (select owner,table_name  from dba_tables@to_xxx where owner='username' and table_name not in (select ORIGINAL_NAME from dba_recyclebin))

select *  from a  minus select *  from b;





--对比表上索引数量

with a as (select table_name,count(*) cnt from dba_indexes where owner in  ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name),
b as (select table_name,count(*) cnt from dba_indexes@to_xxx where owner in ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name)
select *  from b  minus select *  from a;



with a as (select table_name,count(*) cnt from dba_indexes where owner in  ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name),
b as (select table_name,count(*) cnt from dba_indexes@to_xxx where owner in ('username') and table_name not in (select ORIGINAL_NAME from dba_recyclebin) group by table_name)
select *  from a  minus select *  from b;



--对比同义词数量

with a as (select owner,SYNONYM_NAME from dba_synonyms where owner in ('username')),
b as (select owner,SYNONYM_NAME from dba_synonyms@to_xxx where owner in ('username'))
select *  from b  minus select *  from a;




--对比序列数量

with a as (select sequence_owner,SEQUENCE_NAME from dba_sequences where sequence_owner in ('username')),
b as (select sequence_owner,SEQUENCE_NAME from dba_sequences@to_xxx where sequence_owner in ('username'))
select *  from b  minus select *  from a;



--对比触发器数量

with a as (select owner,TRIGGER_NAME,TRIGGER_TYPE from dba_triggers where owner in ('username')),
b as (select owner,TRIGGER_NAME,TRIGGER_TYPE from dba_triggers@to_xxx where owner in ('username'))
select *  from b  minus select *  from a;




--对比约束数量

with a as (select  a.owner,a.CONSTRAINT_NAME,a.CONSTRAINT_TYPE,a.TABLE_NAME,b.column_name from dba_constraints a,dba_cons_columns b where a.owner=b.owner and a.CONSTRAINT_NAME=b.CONSTRAINT_NAME and a.table_name=b.table_name and a.owner in ('username') and a.CONSTRAINT_TYPE='R'),
b as (select  a.owner,a.CONSTRAINT_NAME,a.CONSTRAINT_TYPE,a.TABLE_NAME,b.column_name from dba_constraints@to_xxx a,dba_cons_columns@to_xxx b where a.owner=b.owner and a.CONSTRAINT_NAME=b.CONSTRAINT_NAME and a.table_name=b.table_name and a.owner in ('username') and a.CONSTRAINT_TYPE='R')
select *  from b  minus select *  from a;




--对比用户权限

select GRANTEE,PRIVILEGE from dba_sys_privs@to_xxx where GRANTEE in ('username')
minus
select GRANTEE,PRIVILEGE from dba_sys_privs where GRANTEE in ('username');



select GRANTEE,owner,table_name,PRIVILEGE from dba_tab_privs@to_xxx where GRANTEE in ('username')
minus
select GRANTEE,owner,table_name,PRIVILEGE from dba_tab_privs where GRANTEE in ('username');



select GRANTEE,GRANTED_ROLE from dba_role_privs@to_xxx where GRANTEE in ('username')
minus
select GRANTEE,GRANTED_ROLE from dba_role_privs where GRANTEE in ('username');

--查询库中dblink

select * from dba_db_links@to_xxx;


--查询原库DDL或者创建日期在导入表结构后发生的对象

select owner,object_name,object_type,LAST_DDL_TIME,CREATED from dba_objects@to_xxx where (LAST_DDL_TIME > to_date('20230701 10','yyyymmdd hh24') or CREATED > to_date('20230701 10','yyyymmdd hh24')) and owner in ('username') order by LAST_DDL_TIME asc;"

数据验证 见数据验证

查询目标库当前数据库scn号进行反向同步 select to_char(current_scn) from v$database;

举报

相关推荐

0 条评论