创建表空间及用户、删除

查看表空间路径及大小:

  select tablespace_name,file_id,bytes/1024/1024 兆,file_name from dba_data_files order by file_id;

创建表空间:

  create tablespace spacename datafile '/opt/oracle/app/oradata/orcl/spacename.dbf'size 200m autoextend on next 32m maxsize 2048m;

创建用户:

  create user username identified by userpassword default tablespace spacename ;

密码里有特殊字符的用双引号"psfen23%#"

授权用户:

  grant connect,resource,dba to username ;

红色字体需要替换实际要创建的名称或路径。

删除表空间,同时删除数据文件:

drop tablespace test_data ;

 including contents and datafiles删除数据文件慎用。

 

 将表移动到另一个表空间:

select 'alter table '||tname||' move  tablespace hebeihotel;' from tab ;

 

移动表到另一个表空间,会导致索引不能用:

查找用户下的索引:

select * from user_indexes ui where ui.table_owner='用户名';

索引rebuild

将索引status为unusable的rebuild:

select 'alter index HEBEIHOTEL.'||index_name||' rebuild' abc from user_indexes where status='UNUSABLE'

将搜索的结果转成行,

select replace(wm_concat(t.abc),',',';') from
(
select 'alter index HEBEIHOTEL.'||index_name||' rebuild' abc from user_indexes where status='UNUSABLE'

)t;

然后复制到editplus里,将  ;  用正则表达式全部替换为 ;\n

便于oracle里直接全部运行。

 

 查找表空间名称、大小、剩余空间、文件路径。

select b.file_id 文件ID号,
       b.tablespace_name 表空间名,
       b.bytes / 1024 / 1024 || 'M' 字节数,
       (b.bytes - sum(nvl(a.bytes, 0))) / 1024 / 1024 || 'M' 已使用,
       sum(nvl(a.bytes, 0)) / 1024 / 1024 || 'M' 剩余空间,
       100 - sum(nvl(a.bytes, 0)) / (b.bytes) * 100 占用百分比,
       b.file_name 文件路径
  from dba_free_space a, dba_data_files b
 where a.file_id = b.file_id
 group by b.tablespace_name, b.file_id, b.bytes,b.file_name
 order by b.file_id;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值