Migrating to a New Database
Migrating to a New Database
Tip
Use Instance Migrator if you are on OrientDB and wish to migrate to a self-hosted instance (3.90.2+), or to Sonatype Cloud.
This page documents Database Migrator, the database-level migration utility for self-hosted Nexus Repository. Use Database Migrator when you need to change the database used by an existing self-hosted deployment. Database Migrator supports the following database migration scenarios:
- H2 to PostgreSQL
- PostgreSQL to H2
- OrientDB to H2
- OrientDB to PostgreSQL
Note
The documented workflows require you to shut down Nexus Repository during migration.
Download the latest database migrator utility to receive the latest performance improvements.
See Download the Latest Database Migrator Utility
Considerations Before Migrating
Review the following considerations before migrating:
Database migration is one-way and non-destructive
The original Orient database is not changed and may be used as a recovery point. The migrator does not support migrating back to OrientDB from H2 or PostgreSQL. Running the migrator again overwrites any data in the target database.
Avoid performing maintenance steps during the migration
Run the database migration in the same environment to avoid complications and to simplify recovery when something goes wrong. Use the same version you were using before the migration. Migrating directly to the cloud from on-premises is not supported.
Test the migration before running in production
We recommended performing a test migration using a backup of your production instance. Be aware that a backup instance connecting to cloud blob stores may still be connected to production data. The migration may skip artifacts from the source database when they are not found in the file reference. Consult the migration log files to valid the contents that was migrated.
Searching and cleanup works differently in H2 and PostgreSQL databases. Evaluate that cleanup policies identify the correct components for cleanup.
Review unsupported formats and custom plug-ins
PostgreSQL and H2 do not support Bower or the community formats (e.g., APK, Composer, CPAN, Puppet). A subset of Nuget v2 protocol does not work the same as from OrientDB. Unsupported formats are not migrated. Custom plugins that interact with the database, assets, or components may no longer work with the new databases.
Groovy scripting is not supported in later versions.
Note
Database Migrator Utility does not migrate Repository – Export assets and Repository – Import external files tasks. These tasks reference environment‑specific paths that change between instances. Recreate them in the new instance if the workflow requires Import/Export functionality.
Migration Environment Prerequisite Requirements
Review the requirements below for the database migration:
- Unless you are still on OrientDB, you must first upgrade to the latest version of Nexus Repository
A new version of the migration is released for every version of Nexus Repository to take advantage of improvements and bug fixes to the migration process. Only the latest version of the migration is available for download to avoid support issues. Upgrade to the latest supported version of Nexus Repository for your database.
If you are using OrientDB, then you must upgrade to the latest 3.70.x version and use the database migrator that is associated with that version. See Upgrading to Nexus Repository 3.71.0 and Beyond and Nexus Repository 3.70.x Downloads with OrientDB
The database migrator requires OpenJDK
The database migrator does not support Oracle JDK.Migrating from OrientDB requires using Java 8 or 11
Migrating off of OrientDB will require using the 3.70.x database migrator available at Nexus Repository 3.70.x Downloads with OrientDB. OrientDB does not support Java 17+, so you will need to upgrade your instance's Java version once you have migrated.The migrator requires at least 16GB of available RAM
The migrator requires three times the disk space as your instance's database directory (minimum 10 GB)
The$data-dir/dbdirectory and the temp directory must have enough space for both the backup and the extracted backup to the tmp directory.If migrating to PostgreSQL, the target database must contain a schema with the correct user permissions
The Nexus Repository database user requiresCREATEandUSAGEpermissions on the specified schema, which must also be on thesearch_pathfor that user. If your database administrator provisions a database without a schema, you must create the schema manually before running the migrator.
Post-Migration Tasks
These tasks are critical to the proper functioning of the repository after the migration process and may take a notable amount of time to complete.
Do not restart your instance while the post-migration tasks are running to avoid damaging your browse and search index.
Run the following tasks manually when using these formats:
Rebuild Helm metadataAfter migrating your database, Nexus Repository runs the following tasks:
Rebuild repository browse Rebuild repository searchUse the below states in the task log to follow along with the post-migration process:
repository.rebuild-index create.browse.nodes repository.yum.rebuild.metadata component.normalize.version repository.metrics.blob.size.copy file.blobstore.metrics.datastore.migrationWhen migrating to H2, keep the
nexus.mv.dbandnexus.trace.db(if present). All other files and folders indbare legacy OrientDB data and can be removed. For PostgreSQL migrations, the entiredbdirectory is no longer needed. Before deleting, it is strongly recommended to compress and move thedbdirectory to a backup location.
Migrating From H2 to PostgreSQL
The section covers migrating Nexus Repository instance with an embedded H2 database to an external PostgreSQL database.
Perform a backup of the H2 database using the
Admin - Backup H2 Databasetask.Download the Database Migrator binary and copy it into the
$data-dir/dbdirectory.
See Directories for details on locating the $data-dir.
- A PostgreSQL server must be configured for Nexus Repository to connect to. Follow the instructions in Install Nexus Repository with PostgreSQL. Do not start Nexus Repository with the PostgreSQL configuration until after the migration is complete.
Note
If your database administrator provisions a database without a schema, you must create the schema manually and grant the required permissions to the Nexus Repository database user before proceeding:
CREATE SCHEMA <schema_name>;
GRANT USAGE, CREATE ON SCHEMA <schema_name> TO <nexus_user>;
If you use a schema name other than nexus, update the currentSchema parameter in the --db_url argument in Step 5 accordingly.
Shut down Nexus Repository.
Update the
db_urlin the following command using your PostgreSQL configuration.java -Xmx16G -Xms16G -XX:+UseG1GC -XX:MaxDirectMemorySize=28672M \ -jar nexus-db-migrator-*.jar \ --migration_type=h2_to_postgres \ --db_url="jdbc:postgresql://<database URL>:<port>/nexus?user=postgresUser&password=secretPassword¤tSchema=nexus"
This command must run in the $data-dir/db directory.
Run the following command on the PostgreSQL database to reclaim storage occupied by obsoleted tuples left from the migration.
VACUUM(FULL, ANALYZE, VERBOSE);Start Nexus Repository.
Migrating From PostgreSQL to H2
This topic covers migrating from a PostgreSQL database to an embedded H2 database.
Migrating a Nexus Repository Docker Image to H2
If you are migrating a Nexus Repository Docker image, log into the Docker image and run the Database Migrator following the normal instructions below.
Perform a full backup using the backup task.
Shut down Nexus Repository.
Using your system console, change the directory to
$data-dir/db.Run the following command from the
$data-dir/dbdirectory. Note that you can also include any of the optional parameters listed in the section below when running this command.java -jar nexus-db-migrator-*.jar \ --migration_type=postgres_to_h2 \ --db_url="jdbc:postgresql://<database URL>:<port>/nexus?user=postgresUser&password=secretPassword¤tSchema=nexus"
--db_url="jdbc:postgresql://localhost:5432/nexus?user=postgresUser&password=secretPassword¤tSchema=nexus"– This is the URL to your Postgres databasenexus– database nameuser=postgresUser– database userpassword=secretPassword– database user passwordcurrentSchema=nexus– example database schema (optional).
Note
- Note that you must enter 2 dashes before the
migration_typeparameter. - You must wrap the
db_urlparameter value with double quotes and enter two dashes before thedb_urlparameter.
Edit the
$data-dir/etc/nexus.propertiesfile and add the following line:nexus.datastore.enabled=trueRemove or rename the
nexus-store.propertiesfile you used for PostgreSQL so that Nexus Repository will not continue to try and boot to that properties file.Start Nexus Repository.
Your Nexus Repository instance will now start in H2 mode with a migrated H2 database.
Optional Parameters
-y, --yes:
Parameter to skip waiting for user input and assume a "yes" response to the initial warning.--content_migration=false
Parameter to only migrate the security and config tables: users, roles, and blobstore configuration. Repository content is not migrated.--shutdown_compact=false
Parameter to disable H2 Content DB compression; this is set to true by default.
Migrating From OrientDB to H2
Migrate Nexus Repository instance from OrientDB to H2.
- Perform a database backup using the
Admin - Export Database for backuptask. We recommend copying the backup to another filesystem to avoid impacting the production environment.
The migrator uses the following backup files:
component-<timestamp>.bak
config-<timestamp>.bak
security-<timestamp>.bak
Shut down Nexus Repository.
Run the following command from the location containing your backup.
java -Xmx16G -Xms16G -XX:+UseG1GC \ -XX:MaxDirectMemorySize=28672M \ -jar nexus-db-migrator-*.jar \ --migration_type=h2Copy the produced
nexus.mv.dbfile to your$data-dir/dbdirectory.
See Directories for details.
Edit the
$data-dir/etc/nexus.propertiesfile with the following line:nexus.datastore.enabled=trueStart Nexus Repository.
Complete the post-migration tasks before upgrading Nexus Repository.
Optional Parameters
-y, --yes:
Skip waiting for user input and assume ayesresponse to the initial warning.--content_migration=false
Parameter to migrate the security and config tables: users, roles, and blobstore configuration. Repository content is not migrated.--shutdown_compact=false
Parameter to disable H2 Content DB compression; this istrueby default.
Migrating From OrientDB to PostgreSQL
The section below covers migrating your Nexus Repository instance from OrientDB to an external PostgreSQL database.
When using AWS Aurora as your database, include gssEncMode=disable as a query parameter of JDBC URL.
Create a database called
nexuson the PostgreSQL server. Use UTF8 as its character set to be compatible with Nexus Repository.We recommend setting the PostgreSQL autovacuum configuration to be on.
In the
sonatype-work/nexus3/etc/fabric/directory (i.e.,$data-dir/etc/fabric), createnexus-store.properties; below is a sample that you will need to update with the appropriate configuration.
The user provided must be the database owner.
username=<postgres_user>
password=<postgres_password>
jdbcUrl=jdbc\:postgresql\://<database-host>\:<database-port>/nexus
For versions 3.31.0 - 3.34.1, you will need the following additional properties in your nexus-store.properties file:
name=nexus
type=jdbc
- Servers under heavy load may also need to configure the connection pool size for the database. Nexus Repository uses a default pool of 100, but you may increase this by appending a line like the following example to
nexus-store.properties:
advanced=maximumPoolSize\=200
- Add the following to
$data-dir/etc/nexus.properties
nexus.datastore.enabled=true
Perform a full backup using the backup task
Copy the backup to a clean working location on a different filesystem so that any extraction doesn’t impact the existing production system
Shut down Nexus Repository
Update and run the following command from the location containing your database backup. Use the appropriate values for host, port, username, password, and migrator utility jar file name.
The following parameter is needed for OrientDB Java 11 deployments.
--add-exports java.base/sun.nio.ch=ALL-UNNAMED
java -Xmx16G -Xms16G -XX:+UseG1GC \
-XX:MaxDirectMemorySize=28672M \
-jar nexus-db-migrator-*.jar \
--migration_type=postgres \
--db_url="jdbc:postgresql://<database URL>:<port>/nexus?user=<postgres_user>&password=<postgres_password>"
When using database names and schemas that do not match, you need to add the variable ¤tSchema=<name> to the end of the line. This variable is optional as this is not expected in a standard setup.
<database URL>:<port>– This is the URL to your Postgres databasenexus– database nameuser– database userpassword– database user passwordcurrentSchema=<schema_name>– the schema within your PostgreSQL database. Required if your schema name differs from your database name.- Use 2 dashes before the full-named parameters.
- Use the
db_urlparameter value with double quotes.
- Run the following command on the Nexus Repository database after migrating but before starting Nexus Repository. This will reclaim storage occupied by obsoleted tuples left from the migration.
VACUUM(FULL, ANALYZE, VERBOSE);
- Start Nexus Repository.
Ensure you are still on the same Nexus Repository version you were before the migration (e.g., if you were using 3.70.x, start your newly migrated instance as 3.70.x before upgrading beyond this).
If you encounter errors during the migration to PostgreSQL, it may be necessary to recreate the PostgreSQL database (or schema) before retrying the migration. This ensures a clean environment for the migration process.
Optional Parameters
-y, --yes:
Parameter to skip waiting for user input and assume a "yes" response to the initial warning.--content_migration=false
Parameter to only migrate the security and config tables: users, roles, and blobstore configuration. Repository content is not migrated.--shutdown_compact=false
Parameter to disable H2 Content DB compression; this is set to true by default.--healthcheck
Parameter to run a health check on your OrientDB database. This check focuses on detecting and reporting existing corruption in component and asset classes. The migration will not occur when using this parameter.
java -jar nexus-db-migrator-*.jar --healthcheck