Use an external self-managed TimescaleDB with your installation
Learn how to use an external self-managed TimescaleDB with Harness Self-Managed Enterprise Edition installations.
Harness Self-Managed Enterprise Edition requires you to install a database by default. You can optionally use an external self-managed database with your installation. This enables you to separate your data from node execution. To use an external self-managed TimescaleDB with your Harness Self-Managed Enterprise Edition installation, you must ensure that your hardware, software, and network meet the minimum requirements for installation and configuration. This tutorial describes how to deploy TimescaleDB with VMs and replication.
The controller-worker replication setup described in this tutorial ensures data redundancy and fault tolerance, providing a robust and reliable environment to manage your TimescaleDB.
Limitations
TimescaleDB VMs offer many advantages, but there are a few limitations to consider:
Resource overhead: Running a VM incurs resource overhead, such as CPU and memory usage, which may impact the performance of the PostgreSQL database.
Hardware dependency: VM performance is influenced by the underlying hardware. Ensure that the host system provides sufficient resources for the VM to function optimally.
Complexity: Setting up and managing a VM requires knowledge and expertise in virtualization technologies.
Maintenance overhead: VMs require regular maintenance, including updates, backups, and monitoring, which adds overhead compared to a native TimescaleDB installation.
Hardware requirements
Harness recommends a PostgreSQL three-member replica set configuration with the following minimum hardware:
Three nodes
Four CPU (3*4 = 12 CPU)
24GB RAM (324 = 72GB RAM)
300GB SSD data storage, depending on your requirements
Software requirements
External database setup requires the following software:
Supported OS: TimescaleDB supports Debian 11, Ubuntu, and CentOS
Network requirements
Ensure the following:
Set allowlisting of VMs so each VM can send traffic. Add the source using TimescaleDB, for example, the Kubernetes cluster service range to your allowlist.
Reserve internal and external static addresses for each VM.
Add port 5432 to the NAT firewall settings allowlist on the application cluster so it can connect to the TimescaleDB instance. TimescaleDB uses 5432 as the default communication port. This enables communication between Harness services running in a Self-Managed Enterprise Edition cluster and a self-managed TimescaleDB cluster.
Architecture

TimescaleDB replication architecture uses the native replication capabilities of PostgreSQL to ensure high availability and fault tolerance. It employs a controller-worker configuration, where the controller node handles read and write operations, while the worker nodes act as standby databases for data replication.
Write-ahead logs (WAL) are generated on the controller node and streamed to the standby nodes, allowing them to apply the changes and maintain data consistency. TimescaleDB extends the replication protocol with optimizations specific to time-series data, ensuring accurate replication of time-series operations and metadata.
In the event of controller node failure, a standby node can be promoted as the new controller, ensuring uninterrupted data access and minimal downtime. PostgreSQL does not provide support for automatic failover.
For more information, go to Streaming replication and Write-ahead logging in the PostgreSQL documentation.
High availability
To create a highly-available setup, there will be a DNS record that always points to the primary node of your TimescaleDB replication setup. You can use service discovery with a third-party tool (etcd/Consul/Zookeeper) to track your current primary node's IP address and health status.
You can update the DNS record dynamically using a script or use the service discovery tool's built-in functionality.

Set up TimescaleDB VMs on Debian-based systems
If you installed PostgreSQL through a method other than the apt package manager maintained by Debian or Ubuntu archive, you may receive errors when following these instructions. Harness recommends that you uninstall existing PostgreSQL installations before you continue.
Example passwords used in this tutorial are for instructional purposes only. Replace the examples with your own secure passwords. Harness recommends following your organization's standards for password security, including the use of strong passwords. Strong passwords are:
At least 12 characters long. Longer passwords are more secure.
Any combination of uppercase letters, lowercase letters, numbers, and symbols.
Not a word in the dictionary of any language or the name of a person, place, character, or organization.
Unique for each account.
To set up a TimescaleDB VM, do the following:
Connect to the VM and make sure you are running as root to prevent permission issues.
Add the PostgreSQL third-party repository to get the latest PostgreSQL packages.
Run the PostgreSQL repository setup script.
Add the TimescaleDB third party repository.
Debian:
Ubuntu 21.10 and later:
Install the TimescaleDB GPG key.
Update your local repository list.
Install TimescaleDB.
The output should look similar to the following:
Run TimescaleDB tune.
Set up the TimescaleDB extension on Debian-based systems
To set up TimescaleDB extension on Debian-based systems, do the following:
Restart the service after you enable TimescaleDB using
timescaledb-tune.Open the
psqlcommand-line utility as the postgres superuser on your local system at the command prompt.Run the following as postgres user (default user for postgres).
Run the following.
Upon successful connection, you'll see a message similar to the one below, followed by the psql prompt:
Set the password for the postgres user.
Exit PostgreSQL.
Use the
psqlclient to connect to PostgreSQL.Create an empty database at the
psqlprompt. In this example, our database istsdb.Connect to the database you created.
Add the TimescaleDB extension.
Verify that the TimescaleDB extension is installed using the
\dxcommand at thepsqlprompt. The output should be similar to the following.Run the following to connect directly to your database.
Repeat the steps for all VMs.
Configure replication
When you configure your replication, you will make some updates to controllers and replicas and other updates to only controllers or only replicas.
To configure replication, do the following:
Make sure you are logged in to the VM with superUser access on postgres user.
Run the following on one of your replicas.
Copy the certificates to the other replicas in the same directory
/var/lib/postgresql/.ssh/.Run the following on your controller.
Make the following change to the
pg_hba.conffile in/etc/postgresql/13/main/pg_hba.conffor your controller and replicas. This allows PostgreSQL to accept traffic from other networks and adds them to the allowlist.This example allows everything to the TimescaleDB instance. Harness recommends that you configure your firewall rules to allow only certain IPs to use port 5432.
(Optional) Make the following changes to set your allowlist at the database-level.
Change your directory to edit the
postgresql.confconfiguration file.Set
max_wal_sendersto the number of replicas. Setmax_replication_slotsto the number of replicas plus two. Edit or add the following settings.In your controller only, make sure you are running as Postgres.
Create an archive directory in
/var/lib/postgresql/13/main.
Add the following line to the bottom of your
pg_hba.conffile.Create a new user,
reptest, and log in as Postgres.Create the first replication slot at the psql slot. You can use any name. This example uses
replica_1_slot.
Repeat this step for each replica.
Restart PostgreSQL on your controller and your replicas (run as root).
Initiate replication
After you've completed the above steps, you can initiate your replication. Follow the steps below for your replicas only.
To initiate replication, do the following:
Stop the PostgreSQL service.
Copy the existing data and create a backup.
Restore from the base backup, using the IP address of the primary database and the replication username.
The backup utility prompts you for the
reptestpassword.Create a
standby.signalfile in your data directory.When PostgreSQL finds a
standby.signalfile in its data directory, it starts in recovery mode and streams the WAL through the replication protocol.Restart PostgreSQL in your replicas.
Run the following to check the logs and verify that the replica works.
The output should be similar to the following.
Add entries to your primary instance to verify your replica is synchronized with the primary database and prepared to stream.
Configure your Harness environment and Helm charts
Follow the steps below to set up a Harness Self-Managed Enterprise Edition cluster with an external self-managed TimescaleDB.
Run the following command to ensure your new database has the TimescaleDB extension.
Create two databases,
harnessandharnesstiin the TimescaleDB instance.Create a new secret for your username and password in the same namespace where Harness is installed.
Update your
override-prod.yamlfile with the following fields.
Enable SSL
You have the option to configure SSL on TimescaleDB.
To enable SSL on TimescaleDB, do the following:
Run the following.
Set the following fields in your
override.yamlfile.
Failover functionality
PostgreSQL provides some failover functionality, where the replica is promoted to primary in the event of a failure. This is available using the pg_ctl command or the trigger_file; however, PostgreSQL does not provide support for automatic failover.
Promote standby/secondary to primary
When a primary instance shuts down or is unavailable, the TimescaleDB remains available, but only in read-only mode. You must promote the standby/secondary to primary.
To promote the standby/secondary to primary, do the following:
Run the
pg_ctlpromotecommand.Change the host in your Harness instance, and upgrade your Helm charts.
Recover the former primary
You can recover the former primary VM after you promote the standby/secondary.
Replica promotion affects primary and secondary use in the following way:
Former primary ↔︎ new secondary
New primary ↔︎ former secondary ↔︎ former standby
When you convert the standby instance to primary, operations could occur in the new primary, and the former primary may go out of sync. To have the former primary become the new secondary and the former secondary remain as the new primary, you must add host replication.
To recover the former primary and add host replication, do the following.
Add the host replication in the
pg_hba.conffile in the new primary.Run the following as root.
Copy data to recover the former primary.
The former primary instance is now a new secondary instance.
Enable the pg_cron extension
To utilize scheduled tasks within your PostgreSQL database, you must enable the pg_cron extension on your database instance.
pg_cron functions as a cron-based job scheduler that operates internally within the database as an extension. It adheres to the familiar syntax of regular cron while empowering you to schedule PostgreSQL commands directly from within your database environment.
This approach offers more efficiency compared to relying solely on TimescaleDB. With the capabilities of pg_cron, the system efficiently schedules and executes aggregation tasks essential for generating metric data.
Install pg_cron on your Postgres database
For installations on Red Hat, CentOS, Fedora, or Amazon Linux running PostgreSQL 16 using the PostgreSQL Global Development Group (PGDG):
For installations on Debian or Ubuntu with PostgreSQL 16 using apt.postgresql.org:
Alternatively, you can opt to build pg_cron from its source:
Ensure that pg_config is within your path, for instance:
To ensure that the pg_cron background worker starts with PostgreSQL, add pg_cron to shared_preload_libraries within the postgresql.conf file:
By default, the pg_cron background worker assumes that its metadata tables exist within the Postgres database. However, you can customize this behavior by setting the cron.database_name configuration parameter in the postgresql.conf file:
Previously restricted to GMT, pg_cron now enables you to adapt timezones by setting cron.timezone in the postgresql.conf file. For example:
After restarting PostgreSQL, execute CREATE EXTENSION pg_cron; as a superuser to create the necessary pg_cron functions and metadata tables:
Upgrade TimescaleDB
You can upgrade your self-managed TimescaleDB installation in-place. A major upgrade is when you upgrade from one major version of TimescaleDB to the next major version. For example, when you upgrade from TimescaleDB 13 to TimescaleDB 14.
A minor upgrade is when you upgrade within your current major version of TimescaleDB. For example, when you upgrade from TimescaleDB 13.5, to TimescaleDB 13.6.
For more information, go to About upgrades in the TimescaleDB documentation.
Uninstall TimescaleDB
To uninstall TimescaleDB, do the following:
Last updated
Was this helpful?