I need a query to get all IP's of client users that have already a session to the database, I have an Oracle Database server in my work (hospital), some times the database stop working and can't execute any query that done by Oracle modules of the system which is the interface of the users, so to solve it we have to kill all sessions that connected to the database and make all users to restart sessions, my question is there any way to get the ip address with any information of the session like the consumption of the session?
I need a query to get all IP's of client users that have already a session to the database
You could use SYS_CONTEXT. It would return the following host and IP address information for the current session:
Have a look at this article by Tim Hall.
For example,
SQL> SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;
SYS_CONTEXT('USERENV','IP_ADDRESS')
----------------------------------------------------------
127.0.0.1
SQL>
For me the IP is localhost, so I get 127.0.0.1
Edit From discussions in the comments below, to get the list of the IP address of all the users from v$session, you could use MACHINE
they are connected from.
SELECT utl_inaddr.get_host_address(t.machine), t.* FROM v$session t;