简体   繁体   English

在一个 psql 复制调用中将多个 csv 文件复制到 postgresql 表

[英]copy multiple csv files to postgresql tables in one psql copy call

loading a csv file to my postgresql db table using psql utility copy as below;使用 psql 实用程序副本将 csv 文件加载到我的 postgresql 数据库表,如下所示;

psql -h $host -p $port -d $db -U $username -c "\copy \"$schema\".\"$table\" from '$datafile' with delimiter as ',' csv"

this works great.这很好用。 However, I need to load many files at the same time.但是,我需要同时加载很多文件。 I can run above psql copy command in parallel fashion.我可以并行运行上面的 psql 复制命令。 Since each call starts a new process (my app is do.net core 2.1 and is running on openshift), increasing the number of file also increases the memory and CPU.由于每次调用都会启动一个新进程(我的应用程序是 do.net core 2.1 并且在 openshift 上运行),增加文件数量也会增加 memory 和 CPU。 Process time also increases.处理时间也会增加。 What I actually need is to call psql copy with multiple csv file.我真正需要的是用多个 csv 文件调用 psql copy。 I need to create the parallelization on the db, not on the openshift pod.我需要在数据库上创建并行化,而不是在 openshift pod 上。
How can I do this?我怎样才能做到这一点? If this is not possible, what is the most optimum way to load multiple files at a time?如果这不可能,一次加载多个文件的最佳方法是什么?

Thankx谢谢

cat *.csv | psql -h $host -p $port -d $db -U $username -c "\copy \"$schema\".\"$table\" from STDIN with delimiter as ',' csv"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM