查看表空间路径及大小:
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;