TimescaleDB
Find all the information about how to set up your TimescaleDB instance for Speculare. It will be the core of the whole infrastructure for Speculare.
Speculare is built on top of TimescaleDB which is itself built on top of PostgreSQL and is an extremely scalable Relational / Timeseries Database.
As we need to use some advanced PostgreSQL functionality and to ease the development of our project, we rely on some features of PostgreSQL that need to be enabled as well as some plugins. We'll cover here the configuration needed to be able to run Speculare correctly.
In this document (and the others) I might refer to PostgreSQL for TimescaleDB as they are both pretty much the same thing but with the tweak that TimescaleDB is more like an add-on on top of PostgreSQL.

Setup

We strongly recommend you to use the v13 even if in theory any version above v10 should work just fine.

Install TimescaleDB 13 on Ubuntu

You can refer to this link from Timescale for installation on your system: docs of Timescale. Their docs are really well written !
👏
Upon successful installation of TimescaleDB, I suggest you to install timescaledb-tools as this will allow you to run:
1
timescaledb-tune
Copied!
The above command will offer you to apply certain settings to your PostgreSQL instance (in order to "optimize" it).
You can then verify that PostgreSQL has been installed correctly by running:
1
systemctl status postgresql.service
2
3
● postgresql.service - PostgreSQL RDBMS
4
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
5
Active: active (exited) since Sun 2020-10-07 10:23:46 UTC; 6min ago
6
Main PID: 8159 (code=exited, status=0/SUCCESS)
7
Tasks: 0 (limit: 2362)
8
CGroup: /system.slice/postgresql.service
Copied!

Install wal2json (required)

Speculare rely on one more PostgreSQL plugin, which is wal2json. As a basic explanation of what it does: wal2json convert the events passing through the WAL of PostgreSQL into a JSON structure
You can install it easily by running (or by checking their docs):
1
sudo apt install postgresql-13-wal2json
Copied!

Enable wal2json (required)

You now need to enable both plugins (wal2json & timescaledb) otherwise installing them would be useless. For that you have to edit /etc/postgresql/{version}/main/postgresql.conf to add wal2json & timescaledb to the shared_preload_libraries variable.
1
# - Shared Library Preloading -
2
3
shared_preload_libraries = 'wal2json, timescaledb' # (change requires restart)
4
#local_preload_libraries = ''
5
#session_preload_libraries = ''
6
#jit_provider = 'llvmjit'
Copied!

Set up logical replication

As you probably know, PostgreSQL doesn't offer a real-time API to listen to change over a Web-socket or such. Because of that we had to develop a Change Data Capture service which listen to the WAL output.
This feature allow us to get a stream of changes made within PostgreSQL which is then filtered and broadcasted over Web-socket to subscribed clients. This is done though Speculare-PGCDC.
Logical replication can be enabled by changing a few line in /etc/postgresql/{version}/main/postgresql.conf:
1
# REPLICATION
2
wal_level = logical # minimal, archive, hot_standby, or logical (change requires restart)
3
max_wal_senders = 5 # max number of walsender processes (change requires restart)
4
#wal_keep_segments = 4 # in logfile segments, 16MB each; 0 disables
5
#wal_sender_timeout = 60s # in milliseconds; 0 disables
6
max_replication_slots = 5 # max number of replication slots (change requires restart)
7
synchronous_commit = local # synchronization level;
Copied!
After all those changes, you will need to restart PostgreSQL for changes to take effect.
An important point to note is that those are "default" settings and may not be suitable for production use.
And you should now be ready to use PostgreSQL.
If something is missing in this guide, don't hesitate to open an issue on Github.
Copy link
Contents
Setup