|
给你发个DBA用的一些sql,我自己整理的
--查看表空间的名字及文件所在位置:
select tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) "总空间/MB"
from dba_data_files
order by tablespace_name;
--查询系统临时表空间DBF
select name from v$tempfile;
--查询表空间大小
select a.tablespace_name,
a.bytes / 1024 / 1024 "总空间/MB",
(a.bytes - b.bytes) / 1024 / 1024 "已用空间/MB",
b.bytes / 1024 / 1024 "剩余空间/MB",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "使用率/%"
from (select tablespace_name, sum(bytes) bytes
from dba_data_files
group by tablespace_name) a,
(select tablespace_name, sum(bytes) bytes, max(bytes) largest
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by ((a.bytes - b.bytes) / a.bytes) desc;
--查询用户名,表空间
select username, default_tablespace from dba_users;
--查看所有用户
select * from all_users where username like '%ecms%';
--查看当前用户的缺省表空间
select username,default_tablespace from user_users;
--查询表空间下所有用户的表名
select * from dba_tables where tablespace_name like 'EPMSDEV';
--查看当前用户下的表占用空间大小
Select Segment_Name 表名, Sum(bytes) / 1024 / 1024 "已占用/MB"
From User_Extents
where Segment_Name like '%B_SYS%'
Group By Segment_Name
order by Sum(bytes);
--查看回滚段命中率情况
select rn.name,
rs.gets "被访问次数",
rs.waits "等待回退段块的次数",
(rs.waits / rs.gets) * 100 "命中率"
from v$rollstat rs, v$rollname rn;
--查看所有角色
select * from dba_roles;
--查询某角色具有那些权限
SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE='RESOURCE';
--查看当前用户所拥有的角色
select * from user_role_privs;
--查看所有用户所拥有的角色
select * from dba_role_privs where GRANTED_ROLE like '%DBA%';
--收回权限
revoke dba from gd_ecms;
--授权
grant EXP_FULL_DATABASE,IMP_FULL_DATABASE,connect, resource,create view to gd_ecms;
grant dba to SCMS_DBA_A,SCMS_DBA_B;
--收回操作表空间无限制权限
revoke unlimited tablespace from gd_ecms;
--使角色生效或失效,DBA可以通过控制角色的生效或失效,来暂时回收用户的一部分权限。如使dept1角色失效:
SET ROLE dept1 DISABLE;
--删除角色,这将会影响到拥有该角色的用户和其它角色的权限。用DROP ROLE命令删除角色,如:
DROP ROLE dept1;
--查看某用户所有权限:
select * from dba_sys_privs where grantee = 'EPMS_YN_TEST';
select * from dba_tab_privs where grantee = 'EPMS_YN_TEST';
select * from dba_col_privs where grantee = 'EPMS_YN_TEST';
select * from dba_role_privs where grantee = 'EPMS_YN_TEST'; |
|