Ad Widget

Collapse

How to convert timescale hypertables into regular postgresql tables?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ichano186
    Junior Member
    • May 2021
    • 5

    #1

    How to convert timescale hypertables into regular postgresql tables?

    OS: Centos-7
    zabbix-server: zabbix-server-pgsql-5.0.11
    Database: postgresql12 (timescale version: TimescaleDB 2.0)

    already deployed few zabbix instances with above specification for couple of months and has regular backups.
    Recently met with crashes cause by segfault of the timescale extension
    So the target now is to drop the usage of timescale and just use regular postgresql without losing the data / historical /trends tables

    at the installation procedures, there's a step to apply these command to postgresql
    Code:
    ╰─ zcat /usr/share/doc/zabbix-server-pgsql-5.0.11/timescaledb.sql.gz
    SELECT create_hypertable('history', 'clock', chunk_time_interval => 86400, migrate_data => true);
    SELECT create_hypertable('history_uint', 'clock', chunk_time_interval => 86400, migrate_data => true);
    SELECT create_hypertable('history_log', 'clock', chunk_time_interval => 86400, migrate_data => true);
    SELECT create_hypertable('history_text', 'clock', chunk_time_interval => 86400, migrate_data => true);
    SELECT create_hypertable('history_str', 'clock', chunk_time_interval => 86400, migrate_data => true);
    SELECT create_hypertable('trends', 'clock', chunk_time_interval => 2592000, migrate_data => true);
    SELECT create_hypertable('trends_uint', 'clock', chunk_time_interval => 2592000, migrate_data => true);
    UPDATE config SET db_extension='timescaledb',hk_history_global=1,hk_ trends_global=1;
    UPDATE config SET compression_status=1,compress_older='7d';
    * just dropping the extension will result the lost of those hypertables
    * simple pg_dump and pg_restore won't achive the target

    any specific or guide to convert those hypertables into regular tables inside zabbix database then drop the timescaleDB extension?
    thx in advance
  • ichano186
    Junior Member
    • May 2021
    • 5

    #2
    after following hint of pg_dump (using COPY TO and COPY FROM) of each hypertable

    pg_dump: NOTICE: hypertable data are in the chunks, no data will be copied
    DETAIL: Data for hypertables are stored in the chunks of a hypertable so COPY TO of a hypertable will not copy any data.
    HINT: Use "COPY (SELECT * FROM <hypertable>) TO ..." to copy all data in hypertable, or copy each chunk individually.

    backup current database
    connect to current database, copy current each hypertable to a system file
    stop zabbix-server
    connect to current databass, drop the extension and copy data from previous system files to regular postgresql-12 tables
    edit postgresql.conf, remove timescaledb stuff
    restart postgresql and zabbix-server

    this seems working

    Comment

    Working...