Muokkaa

Jaa


Install SQL Server Java Language Extension on Linux

Applies to: SQL Server 2019 (15.x) - Linux and later versions

Learn how to install the Java Language Extension component for SQL Server on Linux. The Java Language Extension is part of SQL Server Language Extensions and an add-on to the Database Engine.

Although you can install the Database Engine and Language Extensions concurrently, it's a best practice to install and configure the SQL Server Database Engine first so that you can resolve any issues before adding more components.

Prerequisites

  • Package location for the Java extensions is in the SQL Server Linux source repositories. If you already configured source repositories for the Database Engine install, you can run the mssql-server-extensibility-java package install commands using the same repo registration.

Package list

On an internet-connected device, packages are downloaded and installed independently of the Database Engine using the package installer for each operating system. The following table describes all available packages.

Package name Applies-to Description
mssql-server-extensibility All languages Extensibility framework used for the Java language extension
mssql-server-extensibility-java Java Applies to: SQL Server 2019 (15.x) on Linux only

Extensibility framework used for the Java language extension and includes a supported Java runtime

Install Java language extension

You can install Language Extensions and Java on Linux by installing mssql-server-extensibility-java. When you install mssql-server-extensibility-java, the package automatically installs JRE 11 if it isn't already installed. It also adds the JVM path to an environment variable called JRE_HOME.

To enable the Java Language Extension, build a custom binary by following the instructions from the Java Language Extension page on GitHub.

Note

On an internet-connected server, package dependencies are downloaded and installed as part of the main package installation. If your server isn't connected to the internet, see more details in the offline setup.

You can download and install any Java runtime as desired, including the latest Microsoft Build of OpenJDK or officially licensed Java runtime. Starting with SQL Server 2022 (16.x), SQL Server Setup doesn't install a Java runtime.

To enable the Java Language Extension, build a custom binary by following the instructions from the Java Language Extension page on GitHub.

Red Hat install command

You can install Language Extensions for Java on Red Hat using the following command.

Tip

If possible, run yum clean all to refresh packages on the system prior to installation.

# Install as root or sudo
sudo yum install mssql-server-extensibility-java

Ubuntu install command

You can install Language Extensions for Java on Ubuntu using the following command.

Tip

If possible, run apt-get update to refresh packages on the system prior to installation. Additionally, some docker images of Ubuntu might not have the https apt transport option. To install it, use apt-get install apt-transport-https.

# Install as root or sudo
sudo apt-get install mssql-server-extensibility-java

SUSE install command

You can install Language Extensions for Java on SUSE using the following command.

# Install as root or sudo
sudo zypper install mssql-server-extensibility-java

Post-install config (required)

  1. Grant permissions on Linux

    You don't need to perform this step if you use external libraries. The recommended way of working is using external libraries. For help with creating an external library from your jar file, see CREATE EXTERNAL LIBRARY

    If you aren't using external libraries, you need to provide SQL Server with permissions to execute the Java classes in your jar.

    To grant read and execute access to a jar file, run the following chmod command on the jar file. We recommend always putting your class files in a jar when you work with SQL Server. For help with creating a jar, see Create a Java .jar file from class files.

    chmod ug+rx <MyJarFile.jar>
    

    You also need to give mssql_satellite permissions the jar file to read/execute.

    chown mssql_satellite:mssql_satellite <MyJarFile.jar>
    

    Additional configuration is primarily through the mssql-conf tool.

  2. Add the mssql user account used to run the SQL Server service. This is required if you haven't run the setup previously.

    sudo /opt/mssql/bin/mssql-conf setup
    
  3. Enable outbound network access. Outbound network access is disabled by default. To enable outbound requests, set the outboundnetworkaccess Boolean property using the mssql-conf tool. For more information, see Configure SQL Server on Linux with mssql-conf.

    # Run as SUDO or root
    # Enable outbound requests over the network
    sudo /opt/mssql/bin/mssql-conf set extensibility outboundnetworkaccess 1
    
  4. Restart the SQL Server Launchpad service and the Database Engine instance to read the updated values from the INI file. A restart message reminds you whenever an extensibility-related setting is modified.

    systemctl restart mssql-launchpadd
    systemctl restart mssql-server.service
    
  5. Enable external script execution using Azure Data Studio, or another tool like SQL Server Management Studio (Windows only), that runs T-SQL.

    EXECUTE sp_configure 'external scripts enabled', 1;
    
    RECONFIGURE WITH OVERRIDE;
    
  6. Restart the mssql-launchpadd service again.

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

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 Linux.

CREATE EXTERNAL LANGUAGE Java
FROM (
    CONTENT = N'/opt/mssql-extensibility/lib/java-lang-extension.tar.gz',
    FILE_NAME = 'javaextension.so',
    ENVIRONMENT_VARIABLES = N'{"JRE_HOME":"/opt/mssql/lib/zulu-jre-11"}'
);

For the Java extension, the environment variable JRE_HOME is used to determine the path to find and initialize the JVM from.

The CREATE EXTERNAL LANGUAGE DDL provides a parameter (ENVIRONMENT_VARIABLES) to set environment variables specifically for the process hosting the extension. This process is the recommended and most effective way to set environment variables required by external language extensions.

For more information, see CREATE EXTERNAL LANGUAGE.

Verify installation

Java feature integration doesn't include libraries, but you can run grep -r JRE_HOME /etc to confirm creation of the JAVA_HOME environment variable.

To validate installation, run a T-SQL script that executes a system stored procedure invoking Java. You need a query tool for this task. Azure Data Studio is a good choice. Other commonly used tools such as SQL Server Management Studio is Windows-only. If you have a Windows computer with these tools, use it to connect to your Linux installation of the Database Engine.

Full install of SQL Server and Java Language Extension

You can install and configure the Database Engine and Java Language Extension in one procedure by appending Java packages and parameters on a command that installs the Database Engine.

  1. Provide a command line that includes the Database Engine, plus language extension features.

    You can add Java extensibility to a Database Engine install.

    sudo yum install -y mssql-server mssql-server-extensibility-java
    
  2. Accept license agreements and complete the post-install configuration. Use the mssql-conf tool for this task.

    sudo /opt/mssql/bin/mssql-conf setup
    

    This step prompts you to accept the license agreement for the Database Engine, choose an edition, and set the administrator password.

  3. Restart the service, if prompted to do so.

    sudo systemctl restart mssql-server.service
    

Unattended installation

Use the unattended install for the Database Engine and add the packages for mssql-server-extensibility-java.

Offline installation

Follow the Offline installation instructions for steps on installing the packages. Find your download site, and then download specific packages using the package list later in this section.

Tip

Several of the package management tools provide commands that can help you determine package dependencies. For yum, use sudo yum deplist [package]. For Ubuntu, use sudo apt-get install --reinstall --download-only [package name] followed by dpkg -I [package name].deb.

Download site

You can download the packages from https://packages.microsoft.com/. All of the packages for Java are colocated with the Database Engine package.

Download paths

Package Distribution Download location
mssql/extensibility-java packages Red Hat 8 https://packages.microsoft.com/rhel/8/mssql-server-2019/
mssql/extensibility-java packages SUSE v15 https://packages.microsoft.com/sles/15/mssql-server-2019/
mssql/extensibility-java packages Ubuntu 20.04 https://packages.microsoft.com/ubuntu/20.04/mssql-server-2019/pool/main/m/

Package list

Depending on which extensions you want to use, download the packages necessary for a specific language. Exact filenames include platform information in the suffix, but the following file names should help you determine which files to get.

  • Core packages

    • mssql-server-15.0.1000
    • mssql-server-extensibility-15.0.1000
  • Java

    • mssql-server-extensibility-java-15.0.1000

Limitations

Implied authentication is currently not available on Linux at this time, which means you can't connect back to the server from in-progress Java to access data or other resources.

Resource governance

There's parity between Linux and Windows for Resource governance for external resource pools, but the statistics for sys.dm_resource_governor_external_resource_pools currently have different units on Linux.

Note

Statistics in the following table are sourced from the specified Control Groups (cgroups) subsystems.

Column name Description Value on Linux
peak_memory_kb The maximum amount of memory used for the resource pool. On Linux, this statistic is sourced from the memory subsystem, where the value is memory.max_usage_in_bytes
write_io_count The total write IOs issued since the Resource Governor statistics were reset. On Linux, this statistic is sourced from the blkio subsystem, where the value on the write row is blkio.throttle.io_serviced
read_io_count The total read IOs issued since the Resource Governor statistics were reset. On Linux, this statistic is sourced from the blkio subsystem, where value on the read row is blkio.throttle.io_serviced
total_cpu_kernel_ms The cumulative CPU user kernel time in milliseconds since the Resource Governor statistics were reset. On Linux, this statistic is sourced from the cpuacct subsystem, where the value on the user row is cpuacct.stat
total_cpu_user_ms The cumulative CPU user time in milliseconds since the Resource Governor statistics were reset. On Linux, this statistic is sourced from the cpuacct subsystem, where the value on the system row value is cpuacct.stat
active_processes_count The number of external processes running at the moment of the request. On Linux, this statistic is sourced from the pids subsystem, where the value is pids.current