TimescaleDB 时序数据库 之四 timescaledb-parallel-copy

os: centos 7.4
db: postgresql 11.6 + timescaledb 1.5.1

timescaledb-parallel-copy 是一个命令行程序,用于并行化 PostgreSQL 的内置 COPY 功能,以将数据批量插入到 TimescaleDB 中。当开始使用 TimescaleDB 时,我们建议将此程序作为获得更好的大容量插入性能的好方法。

该工具的目的是通过 COPYs 同时运行多个文件来加快大型数据的迁移。除了并行化工作负载之外,该工具还提供了一些标记来改善复制体验。

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 
# 
# su - postgres
Last login: Mon Dec 16 20:13:53 CST 2019 on pts/0
-bash-4.2$ psql
psql (11.6)
Type "help" for help.

postgres=# select version();
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 11.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)

postgres=#

下载安装

# yum install golang
# su - postgres
$ go get github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy
$ cd ./go/bin/
$ ls -l 
total 3000
-rwxrwxr-x 1 postgres postgres 3070633 Apr  9 14:35 timescaledb-parallel-copy

建议可以好好看看 ~/go/src 下面的代码.

使用

$ cd ~/go/bin
$ timescaledb-parallel-copy --help

foo.csv 生产一个 sample 表格式的csv文件。

single-threaded

$ timescaledb-parallel-copy --db-name test --table sample --file foo.csv

2 workers

$ timescaledb-parallel-copy --db-name test --table sample --file foo.csv --workers 2

2 workers, report progress every 30s

$ timescaledb-parallel-copy --db-name test --table sample --file foo.csv --workers 2 --reporting-period 30s

Treat literal string ‘NULL’ as NULLs:

$ timescaledb-parallel-copy --db-name test --table sample --file foo.csv --copy-options "NULL 'NULL' CSV"

参考:
https://github.com/timescale/timescaledb-parallel-copy
https://docs.timescale.com/latest/using-timescaledb/tooling

发布了710 篇原创文章 · 获赞 70 · 访问量 49万+

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/103585808