Ad Widget

Collapse

Alternative script for migrating to TimescaleDB with no downtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pvnick
    Junior Member
    • Jan 2023
    • 1

    #1

    Alternative script for migrating to TimescaleDB with no downtime

    Hi everyone, I wrote some SQL to migrate existing history and trend tables to TimescaleDB with no downtime. It was helpful for me since my tables are combined over a terabyte, and the downtime needed to convert those to TimescaleDB with the provided script was not acceptable.

    Here's the method: Create two new tables - a temp one which uses a trigger to duplicate new data coming in, and then a new table that we bulk insert existing data into in compressed chunks. Once the bulk inserts are finished, we append the incoming data that was received onto the new table and atomically swap the final result with the existing table.

    Since it was helpful to me, I decided to upload the script and share it in case anybody else has a similar usecase: https://gist.github.com/pvnick/a8f9a...7662b6bb273903. It only includes the history_uint table, but extending to other tables is trivial.

    Hope it is helpful to someone!
  • nyatsa2
    Junior Member
    • Jul 2023
    • 1

    #2
    As i know create a new table in TimescaleDB with the desired structure. This table will be used to perform bulk inserts of the existing data in compressed chunks or set up a temporary table that mirrors the structure of the existing table. Use a trigger on the original table to duplicate new incoming data to this temporary table. Transfer the existing data from the original table to the new TimescaleDB table using bulk insert operations. This approach is typically faster than row-by-row inserts.

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #3
      So who inspired who? https://www.zabbix.com/events/zabbix...nda#day2_17:15

      Very clear and detailed presentation it was...

      Comment

      Working...