记一次 TimescaleDB 的数据备份与恢复

服务端开发 · 2022-04-26

TimescaleDB 相关

  • 启动一次服务器,确保已经创建了 senssion 表 和 event
  • 连接数据库

    psql postgres://postgres:xxx@localhost:5432/xxx

TimescaleDB 数据备份与恢复

  • 导出CSV

    set client_encoding=UTF8;
    \COPY (SELECT * FROM senssion) TO 'timescale-senssion.csv' DELIMITER ',' CSV HEADER ENCODING 'UTF8';
    \COPY (SELECT * FROM event) TO 'timescale-event.csv' DELIMITER ',' CSV HEADER ENCODING 'UTF8';
  • 从CSV导入数据

    set client_encoding=UTF8;
    \COPY senssion FROM 'timescale-senssion.csv' DELIMITER ',' CSV HEADER ENCODING 'UTF8';
    \COPY event FROM 'timescale-event.csv' DELIMITER ',' CSV HEADER ENCODING 'UTF8';
Theme Jasmine by Kent Liao