Chinaunix首页 | 论坛 | 博客
  • 博客访问: 562662
  • 博文数量: 126
  • 博客积分: 8010
  • 博客等级: 中将
  • 技术积分: 1112
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-22 11:41
文章分类
文章存档

2010年(1)

2009年(5)

2008年(66)

2007年(54)

我的朋友

分类: Oracle

2008-02-29 12:52:35

set oracle_sid=ora816
exp system/manager file =exp_full.dmp full=y direct =y log=exp_full_log.txt

1.查询出所以包含对象的用户, 用sys用户
select * from
(select distinct owner ,tablespace_name from dba_tables ) a
 where a.owner <>upper('sys') and a.owner<>upper('system');

2. 生成create tablespace 脚本,去除新库中已经存在的表空间,大小要修改的大些。

set pagesize 1000
set linesize 300
spool create_ts.sql
SELECT 'create tablespace '||upper(f.tablespace_name) ||' datafile   '|| '''D:\Oracle\oradata\test1\'
||upper(f.tablespace_name)||'.dbf '''||'  size  '||(d.Tot_grootte_Mb - f.total_bytes)||'M;'
FROM
(SELECT tablespace_name,
round(SUM(bytes)/(1024*1024),2) total_bytes,
round(MAX(bytes)/(1024*1024),2) max_bytes
FROM sys.dba_free_space
GROUP BY tablespace_name) f,
(SELECT dd.tablespace_name, round(SUM(dd.bytes)/(1024*1024),2) Tot_grootte_Mb
FROM
sys.dba_data_files dd
GROUP BY dd.tablespace_name) d
WHERE d.tablespace_name = f.tablespace_name ;
spool off

3.生成create user 脚本,在旧库ora816上执行

set pagesize 1000
set linesize 200
spool create_user.sql
select 'create user '||username||'  identified by values '''||password||''' default tablespace '||default_tablespace||';' from dba_users
where default_tablespace <>upper('system') ;
spool off

4.  全库导入
set oracle_sid=test1
imp system/manager file =exp_full.dmp full=y ignore=y log= imp_full_log.txt

5.比较新旧库文件大小
conn internal/oracle
set pagesize 200
col "表空间名" for a20
SELECT upper(f.tablespace_name) "表空间名",
d.Tot_grootte_Mb "表空间大小(M)",
d.Tot_grootte_Mb - f.total_bytes "已使用空间(M)",
to_char(round((d.Tot_grootte_Mb - f.total_bytes) / d.Tot_grootte_Mb * 100,2),'990.99') "使用比",
f.total_bytes "空闲空间(M)",
f.max_bytes "最大块(M)"
FROM
(SELECT tablespace_name,
round(SUM(bytes)/(1024*1024),2) total_bytes,
round(MAX(bytes)/(1024*1024),2) max_bytes
FROM sys.dba_free_space
GROUP BY tablespace_name) f,
(SELECT dd.tablespace_name, round(SUM(dd.bytes)/(1024*1024),2) Tot_grootte_Mb
FROM
sys.dba_data_files dd
GROUP BY dd.tablespace_name) d
WHERE d.tablespace_name = f.tablespace_name
ORDER BY 1 DESC;

阅读(1635) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~