Prepare the open source relational database with geospatial support to receive IoT and RTLS data from Pareto Anywhere.
Learn how to install the pair for IoT and RTLS applications with Pareto Anywhere.
Pareto Anywhere open source IoT middleware installed.
Install the pair on a specific operating system.
Follow the instructions specific to your operating system to install PostgreSQL:
Open a terminal and then:
sudo apt update sudo apt upgrade sudo apt install postgresql <1 min The installed PostgreSQL version will depend on your OS version (ex: postgresql-16 on Ubuntu 24.10).
Download the latest PostgreSQL version from EDB and follow the installer instructions.
The default installer settings should apply to common use cases.
Again, follow the instructions specific to your operating system to install PostGIS:
Open a terminal and then install PostGIS with the command sudo apt install postgresql-postgis <1 min
The installed PostGIS version will depend on your OS version (ex: postgresql-16-postgis-3 on Ubuntu 24.10).
Run the StackBuilder program provided by the PostgreSQL installation, select the Spatial Extensions / PostGIS option and complete the installation.
The default installer settings should apply to common use cases.
Now that PostgreSQL and PostGIS are installed, it is possible to create a database with the PostGIS extension, which is covered in Step 2 below.
Create the database with PostGIS extension.
Open a terminal and then log in to PostgreSQL as the postgres user with the command sudo -u postgres psql
Once logged in, the terminal prompt should change to postgres=#, accepting database queries. Enter the following queries:
CREATE USER reelyactive WITH ENCRYPTED PASSWORD 'paretoanywhere'; CREATE DATABASE pareto_anywhere WITH OWNER reelyactive; This will create a database called pareto_anywhere owned by user reelyactive with password paretoanywhere.
Remain logged in as the postgres user and change to the pareto_anywhere database with the following command:
\c pareto_anywhere Then enter the following queries:
CREATE EXTENSION postgis; SELECT postgis_full_version(); This will create the PostGIS extension on the pareto_anywhere database. The second query simply verifies the PostGIS version number.*
* ERROR: function postgis_full_version() does not exist would indicate that creation of the PostGIS extension was unsuccessful.
To log out of PostgreSQL, enter exit
Now that the database is created, it is possible to create tables in which data to write the IoT and RTLS data, which is covered in Step 3 below.
Create the database tables and indexes.
The /barnacles-postgres module provides scripts as a convenient alternative to Parts 1-3 below:
npm run create-tables npm run create-indexes Open a terminal and then log in to PostgreSQL as the reelyactive user on the pareto_anywhere database with the command psql -U reelyactive -h 127.0.0.1 -d pareto_anywhere
Once logged in, the terminal prompt should change to pareto_anywhere=>, accepting database queries. Enter the queries to create the tables and indexes, as indicated in Parts 2 & 3 below.
While logged in as the reelyactive user on the pareto_anywhere database, create the raddec, dynamb and spatem tables with the following queries:
CREATE TABLE raddec ( _storeid bigint GENERATED ALWAYS AS IDENTITY, transmittersignature varchar(36) NOT NULL, timestamp timestamptz DEFAULT current_timestamp, raddec JSONB NOT NULL ); CREATE TABLE dynamb ( _storeId bigint GENERATED ALWAYS AS IDENTITY, devicesignature varchar(36) NOT NULL, timestamp timestamptz DEFAULT current_timestamp, dynamb JSONB NOT NULL ); CREATE TABLE spatem ( _storeId bigint GENERATED ALWAYS AS IDENTITY, devicesignature varchar(36) NOT NULL, timestamp timestamptz DEFAULT current_timestamp, spatem JSONB NOT NULL ); SELECT AddGeometryColumn ('spatem','geom',4326,'POINT',3);
The fourth and final query above applies the PostGIS extension, adding a geometry column to the spatem table.
While logged in as the reelyactive user on the pareto_anywhere database, create indexes on the raddec, dynamb and spatem tables with the following queries:
CREATE INDEX raddec_transmitter_idx ON raddec (transmittersignature); CREATE INDEX raddec_timestamp_idx ON raddec USING BRIN(timestamp); CREATE INDEX dynamb_device_idx ON dynamb (devicesignature); CREATE INDEX dynamb_timestamp_idx ON dynamb USING BRIN(timestamp); CREATE INDEX spatem_device_idx ON spatem (devicesignature); CREATE INDEX spatem_timestamp_idx ON spatem USING BRIN(timestamp); Our cheatsheet details the raddec, dynamb and spatem JSON output from the open source IoT middleware.
Observing data from Pareto Anywhere is as simple as running a specific startup script, or, for quick-and-dirty validation, run barnacles-postgres as described below.
If a Pareto Anywhere installation based on the pareto-anywhere package is already present on the same computer as the PostgreSQL database, simply start Pareto Anywhere with the command npm run postgres.
To quickly validate the installation, it is possible to run barnacles-postgres standalone to initiate a database connection as follows:
git clone https://github.com/reelyactive/barnacles-postgres.git cd barnacles-postgres npm install npm start
If the database is correctly configured, barnacles-postgres: connected to database should appear in the console.
Tutorial prepared with ♥ by jeffyactive.
You can reelyActive's open source efforts directly by contributing code & docs, collectively by sharing across your network, and commercially through our packages.Continue exploring our open architecture and all its applications.