Get IP address of oracle client users - oracle

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:
TERMINAL - An operating system identifier for the current session. This is often the client machine name.
HOST - The host name of the client machine.
IP_ADDRESS - The IP address of the client machine.
SERVER_HOST - The host name of the server running the database instance.
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;

Have a look with this query:
SELECT username, status, osuser, process, machine, terminal, logon_time,
lockwait, blocking_session_status, blocking_instance, blocking_session,
UTL_INADDR.GET_HOST_ADDRESS(REGEXP_REPLACE(machine, '^.+\\')) AS client_ip
FROM v$session;

Related

How to get the users desktop/laptop ip address in Oracle SQL procedure

I am using server's putty session to connect to oracle SQL plus and did below queries to get host name and ip address.
these queries are returing the host name and IP address of the application server but my requirement is to get the users laptop host name and IP address to know the user host name and IP address instead of server host name and ip address.
Can anyone help to get the user (laptop) host name and IP address instead of server host name and ip address?
select SYS_CONTEXT('USERENV', 'HOST', 15) INTO v_host from dual;
select SYS_CONTEXT('USERENV', 'IP_ADDRESS', 15) INTO v_ipaddress from dual;
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual
You can use the above query to get the IP address of the client.
I don't think this is possible as the Oracle Sql*plus has no information about your putty client.
So for the Oracle Db the client is your Application Server - form where Sql*plus calls are originating.
One thing you could probably do is set client_info and use that extra information to determine the real client.
Something like this (inside sql script)
DBMS_APPLICATION_INFO.set_client_info(client_info => '&1');
In that case you should pass putty's client value ($SSH_CLIENT environment variable) into your sql script:
sqlplus -S user/password#host << EOF
#/opt/D2RQ/file.sql $SSH_CLIENT
exit;
EOF

How to find out oracle local sessions

If there are any methods to find out the sessions from local machine in Oracle ?
I found that there is a 'PORT' field in v$session for V11.2.0, when we access oracle 11.2.0 on the local machine with sqlplus, the port field is 0, instead when we access oracle 11.2.0 from remote machine with sql developer, the PORT field is remote tcp port.
So we can identify the local sessions by the PORT field except the local connections via tcp with 127.0.0.1.
But another problem is that the oracle version before 11.2.0 don't have the v$session.PORT column.
Thanks
Use the MACHINE, TERMINAL, and PROGRAM columns.
MACHINE will match name of local host.
TERMINAL will be something like pts/1 or the Windows Machine name.
PROGRAM will be something like sqlplus#(TNS V1-V3)<--this is important because you'll also see the various internal stuff like (J001)(W001) etc. You can use a WHERE USERNAME IS NOT NULL to eliminate these unless you are looking to list all local connections.
Hope this is a good start.

establish an oracle database link between databases in two hosts that don't see each other

I have access to one database server through a vpn connection and another through lan connection.
from my machine I would like to copy some entries from one table into the other, like:
insert into destinationtable select * from sourcetable#databaselink where id in ('id1','id2','id3')
Establishing a database link does not work because the servers cannot see each other. Is there any other way to do it?
Install a database on your desktop, create links to both databases, and change the statement to something like this:
insert into destinationtable#databaselink_destination
select * from sourcetable#databaselink_source where id in ('id1','id2','id3')
You may need a virtual machine to bridge the networks. Set the host to one network and set the guest to another, and configure the VM to use both connections.
Depending on your exact configuration you may have additional issues, like licensing, OS privileges, etc. But I've found there is almost always a way to workaround those limitations.

Oracle Connection String for RAC Environment?

I have got an ORACLE RAC Environment access .The details are
Database Name: orcl
Service Name: orcl
IP Address: 192.168.1.1 and 192.168.1.2
SQL> host srvctl status database -d orcl
Instance orcl1 is running on node orclnode1
Instance orcl2 is running on node orclnode2
My concern is my connection, which is being established using
(DESCRIPTION=(ADDRESS=
(PROTOCOL=TCP)(HOST=192.168.1.1) (PORT=1521)
)(CONNECT_DATA=(SID=orcl1)))
But the provider wants it to be connected via the orcl service name .
I don`t have any other info related to this. Am I connecting correctly or I need hostname or IP address for orcl service name.
Your connection string is referencing one instance on one server/node. You should be using the common service name instead, and identifying all the servers it is available on.
The equivalent for you would be something like this (line breaks just for clarity here):
(DESCRIPTION=(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.1)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.2)(PORT=1521))
)(CONNECT_DATA=(SERVICE_NAME=orcl)))
As long as it is resolvable, it shouldn't matter whether you use the DNS names or the IP addresses for the HOST parameters.
You may also need the LOAD_BALANCE or FAILOVER parameters; see the docs.

How do I change the IP address on Oracle 10g

What steps do I need to take to change an IP address for Oracle 10g? I cannot connect to the database after going from a dhcp address to a static IP and a reboot.
If the server's IP address changed, these are the first things I would look at:
The TNSNAMES.ORA file on the client -- does it have the IP address hardcoded? If so, change it. Does it use the machine name? If so, does the machine name resolve to the correct IP address on your client machine?
The LISTENER.ORA file on the server -- does it explicitly specify the old IP address as its listening address?
More info please. Do you mean that you have changed the ip address of the host that the database is on and now you have to connect to it from a different macine, or are you having trouble starting the database after the ip change?
... and what error message do you receive?
Most obvious files to check are:
$ORACLE_HOME/network/admin/tnsnames.ora
$ORACLE_HOME/network/admin/listener.ora
Other than that we'd need more info...
I presume you mean the Oracle 10g DB and not the Oracle 10g Application Server?
Does the database start ok?
Is there anything in the database alert log?
Are the error(s) connecting from a client or the server?
What error message(s) do you get?
Can you ping the machine on it's new address (by both name + IP address) From both client + server?
Does a TNSPING work?
Can you connect using SQL*Plus on the server?
What other tool(s) have you tried connecting with?
Update after comment
Please can you post...
Your old ip address (if you know it)
Your new ip address
Your FQDN (e.g. machine.domain.com)
The output of "ipconfig/all" (or equivalent)
Your listener.ora file
The output of "$ORACLE_HOME/bin/lsnrctl start"
The output of "$ORACLE_HOME/bin/lsnrctl status"
Check that LOCAL_LISTENER is not defined (or defined correctly) in the database - it may not be registering correctly because of an incorrect entry here. Also try 'ALTER SYSTEM REGISTER' to attempt to register with the listener (rather than waiting up to 3 minutes for an auto-register). Examine the listener.log to see the instance registered (service_update * ) and 'lsnrctl status' to see if it is there.
Did you change the hostname in DNS? Can you ping the hostname from another machine?

Resources