Skip to main content

Install Nexus Repository with a PostgreSQL Database

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

This topic covers installing Nexus Repository with an external PostgreSQL database. New Nexus Repository version 3.71.0 installations and above default to using an embedded H2 database.

Determine Current Database

Use the Data Store view to determine the database mode for Nexus Repository.

  • H2: reference to H2 in their JDBC URL

  • PostgreSQL: no reference to H2 in the JDBC URL

Database Configuration Methods

Nexus Repository supports 3 methods for providing the database configuration settings. The settings are checked in the following order:

(1) environment variables, (2) JVM arguments, (3) the properties file

  • When Nexus Repository initially starts, the first connection method encountered is used while the other methods are ignored. Mixing methods is not supported.

  • Choose the method that fits your infrastructure requirements.

    In containerized environments, use environment variables or JVM arguments to avoid modifying the property files stored in the container.

  • New settings take effect on restarting the service.

Installation Instructions

These instructions are to start Nexus Repository using an external PostgreSQL database.

  1. Before proceeding, check the PostgreSQL requirements with the required trigram module installed.

  2. Download the latest Nexus Repository version; expand and install the archive.

  3. Create a PostgreSQL database using the UTF8 character set.

    See the PostgreSQL documentation

  4. Add the license property before deploying to initialize the instance with a professional license. This property is stored in the database and is subsequently later ignored in the configuration file.

    Add the <data-dir>/etc/nexus.properties file with the following property.

    nexus.licenseFile=/path/to/your/sonatype-license.lic
    
  5. The connection configuration is set using any of the following 3 different methods.

    1. Environment Variables

      Pass the connectivity details as environment variables:

      NEXUS_DATASTORE_NEXUS_JDBCURL
      NEXUS_DATASTORE_NEXUS_USERNAME
      NEXUS_DATASTORE_NEXUS_PASSWORD
    2. JVM Arguments

      Specify the properties as JVM arguments:

      -Dnexus.datastore.enabled
      -Dnexus.datastore.nexus.username
      -Dnexus.datastore.nexus.password
      -Dnexus.datastore.nexus.jdbcUrl
    3. nexus-store.properties

      Create the <data-dir>/etc/fabric/nexus-store.properties directory and file with your PostgreSQL configuration.

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

      Colons in the JDBC URL need to be escaped with a backslash (\). For AWS Aurora databases, include the gssEncMode=disable query parameter in the JDBC URL

  6. Start the Nexus Repository instance using a PostgreSQL database.

Configuration Options for PostgreSQL

Set optional configuration settings through the same methods used above. Set multiple advanced properties in the JVM arguments by delimiting the values with "\n".

advanced=maximumPoolSize\=200\nmaxLifetime\=840000

Maximum Pool Size

Servers under heavy load may need increased connection pool size for the database. Nexus Repository uses a default pool of 100.

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.

  • Pass an environment variable

    NEXUS_DATASTORE_NEXUS_ADVANCED="maximumPoolSize=200"
  • Use a JVM argument

    -Dnexus.datastore.nexus.advanced=maximumPoolSize\=200
  • In the nexus-store.properties file

    maximumPoolSize=N
    advanced=maximumPoolSize\=200
    

    Only one setting from above is used. The maximumPoolSize takes precedence over the advanced

Max Lifetime

Configure the max lifetime for database connections when using container orchestration tools, relational database services, or other infrastructure to launch Nexus Repository.

  • The default max lifetime is set to 30 minutes (1800000ms)

  • Set the max lifetime to be several seconds shorter than any infrastructure-imposed connection time limit.

  1. Pass as an environment variable

    NEXUS_DATASTORE_NEXUS_ADVANCED="maxLifetime=840000"
  2. Use a JVM argument

    -Dnexus.datastore.nexus.advanced=maxLifetime\=840000
  3. In the nexus-store.properties file

    advanced=maxLifetime\=840000

PostgreSQL with Pgpool is Not Supported

We do not support the pgpool or other tools to load balance requests to multiple PostgreSQL servers.

When deploying Nexus and using PostgreSQL, we support the AWS, Azure, and GCP abilities to run PostgreSQL in multiple availability zones.

When deploying your own PostgreSQL servers, we recommend using Log Shipping or Streaming Replication to keep the non-primary server up to date.

We do not support reading from a stand-by server during normal operations.