Install Nexus Repository with a PostgreSQL Database
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 in the Administration Menu to determine the database mode used in previously initialized Nexus Repository instances.
H2: reference to H2 in their JDBC URL
PostgreSQL: no reference to H2 in the JDBC URL
Start Nexus Repository with PostgreSQL
These instructions are to start Nexus Repository using an external PostgreSQL database.
Before proceeding, check the PostgreSQL requirements with the required trigram module installed.
Download the latest Nexus Repository version; expand and install the archive.
Create a PostgreSQL database using the UTF8 character set.
See the PostgreSQL documentation
Optional: Add the license property 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 following property to the
nexus.properties
file:nexus.licenseFile=/path/to/your/sonatype-license.lic
See nexus.properties documentation for details.
Set the database configuration using any of the 3 methods shown below.
Start the Nexus Repository instance using a PostgreSQL database.
Database Configuration Methods
Nexus Repository supports 3 methods for providing the database configuration settings. When Nexus Repository initially starts, the first connection method encountered is used while the other methods are ignored. Mixing methods is not supported.
The settings are checked in the following order:
(1) Environment Variables, (2) JVM Arguments, (3) the Properties File
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.
Environment Variables
Pass the connectivity details as environment variables:
NEXUS_DATASTORE_NEXUS_JDBCURL NEXUS_DATASTORE_NEXUS_USERNAME NEXUS_DATASTORE_NEXUS_PASSWORD
JVM Arguments
Specify the properties as JVM arguments:
-Dnexus.datastore.enabled -Dnexus.datastore.nexus.username -Dnexus.datastore.nexus.password -Dnexus.datastore.nexus.jdbcUrl
nexus-store.properties
Create the
<data-dir>/etc/fabric/nexus-store.properties
directory and file with the following properties:username=<postgres_user> password=<postgres_password> jdbcUrl=<jdbcUrl_property>
JDBC Url Property
The format of the PostgreSQL JDBC URL is as follows:
jdbc\:postgresql\://<database-host>\:<database-port>/<database-name>?<param1>=<value1>&<param2>=<value2>
Colons in the JDBC URL need to be escaped with a backslash (\). Parameters are included at the end of the string starting with a question mark (?) and using ampersands (&) in between each parameter.
For AWS Aurora databases, include the gssEncMode=disable
query parameter in the JDBC URL
database-host The database server address (e.g., localhost or an IP address). Use the cluster ingress port when PostgreSQL is deployed with multiple nodes.
database-port The PostgreSQL port (default: 5432).
database-name The name of the database.
param1¶m2 Optional parameters may be included at the end of the query string.
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.
Environment variable
NEXUS_DATASTORE_NEXUS_ADVANCED="maximumPoolSize=200"
JVM argument
-Dnexus.datastore.nexus.advanced=maximumPoolSize\=200
nexus-store.properties file
maximumPoolSize=N advanced=maximumPoolSize\=200
Only one setting from above is used. The
maximumPoolSize
takes precedence over theadvanced
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.
Environment variable
NEXUS_DATASTORE_NEXUS_ADVANCED="maxLifetime=840000"
JVM argument
-Dnexus.datastore.nexus.advanced=maxLifetime\=840000
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.