Create an Oracle Wallet for an Oracle Machine Learning for R Connection

An Oracle wallet is a password-protected container for storing security credentials in Oracle Database.

Wallets provide a secure mechanism for specifying connection details in embedded R scripts.

To create a wallet for an OML4R connection:

  1. Start Oracle Wallet Manager:

    • (Linux and UNIX) At the command line, enter owm.

    • (Windows) Select Start, Programs, Oracle-HOME_NAME, Integrated Management Tools, Wallet Manager.

  2. To create the wallet, follow the instructions in the Oracle Database documentation for your supported platform:

    1. For Oracle Database 12c and later, go to the Oracle Database Documentation page in Oracle Help Center.
    2. Select your version of Oracle Database.
    3. In the Topics section, select Security.
    4. In the Centralized User Management section, select Oracle Database Enterprise User Security Administrator's Guide.
    5. See the chapter Using Oracle Wallet Manager.

    For Oracle Database 11c, Release 11.2.0.4, see Using Oracle Wallet Manager in Oracle Database Advanced Security Guide.

  3. Locate the connection string for the OML4R database in tnsnames.ora. For example:

    mydb_test =
          (DESCRIPTION =
             (ADDRESS =
                (PROTOCOL = TCP)
                (HOST = myserver)
                (PORT = 1521)
             )
             (CONNECT_DATA = (sid=ORCL))
          )
    
  4. Specify the connection information in the wallet. Follow the instructions in the Oracle Database security documentation referenced in Step 2.

  5. After you configure the wallet, you can connect to the OML4R server database by simply specifying the connection identifier. For example:

    ore.connect(conn_string = "mydb_test", all = TRUE)
    

    To learn more about ore.connect, use the R help command:

    help(ore.connect)

To Configure an Oracle Wallet for Use with External Procedures

  1. Create a wallet store.
    $ mkstore -create -wrl /home/oracle/wallet

    When prompted to do so, assign a username and password. This example uses the database user OML_USER with the password apassword and the PDB ORCL.

  2. Assign wallet credentials.
    $ mkstore -wrl /home/oracle/wallet -createCredential ORCL oml_user
     apassword
  3. In SQL*Plus, log in as OML_USER using the wallet.
    $ sqlplus /@ORCL
  4. Show the user.
    SQL> show user;
    USER is "OML_USER"

Example 7-4 Testing the Wallet Connection

This example tests using embedded R execution in the wallet connection in an OML4R session. The example uses the iris data set that is in the datasets package that is included in an R distribution.

ore.doEval(function(){print("TEST")})

TEST_WALLET_DF
 function() {
                 return(as.data.frame(length(iris)))
            }

ore.scriptLoad("TEST_WALLET_DF")

ore.doEval(FUN.NAME="TEST_WALLET_DF")
   length(iris)

Listing for This Example

> ore.doEval(function(){print("TEST")})
[1] "TEST"
> 
> TEST_WALLET_DF
  function() {
                 return(as.data.frame(length(iris)))
             }
> 
> ore.scriptLoad("TEST_WALLET_DF")
> 
> ore.doEval(FUN.NAME="TEST_WALLET_DF")
>    length(iris)
1 5

Note:

In embedded R execution, an R function that creates a database connection will fail because Oracle Database does not support recursive external procedures. To connect an embedded R execution function to a database, use the ore.connect special control argument.