select 'alter system kill session ''' || SID || ',' || SERIAL# || ''';'
from (select distinct a.sid,
a.Serial#,
status,
machine,
LOCKWAIT,
logon_time
from v$session a, v$locked_object b
where (a.status = 'ACTIVE' or a.status = 'INACTIVE')
and a.sid = b.session_id
and b.ORACLE_USERNAME = 'LOANBAK' --加上用户名可过滤用户资源
)
/*2、批量执行第一步生成的语句
alter system kill session 'sid,serial#';
alter system kill session '6976,33967';*/
/*3、查询oracle用户名,机器名,锁表对象*/
SELECT l.session_id sid,
s.serial#,
l.locked_mode,
l.oracle_username,
l.os_user_name,
s.machine,
s.terminal,
o.object_name,
s.logon_time
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid
ORDER BY sid, s.serial#;
11、查询oracle的连接数
2select count(*) from v$session;
32、查询oracle的并发连接数
4select count(*) from v$session where status='ACTIVE';
53、查看不同用户的连接数
6select username,count(username) from v$session where username is not null group by username;
74、查看所有用户:
8select * from all_users;
95、查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
10select * from dba_sys_privs;
11select * from user_sys_privs;
126、查看角色(只能查看登陆用户拥有的角色)所包含的权限
13select * from role_sys_privs;
147、查看用户对象权限:
15select * from dba_tab_privs;
16select * from all_tab_privs;
17select * from user_tab_privs;
188、查看所有角色:
19select * from dba_roles;
209、查看用户或角色所拥有的角色:
21select * from dba_role_privs;
22select * from user_role_privs;
2310、查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
24select * from V$PWFILE_USERS;
select count(*) from v$process --当前的连接数
select value from v$parameter where name = 'processes' --数据库允许的最大连接数
修改最大连接数:
alter system set processes = 300 scope = spfile;
重启数据库:
shutdown immediate;
startup;
--查看当前有哪些用户正在使用数据
SELECT osuser, a.username,cpu_time/executions/1000000||'s', sql_fulltext,machine
from v$session a, v$sqlarea b
where a.sql_address =b.address order by cpu_time/executions desc;
select count(*) from v$session #连接数
select count(*) from v$session where status='ACTIVE' #并发连接数
show parameter processes #最大连接
alter system set processes = value scope = spfile;重启数据库 #修改连接
SQL> Select count(*) from v$session where status='ACTIVE' ;
COUNT(*)
----------
20
SQL> Select count(*) from v$session;
COUNT(*)
----------
187
SQL> show parameter processes;
NAME TYPE VALUE
------------------------------------ ----------- ----------
aq_tm_processes integer 0
db_writer_processes integer 1
gcs_server_processes integer 0
job_queue_processes integer 10
log_archive_max_processes integer 2
processes integer 450
SQL>
并发指active,I SEE
SQL> select count(*) from v$session #连接数
SQL> Select count(*) from v$session where status='ACTIVE' #并发连接数
SQL> show parameter processes #最大连接
SQL> alter system set processes = value scope = spfile;重启数据库 #修改连接
unix 1个用户session 对应一个操作系统 process
而 windows体现在线程
DBA要定时对数据库的连接情况进行检查,看与数据库建立的会话数目是不是正常,如果建立了过多的连接,会消耗数据库的资源。同时,对一些“挂死”的连接,可能会需要DBA手工进行清理。
以下的SQL语句列出当前数据库建立的会话情况:
select sid,serial#,username,program,machine,status
from v$session;
输出结果为:
SID SERIAL# USERNAME PROGRAM MACHINE STATUS
---- ------- ---------- ----------- --------------- --------
1 1 ORACLE.EXE WORK3 ACTIVE
2 1 ORACLE.EXE WORK3 ACTIVE
3 1 ORACLE.EXE WORK3 ACTIVE
4 1 ORACLE.EXE WORK3 ACTIVE
5 3 ORACLE.EXE WORK3 ACTIVE
6 1 ORACLE.EXE WORK3 ACTIVE
7 1 ORACLE.EXE WORK3 ACTIVE
8 27 SYS SQLPLUS.EXE WORKGROUP\\WORK3 ACTIVE
11 5 DBSNMP dbsnmp.exe WORKGROUP\\WORK3 INACTIVE
其中,
SID 会话(session)的ID号;
SERIAL# 会话的序列号,和SID一起用来唯一标识一个会话;
USERNAME 建立该会话的用户名;
PROGRAM 这个会话是用什么工具连接到数据库的;
STATUS 当前这个会话的状态,ACTIVE表示会话正在执行某些任务,INACTIVE表示当前会话没有执行任何操作;
如果DBA要手工断开某个会话,则执行:
alter system kill session \'SID,SERIAL#\'