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.
What the Script Creates
Section titled “What the Script Creates”- The
kataloguedatabase. - The
katalogue_superuserrole, which the api service connects as. Its password is theREPOSITORY_PASSWORDof the api service. - Optionally, the
katalogue_readonlyrole, 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.
Prerequisites
Section titled “Prerequisites”- 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.
psqlandbashinstalled 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.
Initializing the Database
Section titled “Initializing the Database”- Go to the
services/dbfolder of the Katalogue repository. - Run the script, pointing it at your PostgreSQL server:
Add
Terminal window ./install.sh -h <hostname> -p <port> -U <admin username>-ROto also create thekatalogue_readonlyrole:Terminal window ./install.sh -h <hostname> -p <port> -U <admin username> -RO - Enter the passwords when the script asks for them, one after another. Pasting them works, and nothing you type or paste is shown.
- The password of the PostgreSQL admin account.
- The password to give
katalogue_superuser. - The password to give
katalogue_readonly, only if you passed-RO.
- Wait for Install complete!. If anything fails, the script stops at the first error and prints it.
- Set
REPOSITORY_HOSTNAME,REPOSITORY_PORT,REPOSITORY_USERNAME(katalogue_superuser) andREPOSITORY_PASSWORDfor the api service. See Minimum Configuration.
Running Without Prompts
Section titled “Running Without Prompts”To run the script unattended, for example from a provisioning pipeline, put the passwords in a file and pass it with -e:
- Create a file with the passwords, one
KEY=VALUEper line:Terminal window POSTGRES_PASSWORD=<admin password>KATALOGUE_SUPERUSER_PASSWORD=<katalogue_superuser password>KATALOGUE_READONLY_PASSWORD=<katalogue_readonly password>KATALOGUE_READONLY_PASSWORDis 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. - Make the file readable only by you:
Terminal window chmod 600 <path to file> - Run the script with the file:
Terminal window ./install.sh -h <hostname> -p <port> -U <admin username> -e <path to file> - 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.
Setting the Database Locale
Section titled “Setting the Database Locale”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:
./install.sh -h <hostname> -p <port> -U <admin username> -L en-USThe 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-USThe 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 katalogueWITH ENCODING = 'UTF8' TEMPLATE template0 LOCALE_PROVIDER = icu ICU_LOCALE = 'sv-SE';Options
Section titled “Options”| Option | Description | Default |
|---|---|---|
-h, --hostname | PostgreSQL hostname | localhost |
-p, --port | PostgreSQL port | 5432 |
-U, --username | PostgreSQL admin account username | postgres |
-e, --env-file | File to read passwords from | |
-L, --locale | ICU locale of the katalogue database. See Setting the Database Locale | sv-SE |
-RO, --readonly | Also create the katalogue_readonly role | |
-v, --verbose | Show everything psql prints, including notices and the details of an error | |
--help | Show the usage text |
Passwords cannot be passed as options, so they never end up in your shell history or in the process list.