Install SQL Server Machine Learning Services on Windows

THIS TOPIC APPLIES TO:yesSQL Server noAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

Starting in SQL Server 2019, Language Extensions and Java support are provided. This article explains how to install the Language Extensions component by running the SQL Server setup wizard.

Note

This article is for installation of SQL Server Language Extensions on Windows. For Linux, see Install SQL Server 2019 Language Extensions (Java) on Linux

Pre-install checklist

  • SQL Server 2019 Setup is required if you want to install support for Language Extensions.

  • A database engine instance is required. You cannot install just the Language Extensions features, although you can add them incrementally to an existing instance.

  • For business continuity, Always On Availability Groups are supported for Language Extensions. You have to install language extensions, and configure packages, on each node.

  • Installing Language Extensions is supported on a failover cluster in SQL Server 2019.

  • Do not install SQL Server Language Extensions on a domain controller. The Language Extensions portion of setup will fail.

Important

After setup is complete, be sure to complete the post-configuration steps described in this article. These steps include enabling SQL Server to use external code, and adding accounts required for SQL Server to run Java code on your behalf. Configuration changes generally require a restart of the instance, or a restart of the Launchpad service.

Java JRE or JDK prerequisite

Java 8 is currently the supported version. Newer versions, like Java 11, should work with the language extension but is currently not supported. The Java Runtime Environment (JRE) is the minimum requirement, but JDK is useful if you need the Java compiler and development packages. Because the JDK is all inclusive, if you install the JDK, the JRE is not necessary.

You can use your preferred Java 8 distribution. Below are two suggested distributions:

Distribution Java version Operating systems JDK JRE
Zulu OpenJDK 8 Windows and Linux Yes No
Oracle Java SE 8 Windows and Linux Yes Yes

On Windows, we recommend installing the JDK under the default /Program Files/ folder if possible. Otherwise, extra configuration is required to grant permissions to executables. For more information, see the grant permissions (Windows) section in this document.

Note

Given that Java is backwards compatible, earlier versions might work, but the supported and tested version for this early CTP release is Java 8.

Get the installation media

The preview version of SQL Server 2019 is available at the SQL Server 2019 install site.

Run Setup

For local installations, you must run Setup as an administrator. If you install SQL Server from a remote share, you must use a domain account that has read and execute permissions on the remote share.

  1. Ensure a supported version of Java is installed. For more information, see the Java prerequisites.

  2. Start the setup wizard for SQL Server 2019.

  3. On the Installation tab, select New SQL Server stand-alone installation or add features to an existing installation.

  4. On the Feature Selection page, select these options:

    • Database Engine Services

      To use Language Extensions with SQL Server, you must install an instance of the database engine. You can use either a default or a named instance.

    • Machine Learning Services and Language Extensions

      This option installs the Language Extensions component that support Java code execution.

      You can omit R and Python if you wish.

      Feature options for Language Extensions

  5. On the Ready to Install page, verify that these selections are included, and select Install.

    • Database Engine Services
    • Machine Learning Services (in-database)

    Note of the location of the folder under the path ..\Setup Bootstrap\Log where the configuration files are stored. When setup is complete, you can review the installed components in the Summary file.

  6. After setup is complete, if you are instructed to restart the computer, do so now. It is important to read the message from the Installation Wizard when you have finished with Setup. For more information, see View and Read SQL Server Setup Log Files.

Add the JRE_HOME variable

JRE_HOME is a system environment variable that specifies the location of the Java interpreter. In this step, create a system environment variable for it on Windows.

  1. Find and copy the JRE home path (for example, C:\Program Files\Zulu\zulu-8\jre\).

    Depending on your preferred Java distribution, your location of the JDK or JRE might be different than the example path above. Even if you have a JDK installed, you often times will get a JRE sub folder as part of that installation, so point to the JRE folder in that case. The Java extension will attempt to load the jvm.dll from the path %JRE_HOME%\bin\server.

  2. In Control Panel, open System and Security, open System, and click Advanced System Properties.

  3. Click Environment Variables.

  4. Create a new system variable for JRE_HOME with the value of the JDK/JRE path (found in step 1).

  5. Restart Launchpad.

    1. Open SQL Server Configuration Manager.

    2. Under SQL Server Services, right-click SQL Server Launchpad and select Restart.

Grant access to non-default JRE folder

If you did not install the JDK or JRE under program files, you need to perform the following steps. Run the icacls commands from an elevated line to grant access to the SQLRUsergroup and SQL Server service accounts (in ALL_APPLICATION_PACKAGES) for accessing the JRE. The commands will recursively grant access to all files and folders under the given directory path.

  1. Give SQLRUserGroup permissions

    For a named instance, append the instance name to SQLRUsergroup (for example, SQLRUsergroupINSTANCENAME).

    icacls "<PATH to JRE>" /grant "SQLRUsergroup":(OI)(CI)RX /T
    

    You can skip this step if you installed the JDK/JRE in the default folder under program files on Windows.

  2. Give AppContainer permissions

    icacls "<PATH to JRE>" /grant "ALL APPLICATION PACKAGES":(OI)(CI)RX /T
    

Enable script execution

  1. Open SQL Server Management Studio.

    Tip

    You can download and install the appropriate version from this page: Download SQL Server Management Studio (SSMS).

    You can also use Azure Data Studio, which supports administrative tasks and queries against SQL Server.

  2. Connect to the instance where you installed Language Extensions, click New Query to open a query window, and run the following command:

    sp_configure
    

    The value for the property, external scripts enabled, should be 0 at this point. The feature is turned off by default and must be explicitly enabled by an administrator before you can run Java code.

  3. To enable the external scripting feature, run the following statement:

    EXEC sp_configure  'external scripts enabled', 1
    RECONFIGURE WITH OVERRIDE
    

    If you have already enabled the feature for Machine Learning Services, don't run reconfigure a second time for Language Extensions. The underlying extensibility platform supports both.

Restart the service

When the installation is complete, restart the database engine before continuing to the next, enabling script execution.

Restarting the service also automatically restarts the related SQL Server Launchpad service.

You can restart the service using the right-click Restart command for the instance in SSMS, or by using the Services panel in Control Panel, or by using SQL Server Configuration Manager.

Register external language

For each database you want to use language extensions in, you need to register the external language with CREATE EXTERNAL LANGUAGE.

The following example adds an external language called Java to a database on SQL Server on Windows.

CREATE EXTERNAL LANGUAGE Java
FROM (CONTENT = N'<path-to-zip>', FILE_NAME = 'javaextension.dll');
GO

For more information, see CREATE EXTERNAL LANGUAGE.

Verify installation

Check the installation status of the instance in the setup logs.

Use the following steps to verify that all components used to launch external script are running.

  1. In SQL Server Management Studio or Azure Data Studio, open a new query window, and run the following statement:

    EXEC sp_configure  'external scripts enabled'
    

    The run_value is now set to 1.

  2. Open the Services panel or SQL Server Configuration Manager, and verify SQL Server Launchpad service is running. You should have one service for every database engine instance that has language extensions installed. For more information about the service, see Extensibility framework.

Additional configuration

If the verification step was successful, you can run Java Code from SQL Server Management Studio, Azure Data Studio, Visual Studio Code, or any other client that can send T-SQL statements to the server.

If you got an error when running the command, review the additional configuration steps in this section. You might need to make additional appropriate configurations to the service or database.

At the instance level, additional configuration might include:

On the database, you might need the following configuration updates:

Note

Whether additional configuration is required depends on your security schema, where you installed SQL Server, and how you expect users to connect to the database and run external scripts.

Suggested optimizations

Now that you have everything working, you might also want to optimize the server to support language extensions.

Optimize the server for language extensions

The default settings for SQL Server setup are intended to optimize the balance of the server for a variety of services that are supported by the database engine, which might include extract, transform, and load (ETL) processes, reporting, auditing, and applications that use SQL Server data. Therefore, under the default settings, you might find that resources for language extensions are sometimes restricted or throttled, particularly in memory-intensive operations.

To ensure that language extensions jobs are prioritized and resourced appropriately, we recommend that you use SQL Server Resource Governor to configure an external resource pool. You might also want to change the amount of memory that's allocated to the SQL Server database engine, or increase the number of accounts that run under the SQL Server Launchpad service.

If you are using Standard Edition and do not have Resource Governor, you can use Dynamic Management Views (DMVs) and Extended Events, as well as Windows event monitoring, to help manage the server resources.

Next steps

Java developers can get started with some simple examples, and learn the basics of how Java works with SQL Server. For your next step, see the following link: