Search code examples
debugginggdbshared-librariessqlplusisql

How to debug ODBC driver in an Oracle Heterogeneous Services environment?


Oracle Heterogeneous Services is a feature of Oracle DB that allows the database to talk to non-Oracle DBs through their ODBC drivers.

It is fairly straightforward to debug an ODBC driver using ODBC client tools such as isql.

With isql - I can input the driver info at the initial command prompt. isql and similar tools accept the ODBC DSN name and directly loads the driver. Thus when I type: info sharedlibrary at the GDB command-prompt I see the ODBC shared library loaded that I am interested in debugging.

How can I do the same using sqlplus or other Oracle client tool? However, with sqlplus there is no telling when the driver gets loaded.

How do I debug an ODBC driver ("dynamically loaded library") using Oracle Heterogeneous Services?

Environment: Linux Debugger: GDB Oracle Heterogeneous Services: https://docs.oracle.com/cd/A81042_01/DOC/server.816/a76960/hs_conce.htm


Solution

  • sqlplus (CLI) or sqldeveloper (GUI) are purely interfaces to execute queries to an Oracle database. In an Oracle HS context, the tools themselves do not load the ODBC driver. It is the Oracle database that loads the ODBC driver indirectly via dg4odbc. It took me sometime to discover this fact. In order to debug using gdb proceed as follows:

    # Connect to Oracle DB:
    sqlplus system/[email protected]:1521/orcl12c
    
    # After connecting, dg4odbc is still not activated
    # Run a single query for Oracle DB to load the ODBC driver
    # After, initial query dg4odbc is active
    [oracle@oracle_vm ~]$ ps aux|grep dg4odbc
    oracle   17905 17.5  1.0 497392 63244 ? Ssl  13:56   0:01 dg4odbcNORTHWIND_MYSQL (LOCAL=NO)
    
    # Use the PID from above process to debug in GDB
    [oracle@oracle_vm ~]$ gdb dg4odbc 17905
    
    # You can now debug the ODBC driver which is loaded by dg4odbc
    # You can check by running "info sharedlibrary" at the GDB prompt
    # Happy Debugging :)