Postgresql psql启动多个并发.sql脚本并限制进程
背景: 操作系统Win10 postgresql 9.6 postgis 2.5 故事: 我在win文件夹中有200个带有postgres(st_union函数)查询的.slq脚本。 我可以运行一个“for%%f in(*.sql)do(start cmd/c“psql-U postgres-f”%%f“abn2030”)。在这些文件上并行运行bat,我的8个内核有一些素材。 除了200个脚本太多。我正在寻找一种方法来限制运行的'cmd'/'psql'实例。我想检查cmd(或psql)的实例是否正在运行,并启动下一个(排队等待)。只有当cmd/psql的实例数小于15时,才使用sql脚本。(如果这有道理,也许还有其他选择)。 我尝试了powershell和python(在较小的范围内),但我不知道应该使用哪种(如果有的话) powershell: 直接运行。脚本执行时没有问题Postgresql psql启动多个并发.sql脚本并限制进程,postgresql,powershell,psql,Postgresql,Powershell,Psql,背景: 操作系统Win10 postgresql 9.6 postgis 2.5 故事: 我在win文件夹中有200个带有postgres(st_union函数)查询的.slq脚本。 我可以运行一个“for%%f in(*.sql)do(start cmd/c“psql-U postgres-f”%%f“abn2030”)。在这些文件上并行运行bat,我的8个内核有一些素材。 除了200个脚本太多。我正在寻找一种方法来限制运行的'cmd'/'psql'实例。我想检查cmd(或psql)的实例是否
cmd /c ""C:\PostgreSQL\9.6\bin\psql.exe" -U postgres -d db -f "D:\Dropbox\scripts_sql\execute_htunion\pwshl\queries1.SQL""
剧本:(大部分是从另一篇文章中偷来的)
输出:psql:FATAL:role“postgres-fd:\Dropbox\scripts\u sql\execute\u htunion\pwshl\query”不存在
如何在powershell(或其他语言)中发送psql命令中的start.sql
编辑:在.bat中解决,使用: “C:\Program Files\Git\bin\sh.exe”-login-i-C“find.-iname'*.sql'-print0 | xargs--null--max procs=14-i{}psql.exe-U postgres-d db-f{}”应该具有和,这是Linux源命令,串联起来非常适合执行此任务:
find . -name '*.sql' -print0 \
| xargs --null --max-procs=16 -I{} psql.exe -U postgres -d db -f {}
find . -name '*.sql' -print0 \
| xargs --null --max-procs=16 -I{} psql.exe -U postgres -d db -f {}