Lab Objective: How to control connection count or manage db connection in oracle database using DB user profile
reference url: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-PROFILE.html
Steps:
1. Examine the existing profile to which your candidate user is assiged and its limit
set lines 1200 pages 40000 colsep , time on timing on trim on trims on
col username for a20
col profile for a30
col INITIAL_RSRC_CONSUMER_GROUP for a30
col last_login for a40
col profile for a40
col LIMIT for a40
alter session set nls_date_format='DD/MON/YYYY HH24:MI:SS';
select username
,account_Status
,created
,last_login
,profile
,INITIAL_RSRC_CONSUMER_GROUP
from dba_users
where oracle_maintained='N'
order by username;
select *
from dba_profiles
where profile='DEFAULT'
order by resource_name;
snippet from reference:
-- Ideally you would see the IDLE_TIME parameter set to UNLIMITED, when you update this value to some numeral, then the session staying in idle state is expected to be terminated after the set number.
-- The client will get to know that the session is terminated only when they try run the command again
Notice here there is one more limit INACTIVE_ACCOUNT_TIME which looks for the user last login and locks it as per the setting.
Output:
2. Remember updating the existing profile is going to change the profile limit for all the other users who are assigned this profile, so it is better to create a new profile as a clone of existing and update the new profile with the setting needed.
set long 20000
select dbms_metadata.get_ddl('PROFILE','DEFAULT') from dual;
modify alter statement with create statement...
CREATE PROFILE "PROF_IDLECNTL"
LIMIT
COMPOSITE_LIMIT UNLIMITED
SESSIONS_PER_USER UNLIMITED
CPU_PER_SESSION UNLIMITED
CPU_PER_CALL UNLIMITED
LOGICAL_READS_PER_SESSION UNLIMITED
LOGICAL_READS_PER_CALL UNLIMITED
IDLE_TIME 2
CONNECT_TIME UNLIMITED
PRIVATE_SGA UNLIMITED
FAILED_LOGIN_ATTEMPTS 10
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL
PASSWORD_LOCK_TIME 86400/86400
PASSWORD_GRACE_TIME 604800/86400
INACTIVE_ACCOUNT_TIME UNLIMITED;
select * from dba_profiles where profile='&profname' order by resource_name;
Output:
3. Assign the profile to the candidate user
alter user INVENTORYADM profile &profname;
Output:
4. Test if the user session gets terminated
-> login
> use dbeaver to connect to the user
-> run a test query
> open sql editor
SELECT object_name FROM user_objects;
-> check in v$session the session details
select sid,serial#,username,status,state,sql_id,program,logon_time from v$session where username='&usr';
-> leave the session for "2 mins" idle time
-> see if the session is terminated
a. check v$session
select sid,serial#,username,status,state,sql_id,program,logon_time from v$session where username='&usr';
b. try query from the program where user is connected for test and see the response
SELECT object_name FROM user_objects;
Output:
---> it stays in killed state
alert log:
2024-04-20 12:42:17.730000 +01:00
KILL SESSION for sid=(63, 48434):
Reason = profile limit idle_time
Mode = KILL SOFT -/-/NO_REPLAY
Requestor = PMON (orapid = 2, ospid = 11375, inst = 1)
Owner = Process: USER (orapid = 52, ospid = 18254)
Result = ORA-0
KILL SESSION for sid=(112, 46550):
Reason = profile limit idle_time
Mode = KILL SOFT -/-/NO_REPLAY
Requestor = PMON (orapid = 2, ospid = 11375, inst = 1)
Owner = Process: USER (orapid = 51, ospid = 18252)
Result = ORA-0
KILL SESSION for sid=(127, 40145):
Reason = profile limit idle_time
Mode = KILL SOFT -/-/NO_REPLAY
Requestor = PMON (orapid = 2, ospid = 11375, inst = 1)
Owner = Process: USER (orapid = 53, ospid = 18256)
Result = ORA-0
Dbeaver screenshot post session termination:
No comments:
Post a Comment