Database

Database#

To install Carbonio, the availability of a Postgres database is required. It’s possible to install the Postgres database in a separate structure (as long as access to the service is guaranteed) or you can opt to directly access a Postgres database provided by a cloud service provider.

Obviously it’s also possible to install a node dedicated to Postgres in the same infrastructure that hosts the Carbonio nodes. Below are the steps to follow in this case.

Installation of PostgreSQL#

Warning

In case you install this Role on a Node which already features the Mesh and Directory Role, make sure you do not install the service-discover-agent package.

# apt install postgresql-12 service-discover-agent

On a RHEL 8 installation, you need to install PostgreSQL 12 directly from the PostgreSQL repository, so install the repository information.

# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

To make sure that Postresql 12 is installed, run commands

# dnf -qy module disable postgresql
# dnf -y install postgresql12 postgresql12-server service-discover-agent

Once installed, initialise and enable the database

# /usr/pgsql-12/bin/postgresql-12-setup initdb
# systemctl enable --now postgresql-12

Carbonio CE relies on a number of databases to store and keep track of all the objects it needs to manage. The main database can be configured in few steps.

Note

If you are running Carbonio CE on RHEL 8, make sure you installed and configured PostgreSQL 12 according to the instruction in section Preliminary Tasks.

We start by defining a robust password for PostgreSQL’s administrative user.

# read -s -p "Insert Password:" DB_ADM_PWD

When prompted, enter a password of your choice: it will be stored in a variable denoted $DB_ADM_PWD that can be used throughout the whole procedure. It is important to notice that the password is accessible to the user (root) in the current terminal only. No one else can access it and it will be deleted upon logging out.

# su - postgres -c "psql --command=\"CREATE ROLE carbonio_adm WITH LOGIN SUPERUSER encrypted password '$DB_ADM_PWD';\""

Remember to replace the password with a robust password of your choice and store it in a safe place (preferably using a password manager), as you need it in the remainder of the procedure, and you also might need them in the future. This password will be denoted as DB_ADM_PWD.

The second step is to create the database.

# su - postgres -c "psql --command=\"CREATE DATABASE carbonio_adm owner carbonio_adm;\""

You can manually delete the variable–and the password it stores– at any moment with the command below, but remember that you need it in the next step.

# unset DB_ADM_PWD

Finally, allow the other nodes to access the databases that will be stored on this node by running these commands.

# su - postgres -c "psql --command=\"ALTER SYSTEM SET listen_addresses TO '*';\""
# su - postgres -c "psql --command=\"ALTER SYSTEM SET max_connections = 500;\""
# su - postgres -c "psql --command=\"ALTER SYSTEM SET shared_buffers = 5000;\""
# su - postgres -c "psql --command=\"ALTER SYSTEM SET port TO '5433';\""
# echo "host    all             all             0.0.0.0/0            md5" >> /etc/postgresql/12/main/pg_hba.conf
# systemctl restart postgresql
# su - postgres -c "psql --command=\"ALTER SYSTEM SET listen_addresses TO '*';\""
# su - postgres -c "psql --command=\"ALTER SYSTEM SET max_connections = 500;\""
# su - postgres -c "psql --command=\"ALTER SYSTEM SET shared_buffers = 5000;\""
# su - postgres -c "psql --command=\"ALTER SYSTEM SET port TO '5433';\""
# echo "host    all             all             0.0.0.0/0            md5" >> /var/lib/pgsql/12/data/pg_hba.conf
# systemctl restart postgresql-12

Hint

You may replace the 0.0.0.0/0 network with the one within the cluster is installed (172.16.0.0) to prevent unwanted accesses.