Skip to main content

Configuring Nexus Repository Pro for H2 or PostgreSQL

Note

Only available in Sonatype Nexus Repository Pro. Interested in a free trial? Start here.

If you're standing up a new instance of Nexus Repository Pro and wish to begin in a new database mode, follow these instructions:

Installing Nexus Repository Pro

  1. Download the latest Nexus Repository 3 version

  2. Expand and install the archive as with the standard installation instructions

  3. Follow the instructions for your chosen database

Configuring for the Embedded H2

Create the <data-dir>/etc/nexus.properties file and add the following line:

nexus.datastore.enabled=true

You can now start your Nexus Repository instance and use an embedded H2 database.

Configuring for External PostgreSQL (Preferred)

Note

Before proceeding, see the PostgreSQL requirements in our System Requirements document and ensure you have the required trigram module installed.

To use an external PostgreSQL database, follow these additional instructions:

  1. Create a database in a PostgreSQL server

    Note

    When creating your database, ensure it is set to use UTF8 as its character set in order to be compatible with Nexus Repository's character set. For more information, see the PostgreSQL documentation on setting your character set.

  2. Create the <data-dir>/etc/nexus.properties file. Add a property to enable external database access:

    nexus.datastore.enabled=true
  3. On first run only, add the following line, replacing the placeholders with the appropriate filepath to point to your valid Pro license:

    nexus.licenseFile=/path/to/your/sonatype-license.lic
  4. Create a <data-dir>/etc/fabric directory

  5. In the <data-dir>/etc/fabric directory,create a text file named nexus-store.properties

    1. Below is a sample nexus-store.properties that you will need to update with the appropriate configuration.

      username=<postgres_user>
      password=<postgres_password>
      jdbcUrl=jdbc\:postgresql\://<database-host>\:<database-port>/<database-name>

      Note that the JDBC URL format outside of the nexus-store.properties is in the following format (without the backslashes in the nexus-store.properties file): jdbc:postgresql://<database-host>:<database-port>/<database-name>

      Note

      If using AWS Aurora as your database, you will need to include gssEncMode=disable as a query parameter of the JDBC URL.

    2. Note that you can also use the following JVM arguments to specify connection information; you can also specify these in the sonatype-work/nexus3/etc/nexus.properties file without the preceding -D:

      • -Dnexus.datastore.enabled

      • -Dnexus.datastore.nexus.jdbcUrl

      • -Dnexus.datastore.nexus.username

      • -Dnexus.datastore.nexus.password

    3. You can also pass the following connectivity details as environment variables:

      • NEXUS_DATASTORE_NEXUS_JDBCURL

      • NEXUS_DATASTORE_NEXUS_USERNAME

      • NEXUS_DATASTORE_NEXUS_PASSWORD

Note

As of release 3.53.0, you must provide all required database connection fields (JDBC URL, username, password) through the same mechanism. Sonatype Nexus Repository will use the first of the following mechanisms that it encounters and will ignore the others (e.g., if you use environment variables, Sonatype Nexus Repository will ignore the system properties and nexus-store.properties file. Changes made through environment variables and system properties are not written to the nexus-store.properties file). This is evaluated each time you start Sonatype Nexus Repository. The priority order is as follows:

  • Environment variables

  • System Properties

  • sonatype-work/nexus3/etc/fabric/nexus-store.properties

You can now start your Nexus Repository instance and use a PostgreSQL database.

Sonatype Nexus Repository re-evaluates these configuration settings each time you restart an instance; changes will take effect upon restart.

Extra Configuration Options for PostgreSQL

You can configure maxPoolSize and maxLifetime through the same three methods as configuring database connections:

  • Environment variables

  • System properties

  • sonatype-work/nexus3/etc/fabric/nexus-store.properties file

Tip

Best Practices

  • You should use the same method to configure these extra options as you did for configuring the database connection fields.

  • If you are in a highly available (HA) or containerized (e.g., Kubernetes) environment, you should use environment variables or system properties to avoid having to configure multiple nexus-store.properties files.

Maximum Pool Size

Note

Note that, for high availability deployments, you must increase the number of connections that PostgreSQL allows so that your Maximum Connection Pool size does not exceed your the maximum number of allowed connections. See Prerequisite Step: Adjust max_connections.

Servers under heavy load may need increased connection pool size for the database. Nexus Repository uses a default pool of 100, but you may increase this through one of the following ways:

  1. Pass an environment variable

    1. Example: NEXUS_DATASTORE_NEXUS_ADVANCED="maximumPoolSize=200"

  2. Use a JVM argument or specify directly in the sonatype-work/nexus3/etc/nexus.properties file without the preceding -D

    1. Example: -Dnexus.datastore.nexus.advanced

  3. In the nexus-store.properties file

    1. Example:

      username=<postgres_user>
      password=<postgres_password>
      jdbcUrl=jdbc\:postgresql\://<database-host>\:<database-port>/<database-name>
      advanced=maximumPoolSize\=200
      
    2. Note that there are two possible settings in the nexus-store.properties file which use the following priority order:

      1. maximumPoolSize=N

      2. advanced=maximumPoolSize=N

    3. If you set maxPoolSize, it will take precedence over the advanced setting

Sonatype Nexus Repository re-evaluates these configuration settings each time you restart an instance; changes will take effect upon restart.

Max Lifetime

If you use a container orchestration tool, relational database service, or other infrastructure to launch Nexus Repository, you should configure your maxLifetime for database connections.

Ensure your maxLifetime is set to be several seconds shorter than your infrastructure-imposed connection time limit.

By default, maxLifetime is set to 30 minutes (1800000ms), but you may change this through one of the following methods:

  1. Pass as an environment variable

    1. Example: NEXUS_DATASTORE_NEXUS_ADVANCED="maxLifetime=840000"

  2. Use a JVM argument or specify directly in the sonatype-work/nexus3/etc/nexus.properties file without the preceding -D

    1. Example: -Dnexus.datastore.nexus.advanced

  3. In the nexus-store.properties file

    1. Example:

      username=<postgres_user>
      password=<postgres_password>
      jdbcUrl=jdbc\:postgresql\://<database-host>\:<database-port>/<database-name>
      advanced=maxLifetime\=840000

Sonatype Nexus Repository re-evaluates these configuration settings each time you restart an instance; changes will take effect upon restart.

Set Multiple Advanced Settings

To set multiple advanced settings, delimit the values by "\n" as shown in the following example:

advanced=maximumPoolSize\=200\nmaxLifetime\=840000

How Does Nexus Repository Pro Determine Which Database To Use

If you've omitted nexus.datastore.enabled or set it to false, then Nexus Repository will use OrientDB.

If you've configured nexus.datastore.enabled=true, then Nexus Repository determines which database it is meant to use based on the configuration source.

Nexus Repository Pro will look for configuration information from <data-dir>/etc/fabric/ nexus-store.properties before falling back to the embedded database, which is H2.

Tip

Sonatype Nexus Repository Pro users that have migrated away from the default OrientDB database can determine their current database by checking the JDBC URL displayed on the Data Store configuration screen:

  • If the JDBC URL references H2, then you are using an H2 database.

  • If the JDBC URL does not reference H2, then you are using a PostgreSQL database.

If you are a Sonatype Nexus Repository Pro customer and have not migrated from the default OrientDB database, you will not see the Data Store option.

If you are using Sonatype Nexus Repository OSS, you will not see the Data Store option and will be using the default OrientDB database as no other database options are available for OSS deployments.