oracle相关操作

---------表空间使用占比
select f.tablespace_name,d.total_byte “total_byte(M)”,(d.total_byte-f.free_byte) “used_byte(M)”,
f.free_byte “free_byte(M)”,round((1-f.free_byte/d.total_byte)100,2) “used(%)”,round(f.maxbyte/(10241024),2) “maxbyte(M)”
from (select tablespace_name,round(sum(bytes)/(10241024),2) free_byte ,max(bytes) maxbyte from dba_free_space
group by tablespace_name) f,
(select tablespace_name,round(sum(bytes)/(1024
1024),2) total_byte from dba_data_files
group by tablespace_name) d
where f.tablespace_name=d.tablespace_name
order by f.tablespace_name;

–查询表空间对应的数据文件

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

当单个数据文件超过32G应增加数据文件

–用户和表空间对应关系

select username,default_tablespace from dba_users;

--------------新增查询权限用户
create user xxxx identified by xxxx;
grant select any table to xxxx;
grant select any dictionary to xxxx;
grant create session to xxxx;

create user occ2019 identified by occ2019;
grant select any table to occ2019;
grant select any dictionary to occ2019;
grant create session to occ2019;

select name from v$datafile
Select * FROM DBA_DATA_FILES;

–查询表空间对应的数据文件

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

–用户和表空间对应关系

select username,default_tablespace from dba_users;

增加表空间数据文件(dbf文件设置了32G默认自增长。当表空间使用到30G后需要增加表空间数据文件!!!目前一月5G的数据量)
alter tablespace xxxxxxx add datafile;
alter tablespace xxxxxxx add datafile;


1.查看是否开启OMF,如果db_create_file_dest参数为空,说明未启用OMF
show parameter db_create_file_d
2.启用OMF
alter system set db_create_file_dest=’/u01/datafile’;
3.创建表空间(创建完成立即生成第一个datafile,初始化是100M,自动扩展最大32G)
create tablespace xxxxx;
4.查询数据文件的使用率以及占用的磁盘空间
select a.file_name,a.bytes/1024/1024 “TOTAL(M)”,

b.sb/1024/1024 “FREE(M)”,100*

b.sb/a.bytes “FREE%” from dba_data_files a,(select file_id,sum(BYTES) sb from dba_free_space group by file_id) b where a.file_id=b.file_id order by a.file_name;
5.当第一个datafile剩余50M左右需要手动添加datafile
alter tablespace xxxxxxx add datafile;

-------------查询表空间大小及已使用大小—
select tablespace_name,
max_gb,
used_gb,
round(100 * used_gb / max_gb) pct_used
from (select a.tablespace_name tablespace_name,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / power(2, 30),
2) used_gb,
round(a.maxbytes / power(2, 30), 2) max_gb
from (select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible,
‘YES’,
f.maxbytes,
‘NO’,
f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
(select f.tablespace_name, sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
union all
select h.tablespace_name tablespace_name,
round(sum(nvl(p.bytes_used, 0)) / power(2, 30), 2) used_gb,
round(sum(decode(f.autoextensible,
‘YES’,
f.maxbytes,
‘NO’,
f.bytes)) / power(2, 30),
2) max_gb
from v t e m p s p a c e h e a d e r h , v temp_space_header h, v tempspaceheaderh,vtemp_extent_pool p, dba_temp_files f
where p.file_id(+) = h.file_id
and p.tablespace_name(+) = h.tablespace_name
and f.file_id = h.file_id
and f.tablespace_name = h.tablespace_name
group by h.tablespace_name)
order by 4;



----用户对应表空间物理文件路径及大小
select a.TABLESPACE_NAME,a.FILE_ID,a.FILE_NAME,(a.BYTES / 1024 / 1024) as “FILE_SIZE(MB)”,b.tb_size as “TABLESPACE_SIZE(MB)”,((a.BYTES / 1024 / 1024) - b.tb_size) as “RELEASE_SIZE” from dba_data_files a,(select TABLESPACE_NAME,round(max(BLOCK_ID) * 16384 / 1024 / 1024) tb_size from dba_extents group by TABLESPACE_NAME) b where a.TABLESPACE_NAME = b.TABLESPACE_NAME order by a.FILE_ID;


select username,default_tablespace,temporary_tablespace from dba_users
where (default_tablespace=‘SYSTEM’ or temporary_tablespace=‘SYSTEM’) and username not in?? (‘SYSTEM’,‘SYS’);

设置系统表空间自增长
alter database datafile ‘/u01/app/oracle/oradata/oracle/system02.dbf’ autoextend on next 5000M maxsize unlimited;

oracle可管理的最大数据块为2的22次方个,而根据单个数据块大小大小的不同,其最大容量也是不同的。对于OLTP应用,数据块的大小通常为8K,这样,算下来,单个数据文件的大小最大为(2^22)*8K=32G.


oracle如何查看当前有哪些用户连接到数据库

可以执行以下语句:
select username,serial#, sid from v$session; —查询用户会话
alter system kill session 'serial#, sid ';—删除相关用户会话

建议以后台登陆删除用户会话
1、查询oracle的连接数
select count(*) from v s e s s i o n ; 2 、 查 询 o r a c l e 的 并 发 连 接 数 s e l e c t c o u n t ( ∗ ) f r o m v session; 2、查询oracle的并发连接数 select count(*) from v session;2oracleselectcount()fromvsession where status=‘ACTIVE’;
3、查看不同用户的连接数
select username,count(username) from v s e s s i o n w h e r e u s e r n a m e i s n o t n u l l g r o u p b y u s e r n a m e ; 4 、 查 看 所 有 用 户 : s e l e c t ∗ f r o m a l l u s e r s ; 5 、 查 看 用 户 或 角 色 系 统 权 限 ( 直 接 赋 值 给 用 户 或 角 色 的 系 统 权 限 ) : s e l e c t ∗ f r o m d b a s y s p r i v s ; s e l e c t ∗ f r o m u s e r s y s p r i v s ; 6 、 查 看 角 色 ( 只 能 查 看 登 陆 用 户 拥 有 的 角 色 ) 所 包 含 的 权 限 s e l e c t ∗ f r o m r o l e s y s p r i v s ; 7 、 查 看 用 户 对 象 权 限 : s e l e c t ∗ f r o m d b a t a b p r i v s ; s e l e c t ∗ f r o m a l l t a b p r i v s ; s e l e c t ∗ f r o m u s e r t a b p r i v s ; 8 、 查 看 所 有 角 色 : s e l e c t ∗ f r o m d b a r o l e s ; 9 、 查 看 用 户 或 角 色 所 拥 有 的 角 色 : s e l e c t ∗ f r o m d b a r o l e p r i v s ; s e l e c t ∗ f r o m u s e r r o l e p r i v s ; 10 、 查 看 哪 些 用 户 有 s y s d b a 或 s y s o p e r 系 统 权 限 ( 查 询 时 需 要 相 应 权 限 ) s e l e c t ∗ f r o m V session where username is not null group by username; 4、查看所有用户: select * from all_users; 5、查看用户或角色系统权限(直接赋值给用户或角色的系统权限): select * from dba_sys_privs; select * from user_sys_privs; 6、查看角色(只能查看登陆用户拥有的角色)所包含的权限 select * from role_sys_privs; 7、查看用户对象权限: select * from dba_tab_privs; select * from all_tab_privs; select * from user_tab_privs; 8、查看所有角色: select * from dba_roles; 9、查看用户或角色所拥有的角色: select * from dba_role_privs; select * from user_role_privs; 10、查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限) select * from V sessionwhereusernameisnotnullgroupbyusername;4selectfromallusers;5()selectfromdbasysprivs;selectfromusersysprivs;6()selectfromrolesysprivs;7selectfromdbatabprivs;selectfromalltabprivs;selectfromusertabprivs;8selectfromdbaroles;9selectfromdbaroleprivs;selectfromuserroleprivs;10sysdbasysoper()selectfromVPWFILE_USERS;

修改数据库允许的最大连接数:
alter system set processes = 300 scope = spfile;

查看游标数量
Select * from v$open_cursor Where user_name=’’

查询数据库允许的最大连接数:
select value from v$parameter where name = ‘processes’;
或者:show parameter processes;

查询数据库允许的最大游标数:
select value from v$parameter where name = ‘open_cursors’

查看oracle版本
select banner from sys.v_$version;

按降序显示用户"SYSTEM"为每个会话打开的游标数
select o.sid, osuser, machine, count(*) num_curs from v o p e n c u r s o r o , v open_cursor o, v opencursoro,vsession s where user_name = ‘SYSTEM’ and o.sid=s.sid group by o.sid, osuser, machine order by num_curs desc;

—查询用户表大小MB
select Segment_Name,Sum(bytes)/1024/1024 From User_Extents where TABLESPACE_NAME=‘xxxxx’ Group By Segment_Name
select * From User_Extents
—查询SYS_LOB对应表
select owner, table_name, column_name, segment_name, index_name
from dba_lobs where segment_name=‘SYS_LOB0000074348C00006$$’

整理自网络方便使用、备查

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值