For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 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.

TimescaleDB DNS

Set up TimescaleDB VMs on Debian-based systems

To set up a TimescaleDB VM, do the following:

  1. Connect to the VM and make sure you are running as root to prevent permission issues.

  2. Add the PostgreSQL third-party repository to get the latest PostgreSQL packages.

  3. Run the PostgreSQL repository setup script.

  4. Add the TimescaleDB third party repository.

    Debian:

    Ubuntu 21.10 and later:

  5. Install the TimescaleDB GPG key.

  6. Update your local repository list.

  7. Install TimescaleDB.

    The output should look similar to the following:

  8. Run TimescaleDB tune.

Set up the TimescaleDB extension on Debian-based systems

To set up TimescaleDB extension on Debian-based systems, do the following:

  1. Restart the service after you enable TimescaleDB using timescaledb-tune.

  2. Open the psql command-line utility as the postgres superuser on your local system at the command prompt.

  3. Run the following as postgres user (default user for postgres).

  4. Run the following.

    Upon successful connection, you'll see a message similar to the one below, followed by the psql prompt:

  5. Set the password for the postgres user.

  6. Exit PostgreSQL.

  7. Use the psql client to connect to PostgreSQL.

  8. Create an empty database at the psql prompt. In this example, our database is tsdb.

  9. Connect to the database you created.

  10. Add the TimescaleDB extension.

  1. Verify that the TimescaleDB extension is installed using the \dx command at the psql prompt. The output should be similar to the following.

  2. Run the following to connect directly to your database.

  1. 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.

IMPORTANT

When you create new directories or files, always use the postgres user. Run the following command before you create a new directory or file.

To configure replication, do the following:

  1. Make sure you are logged in to the VM with superUser access on postgres user.

  2. Run the following on one of your replicas.

  3. Copy the certificates to the other replicas in the same directory /var/lib/postgresql/.ssh/.

  4. Run the following on your controller.

  5. Make the following change to the pg_hba.conf file in /etc/postgresql/13/main/pg_hba.conf for 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.

  6. (Optional) Make the following changes to set your allowlist at the database-level.

  7. Change your directory to edit the postgresql.conf configuration file.

  8. Set max_wal_senders to the number of replicas. Set max_replication_slots to the number of replicas plus two. Edit or add the following settings.

  9. In your controller only, make sure you are running as Postgres.

  10. Create an archive directory in /var/lib/postgresql/13/main.

  1. Add the following line to the bottom of your pg_hba.conf file.

  2. Create a new user, reptest, and log in as Postgres.

  3. 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.

  1. 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:

  1. Stop the PostgreSQL service.

  2. Copy the existing data and create a backup.

  3. Restore from the base backup, using the IP address of the primary database and the replication username.

    The backup utility prompts you for the reptest password.

  4. Create a standby.signal file in your data directory.

    When PostgreSQL finds a standby.signal file in its data directory, it starts in recovery mode and streams the WAL through the replication protocol.

  5. Restart PostgreSQL in your replicas.

  6. Run the following to check the logs and verify that the replica works.

    The output should be similar to the following.

  7. 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.

  1. Run the following command to ensure your new database has the TimescaleDB extension.

  2. Create two databases, harness and harnessti in the TimescaleDB instance.

  3. Create a new secret for your username and password in the same namespace where Harness is installed.

  4. Update your override-prod.yaml file with the following fields.

Enable SSL

You have the option to configure SSL on TimescaleDB.

To enable SSL on TimescaleDB, do the following:

  1. Run the following.

  2. Set the following fields in your override.yaml file.

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.

NOTE

Before you promote a replica, make sure the primary is completely down.

To promote the standby/secondary to primary, do the following:

  1. Run the pg_ctl promote command.

  2. 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.

  1. Add the host replication in the pg_hba.conf file in the new primary.

  2. Run the following as root.

  3. 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?