Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uniquely identify source JDBC process in Oracle DB

We are developing microservices using java (Spring and Spring Boot), and the access to our Oracle DB is done via the JDBC Oracle Driver.

The problem is that our DBAs can only see on the Oracle side that a "JDBC Thin Client" is connected. There is no better, logical representation of the connected application. Without such identification, it is hard to know which microservice might be behaving badly. Other non-JDBC clients identify themselves clearly with the hostname.

Is there any way to change the identification String so that it represents a clear identity of the source application/process?

Note: Our system runs on Cloud Foundry which uses containers, so a it's not really possible to provide a machine name or anything like that - a logical application name would be preferred.

Thanks

like image 486
odedia Avatar asked Apr 30 '18 07:04

odedia


People also ask

How do I find the Oracle DataSource URL?

Connection URL: The connection URL for the oracle10G database is jdbc:oracle:thin:@localhost:1521:xe where jdbc is the API, oracle is the database, thin is the driver, localhost is the server name on which oracle is running, we may also use IP address, 1521 is the port number and XE is the Oracle service name.

How can I tell who is connected to my Oracle database?

You can find all users currently logged into Oracle by running a query from a command prompt. In Oracle/PLSQL, there is a system view called V$SESSION which shows the session information for each current session in the database.

Does Sqldeveloper use JDBC?

As Oracle SQL Developer is a database, so with working with that everyone needs a JDBC driver installed on it.

How do I find the SID and service name in Oracle 12c?

select instance_name from v$instance; will give you SID name. select name from v$database; will give DB NAME. select instance_name from v$instance; will give you SID name.


2 Answers

The JDBC connection property "oracle.jdbc.v$session.process" can be set (as a system prop -D) to a value that uniquely identifies your microservice and that can then be retrieved in the V$SESSION view ("process" column).

like image 80
Jean de Lavarene Avatar answered Sep 21 '22 00:09

Jean de Lavarene


Thank you everyone for your suggestions, I have tried them all and sadly they did not work.

This is probably since I am connection using Spring Data and the default Hikari connection pool.

After spending hours on it, the final solution was found here: Spring Boot 1.3.5 with Hikari Connection Pool not able to set program name in v$session

spring:
  datasource:
    hikari:
      data-source-properties:
         v$session.program: AppName

Simple, no code changes, and it works!

like image 40
odedia Avatar answered Sep 25 '22 00:09

odedia