If you want to host the database separately from the iBatyr Monitor service and the web interface, prepare the database server and connect the iBatyr Monitor server to it.
Work on the database server
Install the software
Install a clean Ubuntu Server version 20 or 22.
Update packages on the system:
sudo apt update && sudo apt upgrade
Install packages to install the database:
sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https lsb-release curl -y
Add keys to the PostgreSQL repository:
curl -fSsL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql.gpg > /dev/null
Add a repository:
echo deb [arch=amd64,arm64,ppc64el signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main | sudo tee /etc/apt/sources.list.d/postgresql.list
Update the repository lists in the package manager:
sudo apt update
Install PostgreSQL 15:
sudo apt install postgresql-client-15 postgresql-15 -y
Create a user
Find the password on the iBatyr Monitor server using the command:
cat /etc/ibatyr/config | grep PASSWORD
Copy the password. It will be in quotes, for example:
'PASSWORD': '05ce255df14c3308143737316139b77',
Insert the password into the command instead of
парольand execute it on the database server:
sudo -u postgres psql -c "create user ibatyr with password 'пароль';"Example:
sudo -u postgres psql -c "create user ibatyr with password '05ce255df14c3308143737316139b77';"
Change the configuration
Open the configuration file /etc/postgresql/15/main/postgresql.conf for editing.
The example uses Vim, but any editor will do:
sudo vim /etc/postgresql/15/main/postgresql.confFind the line:
#listen_addresses = 'localhost,00.00.00.000' # what IP address(es) to listen on;Remove the # symbol at the beginning of the line and add the IP through which iBatyr Monitor will access the database server.
Note
It is important to specify the exact IP address of the database server. This address defines the interface through which the server accepts requests. It is not associated with the IP address from which requests are coming.
Save your changes and exit the editor.
Open the file /etc/postgresql/15/main/pg_hba.conf for editing:
sudo vim /etc/postgresql/15/main/pg_hba.confAt the end of the file add:
host all all {ip сервера iBatyr Monitor}/{маска} md5For example, if
00.00.00.000is the IP address of the iBatyr Monitor server and 32 is the subnet mask:host all all 00.00.00.000/32 md5
Restart PostgreSQL to apply the changes:
sudo systemctl restart postgresql
Work on the iBatyr Monitor server
Migrate the database
Note
If there is no data on the server, skip this step and go to the Create a database section.
Turn off the iBatyr Monitor server:
ibatyr stop
Create a backup with the command:
ibatyr backup_db
Transfer the backup copy from the /var/lib/ibatyr/ibatyr_backup/ibatyr-db.dump directory to the database server.
Start database recovery on the remote server:
sudo -u postgres pg_restore --verbose --clean --create --format=c {путь до файла бекапа} -d postgresFor example:
sudo -u postgres pg_restore --verbose --clean --create --format=c /home/ibatyr-db.dump -d postgres
Create a database
On the database server, connect to PostgreSQL:
sudo -u postgres psql
Create a database:
CREATE DATABASE ibatyr WITH OWNER = ibatyr ENCODING = 'UTF8' LC_COLLATE = 'ru_RU.UTF-8' LC_CTYPE = 'ru_RU.UTF-8' TEMPLATE = template0;
Select the created database and create the necessary extensions:
\c ibatyr
CREATE EXTENSION pg_trgm;
CREATE EXTENSION ltree;
CREATE EXTENSION cube;
CREATE EXTENSION dblink;
CREATE EXTENSION pgcrypto;
Copy all files from the /usr/share/ibatyr/data/ispell/ directory on the iBatyr Monitor server to the /usr/share/postgresql/15/tsearch_data/ directory.
For example, using the
scpcommand:scp -r /usr/share/ibatyr/data/ispell/* user@10.10.10.2:/usr/share/postgresql/15/tsearch_data/where
user@10.10.10.1is the user name and ip the server address iBatyr Monitor, anduser@10.10.10.2is the user name and the address of the server with the database.
Initialize the database on the iBatyr Monitor server:
ibatyr init
Ready! The database has been moved to a dedicated server.
Connect the database
Turn off the iBatyr Monitor server:
ibatyr stop
Open the iBatyr Monitor configuration file /etc/ibatyr/config:
sudo vim /etc/ibatyr/configFind the block:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'ibatyr', 'USER': 'ibatyr', 'PASSWORD': '05ce255df14c3308143737316139b77', 'HOST': '', 'PORT': '', } }Specify the address and port of the remote PostgreSQL server in HOST and PORT, for example:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'ibatyr', 'USER': 'ibatyr', 'PASSWORD': '05ce255df14c3308143737316139b77', 'HOST': '10.10.13.243', 'PORT': '5432', } }
Disable automatic database startup on the iBatyr Monitor server:
sudo systemctl stop postgresql sudo systemctl disable postgresql
Check your database connection:
ibatyr sqlIf there are no errors and you see the PostgreSQL prompt
(ibatyr=>), the connection was successful.Exit the prompt:
\q
Initialize the database:
ibatyr init
Ready! The database has been moved to a dedicated server.