roracle-databaserstudio-serverroracle

drv <- dbDriver("Oracle") works fine in Command-line R but not working on RStudio Server


as suggested by the title, I'm trying to setup connections to Oracle DBs through R using the library ROracle on a Unix Machine. using R in command line I have 0 problems, but when trying the same exact instruction in RStudio Server i'm stuc with the following error.

drv <- dbDriver("Oracle") Error in .oci.Driver(.oci.drv(), interruptible = interruptible, unicode_as_utf8 = unicode_as_utf8, : Error while trying to retrieve text for error ORA-01804

these are the output of libPaths(): in RStudio Server

.libPaths()
[1] "/home/rs_violac/R/x86_64-redhat-linux-gnu-library/3.5"
[2] "/usr/lib64/R/library"                                 
[3] "/usr/share/R/library"

in R (command line)

> .libPaths()
[1] "/usr/lib64/R/library" "/usr/share/R/library"

I have set the following path: enter image description here

and set the LD to the share oracle.conf file as suggested in other stackoverflow answear

echo "/oracle/app/oracle/product/12.2.0/client/lib" | sudo tee /etc/ld.so.conf.d/oracle.conf

Any idea or suggestion how to resolve?

EDIT: I've tryed setting those enviornments variable in RStudio console but no resolution

Sys.setenv("OCI_INC"="/oracle/app/oracle/product/12.2.0/client")
Sys.setenv("OCI_LIB"="/oracle/app/oracle/product/12.2.0/client/lib")
Sys.setenv("OCI_LIB64"="/oracle/app/oracle/product/12.2.0/client/lib")
Sys.setenv("TNS_ADMIN"="/oracle/app/oracle/product/12.2.0/client/network/admin")
Sys.setenv("LD_LIBRARY_PATH"="/usr/lib64/R/lib::/lib:/usr/lib/jvm/jre/lib/amd64/server:/usr/lib/jvm/jre/lib/amd64:/usr/lib/jvm/java/lib/amd64:/usr/java/packages/lib/amd64:/lib:/usr/lib:/oracle/app/oracle/product/12.2.0/client/lib")
Sys.setenv("ORACLE_HOME"="/oracle/app/oracle/product/12.2.0/client")
Sys.setenv("NLS_LANG"="en_US.UTF-8")
Sys.setenv("ORACLE_BASE"="/oracle/app/oracle")
Sys.setenv("LC_ALL"="en_US.UTF-8")

Now the error is:

Error in .oci.Driver(.oci.drv(), interruptible = interruptible, unicode_as_utf8 = unicode_as_utf8, : ORA-12715: invalid character set specified

the error change is triggered by the setting of ORACLE_HOME env


Solution

  • The rstudio user needs to have ORACLE_HOME and ORACLE_HOSTNAME set in its environment on the server where the rstudio-server runs. You can use a config file .Renviron, with something like the following for example using BASH shell:

    ORACLE_HOME=<your Oracle home>
    ORACLE_HOSTNAME=<your host name>
    export ORACLE_HOME ORACLE_HOSTNAME