Oracle session出現大量的inactive


 

.官網說明

1.1 processes

11gR2 的文檔:

Property

Description

Parameter type

Integer

Default value

100

Modifiable

No

Range of values

6 to operating system dependent

Basic

Yes

Oracle RAC

Multiple instances can have different values.

PROCESSES specifies the maximum numberof operating system user processes that can simultaneously connect to Oracle.Its value should allow for all background processes such as locks, job queueprocesses, and parallel execution processes.

 

The defaultvalues of the SESSIONS and TRANSACTIONS parameters arederived from this parameter. Therefore, if you change the valueof PROCESSES, you should evaluate whether to adjust the values of thosederived parameters.

PROCESSES指定可同時連接到Oracle操作系統用戶進程的最大數目。其值應允許所有后台進程,如鎖,作業隊列進程和並行執行的過程。

在會話和事務參數的默認值是從這個參數的。因此,如果你改變流程的價值,你應該評估是否調整這些衍生參數的值。

http://download.oracle.com/docs/cd/E11882_01/server.112/e25513/initparams198.htm#REFRN10175

1.2 sessions

11gR1:

http://download.oracle.com/docs/cd/B28359_01/server.111/b28320/initparams220.htm#REFRN10197

 

Property

Description

Parameter type

Integer

Default value

Derived: (1.1 * PROCESSES) + 5

Modifiable

No

Range of values

1 to 231

Basic

Yes

 

11gR2

Property

Description

Parameter type

Integer

Default value

Derived: (1.5 * PROCESSES) + 22

Modifiable

No

Range of values

1 to 231

Basic

Yes

 

這里要注意的是到了11gR2里,sessions 的默認值計算方式變了。 該值的計算是針對 dedicate 模式的。

 

SESSIONS specifies the maximum number of sessions that can becreated in the system. Because every login requires a session, this parametereffectively determines the maximum number of concurrent users in the system.You should always set this parameter explicitly to a value equivalent to yourestimate of the maximum number of concurrent users, plus the number ofbackground processes, plus approximately 10% for recursive sessions.

Oracle uses thedefault value of this parameter as its minimum. Values between 1 and thedefault do not trigger errors, but Oracle ignores them and uses the defaultinstead.

The defaultvalues of the ENQUEUE_RESOURCES and TRANSACTIONS parametersare derived from SESSIONS. Therefore, if you increase the valueof SESSIONS, you should consider whether to adjust the valuesof ENQUEUE_RESOURCES and TRANSACTIONS as well. (Notethat ENQUEUE_RESOURCES is obsolete as of Oracle Database 10g release2 (10.2).)

In a shared server environment, the value of PROCESSES canbe quite small. Therefore, Oracle recommends that youadjust the value of SESSIONS to approximately 1.1 * total numberof connections.

SESSIONS指定可在系統中創建的會話的最大數目。因為每次登錄需要一個會話,這個參數有效決定了系統的並發用戶的最大數量。你restimate並發用戶的最大數量,再加上后台進程的數量,你應該始終明確設置此參數值當量,加上遞歸會話約10%。

 

1.3 transactions

11gR2

http://download.oracle.com/docs/cd/E11882_01/server.112/e25513/initparams258.htm#REFRN10222

 

 

Property

Description

Parameter type

Integer

Default value

Derived: (1.1 * SESSIONS)

Modifiable

No

Range of values

4 to 232

Oracle RAC

Multiple instances can have different values.

 

TRANSACTIONS specifieshow many rollback segments to onlinewhen UNDO_MANAGEMENT = MANUAL. The maximum number of concurrenttransactions is now restricted by undo tablespace size(UNDO_MANAGEMENT = AUTO) or the number of online rollback segments(UNDO_MANAGEMENT = MANUAL).

二測試

select * from v$version

Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production

PL/SQL Release 12.1.0.1.0 - Production

CORE 12.1.0.1.0 Production

TNS for Linux: Version 12.1.0.1.0 - Production

NLSRTL Version 12.1.0.1.0 - Production

select count(*) from v$process;

select count(*) from v$session;

select count(*) from v$session where status='ACTIVE';

select username,count(username) from v$session where username is not null group by username;

查詢oracle中的配置值

  select  num,name,type,value,display_value from v$parameter where name in ('processes','sessions')

SESSIONS=(1.5* PROCESSES) + 22

 

三 出現大量sessionINACTIVE

 

1查詢當前的連接數,狀態

 select  b.MACHINE, b.PROGRAM , status ,count(*) from v$process a, 

   v$session b where a.ADDR = b.PADDR and  b.USERNAME is not null   

   group by  b.MACHINE  , b.PROGRAM, status order by count(*) desc; 

2 查詢是否有死鎖

 select * from v$locked_object; 

  select sess.sid,

   sess.serial#,

   lo.oracle_username,

   lo.os_user_name,

   ao.object_name,

   lo.locked_mode

   from v$locked_object lo,

   dba_objects ao,

   v$session sess

where ao.object_id = lo.object_id and lo.session_id = sess.sid

Status:

l Achtive:正執行SQL語句(waiting for/using a resource)

l Inactive:等待操作(即等待需要執行的SQL語句)

l Killed:被標注為刪除

Inactive對數據庫本身沒有什么影響,但是程序如果沒有及時commit,那么就會造成占用過多回話,有兩種方式解決

 

1修改sqlnet.ora文件,新增expire_time=x(minutes)

2 通過alter profile default limit idle_time=10; restart oracle service

 show parameter resource_limit  

alter system set resource_limit=true scope=both;  

select username,profile from DBA_USERS

select distinct(profile) from dba_profiles; 

 SELECT name, value  FROM gv$parameter   WHERE name = 'resource_limit';  

alter user system profile PROFILE9959;--new profile

select sid,serial#,paddr,username,status from v$session where status = 'SNIPED';

select * from dba_profiles--查看詳細的profile的配置信息

select * from dba_profiles where profile='USER_PROFILE_RCS2';

創建function

CREATE OR REPLACE FUNCTION SYS.verify_function_pro_rcs

創建profile

SQL> CREATE PROFILE "USER_PROFILE_RCS2"   LIMIT

  SESSIONS_PER_USER UNLIMITED

  CONNECT_TIME UNLIMITED

  IDLE_TIME UNLIMITED

  LOGICAL_READS_PER_SESSION UNLIMITED

  LOGICAL_READS_PER_CALL UNLIMITED

  COMPOSITE_LIMIT UNLIMITED

  PRIVATE_SGA UNLIMITED

  FAILED_LOGIN_ATTEMPTS 5

  PASSWORD_LIFE_TIME 60

  PASSWORD_REUSE_TIME 14

  PASSWORD_REUSE_MAX 12

  PASSWORD_LOCK_TIME UNLIMITED

  PASSWORD_GRACE_TIME UNLIMITED

  PASSWORD_VERIFY_FUNCTION verify_function_pro_rcs;

Profile created.

Test

SQL> show user;

USER is "SYS"

SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;

 

    CON_ID  DBID NAME    OPEN_MODE

---------- ---------- ------------------------------------------------------------ --------------------

 2 4119682648 PDB$SEED    READ ONLY

 3 2324297228 PDBORCL    READ WRITE

 4  397367019 YHQ_PDB    READ WRITE

 

SQL> alter session set container=pdborcl;

Session altered. 

SQL> alter system set resource_limit=true scope=both;  

System altered.

SQL> create profile test_idletime limit idle_time 10; 

Profile created.

SQL> create user idle_time_user identified by idle_time_user profile test_idletime;

User created.

SQL> grant resource,connect to idle_time_user;

Grant succeeded.

3 另一種解決方法

select A.SID,B.SPID,A.SERIAL#,a.lockwait,A.USERNAME,A.OSUSER,a.logon_time,a.last_call_et/3600 LAST_HOUR,A.STATUS, 

'orakill '||sid||' '||spid HOST_COMMAND,

'alter system kill session '''||A.sid||','||A.SERIAL#||'''' SQL_COMMAND

from v$session A,V$PROCESS B where A.PADDR=B.ADDR AND SID>6

--sid的取值??

一個自動殺 job
CREATE OR REPLACE PROCEDURE "KILL_SESSION" AS
        v_sid number;
        v_serial number;
                killer varchar2(1000);
        CURSOR cursor_session_info is select sid,serial# from v$session where type!='BACKGROUND' and status='INACTIVE' and last_call_et>2700 and username='ICWEB' and machine='orc';
BEGIN
        open cursor_session_info;
        loop
                fetch cursor_session_info into v_sid,v_serial;
                exit when cursor_session_info%notfound;
                                
                                killer:='alter system disconnect session '''||v_sid||','||v_serial||''' post_transaction immediate';
                                                                execute immediate killer;
                                        end loop;
                dbms_output.PUT_LINE(cursor_session_info%rowcount||' users with idle_time>2700s have been killed!');
                close cursor_session_info;
END;
/

這樣做其實還是治標不治本,最好能夠解決連接池自動釋放idle進程的問題

 

--登錄前端應用服務器查看ip連接數

[root@rac1 ~]# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

[root@rac1 ~]# netstat -ntu |grep 8080

[root@rac1 ~]# netstat -ntu |grep 8080|grep TIME_WAIT |wc -l


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM