6.2.1 About Connecting to an On-Premises Oracle Database

OML4Py client components connect a Python session to the OML4Py server components on an on-premises Oracle database server.

The connection makes the data in an on-premises Oracle database schema available to the Python user. It also makes the processing power, memory, and storage capacities of the database server available to the Python session through the OML4Py client interface. To use that data and those capabilities, you must create a connection to the Oracle database server.

To use the Automatic Machine Learning (AutoML) capabilities of OML4Py, the following must be true:

  • A connection pool must be running on the server.
  • You must explicitly use the automl argument in an oml.connect invocation to specify the running connection pool on the server.

Note:

Before you can create an AutoML connection, a database administrator must first activate the database-resident connection pool in your on-premises Oracle database by issuing the following SQL statement:

EXECUTE DBMS_CONNECTION_POOL.START_POOL();

Once started, the connection pool remains in this state until a database administrator explicitly stops it by issuing the following command:

EXECUTE DBMS_CONNECTION_POOL.STOP_POOL();

Note:

Because an AutoML connection requires more database resources than an oml.connect connection without AutoML does, you should create an AutoML connection only if you are going to use the AutoML classes.

Note:

  • Only one type of connection can be active during a Python session: either a connection with AutoML enabled or one without it enabled. You can, however, terminate one type of connection and initiate the other type during the same Python session. Terminating either type of connection results in the automatic clean up of any temporary objects created in the session during that connection.

    If you want to save any objects that you created in one type of connection before changing to the other type, then save the objects in an OML4Py datastore before invoking oml.connect again. You can then reload the objects after reconnecting.

  • The oml.connect function uses the cx_Oracle Python package for database connectivity. In some cases, you might want to use the cx_Oracle.connect function of that package to connect to a database. That function has advantages such as the following:
    • Allows multiple connections to a multiple databases, which might be useful in an running Embedded Python Execution functions

    • Permits some SQL data manipulation language (DML) operations that are not available in an oml.connect connection

    For information on the cx_Oracle.connect function, see Connecting to Oracle Database in the cx_Oracle documentation.

OML4Py Connection Functions

The OML4Py functions related to database connections are the following.

Table 6-1 Connection Functions for OML4Py

Function Description
oml.connect

Establishes an OML4Py connection to an Oracle database.

oml.disconnect

Terminates the Oracle database connection.

oml.isconnected

Indicates whether an active Oracle database connection exists.

oml.check_embed

Indicates whether Embedded Python Execution is enabled in the connected Oracle database.