Database Initialization

Nomatron is in early access. Some advanced workflows may not be covered in the public docs.

Nomatron needs a PostgreSQL database before the server can start successfully.

Use nomatron database init during first-time setup to create the application database if needed, apply schema migrations, seed built-in RBAC data, and bootstrap the root user.

Supported Backend

At the moment, nomatron database init supports PostgreSQL only.

If the configured connection string is not PostgreSQL, the command fails.

What The Command Does

When you run nomatron database init, Nomatron:

  1. Loads and validates configuration from the config file, environment variables, and command-line flags, using the same validation as nomatron server (licensing and Serf settings included).
  2. Requires NOMATRON_ENCRYPTION_KEY.
  3. Connects to PostgreSQL using the configured connection details.
  4. Checks whether the database named in the connection string already exists. If the connection string has no database name, nomatron is used.
  5. Creates that database if it does not exist.
  6. Connects to the target database.
  7. Runs the embedded SQL migrations.
  8. Ensures the JWT signing key exists.
  9. Seeds permissions and built-in RBAC roles.
  10. Creates the root user if no active built-in Nomatron user already exists.
  11. Assigns the default super-admin role to that root user.

Before You Run It

Make sure:

  • PostgreSQL is reachable from the machine running the command;
  • the configured database user can connect to PostgreSQL and create the target database if it does not exist yet;
  • your connection string points at the intended PostgreSQL server and database;
  • the same licensing settings the server will use are available: in the default connected licence mode that means NOMATRON_LICENSE_KEY and NOMATRON_CLUSTER_KEY;
  • NOMATRON_ENCRYPTION_KEY is set to the key the server will use (32 bytes, or base64 of 32 bytes; generate one with openssl rand -base64 32); and
  • you know what root username and password you want to bootstrap.

Generate the cluster key yourself, for example with openssl rand -base64 32. Nomatron does not store or issue cluster keys, so back it up in your secrets manager. Keep both the cluster key and the encryption key for the life of the database. Stored secrets cannot be decrypted without the original encryption key.

The database does not have to be called nomatron. Nomatron uses whatever database the connection string names, and falls back to nomatron only when the connection string has no database name.

Basic Usage

Run database initialization with your normal server config and secrets supplied from your secret store. Do not pass secrets as command-line arguments:

bash
export NOMATRON_LICENSE_KEY="$(cat /run/secrets/nomatron_license_key)"
export NOMATRON_CLUSTER_KEY="$(cat /run/secrets/nomatron_cluster_key)"
export NOMATRON_ENCRYPTION_KEY="$(cat /run/secrets/nomatron_encryption_key)"

nomatron database init --config /etc/nomatron/nomatron.hcl

To supply the database connection string separately from the config file, read it from a file or stdin:

bash
nomatron database init \
  --config /etc/nomatron/nomatron.hcl \
  --database-url-file /run/secrets/nomatron_db_url
bash
printf '%s' "$NOMATRON_DB_URL" | nomatron database init --database-url-stdin

Root User Bootstrap

If you do not supply a root password, database initialization creates a root user with:

  • username: root
  • password: nomatron123

Set the root password before you run init. If you did not, change the root password immediately after your first sign-in. Until you do, the Nomatron UI shows a warning banner, “The Root User is still using the default password”, with a Change Password link (the banner is not shown in dev mode).

Supply the root credentials from a file or stdin:

bash
nomatron database init \
  --config /etc/nomatron/nomatron.hcl \
  --root-username admin \
  --root-password-file /run/secrets/nomatron_root_password

Or with environment variables:

bash
export NOMATRON_ROOT_USERNAME="admin"
export NOMATRON_ROOT_PASSWORD="$(cat /run/secrets/nomatron_root_password)"
nomatron database init --config /etc/nomatron/nomatron.hcl

NOMATRON_DATABASE_ROOT_PASSWORD is also accepted. Flags take precedence over environment variables, and environment variables take precedence over the built-in default.

These overrides are only intended for the first initialization, when Nomatron is bootstrapping the built-in root user for the first time.

Example First-Time Flow

bash
export NOMATRON_LICENSE_KEY="$(cat /run/secrets/nomatron_license_key)"
export NOMATRON_CLUSTER_KEY="$(cat /run/secrets/nomatron_cluster_key)"
export NOMATRON_ENCRYPTION_KEY="$(cat /run/secrets/nomatron_encryption_key)"
export NOMATRON_ROOT_PASSWORD="$(cat /run/secrets/nomatron_root_password)"

nomatron database init \
  --config /etc/nomatron/nomatron.hcl \
  --database-url-file /run/secrets/nomatron_db_url

After that succeeds, start the server with the same keys:

bash
nomatron server --config /etc/nomatron/nomatron.hcl

Re-running The Command

This command is primarily for first-time bootstrap and controlled provisioning workflows.

Some parts of the flow are intentionally repeat-friendly:

  • the target database is only created if it does not already exist; and
  • the existing built-in Nomatron user is reused if one already exists.

If you rerun nomatron database init after bootstrap and also pass --root-username, a --root-password* flag, NOMATRON_ROOT_USERNAME, or NOMATRON_ROOT_PASSWORD, the command fails fast with a clear error. Root credential overrides only apply during the first initialization.

Nomatron does not use reruns of database init to rotate or update the existing root credentials.

However, Nomatron currently runs the embedded SQL migrations directly during initialization, so treat this command as an operational bootstrap step rather than something to run casually on every start.

Common Failure Modes

Missing Licence, Cluster, Or Encryption Key

database init validates configuration the same way the server does. In the default connected mode, expect these errors in this order if values are missing:

  • licensing license_key is required for connected mode
  • licensing cluster_key is required for connected mode
  • NOMATRON_ENCRYPTION_KEY is required

A short or malformed encryption key fails with NOMATRON_ENCRYPTION_KEY must be 32 bytes or base64-encoded 32 bytes.

A leftover serf.join or NOMATRON_SERF_JOIN setting also makes database init fail. Use serf.retry_join instead.

PostgreSQL Permission Errors

If the PostgreSQL user cannot create the target database, initialization fails during the database creation step.

Fix this by either:

  • granting the required create-database privilege; or
  • creating the database ahead of time with your normal database provisioning workflow.

Root Credentials Left At Defaults

For anything beyond a disposable local environment, do not keep the default root password.

Set --root-password-file, --root-password-stdin, or NOMATRON_ROOT_PASSWORD during bootstrap, and store that secret securely. If you did not, change the root password immediately after first sign-in.

Root Override Flags Used After Bootstrap

If the database has already been initialized and a built-in Nomatron user already exists, root credential override flags and environment variables are no longer valid for this command.

Instead of changing the existing root account, nomatron database init returns a clear error explaining that root credential overrides only apply during first initialization.

Command Summary

OptionRequiredWhat it does
--configNoPath to the Nomatron server HCL config file.
--database-url-file / --database-url-stdinNoReads the PostgreSQL connection string from a file or stdin. Takes precedence over the config file database connection string.
--root-usernameNoOverrides the default root username used during first-time bootstrap only.
--root-password-file / --root-password-stdinNoReads the root password used during first-time bootstrap only.

The legacy --database-url and --root-password flags still exist, but they put secrets on the command line. Use the -file or -stdin forms, or environment variables, instead.

Environment variableWhat it does
NOMATRON_DB_URLPostgreSQL connection string.
NOMATRON_ENCRYPTION_KEYRequired. Key used to encrypt stored secrets.
NOMATRON_LICENSE_KEY, NOMATRON_CLUSTER_KEYRequired in connected licence mode (the default).
NOMATRON_ROOT_USERNAMEFirst-time root username.
NOMATRON_ROOT_PASSWORD or NOMATRON_DATABASE_ROOT_PASSWORDFirst-time root password.

For production-style installs:

  • provision PostgreSQL separately;
  • inject the database connection string, licence key, cluster key, encryption key, and root credentials from secrets management rather than hardcoding them;
  • back up the encryption key separately from the database; and
  • run nomatron database init as an explicit bootstrap step before the first server start.

nomatron database init is only for the first setup. To upgrade a database that is already in use, see Upgrade a self-hosted database .