Enabling machine learning on an existing Db2 database

You enable the machine learning (ML) capability on an existing Db2 12.1 database by first running the db2set command and then updating the database. You then need to create temporary table spaces for both the user and system user, and then create the database objects that are required by the In-database Analytics (IDAX) stored procedures.

Before you begin

Ensure that your Db2® database meets the following prerequisites before attempting to enable the ML functionality:
  • Operating system (OS) requirements:
    • Linux x86 (Intel x86) architecture and PPCLE (Linux PowerPC Little Endian) is supported.
    • zLinux is in limited support. IDAX.LINEAR_REGRESSION, IDAX.MAE, and IDAX.MSE are not supported on zLinux.
  • The registry variable DB2_ENABLE_ML_PROCEDURESis set to YES.
  • The Db2 database has user and system temporary table spaces with a 16K page size.
  • The ID that is calling the stored procedure has the USE privilege on both table spaces.
  • The database objects that are used by the IDAX stored procedures are stored in a regular table space. See step 4 for instructions on how to create these objects.
  • The string_units is set to SYSTEM. This setting is required for Db2 to use the IDAX stored procedures:
    db2 update db cfg for <db_alias> using string_units system
    Note: Ensure that there are no string_units values set to CODEUNITS32, as the IDAX stored procedures do not support this setting.
  • The database must not be restrictive.

About this task

You might need to increase the values for the following configuration parameters, for enablement on both new and existing Db2 databases:

Procedure

  1. Enable the machine learning functions in the database:
    db2set DB2_ENABLE_ML_PROCEDURES=YES
  2. Update the database system catalog and include the -a switch to enable the machine learning functionality:
    db2updv121 -a -d <database alias>
  3. Create a 16K user temporary table space and a 16K system user temporary table space:
    db2 "connect to <database_alias>"
    db2 "create bufferpool <buffer_pool_name> immediate size 1000 pagesize 16k"
    db2 "create system temporary tablespace <temp_table_space_name> pagesize 16k managed by automatic 
    storage bufferpool <buffer_pool_name>"
    db2 "drop tablespace <idax_user_temporary_table_space>"
    db2 "create user temporary tablespace <idax_user_temporary_table_space> pagesize 16k bufferpool 
    test16k";
    db2 "grant use of tablespace <idax_user_temporary_table_space> to public";
    db2 "terminate"
    
    where
    • database_alias is the name of the target database.
    • buffer_pool_name is the name of a new buffer pool.
    • temp_table_space_name is the name of a new, temporary system table space.
    • idax_user_temparary_table_space is a new, temporary user table space
  4. Create the database objects that are required for IDAX stored procedures in a user-defined table space:
    db2 "connect to <database alias>"
    db2 "create tablespace <CUST_TAB_SPC>"
    db2 "call sysinstallobjects('IDAX', 'C', '<CUST_TAB_SPC>', null)"
    db2 "grant use of tablespace <CUST_TAB_SPC> to <public/UID>"
    where
    • CUST_TAB_SP is the name of the custom table space that you have created.
    • public/UID defines whether the table space can be used by any UID or a specific UID that is calling the stored procedure.