Skip to content

Repository Database

Katalogue stores everything in a PostgreSQL database called the repository database. Before the api service can start, that database has to be initialized on a PostgreSQL server: the katalogue database, the roles Katalogue connects as, and every table, view and function it uses. The services/db/install.sh script does all of this. It is the same for a production server and for a local development server.

  • The katalogue database.
  • The katalogue_superuser role, which the api service connects as. Its password is the REPOSITORY_PASSWORD of the api service.
  • Optionally, the katalogue_readonly role, intended for other applications integrating with the repository database, or for syncing it to Katalogue as a datasource. It can read every table and view, and write nothing. It is only created when you ask for it.

The roles belong to the PostgreSQL server rather than to the katalogue database, so they remain if the database is dropped. Running the script again on that server reuses them and sets the passwords you enter.

  • A running PostgreSQL server that you can reach from where you run the script.
  • An admin account on that server that can create databases and roles, for example postgres.
  • PostgreSQL 15 or later, built with ICU support. The official PostgreSQL packages and Docker images are.
  • psql and bash installed on the machine you run the script from.
  • A copy of the Katalogue repository, from the release you are deploying.

You can also create an empty katalogue database yourself before running the script, for example when your organization provisions databases from a template. The script then installs into it. If that katalogue database already contains an installation, the script stops without changing anything. To upgrade it instead, follow the Upgrade Procedure.

  1. Go to the services/db folder of the Katalogue repository.
  2. Run the script, pointing it at your PostgreSQL server:
    Terminal window
    ./install.sh -h <hostname> -p <port> -U <admin username>
    Add -RO to also create the katalogue_readonly role:
    Terminal window
    ./install.sh -h <hostname> -p <port> -U <admin username> -RO
  3. Enter the passwords when the script asks for them, one after another. Pasting them works, and nothing you type or paste is shown.
    1. The password of the PostgreSQL admin account.
    2. The password to give katalogue_superuser.
    3. The password to give katalogue_readonly, only if you passed -RO.
  4. Wait for Install complete!. If anything fails, the script stops at the first error and prints it.
  5. Set REPOSITORY_HOSTNAME, REPOSITORY_PORT, REPOSITORY_USERNAME (katalogue_superuser) and REPOSITORY_PASSWORD for the api service. See Minimum Configuration.

To run the script unattended, for example from a provisioning pipeline, put the passwords in a file and pass it with -e:

  1. Create a file with the passwords, one KEY=VALUE per line:
    Terminal window
    POSTGRES_PASSWORD=<admin password>
    KATALOGUE_SUPERUSER_PASSWORD=<katalogue_superuser password>
    KATALOGUE_READONLY_PASSWORD=<katalogue_readonly password>
    KATALOGUE_READONLY_PASSWORD is only read when you pass -RO. A value may be wrapped in single or double quotes. Any password missing from the file is asked for as usual.
  2. Make the file readable only by you:
    Terminal window
    chmod 600 <path to file>
  3. Run the script with the file:
    Terminal window
    ./install.sh -h <hostname> -p <port> -U <admin username> -e <path to file>
  4. Delete the file when you no longer need it.

The script reads the passwords from the file and never runs it, so the file only has to contain the keys above. The admin password can also come from the PGPASSWORD environment variable or from ~/.pgpass, as for psql.

The script exits with 0 when the install completed, and with another code when it failed.

The locale of the katalogue database decides how names are sorted and how case-insensitive matching treats letters such as å, ä and ö, for example in search. It is sv-SE (Swedish) by default.

To use another locale, pass it with -L as an ICU locale name, such as en-US, de-DE or nb-NO:

Terminal window
./install.sh -h <hostname> -p <port> -U <admin username> -L en-US

The locale comes from ICU rather than from the operating system, so it behaves the same on every platform, and nothing has to be installed on the server for it. On PostgreSQL 16 and later, the script stops if the locale is not one ICU recognizes.

Choose the locale before you install: it cannot be changed once the database exists.

When the repository database runs in the Katalogue database Docker image, for example with the provided docker-compose.yml, set the locale with the KATALOGUE_DB_LOCALE environment variable on the database container instead:

db:
environment:
- KATALOGUE_DB_LOCALE=en-US

The image only initializes the database the first time the container starts with an empty data volume, so set the variable before then. Changing it later has no effect on the existing database.

If you create the katalogue database yourself, the script keeps the locale you created it with and ignores -L. To match what the script would create, use:

CREATE DATABASE katalogue
WITH
ENCODING = 'UTF8'
TEMPLATE template0
LOCALE_PROVIDER = icu
ICU_LOCALE = 'sv-SE';
OptionDescriptionDefault
-h, --hostnamePostgreSQL hostnamelocalhost
-p, --portPostgreSQL port5432
-U, --usernamePostgreSQL admin account usernamepostgres
-e, --env-fileFile to read passwords from
-L, --localeICU locale of the katalogue database. See Setting the Database Localesv-SE
-RO, --readonlyAlso create the katalogue_readonly role
-v, --verboseShow everything psql prints, including notices and the details of an error
--helpShow the usage text

Passwords cannot be passed as options, so they never end up in your shell history or in the process list.