Skip to content

Setup a database for Cacao Accounting.

Once you have installed Cacao Accounting from sources or from pypi and have the cacaoctl available in /opt/cacao-accounting/venv/bin/cacaoctl you can setup your database service:

Setup PostgreSQL

Follow the next steps to install PostgreSQL in your system.

Install PostgreSQL with:

sudo apt update
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install -y postgresql
sudo systemctl enable postgresql --now

Install PostgreSQL with:

sudo dnf update
sudo dnf install -y postgresql-server postgresql
sudo postgresql-setup --initdb
sudo systemctl enable postgresql --now

Secure your database with:

sudo -u postgres psql

And in the psql console execute:

ALTER USER postgres WITH ENCRYPTED PASSWORD 'strong_password';
CREATE USER cacaodbuser ENCRYPTED PASSWORD 'cacaodbpwsd';
\q

Warning

It is recommend to use a custom user and password to setup your database. Remember to save your user, password and database name for future reference.

Allow password authentication on the server with:

Install PostgreSQL with:

sudo sed -i '/^local/s/peer/scram-sha-256/' /etc/postgresql/16/main/pg_hba.conf

Install PostgreSQL with:

sudo cp /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.bak
sudo nano /var/lib/pgsql/data/pg_hba.conf

Find the following configuration section within the file

local   all             all                                     peer

And change peer with md5:

local   all             all                                     md5

Restart the database server with:

sudo systemctl restart postgresql

Create the Cacao Accounting database with:

sudo -u postgres cacaoaccountingdb -O cacaodbuser

With this setup you can set the CACAO_DB enviroment variable to the conection string of the database you have created, also set a SECRET_KEY enviroment variable with lowercases, uppercases and numbers.

sudo export CACAO_DB=postgresql+pg8000://cacaodbuser:cacaodbpwsd@localhost/cacaoaccountingdb
sudo export CACAO_KEY=sñldkñsadfmnskpfmskn1235aaaaaaAAAAAAA

Note

Aditional info about Cacao Accounting configuration is available here.

Populate the database and create a new administrator user with:

CACAO_USER=cacaoadmin
CACAO_PSWD=cacaoadminpass
/opt/cacao-accounting/venv/bin/cacaoctl setupdb

Warning

Use a custom user id and password for the administrative user of Cacao Accounting.

If not errors are reported your database show be populated with the system tables and initial records.

You can continue to setup systemd to start Cacao Accounting at startup.