External DB#
This section describes commands required for configuring external PostgreSQL for working with LP. External means that you already have working DB and MQ and want to use them with LP.
You need to specify your external DB and MQ in the configurations of LP services.
Skip this section if you are using PostgreSQL and RabbitMQ from docker containers!
After you perform all the commands from this sections go back to the "Luna Configurator" section.
Create databases in external PostgreSQL#
Note. You database user and other parameters may differ. Consider it during the commands execution.
The sections below describes the databases creation. You should use the "db_create.py" script to create the tables structure, after the table is created. The script launch from the container is described for each service in sections above. E. g. see the "Faces DB tables creation".
PostgreSQL user creation#
Go to the directory.
cd /var/
Create a database user
runuser -u postgres -- psql -c 'create role luna;'
Assign a password to the user
runuser -u postgres -- psql -c "ALTER USER luna WITH PASSWORD 'luna';"
Configurator DB creation#
Create the database for the Configurator service. It is assumed that the DB user is already created.
Go to the directory.
cd /var/
-
Create the database
-
Grant privileges to the database user
-
Allow user to authorize in the DB
runuser -u postgres -- psql -c 'CREATE DATABASE luna_configurator;'
runuser -u postgres -- psql -c 'GRANT ALL PRIVILEGES ON DATABASE luna_configurator TO luna;'
runuser -u postgres -- psql -c 'ALTER ROLE luna WITH LOGIN;'
Handlers DB creation#
Create the database for the Handlers service. It is assumed that the DB user is already created.
Go to the directory.
cd /var/
The sequence of actions corresponds to the commands below:
- Create a database
- Grant privileges to the database and the user
- Enable the user to login into DB
runuser -u postgres -- psql -c 'CREATE DATABASE luna_handlers;'
runuser -u postgres -- psql -c 'GRANT ALL PRIVILEGES ON DATABASE luna_handlers TO luna;'
runuser -u postgres -- psql -c 'ALTER ROLE luna WITH LOGIN;'
Backport 3 DB creation#
Create the database for the Backport 3 service. It is assumed that the DB user is already created.
Go to the directory.
cd /var/
The sequence of actions corresponds to the commands below:
- Create a database
- Grant privileges to the database and the user
- Enable the user to login into DB
runuser -u postgres -- psql -c 'CREATE DATABASE luna_backport3;'
runuser -u postgres -- psql -c 'GRANT ALL PRIVILEGES ON DATABASE luna_backport3 TO luna;'
runuser -u postgres -- psql -c 'ALTER ROLE luna WITH LOGIN;'
Faces DB creation#
Create the database for the Faces service. It is assumed that the DB user is already created.
Go to the directory.
cd /var/
-
Create a database
-
Grant privileges to the database and the user
-
Enable the user to login into DB
runuser -u postgres -- psql -c 'CREATE DATABASE luna_faces;'
runuser -u postgres -- psql -c 'GRANT ALL PRIVILEGES ON DATABASE luna_faces TO luna;'
runuser -u postgres -- psql -c 'ALTER ROLE luna WITH LOGIN;'
Create VLMatch function for Faces DB#
The Faces service requires the VLMatch additional function to be added to the utilized database. LUNA PLATFORM cannot perform matching calculations without this function. The VLMatch function can be added to the PostgreSQL or Oracle database.
The VLMatch library is compiled for your particular database version.
Note! Do not use the library built for another version of DB. For example, the library build for the PostgreSQL of version 12 cannot be used for the PostgreSQL of version 9.6.
This section describes the function creation for PostgreSQL.
The instruction for the Oracle DB is given in the "VLMatch for Oracle" section.
Build VLMatch for PostgreSQL#
You can find all the required files for the VLMatch user-defined extension (UDx) compilation in the following directory:
/var/lib/luna/current/extras/VLMatch/postgres/
The following instruction describes installation for PostgreSQL 12.
For VLMatch UDx function compilation one needs to:
-
Make sure, that PostgreSQL of the required version is installed and launched.
-
Install the required PostgreSQL development environment. You can find more information on the official web site.
-
The llvm-toolset-7-clang is required for postgresql12-devel. Install it from the
centos-release-scl-rh
repository.
yum -y install centos-release-scl-rh
yum -y --enablerepo=centos-sclo-rh-testing install llvm-toolset-7-clang
- Install epel-release for access to extended package repository
yum -y install epel-release
- Install the development environment.
yum -y install postgresql12 postgresql12-server postgresql12-devel
- Install the gcc-c++ package. The package version 4.8 or higher is required.
yum -y install gcc-c++.x86_64
-
Install CMAKE. The version 3.5 or higher is required.
-
Open the make.sh script using a text editor. It includes paths to the currently used PostgreSQL version. Change the following values (if necessary):
SDK_HOME
specifies the path to PostgreSQL home directory. The default value is /usr/pgsql-12/include/server
;
LIB_ROOT
specifies the path to PostgreSQL library root directory. The default value is /usr/pgsql-12/lib
.
Go to the make.sh script directory and run it:
cd /var/lib/luna/current/extras/VLMatch/postgres/
chmod +x make.sh
./make.sh
Add VLMatch function to Faces database#
The VLMatch function should be applied to the PostgreSQL DB.
- Define the function inside the Faces database:
sudo -u postgres -h 127.0.0.1 -- psql -d luna_faces -c "CREATE FUNCTION VLMatch(bytea, bytea, int) RETURNS float8 AS 'VLMatchSource.so', 'VLMatch' LANGUAGE C PARALLEL SAFE;"
- Test function by sending re following request to the service database:
sudo -u postgres -h 127.0.0.1 -- psql -d luna_faces -c "SELECT VLMatch('\x1234567890123456789012345678901234567890123456789012345678901234'::bytea, '\x0123456789012345678901234567890123456789012345678901234567890123'::bytea, 32);"
The result returned by the database must be "0.4765625".
Events DB creation#
Create the database for the Events service. It is assumed that the DB user is already created.
Go to the directory.
cd /var/
-
Create database
-
Grant privileges to database and the user
-
Enable the user to login into DB
runuser -u postgres -- psql -c 'CREATE DATABASE luna_events;'
runuser -u postgres -- psql -c 'GRANT ALL PRIVILEGES ON DATABASE luna_events TO luna;'
runuser -u postgres -- psql -c 'ALTER ROLE luna WITH LOGIN;'
Create VLMatch function for Events DB#
The Events service requires the VLMatch additional function to be added to the utilized database. LUNA PLATFORM cannot perform matching calculations without this function. The VLMatch function can be added to the PostgreSQL.
The VLMatch library is compiled for your particular database version.
Note! Do not use the library built for another version of DB. For example, the library build for the PostgreSQL of version 12 cannot be used for the PostgreSQL of version 9.6.
This section describes the function creation for PostgreSQL. If you use the PostgreSQL database, you have already created and moved the created library during the Faces service launch. See section "Build VLMatch UDx".
Add VLMatch function to Events database#
The VLMatch function should be applied to the PostgreSQL DB.
Define the function inside the Events database:
sudo -u postgres -h 127.0.0.1 -- psql -d luna_events -c "CREATE FUNCTION VLMatch(bytea, bytea, int) RETURNS float8 AS 'VLMatchSource.so', 'VLMatch' LANGUAGE C PARALLEL SAFE;"
Test function within call:
sudo -u postgres -h 127.0.0.1 -- psql -d luna_events -c "SELECT VLMatch('\x1234567890123456789012345678901234567890123456789012345678901234'::bytea, '\x0123456789012345678901234567890123456789012345678901234567890123'::bytea, 32);"
The result returned by the database must be "0.4765625".
PostGIS installation for Events#
The Events service requires PostGIS for working with coordinates.
This instruction describes the PostGIS installation for PostgreSQL 12 database. The PostGIS version depends on the PostgreSQL version.
- Install epel-release for access to extended package repository (necessary for RabbitMQ and other dependencies)
yum -y install epel-release
- Install PostGIS:
yum -y install postgis25_12
- Activate PostGIS in your database:
sudo -u postgres -h 127.0.0.1 -- psql -d luna_events -c "CREATE EXTENSION postgis;";
See additional information about PostGIS on its website:
https://postgis.net/
Admin DB creation#
Create the database for the Admin service. It is assumed that the DB user is already created.
Go to the directory.
cd /var/
-
Create the database
-
Grant privileges to the database user
-
Allow user to authorize in the DB
runuser -u postgres -- psql -c 'CREATE DATABASE luna_admin;'
runuser -u postgres -- psql -c 'GRANT ALL PRIVILEGES ON DATABASE luna_admin TO luna;'
runuser -u postgres -- psql -c 'ALTER ROLE luna WITH LOGIN;'
Tasks DB creation#
Create the database for the Tasks service. It is assumed that the DB user is already created.
Go to the directory.
cd /var/
-
Create the database
-
Grant privileges to the database user
-
Allow user to authorize in the DB
runuser -u postgres -- psql -c 'CREATE DATABASE luna_tasks;'
runuser -u postgres -- psql -c 'GRANT ALL PRIVILEGES ON DATABASE luna_tasks TO luna;'
runuser -u postgres -- psql -c 'ALTER ROLE luna WITH LOGIN;'