暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle复制统计信息

larntor 2024-01-25
412

1.DBMS_STATS.EXPORT_SCHEMA

--创建存储统计信息的表
EXEC DBMS_STATS.CREATE_STAT_TABLE('OWNERNAME', 'STATS_EXPORT');


---把OWNERNAME用户的统计信息导入到STATS_EXPORT表
EXEC DBMS_STATS.EXPORT_SCHEMA_STATS('OWNERNAME', 'STATS_EXPORT', NULL, 'OWNERNAME');


--更新STATS_EXPORT表,把c5列改为要导入统计信息的用户
update STATS_EXPORT set c5='OWNERNAME1';


---导入之前重新确认信息
select t.last_analyzed,t.stattype_locked,t.* from dba_tab_statistics t where owner='OWNERNAME1'; 


----导入统计信息到OWNERNAME1用户
EXEC DBMS_STATS.IMPORT_SCHEMA_STATS('OWNERNAME1', 'STATS_EXPORT', NULL, 'OWNERNAME');


---导入之后重新确认信息
select t.last_analyzed,t.stattype_locked,t.* from dba_tab_statistics t where owner='OWNERNAME1'; 

2.expdp方式导入

--导出用户统计信息
expdp "'/ as sysdba'" directory=dump schemas=OWNERNAME  dumpfile=expstats_0123_01.dmp include=STATISTICS logfile=expstats0123.log 


---确认用户统计信息是否为空
select t.last_analyzed,t.stattype_locked,t.* from dba_tab_statistics t where owner='OWNERNAME1'; 


---导入用户统计信息
impdp "'/ as sysdba'" directory=dump  remap_schema=OWNERNAME:OWNERNAME1  dumpfile=expstats_0123_01.dmp logfile=impstats0123.log 


---导入之后重新确认信息
select t.last_analyzed,t.stattype_locked,t.* from dba_tab_statistics t where owner='OWNERNAME1'; 


----解锁统计信息

EXEC dbms_stats.unlock_schema_stats('OWNERNAME1'); 

----------------------------------------------------

select 'exec dbms_stats.set_table_prefs('''||owner||''','''||table_name||''',''INCREMENTAL'',''TRUE'');'
from (select distinct owner, table_name from DBA_TAB_STATISTICS where stattype_locked IN ('ALL','DATA','CACHE') and owner not in ('SYS','SYSMAN','SYSTEM','WMSYS'));

select 'exec DBMS_STATS.GATHER_TABLE_STATS(ownname=>'''||owner||''',tabname=>'''||table_name||''',method_opt=>''for all columns size auto'',cascade=>true,force=>true,degree=>16);'
from (select distinct owner, table_name from DBA_TAB_STATISTICS where stattype_locked IN ('ALL','DATA','CACHE') and owner not in ('SYS','SYSMAN','SYSTEM','WMSYS'));

exec DBMS_STATS.GATHER_TABLE_STATS(ownname=>'OWNERNAME',tabname=>'xxxxxxxx',method_opt=>'for all columns size auto',cascade=>true,force=>true,degree=>16,no_invalidate=>false);


exec DBMS_STATS.gather_database_stats(method_opt=>'for all columns size auto',cascade=>true,degree=>16,no_invalidate=>false);

exec DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>'OWNERNAME' ,method_opt=>'for all columns size auto',cascade=>true,force=>true,degree=>16,no_invalidate=>false);

select 'exec DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>'''||username||''', method_opt=>''for all columns size auto'',cascade=>true,force=>true,degree=>16,no_invalidate=>false);'
from dba_users where username in

-- no_invalidate=>false 立即失效

最后修改时间:2024-01-25 11:24:05
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论