Bagaimana cara memeriksa jumlah maksimum koneksi yang diizinkan ke database Oracle?

90

Apa cara terbaik, menggunakan SQL, untuk memeriksa jumlah koneksi maksimum yang diperbolehkan untuk database Oracle? Pada akhirnya, saya ingin menunjukkan jumlah sesi saat ini dan jumlah total yang diizinkan, misalnya "Saat ini, 23 dari 80 koneksi digunakan".

Niklas Gustavsson
sumber

Jawaban:

121

Ada beberapa batasan berbeda yang mungkin ikut berperan dalam menentukan jumlah koneksi yang didukung database Oracle. Pendekatan paling sederhana adalah dengan menggunakan parameter SESSIONS dan V $ SESSION, yaitu

Jumlah sesi yang diizinkan database dikonfigurasi

SELECT name, value 
  FROM v$parameter
 WHERE name = 'sessions'

The number of sessions currently active

SELECT COUNT(*)
  FROM v$session

As I said, though, there are other potential limits both at the database level and at the operating system level and depending on whether shared server has been configured. If shared server is ignored, you may well hit the limit of the PROCESSES parameter before you hit the limit of the SESSIONS parameter. And you may hit operating system limits because each session requires a certain amount of RAM.

Justin Cave
sumber
sorry, how can we run this query? I'm receiving "table or view not exist" for "SELECT COUNT(*) FROM v$session"
villager
3
@yin03 - That implies that whatever Oracle user you are using doesn't have privileges on the v$session view. You'd need to ask your DBA to grant you that privilege. Most likely, you'd want the select any dictionary privilege though the select_catalog_role role or a direct grant on just that object would also work.
Justin Cave
36

The sessions parameter is derived from the processes parameter and changes accordingly when you change the number of max processes. See the Oracle docs for further info.

To get only the info about the sessions:

    select current_utilization, limit_value 
    from v$resource_limit 
    where resource_name='sessions';
CURRENT_UTILIZATION LIMIT_VALUE
------------------- -----------
                110         792

Try this to show info about both:

    select resource_name, current_utilization, max_utilization, limit_value 
    from v$resource_limit 
    where resource_name in ('sessions', 'processes');
RESOURCE_NAME CURRENT_UTILIZATION MAX_UTILIZATION LIMIT_VALUE
------------- ------------------- --------------- -----------
processes                      96             309         500
sessions                      104             323         792
FuePi
sumber
34

I thought this would work, based on this source.

SELECT
  'Currently, ' 
  || (SELECT COUNT(*) FROM V$SESSION)
  || ' out of ' 
  || DECODE(VL.SESSIONS_MAX,0,'unlimited',VL.SESSIONS_MAX) 
  || ' connections are used.' AS USAGE_MESSAGE
FROM 
  V$LICENSE VL

However, Justin Cave is right. This query gives better results:

SELECT
  'Currently, ' 
  || (SELECT COUNT(*) FROM V$SESSION)
  || ' out of ' 
  || VP.VALUE 
  || ' connections are used.' AS USAGE_MESSAGE
FROM 
  V$PARAMETER VP
WHERE VP.NAME = 'sessions'
JosephStyons
sumber
sorry, how can we run this query? I'm receiving "table or view not exist" for "SELECT COUNT(*) FROM v$session"
villager
2
@yin03 Are you using Oracle or another type of database? If Oracle, it may be a permissions issue.
JosephStyons
1
flawless query @JosephStyons!
Gaurav
@guarav, I'm glad you found it useful!
JosephStyons
4

Note: this only answers part of the question.

If you just want to know the maximum number of sessions allowed, then you can execute in sqlplus, as sysdba:

SQL> show parameter sessions

This gives you an output like:

    NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
java_max_sessionspace_size           integer     0
java_soft_sessionspace_limit         integer     0
license_max_sessions                 integer     0
license_sessions_warning             integer     0
sessions                             integer     248
shared_server_sessions               integer

The sessions parameter is the one what you want.

botkop
sumber
4

Use gv$session for RAC, if you want get the total number of session across the cluster.

Tom
sumber
1
select count(*),sum(decode(status, 'ACTIVE',1,0)) from v$session where type= 'USER'
saris mohammad
sumber