Skip to main content

Configure Postgres

WARNING

Do not configure Postgres on an existing installation, as it's likely going to cause system instability or break functionality.

Debian, Ubuntu

tip

Since you are following this PostgreSQL guide, when prompted by the installation wizard about database configuration, select "No" as we plan to use an external database. However, during this process, refer to the installation guide for Nginx configuration and note the URL to reach after Postgres configuration.

To set up PostgreSQL, install the required packages and configure the database:

  1. Install PostgreSQL:
sudo apt update
sudo apt install -y postgresql postgresql-contrib
  1. Start and enable PostgreSQL service:
sudo systemctl enable --now postgresql
  1. Create a PostgreSQL user and database for Passbolt:
sudo -u postgres psql

Then, inside the PostgreSQL prompt, run:

CREATE DATABASE passbolt;
CREATE USER passbolt WITH ENCRYPTED PASSWORD 'P4ssb0lt';
GRANT ALL PRIVILEGES ON DATABASE passbolt TO passbolt;
  1. Save and restart PostgreSQL:
sudo systemctl restart postgresql
  1. Continue the installation of passbolt:

You will need to navigate on your browser to the URL of your passbolt instance, from there, you will be able to configure the database section with Postgres instead of MySQL.

Configure Postgres on the webInstaller
fig. Configuring Postgres on the webInstaller

RPM

tip

Since you are following this PostgreSQL guide, when prompted by the installation wizard about database configuration, select "No" as we plan to use an external database. However, during this process, refer to the installation guide for Nginx configuration.

  1. Install PostgreSQL:
sudo dnf install -y postgresql-server postgresql-contrib
  1. Initialize the database:
sudo postgresql-setup --initdb
  1. Start and enable PostgreSQL service:
sudo systemctl enable --now postgresql
  1. Create a PostgreSQL user and database for Passbolt:
sudo -u postgres psql

Then, inside the PostgreSQL prompt, run:

CREATE DATABASE passbolt;
CREATE USER passbolt WITH ENCRYPTED PASSWORD 'P4ssb0lt';
GRANT ALL PRIVILEGES ON DATABASE passbolt TO passbolt;
  1. Continue the installation of passbolt:

You will need to navigate on your browser to the URL of your passbolt instance, from there, you will be able to configure the database section with Postgres instead of MySQL.

Configure Postgres on the webInstaller
fig. Configuring Postgres on the webInstaller

Docker

In order to download the docker compose file based on your edition e.g., CE,PRO. You can follow our Docker installation guide.

Updating the docker compose file

The default db container needs to be changed and there is also a few changes that needs to be done on the passbolt container.

Database container

You can replace the existing db container with the one below in order to use Postgres latest image.

db:
image: postgres:latest
restart: unless-stopped
environment:
POSTGRES_DB: "passbolt"
POSTGRES_USER: "passbolt"
POSTGRES_PASSWORD: "P4ssb0lt"
volumes:
- database_volume:/var/lib/postgresql/data

Passbolt container

Some changes needs to be done on the environment variable, indeed we will no longer use:

  • DATASOURCES_DEFAULT_HOST
  • DATASOURCES_DEFAULT_USERNAME
  • DATASOURCES_DEFAULT_PASSWORD
  • DATASOURCES_DEFAULT_DATABASE

Instead, we will be using these environment variable:

DATASOURCES_DEFAULT_DRIVER: Cake\Database\Driver\Postgres
DATASOURCES_DEFAULT_ENCODING: "utf8"
DATASOURCES_DEFAULT_URL: "postgres://POSTGRES_USER:POSTGRES_PASSWORD@db:5432/POSTGRES_DB?schema=passbolt"

We also need to update the wait-for.sh script in the entrypoint configuration, as we no longer use port 3306 for MariaDB but instead use port 5432 for Postgres:

/usr/bin/wait-for.sh -t 0 db:5432 -- /docker-entrypoint.sh

Then you should be good to go! Docker installation will now work with Postgres database management system.