8
备份和恢复 timescaledb 的超级表 (hypertables)
source link: https://beginor.github.io/2020/06/22/backup-and-restore-hypertables-of-timescaledb.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
备份和恢复 timescaledb 的超级表 (hypertables)
下面是使用 PostgreSQL 内置的工具 pg_dump
和 psql
对超级表 conditions
进行备份和恢复的步骤。
备份超级表架构:
pg_dump -s -d old_db --table conditions -N _timescaledb_internal | \
grep -v _timescaledb_internal > schema.sql
将备份超级表的数据备份到 CSV 文件:
psql -d old_db \
-c "\COPY (SELECT * FROM conditions) TO data.csv DELIMITER ',' CSV"
恢复表的架构:
psql -d new_db < schema.sql
重新构建超级表:
psql -d new_db -c "SELECT create_hypertable('conditions', 'time')"
提示: 传递给
create_hypertable
的参数不必和旧数据库保持一致, 所以这也是重新组织超级表(比如:修改分区键、 分区数量、 等)的好方法。
恢复数据:
psql -d new_db -c "\COPY conditions FROM data.csv CSV"
提示: PostgreSQL 内置的
COPY
命令是单线程的, 如果想要快速导入大量的数据, 建议使用 timescaledb 提供的并行导入工具 parallel importer 。
其它备份方法可以参考 Timescaledb 的官方文档中的备份与恢复。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK