Updating TimescaleDB to 2.0
Use these instructions to update TimescaleDB 1.x to TimescaleDB 2.0
WARNING:These instructions are only for upgrading TimescaleDB 1.x to TimescaleDB 2.0 If you need to upgrade your existing TimescaleDB 1.x to a newer version in the 1.x release line (eg. 1.7.2 to 1.7.4), please see Update TimescaleDB 1.x.
TimescaleDB Release Compatibility
TimescaleDB currently supports the following PostgreSQL releases. If you are not currently running a compatible release, please upgrade before updating TimescaleDB.
TimescaleDB Release | Supported PostgreSQL Release |
---|---|
1.7 | 9.6, 10, 11, 12 |
2.0 | 11, 12 |
2.1 | 11, 12, 13 |
TIP:If you need to upgrade PostgreSQL first, please see our documentation.
Notice of breaking changes from TimescaleDB 1.3+
TimescaleDB 2.0 supports in-place updates just like previous releases. During the update, scripts will automatically configure updated features to work as expected with TimescaleDB 2.0.
Because this is our first major version release in two years, however, we’re providing additional guidance to help you ensure the update completes successfully and everything is configured as expected (and optimized for your workload). In particular, settings related to Continuous Aggregates, compression, and data retention have been modified to provide greater configuration transparency and flexibility, therefore we highly recommend verifying that these settings were migrated correctly.
Before completing the upgrade, we encourage you to read Changes in TimescaleDB 2.0 for a more detailed look at the major changes in TimescaleDB 2.0 and how they impact the way your applications and scripts interact with the API.
Prerequisites
PostgreSQL Compatibility
TimescaleDB 2.0 is not compatible with PostgreSQL 9.6 or 10. If your current PostgreSQL installation is not at least version 11, please upgrade PostgreSQL first. Depending on your current PostgreSQL version and installed TimescaleDB release, you may have to perform multiple upgrades because of compatibility restrictions.
For example, if you are currently running PostgreSQL 10 and TimescaleDB 1.5, the recommended upgrade path to PostgreSQL 12 and TimescaleDB 2.0 would be:
- Update TimescaleDB 1.5 to TimescaleDB 1.7 on PostgreSQL 10
- Upgrade PostgreSQL 10 to PostgreSQL 12 with TimescaleDB 1.7 installed
- Update TimescaleDB 1.7 to TimescaleDB 2.0 on PostgreSQL with the instructions below
TIP:Whenever possible, prefer the most recent supported version, PostgreSQL 12. Please see our Upgrading PostgreSQL guide for help.
Fix Continuous Aggregate Errors Before Upgrading
Before starting the upgrade to TimescaleDB 2.0, we highly recommend checking the database log for errors related to failed retention policies that were occurring in TimescaleDB 1.x and then either remove them or update them to be compatible with existing continuous aggregates. Any remaining retention policies that are still incompatible with the ignore_invalidation_older_than
setting will automatically be disabled during the upgrade and a notice provided.
TIP:Read more about changes to continuous aggregates and data retension policies here.
Update TimescaleDB
Step 1: Verify TimescaleDB 1.x Policy Settings (Optional)
As discussed in the Changes to TimescaleDB 2.0 document, the APIs and setting names that configure various policies are changing. The update process below will automatically configure new policies using your current configurations in TimescaleDB 1.x. If you would like to verify the policy settings after the update is complete, we suggest querying the informational views below and saving the output so that you can refer to it once the update is complete.
Execute the following SQL to save current settings for Continuous Aggregates and other policies to CSV using psql
. If you use an IDE like pgAdmin or DBeaver, save the output to CSV or another appropriate format to inspect later.
Policy Stats
\COPY timescaledb_information.policy_stats TO ‘policy_stats.csv’ csv header
Continuous Aggregate Stats
\COPY timescaledb_information.continuous_aggregate_stats TO ‘continuous_aggregate_stats.csv’ csv header
Drop Chunk Policies
\COPY timescaledb_information.drop_chunks_policies TO ‘drop_chunk_policies.csv’ csv header
Reorder Policy Stats
\COPY timescaledb_information.reorder_policies TO ‘reorder_policies.csv’ csv header
Step 2: Install and Update TimescaleDB Extension
Software upgrades use PostgreSQL’s ALTER EXTENSION
support to update to the latest version. TimescaleDB supports having different extension versions on different databases within the same PostgreSQL instance. This allows you to update extensions independently on different databases. The upgrade process involves three-steps:
- We recommend that you perform a backup of your database via
pg_dump
. - Install the latest version of the TimescaleDB extension.
- Execute the following
psql
command inside any database that you want to update:
ALTER EXTENSION timescaledb UPDATE;
WARNING:When executing
ALTER EXTENSION
, you should connect usingpsql
with the-X
flag to prevent any.psqlrc
commands from accidentally triggering the load of a previous TimescaleDB version on session startup. It must also be the first command you execute in the session.
This will upgrade TimescaleDB to the latest installed version, even if you are several versions behind.
After executing the command, the psql \dx
command should show the latest version:
\dx timescaledb
Name | Version | Schema | Description
-------------+---------+------------+---------------------------------------------------------------------
timescaledb | 2.1.1 | public | Enables scalable inserts and complex queries for time-series data
(1 row)
Step 3: Verify Updated Policy Settings and Jobs
All settings and information previously accessed through separate stats
informational views have now been centralized to a common jobs
view for all types of policies. If you wish to verify that the settings were moved correctly, query the timescaledb_information.jobs
view to verify that each policy was correctly moved and enabled based on your TimescaleDB 1.x setup.
In the example below, we query for all continuous aggregate policy jobs
. Compare the names and settings to the values of the data exported from timescaledb_information.continuous_aggregates
:
SELECT * FROM timescaledb_information.jobs
WHERE application_name LIKE 'Refresh Continuous%';
-[ RECORD 1 ]-----+--------------------------------------------------
job_id | 1001
application_name | Refresh Continuous Aggregate Policy [1001]
schedule_interval | 01:00:00
max_runtime | 00:00:00
max_retries | -1
retry_period | 01:00:00
proc_schema | _timescaledb_internal
proc_name | policy_refresh_continuous_aggregate
owner | postgres
scheduled | t
config | {"start_offset": "20 days", "end_offset": "10
days", "mat_hypertable_id": 2}
next_start | 2020-10-02 12:38:07.014042-04
hypertable_schema | _timescaledb_internal
hypertable_name | _materialized_hypertable_2
Verify the information for each policy type that was exported from TimescaleDB 1.x using the specific listing of jobs
in this view. For continuous aggregates, take special note of the config
information to verify that all settings were converted correctly given the notes in the Updating existing continuous aggregates section of our migration document.
Likewise, you can now verify that all jobs scheduled and running as expected with the new timescaledb_information.job_stats
view. Given the continuous aggregate job
above, querying the new job_stats
view might return information similar to the following.
SELECT * FROM timescaledb_information.job_stats
WHERE job_id = 1001;
-[ RECORD 1 ]----------+------------------------------
hypertable_schema | _timescaledb_internal
hypertable_name | _materialized_hypertable_2
job_id | 1001
last_run_started_at | 2020-10-02 09:38:06.871953-04
last_successful_finish | 2020-10-02 09:38:06.932675-04
last_run_status | Success
job_status | Scheduled
last_run_duration | 00:00:00.060722
next_scheduled_run | 2020-10-02 10:38:06.932675-04
total_runs | 1
total_successes | 1
total_failures | 0