oracle_sql创建和删除表空间、数据库、用户
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
查看
1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name group by t.tablespace_name;
2、查看表空间物理文件的名称及大小
select tablespace_name, file_id, file_name, round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name;
3、查看回滚段名称及大小
select segment_name, tablespace_name, r.status,(initial_extent/1024)
InitialExtent,(next_extent/1024) NextExtent, max_extents, v.curext CurExtent from
dba_rollback_segs r, v$rollstat v Where r.segment_id = n(+) order by segment_name ;
4、查看控制文件
select name from v$controlfile;
5、查看日志文件
select member from v$logfile;
6、查看表空间的使用情况
select sum(bytes)/(1024*1024) as free_space,tablespace_name from dba_free_space group by tablespace_name;
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
(B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE" FROM SYS.SM$TS_AVAIL
A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME;
7、查看数据库库对象
select owner, object_type, status, count(*) count# from all_objects group by owner,
object_type, status;
8、查看数据库的版本
Select version FROM Product_component_version Where SUBSTR(PRODUCT,1,6)='Oracle';
9.查看某个表空间内所占空间大于某个值的段(表或索引):
Select segment_name,bytes FROM dba_segments Where bytes>10000000 AND
tablespace_name='tablespace_name';
10.查看所有表空间的碎片程度(值在30以下表示碎片很多)
select tablespace_name,sum(bytes),sum(free),sum(free)*100/sum(bytes)
from (select b.file_id file_ID, b.tablespace_name tablespace_name, b.bytes Bytes, (b.bytes-sum(nvl(a.bytes,0))) used, sum(nvl(a.bytes,0))
free, sum(nvl(a.bytes,0))/(b.bytes)*100 Percent 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 order by b.file_id) group by tablespace_name order by sum(free)*100/sum(bytes);
11.查看自上次数据库启动以来所有数据文件的读写次数
select substr(,1,5) Drive,
file_name, (fs.phyblkrd+fs.phyblkwrt) from v$filestat fs,v$datafile df where
df.file#=fs.file#;
12.查看数据库中的所有用户:
select * from all_users;
//or
select * from dba_users
创建
1.创建临时表空间
create temporary tablespace mytest
tempfile 'E:/Program/oracle/product/10.1.0/oradata/orcl/mytest.dbf'
size 32m
autoextend on
next 32m maxsize 1024m extent management local;
//必须指定tempfile的参数
2.创建数据表空间
create tablespace mytest_data
logging
datafile'E:/Program/oracle/product/10.1.0/oradata/orcl/mytest_data.dbf'
size 32m
autoextend on
next 32m maxsize 1024m
extent management local;
//必须指定datafile 的参数
3.创建用户并指定表空间
create user testaccount identified by testpwd default tablespace mytest_data temporary tablespace mytest;
4.权限
//授予message 用户dba角色的所以权限
Grant dba to testaccount;
//给用户授予权限
grant connect,resource to testaccount; (db2:指定所有权限)